Skip to content

Commit eabc89a

Browse files
committed
match case
1 parent dcb5b22 commit eabc89a

1 file changed

Lines changed: 32 additions & 38 deletions

File tree

src/histutils/solis.py

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import tifffile
88
except ImportError:
99
tifffile = None
10-
try:
11-
from astropy.io import fits
12-
except ImportError:
13-
fits = None
10+
11+
from astropy.io import fits
1412

1513
from .rawDMCreader import howbig # , whichframes
1614
from .timedmc import frame2ut1
@@ -19,11 +17,9 @@
1917
def getNeoParam(
2018
fn: Path,
2119
FrameIndReq=None,
22-
ut1req=None,
2320
kineticsec=None,
2421
startUTC=None,
25-
cmosinit: dict | None = None,
26-
verbose=False,
22+
cmosinit: dict | None = None
2723
):
2824
"""
2925
assumption is that this is a Neo sCMOS FITS / TIFF file, where Solis chooses to break up the recordings
@@ -38,37 +34,35 @@ def getNeoParam(
3834

3935
nHeadBytes = 0
4036

41-
if fn.suffix.lower() in ".tiff":
42-
if tifffile is None:
43-
raise ImportError("tifffile")
44-
# FIXME didn't the 2011 TIFFs have headers? maybe not.
45-
with tifffile.TiffFile(str(fn)) as f:
46-
Y, X = f[0].shape
47-
cmosinit = {"firstrawind": 1, "lastrawind": len(f)}
48-
elif fn.suffix.lower() in ".fits":
49-
if tifffile is None:
50-
raise ImportError("astropy")
51-
52-
with fits.open(fn, mode="readonly", memmap=False) as f:
53-
kineticsec = f[0].header["KCT"]
54-
# TODO start of night's recording (with some Solis versionss)
55-
startseries = datetime.fromisoformat(f[0].header["DATE"] + "Z")
56-
57-
# TODO wish there was a better way
58-
try:
59-
frametxt = f[0].header["USERTXT1"]
60-
m = re.search(r"(?<=Images\:)\d+-\d+(?=\.)", frametxt)
61-
inds = m.group(0).split("-") # type: ignore[union-attr]
62-
except (KeyError, AttributeError):
63-
# just a single file?
64-
# yes start with 1, end without adding 1 for Andor Solis
65-
inds = [1, f[0].shape[0]]
66-
67-
cmosinit = {"firstrawind": int(inds[0]), "lastrawind": int(inds[1])}
68-
69-
# start = datetime.fromisoformat(f[0].header['FRAME']+'Z') No, incorrect by several hours with some 2015 Solis versions!
70-
71-
Y, X = f[0].shape[-2:]
37+
match fn.suffix.lower():
38+
case ".tiff":
39+
# FIXME didn't the 2011 TIFFs have headers? maybe not.
40+
with tifffile.TiffFile(str(fn)) as f:
41+
Y, X = f[0].shape
42+
cmosinit = {"firstrawind": 1, "lastrawind": len(f)}
43+
case ".fits":
44+
45+
46+
with fits.open(fn, mode="readonly", memmap=False) as f:
47+
kineticsec = f[0].header["KCT"]
48+
# TODO start of night's recording (with some Solis versionss)
49+
startseries = datetime.fromisoformat(f[0].header["DATE"] + "Z")
50+
51+
# TODO wish there was a better way
52+
try:
53+
frametxt = f[0].header["USERTXT1"]
54+
m = re.search(r"(?<=Images\:)\d+-\d+(?=\.)", frametxt)
55+
inds = m.group(0).split("-") # type: ignore[union-attr]
56+
except (KeyError, AttributeError):
57+
# just a single file?
58+
# yes start with 1, end without adding 1 for Andor Solis
59+
inds = [1, f[0].shape[0]]
60+
61+
cmosinit = {"firstrawind": int(inds[0]), "lastrawind": int(inds[1])}
62+
63+
# start = datetime.fromisoformat(f[0].header['FRAME']+'Z') No, incorrect by several hours with some 2015 Solis versions!
64+
65+
Y, X = f[0].shape[-2:]
7266

7367
startUTC = startseries.timestamp()
7468

0 commit comments

Comments
 (0)