Surface NMR processing and inversion GUI
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

calcAkvoKernel.py 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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) < 2:
  53. print ("usage python calcAkvoKernel.py AkvoDataset.yaml Coil1.yaml kparams.yaml SaveString.yaml " )
  54. print ("usage akvoKO AkvoDataset.yaml kparams.yaml SaveString.yaml " )
  55. exit()
  56. AKVO = loadAkvoData(sys.argv[1])
  57. B_inc = AKVO.META["B_0"]["inc"]
  58. B_dec = AKVO.META["B_0"]["dec"]
  59. B0 = AKVO.META["B_0"]["intensity"]
  60. fT = AKVO.transFreq
  61. #gamma = 2.67518e8
  62. #B0 = (fL*2.*np.pi) /gamma * 1e9
  63. # read in kernel params
  64. kparams = loadAkvoData( sys.argv[2] )
  65. Kern = mrln.KernelV0()
  66. TX = []
  67. for tx in kparams['txCoils']:
  68. Coil1 = em1d.PolygonalWireAntenna.DeSerialize( tx )
  69. Coil1.SetNumberOfFrequencies(1)
  70. Coil1.SetFrequency(0, fT)
  71. Coil1.SetCurrent(1.)
  72. Kern.PushCoil( tx.split('.yml')[0], Coil1 )
  73. TX.append( tx.split('.yml')[0] )
  74. RX = []
  75. for rx in kparams['rxCoils']:
  76. if rx not in kparams['txCoils']:
  77. print("new recv")
  78. Coil1 = em1d.PolygonalWireAntenna.DeSerialize( rx )
  79. Coil1.SetNumberOfFrequencies(1)
  80. Coil1.SetFrequency(0, fT)
  81. Coil1.SetCurrent(1.)
  82. Kern.PushCoil( rx.split('.yml')[0], Coil1 )
  83. else:
  84. print("reuse tx coil")
  85. RX.append( rx.split('.yml')[0] )
  86. ## TODO
  87. # pass this in...
  88. lmod = em1d.LayeredEarthEM()
  89. nlay = len(kparams["sigs"])
  90. sigs = np.array(kparams["sigs"])
  91. tops = np.array(kparams["tops"])
  92. bots = np.array(kparams["bots"])
  93. if ( (len(tops)-1) != len(bots)):
  94. print("Layer mismatch")
  95. exit()
  96. thicks = bots - tops[0:-1]
  97. lmod.SetNumberOfLayers(nlay + 1)
  98. lmod.SetLayerThickness(thicks)
  99. lmod.SetLayerConductivity( np.concatenate( ( [0.0], sigs ) ))
  100. #lmod.SetNumberOfLayers(4)
  101. #lmod.SetLayerThickness([15.49, 28.18])
  102. #lmod.SetLayerConductivity([0.0, 1./16.91, 1./24.06, 1./33.23])
  103. lmod.SetMagneticFieldIncDecMag( B_inc, B_dec, B0, lc.NANOTESLA )
  104. Kern.SetLayeredEarthEM( lmod );
  105. Kern.SetIntegrationSize( (kparams["size_n"], kparams["size_e"], kparams["size_d"]) )
  106. Kern.SetIntegrationOrigin( (kparams["origin_n"], kparams["origin_e"], kparams["origin_d"]) )
  107. Kern.SetTolerance( 1e-9*kparams["branchTol"] )
  108. Kern.SetMinLevel( kparams["minLevel"] )
  109. Kern.SetMaxLevel( kparams["maxLevel"] )
  110. Kern.SetHankelTransformType( lc.FHTKEY201 )
  111. Kern.AlignWithAkvoDataset( sys.argv[1] )
  112. if str(kparams["Lspacing"]).strip() == "Geometric":
  113. thick = np.geomspace(kparams["thick1"], kparams["thickN"], num=kparams["nLay"])
  114. elif str(kparams["Lspacing"]) == "Log":
  115. thick = np.logspace(kparams["thick1"], kparams["thickN"], num=kparams["nLay"])
  116. elif str(kparams["Lspacing"]) == "Linear":
  117. thick = np.linspace(kparams["thick1"], kparams["thickN"], num=kparams["nLay"])
  118. else:
  119. print("DOOOM!, in calcAkvoKernel layer spacing was not <Geometric>, <Log>, or <Linear>")
  120. print( str(kparams["Lspacing"]) )
  121. exit()
  122. iface = np.cumsum(thick)
  123. Kern.SetDepthLayerInterfaces(iface)
  124. #Kern.SetDepthLayerInterfaces(np.geomspace(1, 110, num=40))
  125. #Kern.SetDepthLayerInterfaces(np.linspace(1, 110, num=50))
  126. #Kern.SetDepthLayerInterfaces(np.geomspace(1, 110, num=40))
  127. # autAkvoDataNode = YAML::LoadFile(argv[4]);
  128. # Kern->AlignWithAkvoDataset( AkvoDataNode );
  129. #Kern.CalculateK0( ["Coil 1"], ["Coil 1"], False )
  130. Kern.CalculateK0( TX, RX, False )
  131. #yml = open( 'test' + str(Kern.GetTolerance()) + '.yaml', 'w')
  132. yml = open( sys.argv[3], 'w' )
  133. print(Kern, file=yml)
  134. #
  135. K0 = Kern.GetKernel()
  136. plt.matshow(np.abs(K0))
  137. plt.show()
  138. if __name__ == "__main__":
  139. main()