/[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 4310 - (show annotations)
Tue Mar 12 03:23:26 2013 UTC (6 years, 7 months ago) by jfenwick
File MIME type: text/x-python
File size: 2654 byte(s)
examples don't FAIL if tool is not installed
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 def work():
44 # Setup and run the inversion
45 source=NetCdfData(NetCdfData.MAGNETIC, DATASET, scale_factor=DATA_UNITS)
46 db=DomainBuilder(dim=3)
47 db.addSource(source)
48 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
49 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
50 db.setBackgroundMagneticFluxDensity(B_b)
51 db.fixSusceptibilityBelow(depth=thickness)
52
53 inv=MagneticInversion()
54 inv.setSolverTolerance(1e-4)
55 inv.setSolverMaxIterations(50)
56 inv.setup(db)
57 inv.getCostFunction().setTradeOffFactorsModels(MU)
58
59 susceptibility = inv.run()
60 print("susceptibility = %s"%susceptibility)
61
62 B, w = db.getMagneticSurveys()[0]
63 saveSilo("result_magnetic.silo", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
64 print("Results saved in result_magnetic.silo")
65
66 saveVTK("result_magnetic.vtu", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
67 print("Results saved in result_magnetic.vtu")
68
69 saveDataCSV("result_magnetic.csv", susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
70 print("Results saved in result_magnetic.csv")
71
72 print("All done. Have a nice day!")
73
74 if 'NetCdfData' in dir():
75 work()
76 else:
77 print("This example requires scipy's netcdf support which does not appear to be installed.")
78

  ViewVC Help
Powered by ViewVC 1.1.26