Skip to content

Commit e2b4ab7

Browse files
committed
Apply feedback from tgoldina review
1 parent 9df1255 commit e2b4ab7

1 file changed

Lines changed: 25 additions & 47 deletions

File tree

tutorials/spherex/spherex_psf.md

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -228,42 +228,20 @@ For more information about these changes, see the following webpage: [PSF Erratu
228228

229229
Let's first check here if a header update is necessary. We can do that by printing the `VERSION` keyword in the header.
230230

231-
For comparisons versions, we can use the Python-internal `Version()` function from the `packaging.version` package. However, since reprocessed images can have version names such as `6.5.4+psffix1` (which are superior to `6.5.4`, for example), we have to write a little wrapper function such that `Version()` can interpret these correctly.
231+
For comparing versions, we can use the Python-internal `Version()` function from the `packaging.version` package. Images that have already been reprocessed can have version names such as `6.5.4+psffix1` (which are superior to `6.5.4`, for example), and we can use `Version().local` to check for those.
232232

233233
```{code-cell} ipython3
234-
def parse_version(v):
235-
# detect modifiers
236-
modifier = None
237-
base = v
238-
239-
if "+" in v:
240-
base, modifier = v.split("+", 1)
241-
242-
base_version = Version(base)
243-
244-
if modifier is None:
245-
return (0, base_version, 0)
246-
247-
# extract numeric part if present
248-
m = re.search(r'\d+', modifier)
249-
modnum = int(m.group()) if m else 0
250-
251-
return (1, base_version, modnum)
252-
```
253-
254-
Now, we can use this function to properly compare versions.
255-
256-
```{code-cell} ipython3
257-
this_version = parse_version( image_hdul['PRIMARY'].header["VERSION"] )
234+
this_version = Version(image_hdul['PRIMARY'].header["VERSION"])
235+
contains_psffix1 = this_version.local is not None and "psffix1" in this_version.local
258236
print(f"Current version is {this_version}")
259237
260-
if this_version <= parse_version("6.5.5"):
238+
if this_version <= Version("6.5.5") and not contains_psffix1:
261239
print("PSF header needs to be updated! -> Go to Section 5.1 :(")
262240
else:
263241
print("PSF header is already up-to-date! -> Proceed to Section 6 :)")
264242
```
265243

266-
If the version of the SPHEREx spectral image is less or equal than `6.5.5`, we will have to update the header. This is explained in Section 5.1. If the version is later than `6.5.5`, the header is already updated and the PSF issue is fixed. In this case, proceed to Section 6 directly.
244+
If the version of the SPHEREx spectral image is less or equal than `6.5.5` and hasn't already been reprocessed, we will have to update the header. This is explained in Section 5.1. If the version is later than `6.5.5` or includes `"psffix1"`, the header is already updated and the PSF issue is fixed. In this case, proceed to Section 6 directly.
267245

268246
+++
269247

@@ -299,32 +277,32 @@ def update_psf_header(old_hdul):
299277
New SPHEREx Spectral Image HDUL with updated PSF zone data in header and updated version number
300278
"""
301279
302-
def parse_version(v):
303-
# detect modifiers
304-
modifier = None
305-
base = v
280+
VERSION_FIXED = Version("6.5.6")
281+
PSF_FIX_TAG = "psffix1"
306282
307-
if "+" in v:
308-
base, modifier = v.split("+", 1)
283+
def psf_fix_applied(hdul) -> bool:
284+
"""
285+
Return True if the PSF fix has been applied.
286+
287+
Rules:
288+
- If the VERSION header is missing in the primary HDU, the fix is not applied.
289+
- If VERSION >= VERSION_FIXED, the fix is included in the software release.
290+
- Otherwise the local version tag (+...) must contain PSF_FIX_TAG.
291+
"""
292+
header = hdul[0].header
309293
310-
base_version = Version(base)
294+
if "VERSION" not in header:
295+
return False
311296
312-
if modifier is None:
313-
return (0, base_version, 0)
297+
v = Version(header["VERSION"])
314298
315-
# extract numeric part if present
316-
m = re.search(r'\d+', modifier)
317-
modnum = int(m.group()) if m else 0
299+
if v >= VERSION_FIXED:
300+
return True
318301
319-
return (1, base_version, modnum)
302+
return v.local is not None and PSF_FIX_TAG in v.local
320303
321-
## Check if old version
322-
this_version = parse_version( old_hdul['PRIMARY'].header["VERSION"] )
323-
if this_version <= parse_version("6.5.5"):
324-
print(f"Old version detected ({this_version}) -> Update header.")
325-
elif this_version > Version("6.5.5"):
326-
print(f"New version detected ({this_version}) -> Do not update header.")
327-
return(old_hdul)
304+
if psf_fix_applied(old_hdul):
305+
return old_hdul
328306
329307
## Define some auxiliary functions -------
330308
def parse_ixiy_from_comment(comment):

0 commit comments

Comments
 (0)