Skip to content

Commit

Permalink
timetags: make timetags lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Sep 27, 2024
1 parent 7dd2403 commit e3c64b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 16 additions & 2 deletions lumicks/pylake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,12 +917,26 @@ class TimeTags:

def __init__(self, data, start=None, stop=None):
self._src_data = data
self.start = start if start is not None else (self.data[0] if self.data.size > 0 else 0)
self.stop = stop if stop is not None else (self.data[-1] + 1 if self.data.size > 0 else 0)
self._start = start
self._stop = stop

def __len__(self):
return self.data.size

@property
def start(self):
return (
self._start if self._start is not None else (self.data[0] if self.data.size > 0 else 0)
)

@property
def stop(self):
return (
self._stop
if self._stop is not None
else (self.data[-1] + 1 if self.data.size > 0 else 0)
)

@property
def data(self):
return np.asarray(self._src_data)
Expand Down
3 changes: 1 addition & 2 deletions lumicks/pylake/tests/test_file/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def test_global_cache_timetags(h5_file):
if pylake.File.from_h5py(h5_file).format_version == 2:
_get_array.cache_clear()
tags1 = pylake.File.from_h5py(h5_file)["Photon Time Tags"]["Red"]
assert _get_array.cache_info().hits == 3 # start and stop pull the data every time
tags2 = pylake.File.from_h5py(h5_file)["Photon Time Tags"]["Red"]
assert _get_array.cache_info().hits == 6
assert _get_array.cache_info().hits == 0

# These should point to the same data
assert id(tags1.data) == id(tags2.data)
Expand Down

0 comments on commit e3c64b2

Please sign in to comment.