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

Contents of /trunk/downunder/test/python/run_magnetic.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: 3512 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 """2D magnetic inversion example using synthetic data"""
17
18 from __future__ import print_function, division
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 try:
34 import esys.ripley
35 HAVE_RIPLEY = True
36 except ImportError:
37 HAVE_RIPLEY = False
38
39 try:
40 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
41 except KeyError:
42 WORKDIR='.'
43
44 @unittest.skipIf(not HAVE_RIPLEY, "Ripley module not available")
45 class Test_MagneticInversion2D(unittest.TestCase):
46 def test_2D_inversion(self):
47 logging.getLogger('inv.MinimizerLBFGS').setLevel(logging.CRITICAL)
48 logging.getLogger('inv.MagneticInversion').setLevel(logging.CRITICAL)
49 # interesting parameters:
50 depth_offset = 0. * U.km
51 n_humps_h = 1
52 n_humps_v = 1
53 mu = 1.
54 n_cells_in_data = 200
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 source=SyntheticData(DataSource.MAGNETIC, 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, B_b=B_b,
71 data_offset=0, full_knowledge=full_knowledge)
72
73 domainbuilder=DomainBuilder(dim=DIM)
74 domainbuilder.addSource(source)
75 domainbuilder.setVerticalExtents(depth=l_air+THICKNESS+depth_offset,
76 air_layer=l_air, num_cells=n_cells_v)
77 domainbuilder.setBackgroundMagneticFluxDensity(B_b)
78 domainbuilder.setPadding(l_pad)
79 domainbuilder.fixSusceptibilityBelow(depth=THICKNESS+depth_offset)
80
81 inv=MagneticInversion()
82 inv.setSolverTolerance(1e-4)
83 inv.setSolverMaxIterations(50)
84 inv.setup(domainbuilder)
85 inv.getCostFunction().setTradeOffFactorsModels(mu)
86
87 k_new=inv.run()
88 k_ref=source.getReferenceProperty()
89 B, chi = inv.getCostFunction().getForwardModel().getSurvey(0)
90 #saveSilo(os.path.join(WORKDIR, 'results_magnetic_2d'), k=k_new, k_ref=k_ref, B=B, chi=chi)
91
92 if __name__ == '__main__':
93 run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26