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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4535 - (show annotations)
Wed Nov 20 06:37:53 2013 UTC (5 years, 3 months ago) by gross
File MIME type: text/x-python
File size: 3516 byte(s)
strong correlation joint inversion fixed.
1
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2013 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 """3D gravity/magnetic joint inversion example using netCDF data"""
17
18 __copyright__="""Copyright (c) 2009-2013 by University of Queensland
19 http://www.uq.edu.au
20 Primary Business: Queensland, Australia"""
21 __license__="""Licensed under the Open Software License version 3.0
22 http://www.opensource.org/licenses/osl-3.0.php"""
23 __url__="https://launchpad.net/escript-finley"
24
25 # Import required modules
26 from esys.downunder import *
27 from esys.escript import unitsSI as U
28 from esys.escript import saveDataCSV
29 from esys.weipa import *
30
31 # Set parameters
32 MAGNETIC_DATASET = 'data/MagneticSmall.nc'
33 MAG_UNITS = U.Nano * U.Tesla
34 GRAVITY_DATASET = 'data/GravitySmall.nc'
35 GRAV_UNITS = 1e-6 * U.m/(U.sec**2)
36 # background magnetic field components (B_East, B_North, B_Vertical)
37 B_b = [2201.*U.Nano*U.Tesla, 31232.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
38 PAD_X = 0.2
39 PAD_Y = 0.2
40 thickness = 40. * U.km
41 l_air = 6. * U.km
42 n_cells_v = 25
43 mu_gravity = 1.
44 mu_magnetic = 0.1
45 COORDINATES=CartesianReferenceSystem()
46 #COORDINATES=WGS84ReferenceSystem()
47
48
49 def work():
50 # Setup and run the inversion
51 grav_source=NetCdfData(NetCdfData.GRAVITY, GRAVITY_DATASET, scale_factor=GRAV_UNITS, reference_system=COORDINATES)
52 mag_source=NetCdfData(NetCdfData.MAGNETIC, MAGNETIC_DATASET, scale_factor=MAG_UNITS, reference_system=COORDINATES)
53 db=DomainBuilder(dim=3, reference_system=COORDINATES)
54 db.addSource(grav_source)
55 db.addSource(mag_source)
56 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
57 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
58 db.setBackgroundMagneticFluxDensity(B_b)
59 db.fixDensityBelow(depth=thickness)
60 db.fixSusceptibilityBelow(depth=thickness)
61
62 inv=StrongJointGravityMagneticInversion()
63 inv.setSolverTolerance(1e-4)
64 inv.setSolverMaxIterations(50)
65 inv.setup(db)
66 inv.getCostFunction().setTradeOffFactorsModels([mu_gravity, mu_magnetic])
67 inv.getCostFunction().setTradeOffFactorsRegularization(mu = 1.)
68
69 density, susceptibility = inv.run()
70 print("density = %s"%density)
71 print("susceptibility = %s"%susceptibility)
72
73 g, wg = db.getGravitySurveys()[0]
74 B, wB = db.getMagneticSurveys()[0]
75 if saveSilo("result_gravmag.silo", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=wB):
76 print("Results saved in result_gravmag.silo")
77 else:
78 print("Failed to save result_gravmag.silo. Possibly no Silo support.")
79
80 saveVTK("result_gravmag.vtu", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=wB)
81 print("Results saved in result_gravmag.vtu")
82
83 saveDataCSV("result_gravmag.csv", density=density, susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
84 print("Results saved in result_gravmag.csv")
85
86 print("All done. Have a nice day!")
87
88 if 'NetCdfData' in dir():
89 work()
90 else:
91 print("This example requires scipy's netcdf support which does not appear to be installed.")
92

  ViewVC Help
Powered by ViewVC 1.1.26