/[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 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (2 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 3089 byte(s)
Make everyone sad by touching all the files

Copyright dates update

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

  ViewVC Help
Powered by ViewVC 1.1.26