Skip to content

Commit

Permalink
hcam.py -- updates for logging
Browse files Browse the repository at this point in the history
added a set method to hcam.Rbytes, like ucam equivalent
  • Loading branch information
trmrsh committed May 20, 2021
1 parent 7dffd42 commit 520cb53
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions hipercam/hcam.py
Expand Up @@ -304,6 +304,7 @@ def __init__(self, fname, server=False, full=True):
self.toff1 = self.toff2 = 1.0e-3 * E / 2.0
self.toff3 = self.toff4 = 1.0e-3 * E
self.tdead = 1.0e-3 * (FR + W)

elif self.drift:
# Drift mode
LD = hd["ESO DET DRIFT TLINEDUMP"]
Expand Down Expand Up @@ -1380,6 +1381,12 @@ def __init__(self, fname, nframe=1, server=False):

# move to the start of the timing bytes
self.nframe = nframe

# This sets whether on the next call we should regard the file
# position as requiring a reset. Used by 'set' to flag up different
# actions in __call__
self.reset = False

if not server:
self._ffile.seek(
self._hbytes + self._framesize * self.nframe - self.ntbytes
Expand Down Expand Up @@ -1410,23 +1417,11 @@ def __call__(self, nframe=None):
Returns:: the timing bytes of the frame
"""

# set the frame to be read and whether the file pointer needs to be
# reset
if nframe is None:
# just read whatever frame we are on
reset = False
else:
if nframe == 0:
# go for the last one
nframe = self.ntotal()

# update frame counter
reset = self.nframe != nframe
self.nframe = nframe
self.set(nframe)

if self.server:
# define command to send to server
if reset:
if self.reset:
# requires a seek as well as a read
data = json.dumps(dict(action="get_frame", frame_number=self.nframe))
else:
Expand All @@ -1452,7 +1447,7 @@ def __call__(self, nframe=None):

else:
# find the start of the timing data if necessary
if reset:
if self.reset:
self._ffile.seek(
self._hbytes + self._framesize * self.nframe - self.ntbytes
)
Expand All @@ -1465,9 +1460,40 @@ def __call__(self, nframe=None):

# update the internal frame counter
self.nframe += 1
self.reset = False

return tbytes

def set(self, nframe=1):
"""Resets the position so that we are just about to read
the timing data of nframe, but does not read them unlike
__call__
Arguments::
nframe : int | none
frame number to get, starting at 1. 0 for the last (complete)
frame. 'None' indicates that the next frame is wanted.
Returns:: the timing bytes of the frame
"""

old_frame = self.nframe

if nframe is None:
# just read whatever frame we are now on
self.reset = False
else:
if nframe == 0:
# go for the last one
nframe = self.ntotal()

# record whether we need to be in reset mode
# update frame counter
self.reset = self.nframe != nframe
self.nframe = nframe

return old_frame

class Rtime(Rtbytes):
"""Callable, iterable object to generate timing data only from HiPERCAM raw data files.
Expand Down

0 comments on commit 520cb53

Please sign in to comment.