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

Annotation of /trunk/doc/examples/inversion/mag_netcdf.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4433 - (hide annotations)
Fri May 31 12:09:58 2013 UTC (6 years ago) by gross
File MIME type: text/x-python
File size: 2927 byte(s)
some clarifications on geodetic coordinates. 
order of background magnetic flux density component has been corrected: input is now B_east, B_north, B_vertical.


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

  ViewVC Help
Powered by ViewVC 1.1.26