Surface NMR processing and inversion GUI
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. from SEGPlot import *
  2. import sys
  3. sys.path.append( '../tressel' )
  4. import matplotlib.pyplot as plt
  5. import matplotlib.ticker
  6. import scipy.io as sio
  7. import scipy.signal as signal
  8. import numpy as np
  9. import mrsurvey
  10. import pickle
  11. import decay
  12. import cmaps
  13. plt.register_cmap(name='viridis', cmap=cmaps.viridis)
  14. plt.register_cmap(name='inferno', cmap=cmaps.inferno)
  15. plt.register_cmap(name='inferno_r', cmap=cmaps.inferno_r)
  16. plt.register_cmap(name='magma', cmap=cmaps.magma)
  17. plt.register_cmap(name='magma_r', cmap=cmaps.magma_r)
  18. class canvas():
  19. def __init__(self):
  20. self.fig = plt.figure( figsize=(pc2in(20),pc2in(20) ) )
  21. self.ax1 = self.fig.add_subplot((211))
  22. self.ax2 = self.fig.add_subplot((212), sharex=self.ax1)
  23. def draw(self):
  24. plt.draw()
  25. def reAx2(self):
  26. try:
  27. self.fig.clear()
  28. except:
  29. pass
  30. try:
  31. self.ax1.clear()
  32. self.delaxes(self.ax1) #.clear()
  33. except:
  34. pass
  35. try:
  36. self.ax2.clear()
  37. self.delaxes(self.ax2) #.clear()
  38. except:
  39. pass
  40. self.ax1 = self.fig.add_subplot(211)
  41. self.ax2 = self.fig.add_subplot(212)
  42. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  43. self.ax2.tick_params(axis='both', which='major', labelsize=8)
  44. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  45. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  46. self.ax1.yaxis.get_offset_text().set_size(8)
  47. self.ax2.yaxis.get_offset_text().set_size(8)
  48. def reAx4(self):
  49. try:
  50. self.fig.clear()
  51. except:
  52. pass
  53. # two main axes
  54. self.ax1 = self.fig.add_axes([0.15, 0.55, 0.625, 0.3672])
  55. self.ax2 = self.fig.add_axes([0.15, 0.135 , 0.625, 0.3672])
  56. # for colourbars
  57. self.cax1 = self.fig.add_axes([0.8, 0.55 , 0.025, 0.3672])
  58. self.cax2 = self.fig.add_axes([0.8, 0.135, 0.025, 0.3672])
  59. self.ax1.tick_params(axis='both', which='major', labelsize=8)
  60. self.ax2.tick_params(axis='both', which='major', labelsize=8)
  61. self.ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  62. self.ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  63. self.ax1.yaxis.get_offset_text().set_size(8)
  64. self.ax2.yaxis.get_offset_text().set_size(8)
  65. self.cax1.tick_params(axis='both', which='major', labelsize=8)
  66. self.cax2.tick_params(axis='both', which='major', labelsize=8)
  67. self.cax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  68. self.cax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
  69. self.cax1.yaxis.get_offset_text().set_size(8) #.get_text()
  70. self.cax2.yaxis.get_offset_text().set_size(8) #.get_text()
  71. self.cax1.tick_params(labelsize=8)
  72. self.cax2.tick_params(labelsize=8)
  73. #self.ax1.yaxis.minorticks_off()
  74. #self.ax2.yaxis.minorticks_off()
  75. plt.tick_params(
  76. axis='y', # changes apply to the x-axis
  77. which='minor', # both major and minor ticks are affected
  78. bottom='off', # ticks along the bottom edge are off
  79. top='off', # ticks along the top edge are off
  80. labelbottom='off')
  81. if __name__ == "__main__":
  82. first = True
  83. for ffile in sys.argv[1::]:
  84. Canvas = canvas()
  85. pfile = file(ffile)
  86. unpickle = pickle.Unpickler(pfile)
  87. MRS = mrsurvey.GMRDataProcessor()
  88. MRS.DATADICT = unpickle.load()
  89. MRS.pulseType = MRS.DATADICT["INFO"]["pulseType"]
  90. MRS.transFreq = MRS.DATADICT["INFO"]["transFreq"]
  91. MRS.pulseLength = MRS.DATADICT["INFO"]["pulseLength"]
  92. MRS.TuneCapacitance = MRS.DATADICT["INFO"]["TuneCapacitance"]
  93. MRS.samp = MRS.DATADICT["INFO"]["samp"]
  94. MRS.nPulseMoments = MRS.DATADICT["INFO"]["nPulseMoments"]
  95. MRS.deadTime = MRS.DATADICT["INFO"]["deadTime"]
  96. MRS.quadDet(1, True, Canvas)
  97. MRS.gateIntegrate(14, 1, Canvas )
  98. #Canvas.fig.suptitle(r"\textbf{Experiment 0, channel 4}", fontsize=8) #, fontweight='bold')
  99. Canvas.ax1.set_title(r"Experiment 0, channel 4", fontsize=8)
  100. #Canvas.ax1.set_title("Channel 4")
  101. plt.savefig("test.eps", dpi=2200)
  102. if first:
  103. mat = MRS.DATADICT["CA"]
  104. pmat = MRS.DATADICT["CP"]
  105. first = False
  106. else:
  107. mat += MRS.DATADICT["CA"]
  108. pmat += MRS.DATADICT["CP"]
  109. quadSum = True
  110. if quadSum:
  111. Canvas.ax1.clear()
  112. Canvas.ax2.clear()
  113. Canvas.cax1.clear()
  114. Canvas.cax2.clear()
  115. pulse = "Pulse 1"
  116. clip = 1
  117. QQ = np.average(MRS.DATADICT[pulse]["Q"], axis=1 )
  118. im1 = Canvas.ax1.pcolormesh( 1e3*MRS.DATADICT[pulse]["TIMES"][clip-1:-clip], QQ, mat, cmap='coolwarm_r', rasterized=True, vmin=-np.max(np.abs(mat)), vmax=np.max(np.abs(mat)))
  119. im2 = Canvas.ax2.pcolormesh( 1e3*MRS.DATADICT[pulse]["TIMES"][clip-1:-clip], QQ, pmat, cmap='coolwarm_r', rasterized=True, vmin=-np.max(np.abs(pmat)), vmax=np.max(np.abs(pmat)))
  120. cb2 = Canvas.fig.colorbar(im2, cax=Canvas.cax2)
  121. cb2.set_label("Noise residual (nV)", fontsize=8)
  122. #canvas.ax2.yaxis.set_ticks( QQ[0,9::7] )
  123. Canvas.ax1.set_yscale('log')
  124. Canvas.ax2.set_yscale('log')
  125. qlabs = np.append(np.concatenate( (QQ[0:1],QQ[9::10] )), QQ[-1] )
  126. Canvas.ax1.yaxis.set_ticks( qlabs ) # np.append(np.concatenate( (QQ[0:1],QQ[9::10] )), QQ[-1] ) )
  127. Canvas.ax2.yaxis.set_ticks( qlabs ) #np.append(np.concatenate( (QQ[0:1],QQ[9::10] )), QQ[-1] ) )
  128. #formatter = matplotlib.ticker.LogFormatter(10, labelOnlyBase=False)
  129. formatter = matplotlib.ticker.FuncFormatter(lambda x, pos: str((round(x,1))))
  130. Canvas.ax1.yaxis.set_major_formatter(formatter)#matplotlib.ticker.FormatStrFormatter('%d.1'))
  131. Canvas.ax2.yaxis.set_major_formatter(formatter)#matplotlib.ticker.FormatStrFormatter('%d.1'))
  132. plt.setp(Canvas.ax1.get_xticklabels(), visible=False)
  133. t = 1e3*MRS.DATADICT[pulse]["TIMES"][clip-1:-clip],
  134. Canvas.ax1.set_ylim( np.min(QQ), np.max(QQ) )
  135. Canvas.ax2.set_ylim( np.min(QQ), np.max(QQ) )
  136. Canvas.ax1.set_xlim( np.min(t), np.max(t) )
  137. Canvas.ax2.set_xlim( np.min(t), np.max(t) )
  138. cb1 = Canvas.fig.colorbar(im1, cax=Canvas.cax1)
  139. cb1.set_label("Phased amplitude (nV)", fontsize=8)
  140. Canvas.ax2.set_xlabel(r"Time (ms)", fontsize=8)
  141. Canvas.ax1.set_ylabel(r"$q$ ( $\mathrm{A}\cdot\mathrm{s}$)", fontsize=8)
  142. Canvas.ax2.set_ylabel(r"$q$ ( $\mathrm{A}\cdot\mathrm{s}$)", fontsize=8)
  143. plt.savefig("quadSum.eps")
  144. plt.show()