2121# NHEADBYTES = 4
2222
2323
24- def goRead (infn : Path , params : dict [str , T .Any ]) -> tuple :
24+ def read (infn : str | Path , params : dict [str , T .Any ]) -> tuple :
2525
26- infn = Path (infn ).expanduser ()
26+ fn = Path (infn ).expanduser ()
2727 # %% setup data parameters
2828 # preallocate *** LABVIEW USES ROW-MAJOR ORDERING C ORDER
29- finf = getDMCparam (infn , params )
29+ finf = getDMCparam (fn , params )
3030 write_quota (finf ["bytes_frame" ] * finf ["nframeextract" ], params .get ("outfn" ))
3131
3232 rawFrameInd = np .zeros (finf ["nframeextract" ], dtype = np .int64 )
@@ -41,7 +41,7 @@ def goRead(infn: Path, params: dict[str, T.Any]) -> tuple:
4141 order = "C" ,
4242 )
4343 # %% read
44- with infn .open ("rb" ) as fid :
44+ with fn .open ("rb" ) as fid :
4545 # j and i are NOT the same in general when not starting from beginning of file!
4646 for j , i in enumerate (finf ["frameindrel" ]):
4747 D , rawFrameInd [j ] = getDMCframe (fid , i , finf )
@@ -67,9 +67,6 @@ def getDMCparam(fn: Path, params: dict[str, T.Any]) -> dict[str, T.Any]:
6767 "header_bytes" : params ["header_bytes" ],
6868 } # FIXME for DMCdata version 1 only
6969
70- if not fn .is_file (): # leave this here, getsize() doesn't fail on directory
71- raise FileNotFoundError (fn )
72-
7370 # int() in case we are fed a float or int
7471 finf ["super_x" ] = int (params ["xy_pixel" ][0 ] // params ["xy_bin" ][0 ])
7572 finf ["super_y" ] = int (params ["xy_pixel" ][1 ] // params ["xy_bin" ][1 ])
@@ -97,6 +94,9 @@ def howbig(params: dict[str, T.Any], finf: dict[str, T.Any]) -> dict[str, int]:
9794
9895def whichframes (fn : Path , params : dict [str , T .Any ], finf : dict [str , T .Any ]):
9996
97+ if not fn .is_file ():
98+ raise FileNotFoundError (fn )
99+
100100 fileSizeBytes = fn .stat ().st_size
101101
102102 if fileSizeBytes < finf ["bytes_image" ]:
0 commit comments