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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4892 - (show annotations)
Mon Apr 28 03:30:29 2014 UTC (5 years, 4 months ago) by caltinay
File MIME type: text/x-python
File size: 2788 byte(s)
scaled down grav_netcdf test...

1 from __future__ import division
2 from __future__ import print_function
3 ##############################################################################
4 #
5 # Copyright (c) 2009-2014 by University of Queensland
6 # http://www.uq.edu.au
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 # Development 2012-2013 by School of Earth Sciences
14 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
15 #
16 ##############################################################################
17
18 """3D gravity inversion example using netCDF data"""
19
20 __copyright__="""Copyright (c) 2009-2014 by University of Queensland
21 http://www.uq.edu.au
22 Primary Business: Queensland, Australia"""
23 __license__="""Licensed under the Open Software License version 3.0
24 http://www.opensource.org/licenses/osl-3.0.php"""
25 __url__="https://launchpad.net/escript-finley"
26
27 # Import required modules
28 from esys.downunder import *
29 from esys.weipa import *
30 from esys.escript import unitsSI as U
31 from esys.escript import saveDataCSV
32
33
34
35
36 # Set parameters
37 DATASET = 'data/GravitySmall.nc'
38 DATA_UNITS = 1e-6 * U.m/(U.sec**2)
39 PAD_X = 0.2
40 PAD_Y = 0.2
41 thickness = 40. * U.km
42 l_air = 6. * U.km
43 n_cells_v = 15
44 MU = 0.1
45
46 COORDINATES=CartesianReferenceSystem()
47 #COORDINATES=WGS84ReferenceSystem()
48
49 # Setup and run the inversion
50 def work():
51 source=NetCdfData(NetCdfData.GRAVITY, DATASET, scale_factor=DATA_UNITS, reference_system=COORDINATES)
52 db=DomainBuilder(dim=3, reference_system=COORDINATES)
53 db.addSource(source)
54 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
55 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
56 db.fixDensityBelow(depth=thickness)
57
58 inv=GravityInversion()
59 inv.setSolverTolerance(1e-4)
60 inv.setSolverMaxIterations(50)
61 inv.setup(db)
62 inv.getCostFunction().setTradeOffFactorsModels(MU)
63
64 density = inv.run()
65 print("density = %s"%density)
66
67 g, w = db.getGravitySurveys()[0]
68 saveVoxet("result.vo", density=density)
69 if saveSilo("result_gravity.silo", density=density, gravity_anomaly=g, gravity_weight=w):
70 print("Results saved in result_gravity.silo")
71 else:
72 print("Failed to save result_gravity.silo. Possibly no Silo support.")
73
74 saveVTK("result_gravity.vtu", density=density, gravity_anomaly=g, gravity_weight=w)
75 print("Results saved in result_gravity.vtu")
76
77 saveDataCSV("result_gravity.csv", density=density, x=density.getFunctionSpace().getX())
78 print("Results saved in result_gravity.csv")
79
80 print("All done. Have a nice day!")
81
82 if 'NetCdfData' in dir():
83 work()
84 else:
85 print("This example requires scipy's netcdf support which does not appear to be installed.")
86

  ViewVC Help
Powered by ViewVC 1.1.26