/[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 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (2 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 3406 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 ##############################################################################
2 #
3 # Copyright (c) 2009-2018 by The University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Apache License, version 2.0
8 # http://www.apache.org/licenses/LICENSE-2.0
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-2018 by The University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Apache License, version 2.0
23 http://www.apache.org/licenses/LICENSE-2.0"""
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
31
32 # Set parameters
33 DATASET = 'data/MagneticSmall.nc'
34 DATA_UNITS = U.Nano * U.Tesla
35 PAD_X = 0.2
36 PAD_Y = 0.2
37 thickness = 40. * U.km
38 l_air = 6. * U.km
39 n_cells_v = 25
40 MU = 0.1
41 # background magnetic field components (B_East, B_North, B_Vertical)
42 B_b = [2201.*U.Nano*U.Tesla, 31232.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
43
44 COORDINATES=CartesianReferenceSystem()
45 #COORDINATES=WGS84ReferenceSystem()
46
47
48 def work():
49 # Setup and run the inversion
50 source=NetCdfData(NetCdfData.MAGNETIC, DATASET, scale_factor=DATA_UNITS, reference_system=COORDINATES)
51 db=DomainBuilder(dim=3, reference_system=COORDINATES)
52 db.addSource(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.fixSusceptibilityBelow(depth=thickness)
57
58 inv=MagneticInversion(self_demagnetization=True)
59 inv.setSolverTolerance(1e-4)
60 inv.setSolverMaxIterations(50)
61 inv.fixMagneticPotentialAtBottom(False)
62 inv.setup(db)
63 inv.getCostFunction().setTradeOffFactorsModels(MU)
64
65 susceptibility = inv.run()
66 print("susceptibility = %s"%susceptibility)
67
68 B, w = db.getMagneticSurveys()[0]
69 if saveSilo("result_magnetic.silo", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w):
70 print("Results saved in result_magnetic.silo")
71 else:
72 print("Failed to save result_magnetic.silo. Possibly no Silo support.")
73
74 saveVTK("result_magnetic.vtu", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
75 print("Results saved in result_magnetic.vtu")
76
77 saveDataCSV("result_magnetic.csv", susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
78 print("Results saved in result_magnetic.csv")
79
80 print("All done. Have a nice day!")
81
82 try:
83 import pyproj
84 HAVE_PYPROJ = True
85 except ImportError:
86 HAVE_PYPROJ = False
87
88 try:
89 import esys.ripley
90 HAVE_RIPLEY = True
91 except ImportError:
92 HAVE_RIPLEY = False
93
94 if 'NetCdfData' not in dir():
95 print("This example requires scipy's netcdf support which does not appear to be installed.")
96 elif not HAVE_RIPLEY:
97 print("Ripley module required but not available")
98 elif not HAVE_PYPROJ:
99 print("This example requires pyproj to be installed.")
100 else:
101 work()

  ViewVC Help
Powered by ViewVC 1.1.26