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

Contents of /trunk/doc/examples/inversion/mag_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: 3516 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 magnetic 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.weipa import *
29 from esys.escript import unitsSI as U
30 from esys.escript import saveDataCSV,getEscriptParamInt
31
32
33 haveNetcdf=(getEscriptParamInt("NETCDF_BUILD",0)==1)
34
35 # Set parameters
36 DATASET = 'data/MagneticSmall.nc'
37 DATA_UNITS = 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 = 0.1
44 # background magnetic field components (B_East, B_North, B_Vertical)
45 B_b = [2201.*U.Nano*U.Tesla, 31232.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
46
47 COORDINATES=CartesianReferenceSystem()
48 #COORDINATES=WGS84ReferenceSystem()
49
50
51 def work():
52 # Setup and run the inversion
53 source=NetCdfData(NetCdfData.MAGNETIC, DATASET, scale_factor=DATA_UNITS, reference_system=COORDINATES)
54 db=DomainBuilder(dim=3, reference_system=COORDINATES)
55 db.addSource(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.fixSusceptibilityBelow(depth=thickness)
60
61 inv=MagneticInversion(self_demagnetization=True)
62 inv.setSolverTolerance(1e-4)
63 inv.setSolverMaxIterations(50)
64 inv.fixMagneticPotentialAtBottom(False)
65 inv.setup(db)
66 inv.getCostFunction().setTradeOffFactorsModels(MU)
67
68 susceptibility = inv.run()
69 print("susceptibility = %s"%susceptibility)
70
71 B, w = db.getMagneticSurveys()[0]
72 if saveSilo("result_magnetic.silo", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w):
73 print("Results saved in result_magnetic.silo")
74 else:
75 print("Failed to save result_magnetic.silo. Possibly no Silo support.")
76
77 saveVTK("result_magnetic.vtu", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
78 print("Results saved in result_magnetic.vtu")
79
80 saveDataCSV("result_magnetic.csv", susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
81 print("Results saved in result_magnetic.csv")
82
83 print("All done. Have a nice day!")
84
85 try:
86 import pyproj
87 except ImportError:
88 print("This example requires pyproj to be installed.")
89 import sys
90 sys.exit(0)
91
92 try:
93 import esys.ripley
94 HAVE_RIPLEY = True
95 except ImportError:
96 HAVE_RIPLEY = False
97
98 if 'NetCdfData' not in dir():
99 print("This example requires scipy's netcdf support which does not appear to be installed.")
100 elif not HAVE_RIPLEY:
101 print("Ripley module required but not available")
102 elif not haveNetcdf:
103 print("netCDF not available.")
104 else:
105 work()

  ViewVC Help
Powered by ViewVC 1.1.26