forked from lspestrip/striptease
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram_turnon.py
executable file
·138 lines (121 loc) · 4.05 KB
/
program_turnon.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
import logging as log
import re
from rich.logging import RichHandler
from turnon import TurnOnOffProcedure
from striptease import BOARD_TO_W_BAND_POL
DEFAULT_WAITTIME_S = 5.0
def unroll_polarimeters(pol_list):
board_horn_pol = re.compile(r"([GBPROYW][0-6]):(STRIP[0-9][0-9])")
for cur_pol in pol_list:
if cur_pol in ("V", "R", "O", "Y", "G", "B", "I"):
for idx in range(7):
yield (f"{cur_pol}{idx}", None)
# Include the W-band polarimeter
if cur_pol != "I":
yield (BOARD_TO_W_BAND_POL[cur_pol], None)
continue
else:
# Is this polarimeter in a form like "G0:STRIP33"?
m = board_horn_pol.match(cur_pol)
if m:
yield (m.group(1), m.group(2))
else:
yield (cur_pol, None)
if __name__ == "__main__":
from argparse import ArgumentParser, RawDescriptionHelpFormatter
parser = ArgumentParser(
description="Produce a command sequence to turn on one or more polarimeters",
formatter_class=RawDescriptionHelpFormatter,
epilog="""
Usage example:
python3 program_turnon.py --board 2 G0 G3 G4:STRIP33
""",
)
parser.add_argument(
"polarimeters",
metavar="POLARIMETER",
type=str,
nargs="+",
help="Name of the polarimeters/module to turn on. Valid names "
'are "G4", "Y" (meaning that all the 7 polarimeters will '
"be turned on, one after another), etc.",
)
parser.add_argument(
"--board",
metavar="NAME",
type=str,
dest="board",
required=True,
help="Name of the board to use",
)
parser.add_argument(
"--zero-bias",
action="store_true",
default=False,
help="Only set the LNAs to zero bias instead of turning them on to full nominal bias",
)
parser.add_argument(
"--bias-table-file",
metavar="FILE",
type=str,
default=None,
required=True,
help="Path to the Excel file containing the biases to use",
)
parser.add_argument(
"--turnoff",
action="store_true",
default=False,
help="If this flag is present, the procedure will turn the polarimeter *off*",
)
parser.add_argument(
"--det-offset",
default=None,
type=int,
help="Value of the ADC offset to be passed to all the polarimeters. "
"If not specified, the value will be taken from the Excel tables",
)
parser.add_argument(
"--output",
"-o",
metavar="FILENAME",
type=str,
dest="output_filename",
default="",
help="Name of the file where to write the output (in JSON format). "
"If not provided, the output will be sent to stdout.",
)
parser.add_argument(
"--wait-time-sec",
metavar="VALUE",
type=float,
dest="waittime_s",
default=DEFAULT_WAITTIME_S,
help="Time to wait after having altered the bias level for each amplifier "
f"(default: {DEFAULT_WAITTIME_S}, set to 0 to disable)",
)
parser.add_argument(
"--closed-loop",
action="store_true",
help="Set the polarimeter to closed loop mode after turnon, instead of "
"leaving it in open loop.",
)
args = parser.parse_args()
log.basicConfig(
level=log.INFO, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()]
)
proc = TurnOnOffProcedure(
waittime_s=args.waittime_s,
turnon=not args.turnoff,
zero_bias=args.zero_bias,
det_offset=args.det_offset,
bias_file_name=args.bias_table_file,
closed_loop=args.closed_loop,
)
for cur_horn, cur_polarimeter in unroll_polarimeters(args.polarimeters):
log.info("Processing horn %s, polarimeter %s", cur_horn, cur_polarimeter)
proc.set_board_horn_polarimeter(args.board, cur_horn, cur_polarimeter)
proc.run()
proc.output_json(args.output_filename)