Surface NMR processing and inversion GUI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plotData.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. Centres = akvo.Gated[pulse]["abscissa"].data
  68. Q = np.array(akvo.Pulses[pulse]["current"].data)
  69. print("pulse length ", akvo.pulseLength[0])
  70. Q *= akvo.pulseLength[0]
  71. fig = plt.figure( figsize=( pc2in(20), pc2in(26) ) )
  72. ax1 = fig.add_axes([.25,.05,.6,.9])
  73. #im = ax1.pcolormesh(Windows, Q, CA, cmap=cmocean.cm.curl_r, vmin=-np.max(np.abs(CA)), vmax=(np.max(np.abs(CA))))
  74. im = ax1.pcolormesh(Centres, Q, CA, cmap=cmocean.cm.curl_r, vmin=-np.max(np.abs(CA)), vmax=(np.max(np.abs(CA))))
  75. cb = plt.colorbar( im, orientation='horizontal', pad=.175, )
  76. cb.set_label("FID (nV)", fontsize=10)
  77. cb.ax.tick_params(labelsize=10)
  78. ax1.set_yscale('log')
  79. ax1.set_ylabel("Q (A$\cdot$s)", fontsize=10)
  80. ax1.set_xscale('log')
  81. ax1.set_xlabel("time (s)", fontsize=10)
  82. #loc = plticker.MultipleLocator(25) #base=50.0) # this locator puts ticks at regular intervals
  83. #loc = plticker.MaxNLocator(5, steps=[1,2]) #base=50.0) # this locator puts ticks at regular intervals
  84. #ax1.xaxis.set_major_locator(loc)
  85. #ax1.xaxis.set_minor_locator(plticker.NullLocator())
  86. ax1.xaxis.set_major_formatter(FormatStrFormatter('%2.0f'))
  87. ax1.yaxis.set_major_formatter(FormatStrFormatter('%2.1f'))
  88. #plt.figure()
  89. #sns.kdeplot(Windows, Q, CA) #, kind="hex", color="#4CB391")
  90. #sns.heatmap(CA, annot=False, center=0)
  91. #plt.matshow(RE)
  92. #plt.matshow(IM)
  93. plt.savefig("data.pgf")
  94. plt.savefig("data.png", dpi=300)
  95. plt.show()
  96. if __name__ == "__main__":
  97. akvo = loadAkvoData( sys.argv[1] ) #, "Chan. 1")
  98. plotQt(akvo)