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

Contents of /trunk/downunder/test/python/run_inversion_gravmag_2d.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5706 - (show annotations)
Mon Jun 29 03:41:36 2015 UTC (4 years, 2 months ago) by sshaw
File MIME type: text/x-python
File size: 4518 byte(s)
all python files now force use of python3 prints and division syntax to stop sneaky errors appearing in py3 environs
1 ##############################################################################
2 #
3 # Copyright (c) 2003-2015 by The University of Queensland
4 # 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 # Development 2012-2013 by School of Earth Sciences
12 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 #
14 ##############################################################################
15
16 from __future__ import print_function, division
17
18 """2D magnetic/gravity joint inversion example using synthetic data"""
19
20 __copyright__="""Copyright (c) 2003-2015 by The 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 os
28 import esys.escriptcore.utestselect as unittest
29 from esys.escriptcore.testing import *
30 from esys.downunder import *
31 from esys.escript import unitsSI as U
32 from esys.weipa import saveSilo
33
34 try:
35 import esys.ripley
36 HAVE_RIPLEY = True
37 except ImportError:
38 HAVE_RIPLEY = False
39
40 try:
41 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
42 except KeyError:
43 WORKDIR='.'
44
45 @unittest.skipIf(not HAVE_RIPLEY, "Ripley module not available")
46 class Test_MagneticInversion(unittest.TestCase):
47 def test_2D_inversion(self):
48 logging.getLogger('inv.MinimizerLBFGS').setLevel(logging.CRITICAL)
49 logging.getLogger('inv.JointGravityMagneticInversion').setLevel(logging.CRITICAL)
50 # interesting parameters:
51 depth_offset = 10 * U.km
52 n_humps_h = 5
53 n_humps_v = 2
54 n_cells_in_data = 30
55 full_knowledge = False
56 B_b = [2201.*U.Nano*U.Tesla, 31232.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
57 #
58 DIM = 2
59 n_cells_in_data = max(n_humps_h*7, n_cells_in_data)
60 l_data = 100. * U.km
61 l_pad = 40. * U.km
62 THICKNESS = 20. * U.km
63 l_air = 20. * U.km
64 n_cells_v = max(
65 int((2*l_air+THICKNESS+depth_offset)/l_data*n_cells_in_data + 0.5), 25)
66
67
68 grav_data=SyntheticData(DataSource.GRAVITY, n_length=n_humps_h, n_depth=n_humps_v,
69 depth=THICKNESS+depth_offset, depth_offset=depth_offset,
70 DIM=DIM, number_of_elements=n_cells_in_data, length=l_data,
71 data_offset=0, full_knowledge=full_knowledge)
72
73 mag_data=SyntheticData(DataSource.MAGNETIC, n_length=n_humps_h, 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, B_b=B_b,
76 data_offset=0, full_knowledge=full_knowledge, s=l_data/n_humps_h*0.1)
77
78 domainbuilder=DomainBuilder(dim=DIM)
79 domainbuilder.addSource(grav_data)
80 domainbuilder.addSource(mag_data)
81 domainbuilder.setVerticalExtents(depth=l_air+THICKNESS+depth_offset,
82 air_layer=l_air, num_cells=n_cells_v)
83 domainbuilder.setPadding(l_pad)
84 domainbuilder.fixDensityBelow(depth=THICKNESS+depth_offset)
85 domainbuilder.fixSusceptibilityBelow(depth=THICKNESS+depth_offset)
86 domainbuilder.setBackgroundMagneticFluxDensity(B_b)
87
88 inv=JointGravityMagneticInversion()
89 inv.setSolverTolerance(1e-4)
90 inv.setSolverMaxIterations(500)
91 inv.setup(domainbuilder)
92
93 inv.getCostFunction().setTradeOffFactorsModels([1., 0.01])
94 inv.getCostFunction().setTradeOffFactorsRegularization(mu = [1.e-2,1.e-2], mu_c=1000.)
95
96 rho_ref = grav_data.getReferenceProperty()
97 k_ref = mag_data.getReferenceProperty()
98
99 rho_new, k_new = inv.run()
100
101 # print("rho_new = %s"%rho_new)
102 # print("rho = %s"%rho_ref)
103 # print("k_new = %s"%k_new)
104 # print("k = %s"%k_ref)
105
106 g, chi = inv.getCostFunction().getForwardModel(inv.DENSITY).getSurvey(0)
107 B, chi = inv.getCostFunction().getForwardModel(inv.SUSCEPTIBILITY).getSurvey(0)
108
109 # saveSilo(os.path.join(WORKDIR, 'results_joint_2d'),
110 # density=rho_new, density_ref=rho_ref,
111 # susceptibility=k_new, susceptibility_ref=k_ref,
112 # g_data=g, B_data=B, chi=chi)
113
114 if __name__ == '__main__':
115 run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26