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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4392 - (show annotations)
Mon May 6 02:18:33 2013 UTC (6 years, 1 month ago) by caltinay
File MIME type: text/x-python
File size: 2887 byte(s)
More saveSilo checks.

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 magnetic 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.weipa import *
28 from esys.escript import unitsSI as U
29 from esys.escript import saveDataCSV
30
31 # Set parameters
32 DATASET = 'data/MagneticSmall.nc'
33 DATA_UNITS = U.Nano * U.Tesla
34 PAD_X = 0.2
35 PAD_Y = 0.2
36 thickness = 40. * U.km
37 l_air = 6. * U.km
38 n_cells_v = 25
39 MU = 0.1
40 # background magnetic field components (B_North, B_East, B_Vertical)
41 B_b = [31232.*U.Nano*U.Tesla, 2201.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
42
43 COORDINATES=WGS84ReferenceSystem()
44
45
46 def work():
47 # Setup and run the inversion
48 source=NetCdfData(NetCdfData.MAGNETIC, DATASET, scale_factor=DATA_UNITS, reference_system=COORDINATES)
49 db=DomainBuilder(dim=3, reference_system=COORDINATES)
50 db.addSource(source)
51 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
52 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
53 db.setBackgroundMagneticFluxDensity(B_b)
54 db.fixSusceptibilityBelow(depth=thickness)
55
56 inv=MagneticInversion()
57 inv.setSolverTolerance(1e-4)
58 inv.setSolverMaxIterations(50)
59 inv.fixMagneticPotentialAtBottom(False)
60 inv.setup(db)
61 inv.getCostFunction().setTradeOffFactorsModels(MU)
62
63 susceptibility = inv.run()
64 print("susceptibility = %s"%susceptibility)
65
66 B, w = db.getMagneticSurveys()[0]
67 if saveSilo("result_magnetic.silo", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w):
68 print("Results saved in result_magnetic.silo")
69 else:
70 print("Failed to save result_magnetic.silo. Possibly no Silo support.")
71
72 saveVTK("result_magnetic.vtu", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
73 print("Results saved in result_magnetic.vtu")
74
75 saveDataCSV("result_magnetic.csv", susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
76 print("Results saved in result_magnetic.csv")
77
78 print("All done. Have a nice day!")
79
80 if 'NetCdfData' in dir():
81 work()
82 else:
83 print("This example requires scipy's netcdf support which does not appear to be installed.")
84

  ViewVC Help
Powered by ViewVC 1.1.26