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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import yaml
  2. import os, sys
  3. import numpy as np
  4. def slicedict(d, s):
  5. return {k:v for k,v in d.items() if k.startswith(s)}
  6. # Converts Lemma/Merlin/Akvo serialized Eigen arrays into numpy ones for use by Python
  7. class VectorXr(yaml.YAMLObject):
  8. """
  9. Converts Lemma/Merlin/Akvo serialized Eigen arrays into numpy ones for use by Python
  10. """
  11. yaml_tag = u'VectorXr'
  12. def __init__(self, array):
  13. self.size = np.shape(array)[0]
  14. self.data = array.tolist()
  15. def __repr__(self):
  16. # Converts to numpy array on import
  17. return "np.array(%r)" % (self.data)
  18. class AkvoData(yaml.YAMLObject):
  19. """
  20. Reads an Akvo serialized dataset into a standard python dictionary
  21. """
  22. yaml_tag = u'AkvoData'
  23. def __init__(self, array):
  24. pass
  25. #self.size = np.shape(array)[0]
  26. #self.Imp = array.tolist()
  27. def __repr__(self):
  28. # Converts to a dictionary with Eigen vectors represented as Numpy arrays
  29. return self
  30. def loadAkvoData(fnamein, chan):
  31. """ Loads data from an Akvo YAML file. The 0.02 is hard coded as the pulse length. This needs to be
  32. corrected in future kernel calculations. The current was reported but not the pulse length.
  33. """
  34. fname = (os.path.splitext(fnamein)[0])
  35. with open(fnamein, 'r') as stream:
  36. try:
  37. AKVO = (yaml.load(stream))
  38. except yaml.YAMLError as exc:
  39. print(exc)
  40. return AKVO
  41. def plotQt( akvo ):
  42. import matplotlib.pyplot as plt
  43. plt.style.use('ggplot')
  44. for pulse in akvo.Gated:
  45. if pulse[0:5] == "Pulse":
  46. #print(akvo.GATED[pulse].keys())
  47. nq = akvo.Pulses[pulse]["current"].size
  48. for chan in slicedict(akvo.Gated[pulse], "Chan."):
  49. # accumulate pulse moments
  50. X = np.zeros( (nq, len( akvo.Gated[pulse]["abscissa"].data )) )
  51. for q in range(nq):
  52. plt.plot( akvo.Gated[pulse]["abscissa"].data, akvo.Gated[pulse][chan]["Q-" + str(q)+" CA"].data )
  53. X[q] = akvo.Gated[pulse][chan]["Q-" + str(q)+" CA"].data
  54. plt.matshow(X)
  55. plt.show()
  56. if __name__ == "__main__":
  57. akvo = loadAkvoData( sys.argv[1] , "Chan. 1")
  58. plotQt(akvo)