/[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 6812 - (hide annotations)
Fri May 3 00:36:47 2019 UTC (4 months, 2 weeks ago) by aellery
File MIME type: text/x-python
File size: 4067 byte(s)
Another silo fix


1 caltinay 4175 ##############################################################################
2     #
3 jfenwick 6651 # Copyright (c) 2009-2018 by The University of Queensland
4 caltinay 4175 # http://www.uq.edu.au
5     #
6     # Primary Business: Queensland, Australia
7 jfenwick 6112 # Licensed under the Apache License, version 2.0
8     # http://www.apache.org/licenses/LICENSE-2.0
9 caltinay 4175 #
10     # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
12     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 caltinay 4175 #
14     ##############################################################################
15    
16     """3D gravity/magnetic joint inversion example using netCDF data"""
17 sshaw 5707 from __future__ import division, print_function
18 caltinay 4175
19 jfenwick 6651 __copyright__="""Copyright (c) 2009-2018 by The University of Queensland
20 caltinay 4175 http://www.uq.edu.au
21     Primary Business: Queensland, Australia"""
22 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
23     http://www.apache.org/licenses/LICENSE-2.0"""
24 caltinay 4175 __url__="https://launchpad.net/escript-finley"
25    
26     # Import required modules
27     from esys.downunder import *
28     from esys.escript import unitsSI as U
29 caltinay 6174 from esys.escript import saveDataCSV
30 caltinay 4267 from esys.weipa import *
31 gross 6763 import logging
32     logger=logging.getLogger('inv.MinimizerLBFGS')
33     logger.setLevel(logging.DEBUG)
34 caltinay 4175
35     # Set parameters
36 caltinay 4267 MAGNETIC_DATASET = 'data/MagneticSmall.nc'
37 caltinay 4287 MAG_UNITS = U.Nano * U.Tesla
38 caltinay 4267 GRAVITY_DATASET = 'data/GravitySmall.nc'
39     GRAV_UNITS = 1e-6 * U.m/(U.sec**2)
40 gross 4433 # background magnetic field components (B_East, B_North, B_Vertical)
41     B_b = [2201.*U.Nano*U.Tesla, 31232.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
42 caltinay 4175 PAD_X = 0.2
43     PAD_Y = 0.2
44     thickness = 40. * U.km
45     l_air = 6. * U.km
46     n_cells_v = 25
47 gross 6763 mu_gravity = 10./2
48     mu_magnetic = 0.1/2/2
49 gross 4374 COORDINATES=CartesianReferenceSystem()
50     #COORDINATES=WGS84ReferenceSystem()
51 caltinay 4175
52 gross 4373
53 jfenwick 4310 def work():
54     # Setup and run the inversion
55 gross 4373 grav_source=NetCdfData(NetCdfData.GRAVITY, GRAVITY_DATASET, scale_factor=GRAV_UNITS, reference_system=COORDINATES)
56     mag_source=NetCdfData(NetCdfData.MAGNETIC, MAGNETIC_DATASET, scale_factor=MAG_UNITS, reference_system=COORDINATES)
57     db=DomainBuilder(dim=3, reference_system=COORDINATES)
58 jfenwick 4310 db.addSource(grav_source)
59     db.addSource(mag_source)
60     db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
61     db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
62     db.setBackgroundMagneticFluxDensity(B_b)
63     db.fixDensityBelow(depth=thickness)
64     db.fixSusceptibilityBelow(depth=thickness)
65 caltinay 4175
66 jfenwick 4310 inv=JointGravityMagneticInversion()
67     inv.setSolverTolerance(1e-4)
68 aellery 6767 inv.setSolverMaxIterations(100)
69 jfenwick 4310 inv.setup(db)
70     inv.getCostFunction().setTradeOffFactorsModels([mu_gravity, mu_magnetic])
71     inv.getCostFunction().setTradeOffFactorsRegularization(mu = [1.,1.], mu_c=1.)
72 caltinay 4175
73 jfenwick 4310 density, susceptibility = inv.run()
74     print("density = %s"%density)
75     print("susceptibility = %s"%susceptibility)
76 caltinay 4175
77 jfenwick 4310 g, wg = db.getGravitySurveys()[0]
78     B, wB = db.getMagneticSurveys()[0]
79 aellery 6812 if saveSilo("result_gravmag.silo", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=wB):
80     print("Results saved in result_gravmag.silo")
81     else:
82 caltinay 4391 print("Failed to save result_gravmag.silo. Possibly no Silo support.")
83 caltinay 4175
84 jfenwick 4310 saveVTK("result_gravmag.vtu", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=wB)
85     print("Results saved in result_gravmag.vtu")
86 caltinay 4267
87 jfenwick 4310 saveDataCSV("result_gravmag.csv", density=density, susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
88     print("Results saved in result_gravmag.csv")
89 caltinay 4267
90 jfenwick 4310 print("All done. Have a nice day!")
91 caltinay 4267
92 sshaw 4895 try:
93     import pyproj
94 caltinay 6274 HAVE_PYPROJ = True
95 sshaw 4895 except ImportError:
96 caltinay 6274 HAVE_PYPROJ = False
97 sshaw 4895
98 sshaw 5288 try:
99 caltinay 6274 import esys.ripley
100     HAVE_RIPLEY = True
101 sshaw 5288 except ImportError:
102 caltinay 6274 HAVE_RIPLEY = False
103 sshaw 5288
104     if 'NetCdfData' not in dir():
105     print("This example requires scipy's netcdf support which does not appear to be installed.")
106     elif not HAVE_RIPLEY:
107     print("Ripley module not available")
108 caltinay 6274 elif not HAVE_PYPROJ:
109     print("This example requires pyproj to be installed.")
110 jfenwick 4310 else:
111 sshaw 5288 work()
112 jfenwick 4310

  ViewVC Help
Powered by ViewVC 1.1.26