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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4433 - (show annotations)
Fri May 31 12:09:58 2013 UTC (5 years, 10 months ago) by gross
File MIME type: text/x-python
File size: 4808 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=CartesianReferenceSystem()
54
55 def work():
56 # read data:
57 source_g=NetCdfData(NetCdfData.GRAVITY, GRAVITY_DATASET, scale_factor=GRAV_UNITS, reference_system=COORDINATES)
58 source_m=NetCdfData(NetCdfData.MAGNETIC, MAGNETIC_DATASET, scale_factor=MAG_UNITS, reference_system=COORDINATES)
59
60 # create domain:
61 db=DomainBuilder(dim=3, reference_system=COORDINATES)
62 db.addSource(source_g)
63 db.addSource(source_m)
64 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
65 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
66 db.fixDensityBelow(depth=thickness)
67 db.fixSusceptibilityBelow(depth=thickness)
68
69 dom=db.getDomain()
70 DIM=dom.getDim()
71
72 # create mappings with standard parameters
73 rho_mapping=DensityMapping(dom)
74 k_mapping=SusceptibilityMapping(dom)
75
76 # create regularization with two level set functions:
77 reg_mask=Data(0.,(2,), Solution(dom))
78 reg_mask[0] = db.getSetDensityMask() # mask for locations where m[0]~rho is known
79 reg_mask[1] = db.getSetSusceptibilityMask() # mask for locations where m[0]~k is known
80 regularization=Regularization(dom, numLevelSets=2,
81 w1=np.ones((2,DIM)), # consider gradient terms
82 wc=[[0,1],[0,0]], # and cross-gradient term
83 coordinates=COORDINATES,
84 location_of_set_m=reg_mask)
85
86 # create forward model for gravity
87 # get data with deviation
88 g,sigma_g=db.getGravitySurveys()[0]
89 # turn the scalars into vectors (vertical direction)
90 d=kronecker(DIM)[DIM-1] # == (0 0 1)
91 w=safeDiv(1., sigma_g)
92
93 # multipling by d extracts only the z component (since we only measure in vertical)
94 gravity_model=GravityModel(dom, w*d, g*d, coordinates=COORDINATES)
95 gravity_model.rescaleWeights(rho_scale=rho_mapping.getTypicalDerivative())
96
97 # create forward model for magnetic
98 d=normalize(np.array(B_b)) # direction of measurement
99 B,sigma_B=db.getMagneticSurveys()[0]
100 w=safeDiv(1., sigma_B)
101
102 magnetic_model=MagneticModel(dom, w*d, B*d, B_b, coordinates=COORDINATES)
103 magnetic_model.rescaleWeights(k_scale=k_mapping.getTypicalDerivative())
104
105
106 # finally we can set up the cost function:
107 cf=InversionCostFunction(regularization,
108 ((rho_mapping,0), (k_mapping, 1)),
109 ((gravity_model,0), (magnetic_model,1)) )
110
111 cf.setTradeOffFactorsModels([MU_GRAVITY, MU_MAGNETIC])
112
113 # sun solver:
114 solver=MinimizerLBFGS()
115 solver.setCostFunction(cf)
116 solver.setTolerance(1e-4)
117 solver.setMaxIterations(50)
118 solver.run(Data(0.,(2,),Solution(dom)))
119 m=solver.getResult()
120 density, susceptibility = cf.getProperties(m)
121
122
123 # write everything to file:
124 saveSilo("result_gravmag.silo",
125 density=density, susceptability=susceptibility,
126 g_data=g, sigma_g=sigma_g, B_data=B, sigma_B=sigma_B)
127 saveVTK("result_gravmag.vtu",
128 density=density, susceptability=susceptibility,
129 g_data=g, sigma_g=sigma_g, B_data=B, sigma_B=sigma_B)
130
131 print("All done. Have a nice day!")
132
133 if 'NetCdfData' in dir():
134 work()
135 else:
136 print("This example requires scipy's netcdf support which does not appear to be installed.")
137

  ViewVC Help
Powered by ViewVC 1.1.26