Skip to content

Commit ae94fc5

Browse files
committed
replace deprecated calls
1 parent 022b267 commit ae94fc5

6 files changed

Lines changed: 48 additions & 61 deletions

File tree

src/histutils/camclass.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import numpy as np
44
from numpy.testing import assert_allclose
5-
from datetime import datetime
5+
from datetime import datetime, timezone
66
from scipy.signal import savgol_filter
77
from numpy.random import poisson
88
import h5py
@@ -19,8 +19,9 @@
1919
from .plots import plotnear_rc, plotlsq_rc
2020

2121

22-
class Cam: # use this like an advanced version of Matlab struct
22+
class Cam:
2323
"""
24+
use this like an advanced version of Matlab struct
2425
simple mode via try except attributeerror
2526
"""
2627

@@ -279,8 +280,8 @@ def __init__(
279280

280281
logging.info(
281282
f"Camera {self.name} start/stop UTC:"
282-
f"{datetime.utcfromtimestamp(self.ut1unix[0])} / "
283-
f"{datetime.utcfromtimestamp(self.ut1unix[-1])} "
283+
f"{datetime.fromtimestamp(self.ut1unix[0], timezone.utc)} / "
284+
f"{datetime.fromtimestamp(self.ut1unix[-1], timezone.utc)} "
284285
f"{self.ut1unix.size} frames."
285286
)
286287

src/histutils/convert/__main__.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,27 @@
2727
#
2828
from ..dio import dir2fn, vid2h5
2929
from ..rawDMCreader import goRead
30-
from ..plots import doPlayMovie, doplotsave
3130

3231

33-
def dmclooper(p):
32+
def dmclooper(p: dict):
3433

3534
params = {
36-
"kineticsec": p.kineticsec,
37-
"rotccw": p.rotccw,
38-
"transpose": p.transpose,
39-
"flipud": p.flipud,
40-
"fliplr": p.fliplr,
41-
"fire": p.fire,
42-
"sensorloc": p.loc,
35+
"kineticsec": p["kineticsec"],
36+
"rotccw": p["rotccw"],
37+
"transpose": p["transpose"],
38+
"flipud": p["flipud"],
39+
"fliplr": p["fliplr"],
40+
"fire": p["fire"],
41+
"sensorloc": p["loc"],
4342
"cmdlog": " ".join(argv),
44-
"header_bytes": p.headerbytes,
45-
"xy_pixel": p.pix,
46-
"xy_bin": p.bin,
47-
"frame_request": p.frames,
43+
"header_bytes": p["headerbytes"],
44+
"xy_pixel": p["pix"],
45+
"xy_bin": p["bin"],
46+
"frame_request": p["frames"],
4847
}
4948

5049
# %% find file(s) user specified
51-
infn = Path(p.infile).expanduser()
50+
infn = Path(p["infile"]).expanduser()
5251
if infn.is_file():
5352
flist = [infn]
5453
elif infn.is_dir():
@@ -59,7 +58,7 @@ def dmclooper(p):
5958
N = len(flist)
6059

6160
for i, fn in enumerate(flist):
62-
params["outfn"] = dir2fn(p.outdir, fn, ".h5")
61+
params["outfn"] = dir2fn(p["outdir"], fn, ".h5")
6362
if params["outfn"].is_file():
6463
logging.warning(f"\nskipping {params['outfn']} {fn}")
6564
continue
@@ -71,17 +70,6 @@ def dmclooper(p):
7170
rawImgData, rawind, finf = goRead(fn, params)
7271
# %% convert
7372
vid2h5(None, ut1=finf["ut1"], rawind=rawind, ticks=None, params=params)
74-
# %% optional plot
75-
if p.movie:
76-
plots(rawImgData, rawind, finf)
77-
78-
79-
def plots(rawImgData, rawind, finf):
80-
try:
81-
doPlayMovie(rawImgData, p.movie, ut1_unix=finf["ut1"], clim=p.clim)
82-
doplotsave(p.infile, rawImgData, rawind, p.clim, p.hist, p.avg)
83-
except Exception:
84-
pass
8573

8674

8775
if __name__ == "__main__":
@@ -164,4 +152,4 @@ def plots(rawImgData, rawind, finf):
164152
level=logging.INFO,
165153
)
166154

167-
dmclooper(P)
155+
dmclooper(vars(P))

src/histutils/dio.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import numpy as np
33
import h5py
44
from typing import Any
5-
from datetime import datetime
5+
from datetime import datetime, timezone
66
import logging
77

88

9-
def dir2fn(ofn: Path, ifn: Path, suffix: str = ".h5") -> Path | None:
9+
def dir2fn(ofn: Path, ifn: Path, suffix: str = ".h5") -> Path:
1010
"""
1111
1212
Parameters
@@ -25,27 +25,19 @@ def dir2fn(ofn: Path, ifn: Path, suffix: str = ".h5") -> Path | None:
2525
ofn: pathlib.Path
2626
filename to write
2727
"""
28-
if not ofn: # no output file desired
29-
return None
3028

3129
ofn = Path(ofn).expanduser()
3230
ifn = Path(ifn).expanduser()
3331
if not ifn.is_file():
3432
raise FileNotFoundError(ifn)
3533

36-
if ofn.suffix == suffix: # must already be a filename
37-
pass
38-
else: # must be a directory
34+
if ofn.suffix != suffix:
35+
# must be a directory
3936
ofn.mkdir(parents=True, exist_ok=True)
4037
ofn = ofn / ifn.with_suffix(suffix).name
4138

42-
try:
43-
if ofn.samefile(ifn):
44-
raise FileExistsError(f"do not overwrite input file! {ifn}")
45-
except (
46-
FileNotFoundError
47-
): # a good thing, the output file doesn't exist and hence it's not the input file
48-
pass
39+
if ofn.is_file() and ofn.samefile(ifn):
40+
raise FileExistsError(f"do not overwrite input file! {ifn}")
4941

5042
return ofn
5143

@@ -143,8 +135,8 @@ def vid2h5(
143135

144136
if ut1 is not None:
145137
print(
146-
f"writing from {datetime.utcfromtimestamp(ut1[0])}"
147-
f"to {datetime.utcfromtimestamp(ut1[-1])}"
138+
f"writing from {datetime.fromtimestamp(ut1[0], timezone.utc)}"
139+
f"to {datetime.fromtimestamp(ut1[-1], timezone.utc)}"
148140
)
149141
if "ut1_unix" not in f:
150142
fut1 = f.create_dataset(

src/histutils/plots.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
except ImportError:
99
skml = None
1010
#
11-
from mpl_toolkits.mplot3d import Axes3D # noqa: F401
1211
from matplotlib.pyplot import figure, hist, draw, pause, show
1312
from matplotlib.colors import LogNorm
1413

@@ -18,15 +17,22 @@
1817
from pymap3d import ecef2geodetic
1918

2019

21-
def doPlayMovie(data, playMovie, ut1_unix=None, rawFrameInd=None, clim=None):
22-
if not playMovie or data is None:
20+
def doPlayMovie(
21+
data,
22+
playMovie: float | None,
23+
ut1_unix: list[int] | None = None,
24+
rawFrameInd: list[int] | None = None,
25+
clim: tuple[int, int] | None = None,
26+
) -> None:
27+
28+
if playMovie is None or data is None:
2329
return
2430
# %%
2531
# sfmt = ScalarFormatter(useMathText=True)
2632
hf1 = figure(1)
2733
hAx = hf1.gca()
2834

29-
try:
35+
if clim is not None:
3036
hIm = hAx.imshow(
3137
data[0, ...],
3238
vmin=clim[0],
@@ -35,7 +41,7 @@ def doPlayMovie(data, playMovie, ut1_unix=None, rawFrameInd=None, clim=None):
3541
origin="lower",
3642
norm=LogNorm(),
3743
)
38-
except TypeError: # clim wasn't specified properly
44+
else:
3945
print("setting image viewing limits based on first frame")
4046
hIm = hAx.imshow(data[0, ...], cmap="gray", origin="lower", norm=LogNorm())
4147

@@ -52,14 +58,14 @@ def doPlayMovie(data, playMovie, ut1_unix=None, rawFrameInd=None, clim=None):
5258

5359
for i, d in enumerate(data):
5460
hIm.set_data(d)
55-
try:
61+
if ut1_unix is not None and rawFrameInd is not None:
5662
if titleut:
5763
hT.set_text(
58-
f"UT1 estimate: {datetime.utcfromtimestamp(ut1_unix[i])} RelFrame#: {i}"
64+
f"UT1 estimate: {datetime.fromtimestamp(ut1_unix[i])} RelFrame#: {i}"
5965
)
6066
else:
6167
hT.set_text(f"RawFrame#: {rawFrameInd[i]} RelFrame# {i}")
62-
except TypeError:
68+
else:
6369
hT.set_text(f"RelFrame# {i}")
6470

6571
draw()

src/histutils/plotsimul.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from matplotlib.pyplot import figure
66

77
# from matplotlib.colors import LogNorm
8-
from datetime import datetime
8+
from datetime import datetime, timezone
99

1010
#
1111
from astropy.visualization.mpl_normalize import ImageNormalize
@@ -44,7 +44,7 @@ def plotPlainImg(cam, rawdata, t, odir):
4444
ax.text(
4545
0.05,
4646
0.075,
47-
datetime.utcfromtimestamp(C.tKeo[t]).isoformat()[:-3],
47+
datetime.fromtimestamp(C.tKeo[t], timezone.utc).isoformat()[:-3],
4848
ha="left",
4949
va="top",
5050
transform=ax.transAxes,
@@ -192,7 +192,7 @@ def updateframe(t, raw, wavelen, cam, ax, fg):
192192
hc = fg.colorbar(hi, ax=ax) # not cax!
193193
hc.set_label(f"{raw.dtype} data numbers")
194194

195-
dtframe = datetime.utcfromtimestamp(cam.tKeo[t])
195+
dtframe = datetime.fromtimestamp(cam.tKeo[t], timezone.utc)
196196

197197
if cam.name == "asi":
198198
dtstr = datetime.strftime(dtframe, "%H:%M:%S")

src/histutils/simulFrame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import logging
9-
from datetime import datetime
9+
from datetime import datetime, timezone
1010
from time import time
1111
import h5py
1212
from numpy import arange, unique, atleast_1d, around, array, isfinite
@@ -70,8 +70,8 @@ def HSTsync(sim, cam, verbose):
7070

7171
logging.info(
7272
f"{tall.size} mutual frames available "
73-
f"from {datetime.utcfromtimestamp(mutualStart)}"
74-
f"to {datetime.utcfromtimestamp(mutualStop)}"
73+
f"from {datetime.fromtimestamp(mutualStart, timezone.utc)}"
74+
f"to {datetime.fromtimestamp(mutualStop, timezone.utc)}"
7575
)
7676
# %% adjust start/stop to user request
7777
try:

0 commit comments

Comments
 (0)