/[escript]/branches/doubleplusgood/doc/examples/inversion/mag_netcdf.py
ViewVC logotype

Annotation of /branches/doubleplusgood/doc/examples/inversion/mag_netcdf.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4158 - (hide annotations)
Wed Jan 23 07:02:21 2013 UTC (6 years, 3 months ago) by caltinay
Original Path: trunk/doc/examples/inversion/magnetic_netcdf.py
File MIME type: text/x-python
File size: 2202 byte(s)
Write output even when max iterations reached.

1 caltinay 4157
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 magnetic 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 caltinay 4158 from esys.downunder.minimizers import MinimizerMaxIterReached
28 caltinay 4157 from esys.escript import unitsSI as U
29     from esys.weipa import saveSilo
30    
31     # Set parameters
32     DATASET = 'magnetic_anomaly.nc'
33     latitude = -28.5
34     PAD_X = 0.2
35     PAD_Y = 0.2
36     thickness = 40. * U.km
37     l_air = 6. * U.km
38     n_cells_v = 25
39     mu = 0.1
40    
41     # Setup and run the inversion
42     B_b=simpleGeoMagneticFluxDensity(latitude=latitude)
43     source=NetCdfData(NetCdfData.MAGNETIC, DATASET)
44     db=DomainBuilder(dim=3)
45     db.addSource(source)
46     db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
47     db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
48     db.setBackgroundMagneticFluxDensity(B_b)
49     db.fixDensityBelow(depth=thickness)
50    
51     inv=MagneticInversion()
52     inv.setSolverTolerance(1e-4)
53     inv.setSolverMaxIterations(50)
54     inv.setup(db)
55     inv.getCostFunction().setTradeOffFactorsModels(mu)
56    
57     print("Starting inversion, please stand by...")
58 caltinay 4158 try:
59     susceptibility = inv.run()
60     except MinimizerMaxIterReached as e:
61     print(e)
62     susceptibility = inv.p
63    
64 caltinay 4157 print("susceptibility = %s"%susceptibility)
65    
66     # Save results
67     B, w = inv.getCostFunction().getForwardModel().getSurvey(0)
68     saveSilo("result_magnetic.silo", susceptibility=susceptibility, magnetic_anomaly=B[2], magnetic_weight=w[2])
69     print("Results saved in result_magnetic.silo. Good bye.")
70    

  ViewVC Help
Powered by ViewVC 1.1.26