Skip to content

Commit cf74f0c

Browse files
committed
updated to new version fix x.y+psffix1
1 parent 1056179 commit cf74f0c

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

tutorials/spherex/spherex_psf.md

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,27 @@ For more information about these changes, see the following webpage: [PSF Erratu
225225

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

228-
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-001` (which are superior to `6.5.4`, for example), we have to write a little wrapper function such that `Version()` can interpret these correctly.
228+
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.
229229

230230
```{code-cell} ipython3
231231
def parse_version(v):
232-
'''
233-
Parses versions correctly such that "6.5.4-001" is later than "6.5.5".
234-
'''
235-
if "-" in v:
236-
base, mod = v.split("-", 1)
237-
return (1, Version(base), int(mod)) # modified versions always rank higher
238-
else:
239-
return (0, Version(v), 0)
232+
# detect modifiers
233+
modifier = None
234+
base = v
235+
236+
if "+" in v:
237+
base, modifier = v.split("+", 1)
238+
239+
base_version = Version(base)
240+
241+
if modifier is None:
242+
return (0, base_version, 0)
243+
244+
# extract numeric part if present
245+
m = re.search(r'\d+', modifier)
246+
modnum = int(m.group()) if m else 0
247+
248+
return (1, base_version, modnum)
240249
```
241250

242251
Now, we can use this function to properly compare versions.
@@ -288,11 +297,25 @@ def update_psf_header(old_hdul):
288297
"""
289298
290299
def parse_version(v):
291-
if "-" in v:
292-
base, mod = v.split("-", 1)
293-
return (1, Version(base), int(mod)) # modified versions always rank higher
294-
else:
295-
return (0, Version(v), 0)
300+
# detect modifiers
301+
modifier = None
302+
base = v
303+
304+
if "+" in v:
305+
base, modifier = v.split("+", 1)
306+
elif "-" in v:
307+
base, modifier = v.split("-", 1)
308+
309+
base_version = Version(base)
310+
311+
if modifier is None:
312+
return (0, base_version, 0)
313+
314+
# extract numeric part if present
315+
m = re.search(r'\d+', modifier)
316+
modnum = int(m.group()) if m else 0
317+
318+
return (1, base_version, modnum)
296319
297320
## Check if old version
298321
this_version = parse_version( old_hdul['PRIMARY'].header["VERSION"] )
@@ -472,7 +495,7 @@ def update_psf_header(old_hdul):
472495
new_hdul.append(old.copy())
473496
474497
## TO DO: UPDATE VERSION
475-
new_hdul['PRIMARY'].header["VERSION"] = new_hdul['PRIMARY'].header["VERSION"] + "-001" # SET NEW VERSION HERE
498+
new_hdul['PRIMARY'].header["VERSION"] = new_hdul['PRIMARY'].header["VERSION"] + "+psffix1" # SET NEW VERSION HERE
476499
477500
return(new_hdul)
478501
```

0 commit comments

Comments
 (0)