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

Annotation of /branches/doubleplusgood/doc/examples/inversion/mag_netcdf.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4345 - (hide annotations)
Fri Mar 29 07:09:41 2013 UTC (6 years ago) by jfenwick
File MIME type: text/x-python
File size: 2696 byte(s)
Spelling fixes
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 jfenwick 4345 from esys.weipa import *
28 caltinay 4157 from esys.escript import unitsSI as U
29 jfenwick 4345 from esys.escript import saveDataCSV
30 caltinay 4157
31     # Set parameters
32 jfenwick 4345 DATASET = 'data/MagneticSmall.nc'
33     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 jfenwick 4345 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 caltinay 4157
43 jfenwick 4345 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 caltinay 4157
53 jfenwick 4345 inv=MagneticInversion()
54     inv.setSolverTolerance(1e-4)
55     inv.setSolverMaxIterations(50)
56     inv.fixMagneticPotentialAtBottom(False)
57     inv.setup(db)
58     inv.getCostFunction().setTradeOffFactorsModels(MU)
59 caltinay 4157
60 jfenwick 4345 susceptibility = inv.run()
61     print("susceptibility = %s"%susceptibility)
62 caltinay 4158
63 jfenwick 4345 B, w = db.getMagneticSurveys()[0]
64     saveSilo("result_magnetic.silo", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
65     print("Results saved in result_magnetic.silo")
66 caltinay 4157
67 jfenwick 4345 saveVTK("result_magnetic.vtu", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
68     print("Results saved in result_magnetic.vtu")
69 caltinay 4157
70 jfenwick 4345 saveDataCSV("result_magnetic.csv", susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
71     print("Results saved in result_magnetic.csv")
72    
73     print("All done. Have a nice day!")
74    
75     if 'NetCdfData' in dir():
76     work()
77     else:
78     print("This example requires scipy's netcdf support which does not appear to be installed.")
79    

  ViewVC Help
Powered by ViewVC 1.1.26