forked from simonsobs/sotodlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hardware.py
136 lines (118 loc) · 5.2 KB
/
test_hardware.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
# Copyright (c) 2018-2019 Simons Observatory.
# Full license can be found in the top level "LICENSE" file.
"""Test hardware model creation, dump, and load.
"""
import os
import unittest
from unittest import TestCase
from collections import OrderedDict
from sotodlib.core import Hardware
from sotodlib.sim_hardware import sim_nominal
from sotodlib.vis_hardware import plot_detectors
from ._helpers import create_outdir, mpi_multi
try:
# Import sotodlib toast module first, which sets global toast defaults
import sotodlib.toast as sotoast
import toast
from sotodlib.toast import sim_focalplane as toastsf
toast_available = True
except ImportError:
toast_available = False
@unittest.skipIf(mpi_multi(), "Running with multiple MPI processes")
class HardwareTest(TestCase):
def setUp(self):
fixture_name = os.path.splitext(os.path.basename(__file__))[0]
self.outdir = create_outdir(fixture_name)
self.skip_plots = False
if "SOTODLIB_TEST_DISABLE_PLOTS" in os.environ:
self.skip_plots = os.environ["SOTODLIB_TEST_DISABLE_PLOTS"]
def test_config_example(self):
outpath = os.path.join(self.outdir, "hardware_example.toml.gz")
hw = sim_nominal()
hw.dump(outpath, overwrite=True, compress=True)
hwcheck = Hardware(outpath)
checkpath = os.path.join(self.outdir, "hardware_example_check.toml.gz")
hwcheck.dump(checkpath, overwrite=True, compress=True)
return
def test_sim_wafer(self):
if not toast_available:
print("TOAST cannot be imported- skipping unit test", flush=True)
return
hw = sim_nominal()
# Simulate some wafers
for tele, teleprops in hw.data["telescopes"].items():
if tele != "SAT1":
continue
platescale = teleprops["platescale"]
fwhm = teleprops["fwhm"]
for tube_slot in teleprops["tube_slots"]:
if tube_slot != "ST1":
continue
tubeprops = hw.data["tube_slots"][tube_slot]
for wafer in tubeprops["wafer_slots"]:
if wafer != "w25":
continue
outpath = os.path.join(
self.outdir, "wafer_{}.toml.gz".format(wafer))
del hw.data["detectors"]
dets = toastsf.sim_wafer_detectors(hw, wafer, platescale, fwhm)
hw.data["detectors"] = dets
hw.dump(outpath, overwrite=True, compress=True)
if not self.skip_plots:
outpath = os.path.join(
self.outdir,
"wafer_{}.pdf".format(wafer)
)
plot_detectors(hw.data["detectors"], outpath, labels=True)
return
def test_sim_telescope(self):
if not toast_available:
print("TOAST cannot be imported- skipping unit test", flush=True)
return
fullhw = sim_nominal()
# SAT test
toastsf.sim_telescope_detectors(fullhw, "SAT1")
hw = fullhw.select(match={"wafer_slot": ["w25",],})
outpath = os.path.join(self.outdir, "telescope_SAT1_w25.toml.gz")
hw.dump(outpath, overwrite=True, compress=True)
if not self.skip_plots:
outpath = os.path.join(self.outdir, "telescope_SAT1_w25.pdf")
plot_detectors(hw.data["detectors"], outpath, labels=False)
fullhw.data["detectors"] = OrderedDict()
# LAT test
toastsf.sim_telescope_detectors(fullhw, "LAT")
hw = fullhw.select(match={"tube_slots": ["c1",],})
outpath = os.path.join(self.outdir, "telescope_LAT_c1.toml.gz")
hw.dump(outpath, overwrite=True, compress=True)
if not self.skip_plots:
outpath = os.path.join(self.outdir, "telescope_LAT_c1.pdf")
plot_detectors(hw.data["detectors"], outpath, labels=False)
return
def test_sim_full(self):
if not toast_available:
print("TOAST cannot be imported- skipping unit test", flush=True)
return
hw = sim_nominal()
for tele, teleprops in hw.data["telescopes"].items():
if tele != "SAT1":
continue
toastsf.sim_telescope_detectors(hw, tele)
dbpath = os.path.join(self.outdir, "hardware_SAT1.toml.gz")
hw.dump(dbpath, overwrite=True, compress=True)
check = Hardware(dbpath)
# Test selection of 90GHz detectors on wafers 25 and 26 which have
# "A" polarization configuration and are located in pixels 20-29.
wbhw = hw.select(
match={"wafer_slot": ["w25", "w26"],
"band": "SAT_f090",
"pol": "A",
"pixel": "02."})
dbpath = os.path.join(self.outdir, "w25-26_p20-29_SAT_f090_A.toml.gz")
wbhw.dump(dbpath, overwrite=True, compress=True)
check = Hardware(dbpath)
self.assertTrue(len(check.data["detectors"]) == 20)
chkpath = os.path.join(self.outdir, "w25-26_p20-29_SAT_f090_A.txt")
with open(chkpath, "w") as f:
for d in check.data["detectors"]:
f.write("{}\n".format(d))
return