/[escript]/trunk/doc/examples/inversion/gravmag_wgs84_nodriver.py
ViewVC logotype

Contents of /trunk/doc/examples/inversion/gravmag_wgs84_nodriver.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4433 - (show annotations)
Fri May 31 12:09:58 2013 UTC (6 years, 3 months ago) by gross
File MIME type: text/x-python
File size: 4704 byte(s)
some clarifications on geodetic coordinates. 
order of background magnetic flux density component has been corrected: input is now B_east, B_north, B_vertical.


1 ##############################################################################
2 #
3 # Copyright (c) 2012-2013 by University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Open Software License version 3.0
8 # http://www.opensource.org/licenses/osl-3.0.php
9 #
10 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 # Development since 2012 by School of Earth Sciences
12 #
13 ##############################################################################
14
15 """
16 Advanced 3D gravity/magnetic joint inversion example without using any
17 inversion drivers
18 """
19
20 __copyright__="""Copyright (c) 2012-2013 by University of Queensland
21 http://www.uq.edu.au
22 Primary Business: Queensland, Australia"""
23 __license__="""Licensed under the Open Software License version 3.0
24 http://www.opensource.org/licenses/osl-3.0.php"""
25 __url__="https://launchpad.net/escript-finley"
26
27 # Import required modules
28 import numpy as np
29 from esys.downunder import *
30 from esys.escript import unitsSI as U
31 from esys.escript import *
32 from esys.weipa import *
33
34 # Set parameters
35 MAGNETIC_DATASET = 'data/MagneticSmall.nc'
36 MAG_UNITS = U.Nano * U.V * U.sec / (U.m**2)
37 GRAVITY_DATASET = 'data/GravitySmall.nc'
38 GRAV_UNITS = 1e-6 * U.m/(U.sec**2)
39 # background magnetic field components (B_East, B_North, B_Vertical)
40 B_b = [2201.*U.Nano*U.Tesla, 31232.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
41
42 thickness = 40. * U.km # below surface
43 l_air = 6. * U.km # above surface
44 n_cells_v = 25 # number of cells in vertical direction
45
46 # apply 20% padding
47 PAD_X = 0.2
48 PAD_Y = 0.2
49
50 MU_GRAVITY = 10.
51 MU_MAGNETIC = 0.1
52
53 COORDINATES=WGS84ReferenceSystem()
54
55
56
57 def work():
58 # read data:
59 source_g=NetCdfData(NetCdfData.GRAVITY, GRAVITY_DATASET, scale_factor=GRAV_UNITS, reference_system=COORDINATES)
60 source_m=NetCdfData(NetCdfData.MAGNETIC, MAGNETIC_DATASET, scale_factor=MAG_UNITS, reference_system=COORDINATES)
61
62 # create domain:
63 db=DomainBuilder(dim=3, reference_system=COORDINATES)
64 db.addSource(source_g)
65 db.addSource(source_m)
66 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
67 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
68 db.fixDensityBelow(depth=thickness)
69 db.fixSusceptibilityBelow(depth=thickness)
70
71 dom=db.getDomain()
72 DIM=dom.getDim()
73
74 # create mappings with standard parameters
75 rho_mapping=DensityMapping(dom)
76 k_mapping=SusceptibilityMapping(dom)
77
78 # create regularization with two level set functions:
79 reg_mask=Data(0.,(2,), Solution(dom))
80 reg_mask[0] = db.getSetDensityMask() # mask for locations where m[0]~rho is known
81 reg_mask[1] = db.getSetSusceptibilityMask() # mask for locations where m[0]~k is known
82 regularization=Regularization(dom, numLevelSets=2,
83 w1=np.ones((2,DIM)), # consider gradient terms
84 wc=[[0,1],[0,0]], # and cross-gradient term
85 coordinates=COORDINATES,
86 location_of_set_m=reg_mask)
87
88 # create forward model for gravity
89 # get data with deviation
90 g,sigma_g=db.getGravitySurveys()[0]
91 # turn the scalars into vectors (vertical direction)
92 d=kronecker(DIM)[DIM-1]
93 w=safeDiv(1., sigma_g)
94
95 gravity_model=GravityModel(dom, w*d, g*d, coordinates=COORDINATES)
96 gravity_model.rescaleWeights(rho_scale=rho_mapping.getTypicalDerivative())
97
98 # create forward model for magnetic
99 d=normalize(np.array(B_b)) # direction of measurement
100 B,sigma_B=db.getMagneticSurveys()[0]
101 w=safeDiv(1., sigma_B)
102
103 magnetic_model=MagneticModel(dom, w*d, B*d, B_b, coordinates=COORDINATES)
104 magnetic_model.rescaleWeights(k_scale=k_mapping.getTypicalDerivative())
105
106
107 # finally we can set up the cost function:
108 cf=InversionCostFunction(regularization,
109 ((rho_mapping,0), (k_mapping, 1)),
110 ((gravity_model,0), (magnetic_model,1)) )
111
112 cf.setTradeOffFactorsModels([MU_GRAVITY, MU_MAGNETIC])
113
114 # sun solver:
115 solver=MinimizerLBFGS()
116 solver.setCostFunction(cf)
117 solver.setTolerance(1e-4)
118 solver.setMaxIterations(50)
119 solver.run(Data(0.,(2,),Solution(dom)))
120 m=solver.getResult()
121 density, susceptibility = cf.getProperties(m)
122
123
124 # write everything to file:
125 saveSilo("result_gravmag.silo",
126 density=density, susceptability=susceptibility,
127 g_data=g, sigma_g=sigma_g, B_data=B, sigma_B=sigma_B)
128 saveVTK("result_gravmag.vtu",
129 density=density, susceptability=susceptibility,
130 g_data=g, sigma_g=sigma_g, B_data=B, sigma_B=sigma_B)
131
132 print("All done. Have a nice day!")
133
134 if 'NetCdfData' in dir():
135 work()
136 else:
137 print("This example requires scipy's netcdf support which does not appear to be installed.")
138

  ViewVC Help
Powered by ViewVC 1.1.26