-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasis_viewer.py
47 lines (40 loc) · 1.43 KB
/
basis_viewer.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
40
41
42
43
44
45
46
47
import ICAize as ize
import stack
import matplotlib.pyplot as plt
import numpy as np
from astropy.utils.compat import argparse
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Build and test models based on dim reductions and provided spectra'
)
parser.add_argument(
'--spectra_path', type=str, default='.', metavar='PATH',
help='Spectra path to work from, if not ''.'''
)
parser.add_argument(
'--method', type=str, default='ICA', metavar='METHOD',
help='Dim reduction method to load data for'
)
parser.add_argument(
'--file_path', type=str, default=None, metavar='FILE_PATH',
help='COMPLETE path from which to load a dim reduction'
)
args = parser.parse_args()
data_model = None
scaler = None
if args.file_path is not None:
data_model, scaler = ize.unpickle_model(filename=args.file_path)
else:
data_model, scaler = ize.unpickle_model(path=args.spectra_path, method=args.method)
components = ize.get_components(args.method, data_model)
offset = 0
for i, comp_i in enumerate(components):
if i > 0:
offset += np.max(np.abs(comp_i[comp_i < 0])) * 1.2
plt.plot(stack.skyexp_wlen_out, comp_i + offset)
offset += np.max(comp_i[comp_i > 0]) * 1.2
plt.show()
plt.close()
if __name__ == '__main__':
main()