-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectSIAF.py
More file actions
293 lines (273 loc) · 14.6 KB
/
Copy pathselectSIAF.py
File metadata and controls
293 lines (273 loc) · 14.6 KB
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
139
140
141
142
143
144
145
146
147
148
149
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
###############################################################
# ASB-25623 Notebook to display Telescope/Instrument footprints on sky viewer
#
# ASB-25623 Brian McLean Initial prototype v0.1 2024-02-29
# ASB-27005 Brian McLean Add DS9 region output 2024-05-15
###############################################################
# Imports
import numpy as np
import pysiaf
from astropy.coordinates import SkyCoord
from regions import CircleSkyRegion, PolygonSkyRegion
###############################################################
# Take user input to create list of aperture siaf info and v2,v3 reference points
def defineApertures(selectedTelescope, selectedInstrument, selectedAperture):
# Create lists of individual apertures that make up selected instrument FOV and get v2,v3 of reference point
apertureList = []
if selectedTelescope.lower() == 'roman':
telescopeSiaf = pysiaf.Siaf(selectedTelescope)
if selectedInstrument.lower() == 'wfi':
if selectedAperture.lower() == 'all':
apertureNames = ['WFI01_FULL', 'WFI02_FULL', 'WFI03_FULL', 'WFI04_FULL', 'WFI05_FULL', 'WFI06_FULL',
'WFI07_FULL', 'WFI08_FULL', 'WFI09_FULL', 'WFI10_FULL', 'WFI11_FULL', 'WFI12_FULL',
'WFI13_FULL', 'WFI14_FULL', 'WFI15_FULL', 'WFI16_FULL', 'WFI17_FULL', 'WFI18_FULL']
V2Ref = telescopeSiaf.apertures['WFI_CEN'].V2Ref
V3Ref = telescopeSiaf.apertures['WFI_CEN'].V3Ref
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
elif selectedInstrument.lower() == 'cgi':
apertureNames = ['CGI_CEN']
V2Ref = telescopeSiaf.apertures['CGI_CEN'].V2Ref
V3Ref = telescopeSiaf.apertures['CGI_CEN'].V3Ref
elif selectedInstrument.lower() == 'all':
apertureNames = ['WFI01_FULL', 'WFI02_FULL', 'WFI03_FULL', 'WFI04_FULL', 'WFI05_FULL', 'WFI06_FULL',
'WFI07_FULL', 'WFI08_FULL', 'WFI09_FULL', 'WFI10_FULL', 'WFI11_FULL', 'WFI12_FULL',
'WFI13_FULL', 'WFI14_FULL', 'WFI15_FULL', 'WFI16_FULL', 'WFI17_FULL', 'WFI18_FULL',
'BORESIGHT', 'CGI_CEN']
V2Ref = 0.0
V3Ref = 0.0
else:
print('Unrecognized instrument')
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedTelescope.lower() == 'jwst':
if selectedInstrument.lower() == 'fgs':
telescopeSiaf = pysiaf.Siaf(selectedInstrument)
if selectedAperture.lower() == 'all':
apertureNames = ['FGS1_FULL', 'FGS2_FULL']
V2Ref = +100.0
V3Ref = -700.0
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'miri':
telescopeSiaf = pysiaf.Siaf(selectedInstrument)
if selectedAperture.lower() == 'all':
apertureNames = ['MIRIM_FULL', 'MIRIM_MASKLYOT',
'MIRIM_MASK1550', 'MIRIM_MASK1140', 'MIRIM_MASK1065']
V2Ref = -425.0
V3Ref = -375.0
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'nircam':
telescopeSiaf = pysiaf.Siaf(selectedInstrument)
if selectedAperture.lower() == 'all':
apertureNames = ['NRCA1_FULL', 'NRCA2_FULL', 'NRCA3_FULL', 'NRCA4_FULL', 'NRCA5_FULL',
'NRCB1_FULL', 'NRCB2_FULL', 'NRCB3_FULL', 'NRCB4_FULL', 'NRCB5_FULL']
V2Ref = 0.0
V3Ref = -500.0
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'nirspec':
telescopeSiaf = pysiaf.Siaf(selectedInstrument)
if selectedAperture.lower() == 'all':
apertureNames = ['NRS_FULL_MSA1', 'NRS_FULL_MSA2', 'NRS_FULL_MSA3', 'NRS_FULL_MSA4',
'NRS1_FULL', 'NRS2_FULL']
V2Ref = +375.0
V3Ref = -425.0
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'niriss':
telescopeSiaf = pysiaf.Siaf(selectedInstrument)
if selectedAperture.lower() == 'all':
apertureNames = ['NIS_CEN', 'NIS_AMIFULL']
V2Ref = -300.0
V3Ref = -700.0
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'all':
telescopeSiaf = pysiaf.Siaf('FGS')
apertureNames = ['FGS1_FULL', 'FGS2_FULL']
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
telescopeSiaf = pysiaf.Siaf('MIRI')
apertureNames = ['MIRIM_FULL', 'MIRIM_MASKLYOT',
'MIRIM_MASK1550', 'MIRIM_MASK1140', 'MIRIM_MASK1065']
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
telescopeSiaf = pysiaf.Siaf('NIRCAM')
apertureNames = ['NRCA1_FULL', 'NRCA2_FULL', 'NRCA3_FULL', 'NRCA4_FULL', 'NRCA5_FULL',
'NRCB1_FULL', 'NRCB2_FULL', 'NRCB3_FULL', 'NRCB4_FULL', 'NRCB5_FULL']
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
telescopeSiaf = pysiaf.Siaf('NIRSPEC')
apertureNames = ['NRS_FULL_MSA1', 'NRS_FULL_MSA2', 'NRS_FULL_MSA3', 'NRS_FULL_MSA4',
'NRS1_FULL', 'NRS2_FULL']
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
telescopeSiaf = pysiaf.Siaf('NIRISS')
apertureNames = ['NIS_CEN', 'NIS_AMIFULL']
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
V2Ref = 0.0
V3Ref = 0.0
else:
print('Unrecognized instrument')
elif selectedTelescope.lower() == 'hst':
telescopeSiaf = pysiaf.Siaf(selectedTelescope)
if selectedInstrument.lower() == 'acs':
if selectedAperture.lower() == 'all':
apertureNames = ['JWFC1', 'JWFC2', 'JHRC', 'JSBC']
V2Ref = telescopeSiaf.apertures['JWFCENTER'].V2Ref
V3Ref = telescopeSiaf.apertures['JWFCENTER'].V3Ref
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'cos':
if selectedAperture.lower() == 'all':
apertureNames = ['LFMAC', 'LNMAC']
V2Ref = telescopeSiaf.apertures['LFMAC'].V2Ref
V3Ref = telescopeSiaf.apertures['LFMAC'].V3Ref
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'fgs':
if selectedAperture.lower() == 'all':
apertureNames = ['FGS1', 'FGS2', 'FGS3']
V2Ref = 0.0
V3Ref = 0.0
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'nicmos':
if selectedAperture.lower() == 'all':
apertureNames = ['NIC1', 'NIC2', 'NIC3']
V2Ref = telescopeSiaf.apertures['NIC1'].V2Ref
V3Ref = telescopeSiaf.apertures['NIC1'].V3Ref
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'stis':
if selectedAperture.lower() == 'all':
apertureNames = ['OVIS', 'ONUV', 'OFUV']
V2Ref = telescopeSiaf.apertures['OVIS'].V2Ref
V3Ref = telescopeSiaf.apertures['OVIS'].V3Ref
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'wfc3':
if selectedAperture.lower() == 'all':
apertureNames = ['IUVIS1', 'IUVIS2', 'IIR']
V2Ref = telescopeSiaf.apertures['IIR'].V2Ref
V3Ref = telescopeSiaf.apertures['IIR'].V3Ref
else:
apertureNames = [selectedAperture]
V2Ref = telescopeSiaf.apertures[selectedAperture].V2Ref
V3Ref = telescopeSiaf.apertures[selectedAperture].V3Ref
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
elif selectedInstrument.lower() == 'all':
apertureNames = ['JWFC1', 'JWFC2', 'JHRC', 'JSBC',
'LFMAC',
'FGS1', 'FGS2', 'FGS3',
'NIC1', 'NIC2', 'NIC3',
'OVIS', 'ONUV', 'OFUV',
'IUVIS1', 'IUVIS2', 'IIR']
V2Ref = 0.0
V3Ref = 0.0
else:
print('Unrecognized instrument')
for name in apertureNames:
apertureList.append(telescopeSiaf[name])
else:
print('Unrecognized telescope')
return apertureList, V2Ref, V3Ref
###############################################################
# Find the selected aperture vertices
def getVertices(apertureSiaf):
if (apertureSiaf.observatory == 'Roman' and apertureSiaf.AperShape == 'QUAD'):
xVertices = np.array([apertureSiaf.XIdlVert1, apertureSiaf.XIdlVert2,
apertureSiaf.XIdlVert3, apertureSiaf.XIdlVert4])
yVertices = np.array([apertureSiaf.YIdlVert1, apertureSiaf.YIdlVert2,
apertureSiaf.YIdlVert3, apertureSiaf.YIdlVert4])
if (apertureSiaf.observatory == 'JWST' and apertureSiaf.AperShape == 'QUAD'):
xVertices = np.array([apertureSiaf.XIdlVert1, apertureSiaf.XIdlVert2,
apertureSiaf.XIdlVert3, apertureSiaf.XIdlVert4])
yVertices = np.array([apertureSiaf.YIdlVert1, apertureSiaf.YIdlVert2,
apertureSiaf.YIdlVert3, apertureSiaf.YIdlVert4])
if (apertureSiaf.observatory == 'HST' and (apertureSiaf.AperShape == 'QUAD' or apertureSiaf.AperShape == 'RECT')):
xVertices = np.array(
[apertureSiaf.v1x, apertureSiaf.v2x, apertureSiaf.v3x, apertureSiaf.v4x])
yVertices = np.array(
[apertureSiaf.v1y, apertureSiaf.v2y, apertureSiaf.v3y, apertureSiaf.v4y])
if (apertureSiaf.observatory == 'HST' and apertureSiaf.AperShape == 'CIRC'):
xVertices = apertureSiaf.V2Ref
yVertices = apertureSiaf.V3Ref
if (apertureSiaf.observatory == 'HST' and apertureSiaf.AperShape == 'PICK'):
print('Unsupported shape ', apertureSiaf.AperShape)
xVertices = None
yVertices = None
return xVertices, yVertices
###############################################################
# Take the sky coordinates of the aperture vertices and convert to an STC-S string
def computeStcsFootprint(apertureSiaf, skyRa, skyDec):
if (apertureSiaf.AperShape == 'QUAD' or apertureSiaf.AperShape == 'RECT'):
apertureSregion = 'POLYGON ICRS {:.8f} {:.8f} {:.8f} {:.8f} {:.8f} {:.8f} {:.8f} {:.8f} '.format(
skyRa[0], skyDec[0], skyRa[1], skyDec[1], skyRa[2], skyDec[2], skyRa[3], skyDec[3])
elif apertureSiaf.AperShape == 'CIRC':
radius = apertureSiaf.maj/3600.0
apertureSregion = 'CIRCLE ICRS {} {} {} '.format(skyRa, skyDec, radius)
else:
print('Unsupported shape {}').format(apertureSiaf.AperShape)
return apertureSregion
###############################################################
# Take the sky coordinates of the aperture vertices and convert to an SkyCoord region object
def computeRegionFootprint(apertureSiaf, skyRa, skyDec):
if (apertureSiaf.AperShape == 'QUAD' or apertureSiaf.AperShape == 'RECT'):
vertices = SkyCoord([skyRa[0], skyRa[1], skyRa[2], skyRa[3]], [
skyDec[0], skyDec[1], skyDec[2], skyDec[3]], unit='deg')
region_sky = PolygonSkyRegion(vertices=vertices)
elif apertureSiaf.AperShape == 'CIRC':
radius = apertureSiaf.maj/3600.0
center_sky = SkyCoord(skyRa, skyDec, unit='deg')
region_sky = CircleSkyRegion(center=center_sky, radius=radius)
else:
print('Unsupported shape {}').format(apertureSiaf.AperShape)
return region_sky
###############################################################