instrument.py 5.16 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
from typing import Optional
from .dict import DotDict
BO ZHANG's avatar
BO ZHANG committed
3
4
5


class Detector:
BO ZHANG's avatar
BO ZHANG committed
6
7
8
9
10
11
    def __init__(
        self,
        name: str = "01",
        is_effective: bool = True,
    ):
        self.name: str = name
BO ZHANG's avatar
BO ZHANG committed
12
13
14
15
16
17
        self.is_effective: bool = is_effective

    def __repr__(self):
        return f"<Detector: {self.name}, is_effective: {self.is_effective}>"


BO ZHANG's avatar
BO ZHANG committed
18
19
20
21
22
23
24
25
26
27
28
# d = Detector(name="01", is_effective=True)


class SimpleInstrument(DotDict):
    def __init__(self, name: str, detectors: list[Detector]):
        self._name = name
        super().__init__(**{d.name: d for d in detectors})

    @property
    def name(self):
        return self._name
BO ZHANG's avatar
BO ZHANG committed
29
30
31

    @property
    def detectors(self):
BO ZHANG's avatar
BO ZHANG committed
32
        return list(self.values())
BO ZHANG's avatar
BO ZHANG committed
33
34
35

    @property
    def detector_names(self):
BO ZHANG's avatar
BO ZHANG committed
36
        return list(self.keys())
BO ZHANG's avatar
BO ZHANG committed
37
38

    @property
BO ZHANG's avatar
BO ZHANG committed
39
40
    def n_detector(self):
        return len(self.detectors)
BO ZHANG's avatar
BO ZHANG committed
41
42

    @property
BO ZHANG's avatar
BO ZHANG committed
43
44
    def effective_detectors(self):
        return [d for d in self.detectors if d.is_effective]
BO ZHANG's avatar
BO ZHANG committed
45
46

    @property
BO ZHANG's avatar
BO ZHANG committed
47
48
    def effective_detector_names(self):
        return [d.name for d in self.detectors if d.is_effective]
BO ZHANG's avatar
BO ZHANG committed
49
50
51
52
53
54

    @property
    def n_effective_detector(self):
        return len(self.effective_detectors)

    def __repr__(self):
BO ZHANG's avatar
BO ZHANG committed
55
56
57
58
59
60
        return (
            f"<SimpleInstrument: {self.name}, "
            f"{self.n_detector} detectors, "
            f"{self.n_effective_detector} effective>"
        )

BO ZHANG's avatar
BO ZHANG committed
61

BO ZHANG's avatar
BO ZHANG committed
62
63
64
65
66
# detectors = [Detector(name=f"{_}") for _ in range(10)]
# si = SimpleInstrument(
#     name="SomeInstrument",
#     detectors=detectors,
# )
BO ZHANG's avatar
BO ZHANG committed
67
68


BO ZHANG's avatar
BO ZHANG committed
69
class ComplexInstrument(DotDict):
BO ZHANG's avatar
BO ZHANG committed
70
71
72
73
74
    def __init__(
        self,
        name: str,
        instruments: list[SimpleInstrument],
    ):
BO ZHANG's avatar
BO ZHANG committed
75
76
77
78
79
80
81
82
83
84
        super().__init__(**{i.name: i for i in instruments})
        self._name = name

    @property
    def name(self):
        return self._name

    @property
    def instruments(self):
        return list(self.values())
BO ZHANG's avatar
BO ZHANG committed
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

    @property
    def n_instrument(self):
        return len(self.instruments)

    @property
    def n_detector(self):
        return sum([i.n_detector for i in self.instruments])

    @property
    def n_effective_detector(self):
        return sum([i.n_effective_detector for i in self.instruments])

    @property
    def detectors(self):
        return [d for i in self.instruments for d in i.detectors]

    @property
    def detector_names(self):
        return [d.name for i in self.instruments for d in i.detectors]

    @property
    def effective_detectors(self):
        return [d for i in self.instruments for d in i.effective_detectors]

    @property
    def effective_detector_names(self):
        return [d.name for i in self.instruments for d in i.effective_detectors]

    def __repr__(self):
        str_instruments = ",".join([_.__repr__() for _ in self.instruments])
        return f"[ComplexInstrument: {self.name}, {str_instruments}]"


BO ZHANG's avatar
BO ZHANG committed
119
class Telescope(DotDict):
BO ZHANG's avatar
BO ZHANG committed
120
121
122
123
124
    def __init__(
        self,
        name: str,
        instruments: list[SimpleInstrument | ComplexInstrument],
    ):
BO ZHANG's avatar
BO ZHANG committed
125
126
127
128
129
130
131
132
133
134
        super().__init__(**{i.name: i for i in instruments})
        self._name = name

    @property
    def name(self):
        return self._name

    @property
    def instruments(self):
        return list(self.values())
BO ZHANG's avatar
BO ZHANG committed
135
136
137
138
139

    @property
    def n_instrument(self):
        return len(self.instruments)

BO ZHANG's avatar
BO ZHANG committed
140
141
142
143
144
    # def plan_to_detector(self, plan_data):
    #     # convert to dict
    #     plan_dict = dict(plan_data)
    #     if plan_dict["instrument"] == "HSTDM":

BO ZHANG's avatar
BO ZHANG committed
145
146
147
148

mbi = SimpleInstrument(
    name="MBI",
    detectors=[
BO ZHANG's avatar
BO ZHANG committed
149
        Detector(name=_, is_effective=True)
BO ZHANG's avatar
BO ZHANG committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
        for _ in [
            "06",
            "07",
            "08",
            "09",
            "11",
            "12",
            "13",
            "14",
            "15",
            "16",
            "17",
            "18",
            "19",
            "20",
            "22",
            "23",
            "24",
            "25",
        ]
    ],
)


sls = SimpleInstrument(
    name="SLS",
    detectors=[
BO ZHANG's avatar
BO ZHANG committed
177
        Detector(name=_, is_effective=True)
BO ZHANG's avatar
BO ZHANG committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
        for _ in [
            "01",
            "02",
            "03",
            "04",
            "05",
            "10",
            "21",
            "26",
            "27",
            "28",
            "29",
            "30",
        ]
    ],
)

ir = SimpleInstrument(
    name="IR",
    detectors=[Detector(name=f"IR{_}{_}", is_effective=False) for _ in range(1, 9)],
)

mci = SimpleInstrument(
    name="MCI",
BO ZHANG's avatar
BO ZHANG committed
202
    detectors=[Detector(name=_, is_effective=True) for _ in ["C1", "C2", "C3"]],
BO ZHANG's avatar
BO ZHANG committed
203
204
205
206
)

ifs = SimpleInstrument(
    name="IFS",
BO ZHANG's avatar
BO ZHANG committed
207
    detectors=[Detector(name=_, is_effective=True) for _ in ["B", "R"]],
BO ZHANG's avatar
BO ZHANG committed
208
209
210
211
)

cpic = SimpleInstrument(
    name="CPIC",
BO ZHANG's avatar
BO ZHANG committed
212
213
214
215
    detectors=[
        Detector(name="VIS", is_effective=True),
        Detector(name="NIR", is_effective=False),
    ],
BO ZHANG's avatar
BO ZHANG committed
216
217
218
219
)

hstdm = SimpleInstrument(
    name="HSTDM",
BO ZHANG's avatar
BO ZHANG committed
220
    detectors=[Detector(name=_) for _ in ["SIS1", "SIS2"]],
BO ZHANG's avatar
BO ZHANG committed
221
222
223
224
225
226
227
228
229
230
231
)

msc = ComplexInstrument(
    name="MSC",
    instruments=[mbi, sls, ir],
)

csst = Telescope(
    name="CSST",
    instruments=[msc, mci, ifs, cpic, hstdm],
)
BO ZHANG's avatar
BO ZHANG committed
232
233
234
235
236
237
238
239
240
241
242
243

# csst
# csst.MSC
# csst.MSC.MBI
# csst.MSC.SLS
# csst.MSC.IR
# csst.MCI
# csst.IFS
# csst.CPIC
# csst.HSTDM
# csst.HSTDM.effective_detectors
# csst.HSTDM.n_effective_detector