-
Notifications
You must be signed in to change notification settings - Fork 35
/
example.py
39 lines (28 loc) · 1.11 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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")
# 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]}")
print(f"Absorption elements num: " f'{len(abs)}')
try:
import matplotlib.pyplot as plt
print("Plotting AB")
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])