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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5707 - (show annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 6 months ago) by sshaw
File MIME type: text/x-python
File size: 4073 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) 2009-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
16 """3D gravity/magnetic joint inversion example using netCDF data"""
17 from __future__ import division, print_function
18
19 __copyright__="""Copyright (c) 2009-2015 by The University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Open Software License version 3.0
23 http://www.opensource.org/licenses/osl-3.0.php"""
24 __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 from esys.escript import saveDataCSV, getEscriptParamInt
30 from esys.weipa import *
31
32 haveNetcdf=(getEscriptParamInt("NETCDF_BUILD",0)==1)
33
34 # Set parameters
35 MAGNETIC_DATASET = 'data/MagneticSmall.nc'
36 MAG_UNITS = U.Nano * U.Tesla
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 PAD_X = 0.2
42 PAD_Y = 0.2
43 thickness = 40. * U.km
44 l_air = 6. * U.km
45 n_cells_v = 25
46 mu_gravity = 10.
47 mu_magnetic = 0.1
48 COORDINATES=CartesianReferenceSystem()
49 #COORDINATES=WGS84ReferenceSystem()
50
51
52 def work():
53 # Setup and run the inversion
54 grav_source=NetCdfData(NetCdfData.GRAVITY, GRAVITY_DATASET, scale_factor=GRAV_UNITS, reference_system=COORDINATES)
55 mag_source=NetCdfData(NetCdfData.MAGNETIC, MAGNETIC_DATASET, scale_factor=MAG_UNITS, reference_system=COORDINATES)
56 db=DomainBuilder(dim=3, reference_system=COORDINATES)
57 db.addSource(grav_source)
58 db.addSource(mag_source)
59 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
60 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
61 db.setBackgroundMagneticFluxDensity(B_b)
62 db.fixDensityBelow(depth=thickness)
63 db.fixSusceptibilityBelow(depth=thickness)
64
65 inv=JointGravityMagneticInversion()
66 inv.setSolverTolerance(1e-4)
67 inv.setSolverMaxIterations(50)
68 inv.setup(db)
69 inv.getCostFunction().setTradeOffFactorsModels([mu_gravity, mu_magnetic])
70 inv.getCostFunction().setTradeOffFactorsRegularization(mu = [1.,1.], mu_c=1.)
71
72 density, susceptibility = inv.run()
73 print("density = %s"%density)
74 print("susceptibility = %s"%susceptibility)
75
76 g, wg = db.getGravitySurveys()[0]
77 B, wB = db.getMagneticSurveys()[0]
78 if saveSilo("result_gravmag.silo", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=wB):
79 print("Results saved in result_gravmag.silo")
80 else:
81 print("Failed to save result_gravmag.silo. Possibly no Silo support.")
82
83 saveVTK("result_gravmag.vtu", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=wB)
84 print("Results saved in result_gravmag.vtu")
85
86 saveDataCSV("result_gravmag.csv", density=density, susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
87 print("Results saved in result_gravmag.csv")
88
89 print("All done. Have a nice day!")
90
91 try:
92 import pyproj
93 except ImportError:
94 print("This example requires pyproj to be installed.")
95 import sys
96 sys.exit(0)
97
98 try:
99 import esys.ripley
100 HAVE_RIPLEY = True
101 except ImportError:
102 HAVE_RIPLEY = False
103
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 elif not haveNetcdf:
109 print("netCDF not available.")
110 else:
111 work()
112

  ViewVC Help
Powered by ViewVC 1.1.26