/[escript]/trunk/downunder/test/python/run_gravity.py
ViewVC logotype

Annotation of /trunk/downunder/test/python/run_gravity.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5706 - (hide annotations)
Mon Jun 29 03:41:36 2015 UTC (4 years, 3 months ago) by sshaw
File MIME type: text/x-python
File size: 3341 byte(s)
all python files now force use of python3 prints and division syntax to stop sneaky errors appearing in py3 environs
1 jfenwick 3981 ##############################################################################
2 caltinay 3947 #
3 jfenwick 5593 # Copyright (c) 2003-2015 by The University of Queensland
4 jfenwick 3981 # http://www.uq.edu.au
5 caltinay 3947 #
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 jfenwick 3981 # 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 jfenwick 3981 #
14     ##############################################################################
15 caltinay 3947
16 sshaw 5706 from __future__ import print_function, division
17    
18 sshaw 5288 """2D gravity inversion example using synthetic data"""
19    
20 jfenwick 5593 __copyright__="""Copyright (c) 2003-2015 by The University of Queensland
21 jfenwick 3981 http://www.uq.edu.au
22 caltinay 3947 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 os
28 sshaw 5288 import esys.escriptcore.utestselect as unittest
29     from esys.escriptcore.testing import *
30 caltinay 4060 from esys.downunder import *
31 caltinay 3947 from esys.escript import unitsSI as U
32 caltinay 4060 from esys.weipa import saveSilo
33 sshaw 5288 import logging
34 caltinay 3947
35 sshaw 5288 try:
36     import esys.ripley
37     HAVE_RIPLEY = True
38     except ImportError:
39     HAVE_RIPLEY = False
40    
41     try:
42     WORKDIR=os.environ['DOWNUNDER_WORKDIR']
43 caltinay 3947 except KeyError:
44 sshaw 5288 WORKDIR='.'
45 caltinay 3947
46 sshaw 5288 @unittest.skipIf(not HAVE_RIPLEY, "Ripley module not available")
47     class Test_GravityInversion2D(unittest.TestCase):
48     def test_inversion(self):
49     #be quiet about it
50     logging.getLogger('inv.MinimizerLBFGS').setLevel(logging.CRITICAL)
51     logging.getLogger('inv.GravityInversion').setLevel(logging.CRITICAL)
52 caltinay 3947
53 sshaw 5288 # interesting parameters:
54     n_humps_h = 3
55     n_humps_v = 1
56     mu = 100
57     n_cells_in_data = 100
58     # ignore:
59     full_knowledge = False
60     depth_offset = 0. * U.km
61     #
62     DIM = 2
63     n_cells_in_data = max(n_humps_h*7, n_cells_in_data)
64     l_data = 100. * U.km
65     l_pad = 40. * U.km
66     THICKNESS = 20. * U.km
67     l_air = 20. * U.km
68     n_cells_v = max(int((2*l_air+THICKNESS+depth_offset)/ \
69     l_data*n_cells_in_data + 0.5), 25)
70 gross 4033
71    
72 sshaw 5288 source=SyntheticData(DataSource.GRAVITY, n_length=n_humps_h,
73     n_depth=n_humps_v,
74     depth=THICKNESS+depth_offset, depth_offset=depth_offset,
75     DIM=DIM, number_of_elements=n_cells_in_data, length=l_data,
76     data_offset=0, full_knowledge=full_knowledge)
77 caltinay 3947
78 sshaw 5288 domainbuilder=DomainBuilder(dim=DIM)
79     domainbuilder.addSource(source)
80     domainbuilder.setVerticalExtents(depth=l_air+THICKNESS+depth_offset,
81     air_layer=l_air, num_cells=n_cells_v)
82     domainbuilder.setPadding(l_pad)
83     domainbuilder.fixDensityBelow(depth=THICKNESS+depth_offset)
84    
85     inv=GravityInversion()
86     inv.setSolverTolerance(1e-4)
87     inv.setSolverMaxIterations(50)
88     inv.setup(domainbuilder)
89     inv.getCostFunction().setTradeOffFactorsModels(mu)
90    
91     rho_new = inv.run()
92     rho_ref = source.getReferenceProperty()
93     g, chi = inv.getCostFunction().getForwardModel().getSurvey(0)
94    
95     if __name__ == '__main__':
96     run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26