/[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 4362 - (show annotations)
Tue Apr 16 04:37:13 2013 UTC (6 years, 4 months ago) by caltinay
File MIME type: text/x-python
File size: 2422 byte(s)
Implemented NumpyData downunder source (w/ tests).
Added check of data dimensionality to domainbuilder since data_dim must equal
domain_dim-1 at the moment.

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 gravity 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
32
33
34 # Set parameters
35 DATASET = 'data/GravitySmall.nc'
36 DATA_UNITS = 1e-6 * U.m/(U.sec**2)
37 PAD_X = 0.2
38 PAD_Y = 0.2
39 thickness = 40. * U.km
40 l_air = 6. * U.km
41 n_cells_v = 25
42 MU = 0.1
43
44 # Setup and run the inversion
45 def work():
46 source=NetCdfData(NetCdfData.GRAVITY, DATASET, scale_factor=DATA_UNITS)
47 db=DomainBuilder(dim=3)
48 db.addSource(source)
49 db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
50 db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
51 db.fixDensityBelow(depth=thickness)
52
53 inv=GravityInversion()
54 inv.setSolverTolerance(1e-4)
55 inv.setSolverMaxIterations(50)
56 inv.setup(db)
57 inv.getCostFunction().setTradeOffFactorsModels(MU)
58
59 density = inv.run()
60 print("density = %s"%density)
61
62 g, w = db.getGravitySurveys()[0]
63 saveVoxet("result.vo", density=density)
64 saveSilo("result_gravity.silo", density=density, gravity_anomaly=g, gravity_weight=w)
65 print("Results saved in result_gravity.silo")
66
67 saveVTK("result_gravity.vtu", density=density, gravity_anomaly=g, gravity_weight=w)
68 print("Results saved in result_gravity.vtu")
69
70 saveDataCSV("result_gravity.csv", density=density, x=density.getFunctionSpace().getX())
71 print("Results saved in result_gravity.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