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

  ViewVC Help
Powered by ViewVC 1.1.26