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

Annotation of /trunk/doc/examples/inversion/gravmag_netcdf.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4433 - (hide annotations)
Fri May 31 12:09:58 2013 UTC (5 years, 11 months ago) by gross
File MIME type: text/x-python
File size: 3525 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 caltinay 4175
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 caltinay 4267 from esys.escript import saveDataCSV
29     from esys.weipa import *
30 caltinay 4175
31     # Set parameters
32 caltinay 4267 MAGNETIC_DATASET = 'data/MagneticSmall.nc'
33 caltinay 4287 MAG_UNITS = U.Nano * U.Tesla
34 caltinay 4267 GRAVITY_DATASET = 'data/GravitySmall.nc'
35     GRAV_UNITS = 1e-6 * U.m/(U.sec**2)
36 gross 4433 # 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 caltinay 4175 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 = 10.
44     mu_magnetic = 0.1
45 gross 4374 COORDINATES=CartesianReferenceSystem()
46     #COORDINATES=WGS84ReferenceSystem()
47 caltinay 4175
48 gross 4373
49 jfenwick 4310 def work():
50     # Setup and run the inversion
51 gross 4373 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 jfenwick 4310 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 caltinay 4175
62 jfenwick 4310 inv=JointGravityMagneticInversion()
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.,1.], mu_c=1.)
68 caltinay 4175
69 jfenwick 4310 density, susceptibility = inv.run()
70     print("density = %s"%density)
71     print("susceptibility = %s"%susceptibility)
72 caltinay 4175
73 jfenwick 4310 g, wg = db.getGravitySurveys()[0]
74     B, wB = db.getMagneticSurveys()[0]
75 caltinay 4391 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 caltinay 4175
80 jfenwick 4310 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 caltinay 4267
83 jfenwick 4310 saveDataCSV("result_gravmag.csv", density=density, susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
84     print("Results saved in result_gravmag.csv")
85 caltinay 4267
86 jfenwick 4310 print("All done. Have a nice day!")
87 caltinay 4267
88 jfenwick 4310 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