-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
49 lines (38 loc) · 1.5 KB
/
manage.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
48
49
"""
Base module for CLI handling users requests for plotting and files conversion
"""
from pathlib import Path
import sys
BASE_DIR = 'output/ptTables'
def main():
"""
Handles commands running with `python manage.py`:
`python manage.py convert`: CLI-interactive command for converting ptbin PT-files to human-readable formats
`python manage.py plot`: CLI-interactive command for plotting spectra
"""
if len(sys.argv) < 2:
print("Usage: manage.py <command> [options]")
sys.exit(1)
command = sys.argv[1]
latest_run_file = Path(BASE_DIR) / 'latest_run.txt'
with open(latest_run_file, 'r') as f:
subdir = f.read().strip()
if not subdir:
sys.exit("Error: latest_run.txt is empty.")
if command == 'convert':
from handlers.convert import convert_pttable
level = int(input("Enter the level number: "))
convert_pttable(Path(BASE_DIR) / subdir, level)
elif command == 'plot':
from handlers.plot import generate_plot
from handlers.parsers import plot_parser
level = int(input("Enter the level number: "))
vl = float(input("Enter the left boundary for plot (cm-1): "))
vr = float(input("Enter the right boundary for plot (cm-1): "))
x_data, y_data, parameters = plot_parser(Path(BASE_DIR) / subdir, level, vl, vr)
generate_plot(x_data, y_data, parameters)
else:
print(f"Unknown command: {command}")
sys.exit(1)
if __name__ == '__main__':
main()