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

  ViewVC Help
Powered by ViewVC 1.1.26