Surface NMR processing and inversion GUI
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

calcAkvoKernel.py 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import os, sys
  2. import numpy as np
  3. from ruamel import yaml
  4. import pyLemma.LemmaCore as lc
  5. import pyLemma.Merlin as mrln
  6. import pyLemma.FDEM1D as em1d
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9. import seaborn as sns
  10. sns.set(style="ticks")
  11. from ruamel import yaml
  12. #import cmocean
  13. #from SEGPlot import *
  14. #from matplotlib.ticker import FormatStrFormatter
  15. #import matplotlib.ticker as plticker
  16. # Converts Lemma/Merlin/Akvo serialized Eigen arrays into numpy ones for use by Python
  17. class VectorXr(yaml.YAMLObject):
  18. """
  19. Converts Lemma/Merlin/Akvo serialized Eigen arrays into numpy ones for use by Python
  20. """
  21. yaml_tag = u'VectorXr'
  22. def __init__(self, array):
  23. self.size = np.shape(array)[0]
  24. self.data = array.tolist()
  25. def __repr__(self):
  26. # Converts to numpy array on import
  27. return "np.array(%r)" % (self.data)
  28. class AkvoData(yaml.YAMLObject):
  29. """
  30. Reads an Akvo serialized dataset into a standard python dictionary
  31. """
  32. yaml_tag = u'AkvoData'
  33. def __init__(self, array):
  34. pass
  35. #self.size = np.shape(array)[0]
  36. #self.Imp = array.tolist()
  37. def __repr__(self):
  38. # Converts to a dictionary with Eigen vectors represented as Numpy arrays
  39. return self
  40. def loadAkvoData(fnamein):
  41. """ Loads data from an Akvo YAML file. The 0.02 is hard coded as the pulse length. This needs to be
  42. corrected in future kernel calculations. The current was reported but not the pulse length.
  43. """
  44. fname = (os.path.splitext(fnamein)[0])
  45. with open(fnamein, 'r') as stream:
  46. try:
  47. AKVO = (yaml.load(stream, Loader=yaml.Loader))
  48. except yaml.YAMLError as exc:
  49. print(exc)
  50. return AKVO
  51. def main():
  52. if len(sys.argv) < 3:
  53. print ("usage python calcAkvoKernel.py AkvoDataset.yaml Coil1.yaml kparams.yaml SaveString.yaml " )
  54. exit()
  55. AKVO = loadAkvoData(sys.argv[1])
  56. B_inc = AKVO.META["B_0"]["inc"]
  57. B_dec = AKVO.META["B_0"]["dec"]
  58. B0 = AKVO.META["B_0"]["intensity"]
  59. fT = AKVO.transFreq
  60. #gamma = 2.67518e8
  61. #B0 = (fL*2.*np.pi) /gamma * 1e9
  62. Coil1 = em1d.PolygonalWireAntenna.DeSerialize( sys.argv[2] )
  63. Coil1.SetNumberOfFrequencies(1)
  64. Coil1.SetFrequency(0, fT)
  65. Coil1.SetCurrent(1.)
  66. # read in kernel params
  67. kparams = loadAkvoData( sys.argv[3] )
  68. ## TODO
  69. # pass this in...
  70. lmod = em1d.LayeredEarthEM()
  71. nlay = len(kparams["sigs"])
  72. sigs = np.array(kparams["sigs"])
  73. tops = np.array(kparams["tops"])
  74. bots = np.array(kparams["bots"])
  75. if ( (len(tops)-1) != len(bots)):
  76. print("Layer mismatch")
  77. exit()
  78. thicks = bots - tops[0:-1]
  79. lmod.SetNumberOfLayers(nlay + 1)
  80. lmod.SetLayerThickness(thicks)
  81. lmod.SetLayerConductivity( np.concatenate( ( [0.0], sigs ) ))
  82. #lmod.SetNumberOfLayers(4)
  83. #lmod.SetLayerThickness([15.49, 28.18])
  84. #lmod.SetLayerConductivity([0.0, 1./16.91, 1./24.06, 1./33.23])
  85. lmod.SetMagneticFieldIncDecMag( B_inc, B_dec, B0, lc.NANOTESLA )
  86. Kern = mrln.KernelV0()
  87. Kern.PushCoil( "Coil 1", Coil1 )
  88. Kern.SetLayeredEarthEM( lmod );
  89. Kern.SetIntegrationSize( (kparams["size_n"], kparams["size_e"], kparams["size_d"]) )
  90. Kern.SetIntegrationOrigin( (kparams["origin_n"], kparams["origin_e"], kparams["origin_d"]) )
  91. Kern.SetTolerance( 1e-9*kparams["branchTol"] )
  92. Kern.SetMinLevel( kparams["minLevel"] )
  93. Kern.SetMaxLevel( kparams["maxLevel"] )
  94. Kern.SetHankelTransformType( lc.FHTKEY201 )
  95. Kern.AlignWithAkvoDataset( sys.argv[1] )
  96. if str(kparams["Lspacing"]).strip() == "Geometric":
  97. thick = np.geomspace(kparams["thick1"], kparams["thickN"], num=kparams["nLay"])
  98. elif str(kparams["Lspacing"]) == "Log":
  99. thick = np.logspace(kparams["thick1"], kparams["thickN"], num=kparams["nLay"])
  100. elif str(kparams["Lspacing"]) == "Linear":
  101. thick = np.linspace(kparams["thick1"], kparams["thickN"], num=kparams["nLay"])
  102. else:
  103. print("DOOOM!, in calcAkvoKernel layer spacing was not <Geometric>, <Log>, or <Linear>")
  104. print( str(kparams["Lspacing"]) )
  105. exit()
  106. iface = np.cumsum(thick)
  107. Kern.SetDepthLayerInterfaces(iface)
  108. #Kern.SetDepthLayerInterfaces(np.geomspace(1, 110, num=40))
  109. #Kern.SetDepthLayerInterfaces(np.linspace(1, 110, num=50))
  110. #Kern.SetDepthLayerInterfaces(np.geomspace(1, 110, num=40))
  111. # autAkvoDataNode = YAML::LoadFile(argv[4]);
  112. # Kern->AlignWithAkvoDataset( AkvoDataNode );
  113. Kern.CalculateK0( ["Coil 1"], ["Coil 1"], False )
  114. #yml = open( 'test' + str(Kern.GetTolerance()) + '.yaml', 'w')
  115. yml = open( sys.argv[4], 'w' )
  116. print(Kern, file=yml)
  117. K0 = Kern.GetKernel()
  118. plt.matshow(np.abs(K0))
  119. plt.show()
  120. if __name__ == "__main__":
  121. main()