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

Diff of /branches/doubleplusgood/doc/examples/inversion/mag_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 *
27  from esys.downunder.minimizers import MinimizerMaxIterReached  from esys.weipa import *
28  from esys.escript import unitsSI as U  from esys.escript import unitsSI as U
29  from esys.weipa import saveSilo  from esys.escript import saveDataCSV
30    
31  # Set parameters  # Set parameters
32  DATASET = 'magnetic_anomaly.nc'  DATASET = 'data/MagneticSmall.nc'
33  latitude = -28.5  DATA_UNITS = U.Nano * U.Tesla
34  PAD_X = 0.2  PAD_X = 0.2
35  PAD_Y = 0.2  PAD_Y = 0.2
36  thickness = 40. * U.km  thickness = 40. * U.km
37  l_air = 6. * U.km  l_air = 6. * U.km
38  n_cells_v = 25  n_cells_v = 25
39  mu = 0.1  MU = 0.1
40    # background magnetic field components (B_North, B_East, B_Vertical)
41  # Setup and run the inversion  B_b = [31232.*U.Nano*U.Tesla, 2201.*U.Nano*U.Tesla, -41405.*U.Nano*U.Tesla]
42  B_b=simpleGeoMagneticFluxDensity(latitude=latitude)  
43  source=NetCdfData(NetCdfData.MAGNETIC, DATASET)  def work():
44  db=DomainBuilder(dim=3)    # Setup and run the inversion
45  db.addSource(source)    source=NetCdfData(NetCdfData.MAGNETIC, DATASET, scale_factor=DATA_UNITS)
46  db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)    db=DomainBuilder(dim=3)
47  db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)    db.addSource(source)
48  db.setBackgroundMagneticFluxDensity(B_b)    db.setVerticalExtents(depth=thickness, air_layer=l_air, num_cells=n_cells_v)
49  db.fixSusceptibilityBelow(depth=thickness)    db.setFractionalPadding(pad_x=PAD_X, pad_y=PAD_Y)
50      db.setBackgroundMagneticFluxDensity(B_b)
51  inv=MagneticInversion()    db.fixSusceptibilityBelow(depth=thickness)
52  inv.setSolverTolerance(1e-4)  
53  inv.setSolverMaxIterations(50)    inv=MagneticInversion()
54  inv.setup(db)    inv.setSolverTolerance(1e-4)
55  inv.getCostFunction().setTradeOffFactorsModels(mu)    inv.setSolverMaxIterations(50)
56      inv.fixMagneticPotentialAtBottom(False)
57  print("Starting inversion, please stand by...")    inv.setup(db)
58  try:    inv.getCostFunction().setTradeOffFactorsModels(MU)
59      susceptibility = inv.run()  
60  except MinimizerMaxIterReached as e:    susceptibility = inv.run()
61      print(e)    print("susceptibility = %s"%susceptibility)
62      susceptibility = inv.p  
63      B, w =  db.getMagneticSurveys()[0]
64  print("susceptibility = %s"%susceptibility)    saveSilo("result_magnetic.silo", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
65      print("Results saved in result_magnetic.silo")
66  # Save results  
67  B, w =  inv.getCostFunction().getForwardModel().getSurvey(0)    saveVTK("result_magnetic.vtu", susceptibility=susceptibility, magnetic_anomaly=B, magnetic_weight=w)
68  saveSilo("result_magnetic.silo", susceptibility=susceptibility, magnetic_anomaly=B[2], magnetic_weight=w[2])    print("Results saved in result_magnetic.vtu")
69  print("Results saved in result_magnetic.silo. Good bye.")  
70      saveDataCSV("result_magnetic.csv", susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX())
71      print("Results saved in result_magnetic.csv")
72    
73      print("All done. Have a nice day!")
74    
75    if 'NetCdfData' in dir():
76      work()
77    else:
78      print("This example requires scipy's netcdf support which does not appear to be installed.")
79    

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

  ViewVC Help
Powered by ViewVC 1.1.26