You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/spherex/spherex_psf.md
+288-4Lines changed: 288 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,10 +21,20 @@ kernelspec:
21
21
22
22
+++
23
23
24
+
```{warning}
25
+
In the SPHEREx spectral image versions prior to XXXX, there was a missmatch between the spatial layout of the PSF zones and the the indexing of the PSF zones in the header. This has now been fixed in versions post XXXX.
26
+
However, users using the old versions will need to implement and extra step (described below in Section 5) to update the image header.
27
+
28
+
For more information, see the following webpage: [PSF Erratum](WEBPAGE)
29
+
```
30
+
31
+
+++
32
+
24
33
## 1. Learning Goals
25
34
26
35
* Determine how pixels in a SPHEREx cutout map to the pixels in the parent SPHEREx spectral image.
27
36
* Understand the structure of the PSF extension in a SPHEREx cutout (which is the same as the PSF extension in the parent spectral image)
37
+
* Learn how to tell which version of the SPHEREx spectral image you are looking at, and how to interpret this information to obtain the correct PSF extension for the SPHEREx spectral images.
28
38
* Learn which plane in a SPHEREx cutout PSF extension cube most accurately describes the coordinates you are interested in.
29
39
30
40
+++
@@ -59,6 +69,7 @@ import http.client
59
69
import re
60
70
import time
61
71
import urllib.error
72
+
import copy
62
73
63
74
import astropy.units as u
64
75
import matplotlib.pyplot as plt
@@ -120,10 +131,10 @@ print("Time to do TAP query: {:2.2f} seconds.".format(time.time() - t1))
120
131
print("Number of images found: {}".format(len(results)))
121
132
```
122
133
123
-
:::{note}
134
+
```{note}
124
135
SPHEREx data are also available via SIA which can provide a simpler interface for many queries, as demonstrated in {ref}`spherex-intro`.
125
136
An advantage of the method shown above is that it provides access to data immediately after ingestion (which occurs weekly) and is not subject to the same ~1 day delay as SIA.
126
-
:::
137
+
```
127
138
128
139
For this example, we focus on the first one of the retrieved SPHEREx spectral images.
129
140
@@ -148,6 +159,7 @@ for attempt in range(max_retries):
148
159
try:
149
160
# Read the data.
150
161
with fits.open(spectral_image_url) as hdul:
162
+
image_hdul = copy.deepcopy(hdul)
151
163
cutout_header = hdul['IMAGE'].header
152
164
psf_header = hdul['PSF'].header
153
165
cutout = hdul['IMAGE'].data
@@ -183,10 +195,282 @@ This means that the actual size of the PSFs is about 10x10 SPHEREx pixels, which
183
195
184
196
+++
185
197
186
-
Let's look at a small part of the PSF header to understand its format:
198
+
Let's look at a small part of the PSF header to understand its format.
199
+
200
+
```{code-cell} ipython3
201
+
psf_header[0:30]
202
+
```
203
+
204
+
We confirm that the oversampling factor (`OVERSAMP`) is 10.
205
+
The PSFs are distributed in an even grid with 11x11 zones.
206
+
Each of the 121 PSFs is responsible for one of these zones.
207
+
The PSF header therefore includes the center position of these zones as well as the width of the zones.
208
+
These center coordinate are specified with `XCTR_i` and `YCTR_i`, respectively, where i = 1...121.
209
+
The widths are specified with `XWID_i` and `YWID_i`, respectively, where again i = 1...121.
210
+
The zones have approximately equal widths and are arranged in an even grid.
211
+
The size of the zones is sufficient to capture well the changes of the PSF size and structure with wavelength and spatial coordinates.
212
+
213
+
The goal of this tutorial now is to find the PSF corresponding to our input coordinates of interest.
214
+
215
+
+++
216
+
217
+
```{warning}
218
+
In the SPHEREx spectral image versions prior to XXXX, there was a missmatch between the spatial layout of the PSF zones and the the indexing of the PSF zones in the header. This has now been fixed in versions post XXXX.
219
+
220
+
For more information, see the following webpage: [PSF Erratum](WEBPAGE)
221
+
222
+
**Users using the old versions will need to implement and extra step (described below) to update the image header.**
223
+
```
224
+
225
+
Let's first check if a header update is necessary. We can do that by checking the `VERSION` keyword in the header.
226
+
227
+
```{code-cell} ipython3
228
+
image_hdul['PRIMARY'].header["VERSION"]
229
+
```
230
+
231
+
If the version of the SPHEREx spectral image is less than `6.4`, we will have to update the header. This is explained in Section 5.1. If the version is later than `6.4`, the header is already updated and the PSF issue is fixed. In this case, proceed to Section 6 directly.
232
+
233
+
+++
234
+
235
+
### 5.1 Updating Old SPHEREx Spectral Image Data (`VERSIONS` < XXX)
236
+
237
+
+++
238
+
239
+
The function that can be used to update the header is shown below. The function
240
+
* first checks if a header update is necessary
241
+
* changes the PSF zone indexing and
242
+
* changes the version of the header such that it is consistent with the new released images
243
+
244
+
Note that this function an work as standalone function to process many images.
245
+
246
+
```{code-cell} ipython3
247
+
def update_psf_header(old_hdul):
248
+
"""
249
+
Fix a old PSF FITS file header by rewriting only the per-plane header metadata
250
+
so that plane k corresponds to x-fast ordering:
251
+
k0 = iy * bins_x + ix
252
+
253
+
The cube data are left untouched.
254
+
255
+
Parameters
256
+
----------
257
+
old_hdul : astropy hdul
258
+
Old SPHEREx Spectral Image HDUL
259
+
260
+
Return
261
+
----------
262
+
new_hdul : astropy hdul
263
+
New SPHEREx Spectral Image HDUL with updated PSF zone data in header and updated version number
0 commit comments