/[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 4310 - (show annotations)
Tue Mar 12 03:23:26 2013 UTC (6 years, 7 months ago) by jfenwick
File MIME type: text/x-python
File size: 3266 byte(s)
examples don't FAIL if tool is not installed
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_North, B_East, B_Vertical)
37 B_b = [31232.*U.Nano*U.Tesla, 2201.*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 = 10.
44 mu_magnetic = 0.1
45
46 def work():
47 # Setup and run the inversion
48 grav_source=NetCdfData(NetCdfData.GRAVITY, GRAVITY_DATASET, scale_factor=GRAV_UNITS)
49 mag_source=NetCdfData(NetCdfData.MAGNETIC, MAGNETIC_DATASET, scale_factor=MAG_UNITS)
50 db=DomainBuilder(dim=3)
51 db.addSource(grav_source)
52 db.addSource(mag_source)
53 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
54 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
55 db.setBackgroundMagneticFluxDensity(B_b)
56 db.fixDensityBelow(depth=thickness)
57 db.fixSusceptibilityBelow(depth=thickness)
58
59 inv=JointGravityMagneticInversion()
60 inv.setSolverTolerance(1e-4)
61 inv.setSolverMaxIterations(50)
62 inv.setup(db)
63 inv.getCostFunction().setTradeOffFactorsModels([mu_gravity, mu_magnetic])
64 inv.getCostFunction().setTradeOffFactorsRegularization(mu = [1.,1.], mu_c=1.)
65
66 density, susceptibility = inv.run()
67 print("density = %s"%density)
68 print("susceptibility = %s"%susceptibility)
69
70 g, wg = db.getGravitySurveys()[0]
71 B, wB = db.getMagneticSurveys()[0]
72 saveSilo("result_gravmag.silo", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=wB)
73 print("Results saved in result_gravmag.silo")
74
75 saveVTK("result_gravmag.vtu", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=wB)
76 print("Results saved in result_gravmag.vtu")
77
78 saveDataCSV("result_gravmag.csv", density=density, susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
79 print("Results saved in result_gravmag.csv")
80
81 print("All done. Have a nice day!")
82
83 if 'NetCdfData' in dir():
84 work()
85 else:
86 print("This example requires scipy's netcdf support which does not appear to be installed.")
87

  ViewVC Help
Powered by ViewVC 1.1.26