brukeropusreader/example.py

40 lines
1.1 KiB
Python
Raw Permalink Normal View History

import argparse
import sys
from brukeropusreader import read_file
def main(path_to_file):
print(f"Reading opus file from path" f"{path_to_file}")
opus_data = read_file(path_to_file)
print(f"Data fields: " f"{list(opus_data.keys())}")
ab_x = opus_data.get_range("AB")
2020-05-28 03:37:34 -04:00
# the "AB" data can contain more null values at the end (at least 1)
# so the getting useful data requires slicing the array:
abs = opus_data["AB"][0:len(ab_x)]
print(f"Absorption spectrum range: " f"{ab_x[0]} {ab_x[-1]}")
2020-05-28 03:37:34 -04:00
print(f"Absorption elements num: " f'{len(abs)}')
try:
import matplotlib.pyplot as plt
print("Plotting AB")
2020-05-28 03:37:34 -04:00
plt.plot(opus_data.get_range("AB"), abs)
plt.show()
print("Plotting interpolated AB")
plt.plot(*opus_data.interpolate(ab_x[0], ab_x[-1], 100))
plt.show()
except ImportError:
print(f"Install matplotlib to plot spectra")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("opus_path", help="Path to opus file", action="store")
args = parser.parse_args()
main(sys.argv[1])