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

Diff of /branches/doubleplusgood/doc/examples/inversion/gravmag_netcdf.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4344 by jfenwick, Wed Feb 27 03:42:40 2013 UTC revision 4345 by jfenwick, Fri Mar 29 07:09:41 2013 UTC
# Line 24  __url__="https://launchpad.net/escript-f Line 24  __url__="https://launchpad.net/escript-f
24    
25  # Import required modules  # Import required modules
26  from esys.downunder import *  from esys.downunder import *
 from esys.downunder.minimizers import MinimizerMaxIterReached  
27  from esys.escript import unitsSI as U  from esys.escript import unitsSI as U
28  from esys.weipa import saveSilo  from esys.escript import saveDataCSV
29    from esys.weipa import *
30    
31  # Set parameters  # Set parameters
32  MAGNETIC_DATASET = 'magnetic_anomaly.nc'  MAGNETIC_DATASET = 'data/MagneticSmall.nc'
33  GRAVITY_DATASET = 'gravity_anomaly.nc'  MAG_UNITS = U.Nano * U.Tesla
34  latitude = -28.5  GRAVITY_DATASET = 'data/GravitySmall.nc'
35    GRAV_UNITS = 1e-6 * U.m/(U.sec**2)
36    # background magnetic field components (B_North, B_East, B_Vertical)
37    B_b = [31232.*U.Nano*U.Tesla, 2201.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
38  PAD_X = 0.2  PAD_X = 0.2
39  PAD_Y = 0.2  PAD_Y = 0.2
40  thickness = 40. * U.km  thickness = 40. * U.km
# Line 40  n_cells_v = 25 Line 43  n_cells_v = 25
43  mu_gravity = 10.  mu_gravity = 10.
44  mu_magnetic = 0.1  mu_magnetic = 0.1
45    
46  # Setup and run the inversion  def work():
47  B_b=simpleGeoMagneticFluxDensity(latitude=latitude)    # Setup and run the inversion
48  grav_source=NetCdfData(NetCdfData.GRAVITY, GRAVITY_DATASET)    grav_source=NetCdfData(NetCdfData.GRAVITY, GRAVITY_DATASET, scale_factor=GRAV_UNITS)
49  mag_source=NetCdfData(NetCdfData.MAGNETIC, MAGNETIC_DATASET)    mag_source=NetCdfData(NetCdfData.MAGNETIC, MAGNETIC_DATASET, scale_factor=MAG_UNITS)
50  db=DomainBuilder(dim=3)    db=DomainBuilder(dim=3)
51  db.addSource(grav_source)    db.addSource(grav_source)
52  db.addSource(mag_source)    db.addSource(mag_source)
53  db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)    db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
54  db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)    db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
55  db.setBackgroundMagneticFluxDensity(B_b)    db.setBackgroundMagneticFluxDensity(B_b)
56  db.fixDensityBelow(depth=thickness)    db.fixDensityBelow(depth=thickness)
57  db.fixSusceptibilityBelow(depth=thickness)    db.fixSusceptibilityBelow(depth=thickness)
58    
59  inv=JointGravityMagneticInversion()    inv=JointGravityMagneticInversion()
60  inv.setSolverTolerance(1e-4)    inv.setSolverTolerance(1e-4)
61  inv.setSolverMaxIterations(50)    inv.setSolverMaxIterations(50)
62  inv.setup(db)    inv.setup(db)
63  inv.getCostFunction().setTradeOffFactorsModels([mu_gravity, mu_magnetic])    inv.getCostFunction().setTradeOffFactorsModels([mu_gravity, mu_magnetic])
64  inv.getCostFunction().setTradeOffFactorsRegularization(mu = [1.,1.], mu_c=1.)    inv.getCostFunction().setTradeOffFactorsRegularization(mu = [1.,1.], mu_c=1.)
65    
66  print("Starting inversion, please stand by...")    density, susceptibility = inv.run()
67  try:    print("density = %s"%density)
68      density, susceptibility = inv.run()    print("susceptibility = %s"%susceptibility)
69  except MinimizerMaxIterReached as e:  
70      print(e)    g, wg = db.getGravitySurveys()[0]
71      density, susceptibility = inv.p    B, wB = db.getMagneticSurveys()[0]
72      saveSilo("result_gravmag.silo", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B,   magnetic_weight=wB)
73  print("density = %s"%density)    print("Results saved in result_gravmag.silo")
74  print("susceptibility = %s"%susceptibility)  
75      saveVTK("result_gravmag.vtu", density=density, gravity_anomaly=g, gravity_weight=wg, susceptibility=susceptibility, magnetic_anomaly=B,   magnetic_weight=wB)
76  # Save results    print("Results saved in result_gravmag.vtu")
77  gravSurveys = db.getGravitySurveys()  
78  magSurveys = db.getMagneticSurveys()    saveDataCSV("result_gravmag.csv", density=density, susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
79  g, wg =  gravSurveys[0]    print("Results saved in result_gravmag.csv")
80  B, wB =  magSurveys[0]  
81  saveSilo("result_gravmag.silo", density=density, gravity_anomaly=g[2], gravity_weight=wg[2], susceptibility=susceptibility, magnetic_anomaly=B[2], magnetic_weight=wB[2])    print("All done. Have a nice day!")
82  print("Results saved in result_gravmag.silo. Good bye.")  
83    if 'NetCdfData' in dir():
84      work()
85    else:
86      print("This example requires scipy's netcdf support which does not appear to be installed.")
87    

Legend:
Removed from v.4344  
changed lines
  Added in v.4345

  ViewVC Help
Powered by ViewVC 1.1.26