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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5707 - (hide annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 9 months ago) by sshaw
File MIME type: text/x-python
File size: 3200 byte(s)
adding copyright headers to files without copyright info, moved header to top of file in some cases where it wasn't
1 caltinay 4112 ##############################################################################
2     #
3 jfenwick 5593 # Copyright (c) 2009-2015 by The University of Queensland
4 caltinay 4112 # http://www.uq.edu.au
5     #
6     # Primary Business: Queensland, Australia
7     # Licensed under the Open Software License version 3.0
8     # http://www.opensource.org/licenses/osl-3.0.php
9     #
10     # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
12     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 caltinay 4112 #
14     ##############################################################################
15    
16 caltinay 4148 """3D gravity inversion example using netCDF data"""
17 sshaw 5707 from __future__ import division, print_function
18 caltinay 4148
19 jfenwick 5593 __copyright__="""Copyright (c) 2009-2015 by The University of Queensland
20 caltinay 4112 http://www.uq.edu.au
21     Primary Business: Queensland, Australia"""
22     __license__="""Licensed under the Open Software License version 3.0
23     http://www.opensource.org/licenses/osl-3.0.php"""
24     __url__="https://launchpad.net/escript-finley"
25    
26     # Import required modules
27 caltinay 4148 from esys.downunder import *
28 gross 4199 from esys.weipa import *
29 caltinay 4112 from esys.escript import unitsSI as U
30 jfenwick 5322 from esys.escript import saveDataCSV,getEscriptParamInt
31 caltinay 4112
32 jfenwick 4310
33 jfenwick 5322 haveNetcdf=(getEscriptParamInt("NETCDF_BUILD",0)==1)
34 jfenwick 4310
35 caltinay 4112 # Set parameters
36 caltinay 4267 DATASET = 'data/GravitySmall.nc'
37     DATA_UNITS = 1e-6 * U.m/(U.sec**2)
38 caltinay 4148 PAD_X = 0.2
39     PAD_Y = 0.2
40     thickness = 40. * U.km
41     l_air = 6. * U.km
42 caltinay 4892 n_cells_v = 15
43 gross 4199 MU = 0.1
44 caltinay 4112
45 gross 4374 COORDINATES=CartesianReferenceSystem()
46     #COORDINATES=WGS84ReferenceSystem()
47 gross 4373
48 caltinay 4112 # Setup and run the inversion
49 jfenwick 4310 def work():
50 gross 4373 source=NetCdfData(NetCdfData.GRAVITY, DATASET, scale_factor=DATA_UNITS, reference_system=COORDINATES)
51     db=DomainBuilder(dim=3, reference_system=COORDINATES)
52 jfenwick 4310 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.fixDensityBelow(depth=thickness)
56 gross 4120
57 jfenwick 4310 inv=GravityInversion()
58     inv.setSolverTolerance(1e-4)
59     inv.setSolverMaxIterations(50)
60     inv.setup(db)
61     inv.getCostFunction().setTradeOffFactorsModels(MU)
62 gross 4122
63 jfenwick 4310 density = inv.run()
64     print("density = %s"%density)
65 caltinay 4112
66 jfenwick 4310 g, w = db.getGravitySurveys()[0]
67 caltinay 4362 saveVoxet("result.vo", density=density)
68 caltinay 4391 if saveSilo("result_gravity.silo", density=density, gravity_anomaly=g, gravity_weight=w):
69     print("Results saved in result_gravity.silo")
70     else:
71     print("Failed to save result_gravity.silo. Possibly no Silo support.")
72 caltinay 4112
73 jfenwick 4310 saveVTK("result_gravity.vtu", density=density, gravity_anomaly=g, gravity_weight=w)
74     print("Results saved in result_gravity.vtu")
75 gross 4202
76 jfenwick 4310 saveDataCSV("result_gravity.csv", density=density, x=density.getFunctionSpace().getX())
77     print("Results saved in result_gravity.csv")
78 gross 4202
79 jfenwick 4310 print("All done. Have a nice day!")
80 caltinay 4267
81 sshaw 4895 try:
82     import pyproj
83     except ImportError:
84     print("This example requires pyproj to be installed.")
85     import sys
86     sys.exit(0)
87    
88 sshaw 5288 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 not available")
98 jfenwick 5322 elif not haveNetcdf:
99     print("netCDF not available.")
100 jfenwick 4310 else:
101 sshaw 5288 work()
102 jfenwick 4310

  ViewVC Help
Powered by ViewVC 1.1.26