Surface NMR processing and inversion GUI
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

plotyaml.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from ruamel import yaml
  2. import os, sys
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import seaborn as sns
  6. sns.set(style="ticks")
  7. import cmocean
  8. from SEGPlot import *
  9. from matplotlib.ticker import FormatStrFormatter
  10. import matplotlib.ticker as plticker
  11. def slicedict(d, s):
  12. return {k:v for k,v in d.items() if k.startswith(s)}
  13. # Converts Lemma/Merlin/Akvo serialized Eigen arrays into numpy ones for use by Python
  14. class VectorXr(yaml.YAMLObject):
  15. """
  16. Converts Lemma/Merlin/Akvo serialized Eigen arrays into numpy ones for use by Python
  17. """
  18. yaml_tag = u'VectorXr'
  19. def __init__(self, array):
  20. self.size = np.shape(array)[0]
  21. self.data = array.tolist()
  22. def __repr__(self):
  23. # Converts to numpy array on import
  24. return "np.array(%r)" % (self.data)
  25. class AkvoData(yaml.YAMLObject):
  26. """
  27. Reads an Akvo serialized dataset into a standard python dictionary
  28. """
  29. yaml_tag = u'AkvoData'
  30. def __init__(self, array):
  31. pass
  32. #self.size = np.shape(array)[0]
  33. #self.Imp = array.tolist()
  34. def __repr__(self):
  35. # Converts to a dictionary with Eigen vectors represented as Numpy arrays
  36. return self
  37. def loadAkvoData(fnamein):
  38. """ Loads data from an Akvo YAML file. The 0.02 is hard coded as the pulse length. This needs to be
  39. corrected in future kernel calculations. The current was reported but not the pulse length.
  40. """
  41. fname = (os.path.splitext(fnamein)[0])
  42. with open(fnamein, 'r') as stream:
  43. try:
  44. AKVO = (yaml.load(stream, Loader=yaml.Loader))
  45. except yaml.YAMLError as exc:
  46. print(exc)
  47. return AKVO
  48. def plotQt( akvo ):
  49. plt.style.use('ggplot')
  50. #plt.style.use('seaborn-white')
  51. for pulse in akvo.Gated:
  52. if pulse[0:5] == "Pulse":
  53. #print(akvo.GATED[pulse].keys())
  54. nq = akvo.Pulses[pulse]["current"].size
  55. for chan in slicedict(akvo.Gated[pulse], "Chan."):
  56. # accumulate pulse moments
  57. CA = np.zeros( (nq, len( akvo.Gated[pulse]["abscissa"].data )) )
  58. RE = np.zeros( (nq, len( akvo.Gated[pulse]["abscissa"].data )) )
  59. IM = np.zeros( (nq, len( akvo.Gated[pulse]["abscissa"].data )) )
  60. for q in range(nq):
  61. #plt.plot( akvo.Gated[pulse]["abscissa"].data, akvo.Gated[pulse][chan]["Q-" + str(q)+" CA"].data )
  62. CA[q] = akvo.Gated[pulse][chan]["Q-" + str(q)+" CA"].data
  63. RE[q] = akvo.Gated[pulse][chan]["Q-" + str(q)+" RE"].data
  64. IM[q] = akvo.Gated[pulse][chan]["Q-" + str(q)+" IM"].data
  65. #X[q] = akvo.Gated[pulse][chan]["Q-" + str(q)+" RE"].data
  66. Windows = akvo.Gated[pulse]["windows"].data
  67. Q = np.array(akvo.Pulses[pulse]["current"].data)
  68. print("pulse length ", akvo.pulseLength[0])
  69. Q *= akvo.pulseLength[0]
  70. fig = plt.figure( figsize=( pc2in(20), pc2in(26) ) )
  71. ax1 = fig.add_axes([.25,.05,.6,.9])
  72. im = ax1.pcolormesh(Windows,Q,CA, cmap=cmocean.cm.curl_r, vmin=-np.max(np.abs(CA)), vmax=(np.max(np.abs(CA))))
  73. cb = plt.colorbar( im, orientation='horizontal', pad=.175, )
  74. cb.set_label("FID (nV)", fontsize=10)
  75. cb.ax.tick_params(labelsize=10)
  76. ax1.set_yscale('log')
  77. ax1.set_ylabel("Q (A$\cdot$s)", fontsize=10)
  78. ax1.set_xscale('log')
  79. ax1.set_xlabel("time (s)", fontsize=10)
  80. #loc = plticker.MultipleLocator(25) #base=50.0) # this locator puts ticks at regular intervals
  81. #loc = plticker.MaxNLocator(5, steps=[1,2]) #base=50.0) # this locator puts ticks at regular intervals
  82. #ax1.xaxis.set_major_locator(loc)
  83. #ax1.xaxis.set_minor_locator(plticker.NullLocator())
  84. ax1.xaxis.set_major_formatter(FormatStrFormatter('%2.0f'))
  85. ax1.yaxis.set_major_formatter(FormatStrFormatter('%2.1f'))
  86. #plt.figure()
  87. #sns.kdeplot(Windows, Q, CA) #, kind="hex", color="#4CB391")
  88. #sns.heatmap(CA, annot=False, center=0)
  89. #plt.matshow(RE)
  90. #plt.matshow(IM)
  91. plt.savefig("data.pdf")
  92. plt.show()
  93. if __name__ == "__main__":
  94. akvo = loadAkvoData( sys.argv[1] ) #, "Chan. 1")
  95. plotQt(akvo)