Surface NMR processing and inversion GUI
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

calcAkvoKernel.py 5.3KB

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