Support read-slice input to `Viz.maxmin()`

Acts as short cut when pipe-lining from `Viz.update_graphics()` (which
now returns the needed in-view array-relative-read-slice as output) such
that `Viz.read()` and `.datums_range()` doesn't need to be called
internally multiple times. In this case where `i_read_range` is provided
we of course skip doing time index translations and consequently lookup
the appropriate (epoch-time) index indices for caching.
multichartz
Tyler Goodlet 2023-01-18 14:52:07 -05:00
parent b45c027db8
commit 7d404ed7ef
1 changed files with 61 additions and 38 deletions

View File

@ -330,6 +330,7 @@ class Viz(msgspec.Struct): # , frozen=True):
self,
x_range: slice | tuple[int, int] | None = None,
i_read_range: tuple[int, int] | None = None,
use_caching: bool = True,
) -> tuple[float, float] | None:
@ -343,7 +344,7 @@ class Viz(msgspec.Struct): # , frozen=True):
profiler = Profiler(
msg=f'{name} -> `{str(self)}.maxmin()`',
disabled=not pg_profile_enabled(),
ms_threshold=ms_slower_then,
ms_threshold=4,
delayed=True,
)
@ -351,8 +352,17 @@ class Viz(msgspec.Struct): # , frozen=True):
if shm is None:
return None
do_print: bool = False
arr = shm.array
if i_read_range is not None:
read_slc = slice(*i_read_range)
index = arr[read_slc][self.index_field]
if not index.size:
return None
ixrng = (index[0], index[-1])
else:
if x_range is None:
(
l,
@ -368,9 +378,8 @@ class Viz(msgspec.Struct): # , frozen=True):
# TODO: hash the slice instead maybe?
# https://stackoverflow.com/a/29980872
ixrng = (round(lbar), round(rbar))
lbar, rbar = ixrng = round(x_range[0]), round(x_range[1])
do_print: bool = False
if use_caching:
cached_result = self._mxmns.get(ixrng)
if cached_result:
@ -386,6 +395,7 @@ class Viz(msgspec.Struct): # , frozen=True):
mxmn,
)
if i_read_range is None:
# get relative slice indexes into array
if self.index_field == 'time':
read_slc = slice_from_time(
@ -657,13 +667,17 @@ class Viz(msgspec.Struct): # , frozen=True):
profiler = Profiler(
msg=f'Viz.update_graphics() for {self.name}',
disabled=not pg_profile_enabled(),
ms_threshold=4,
# ms_threshold=ms_slower_then,
ms_threshold=ms_slower_then,
# ms_threshold=4,
)
# shm read and slice to view
read = (
xfirst, xlast, src_array,
ivl, ivr, in_view,
xfirst,
xlast,
src_array,
ivl,
ivr,
in_view,
) = self.read(profiler=profiler)
profiler('read src shm data')
@ -675,7 +689,10 @@ class Viz(msgspec.Struct): # , frozen=True):
or not render
):
# print('exiting early')
return graphics
return (
(ivl, ivr),
graphics,
)
should_redraw: bool = False
ds_allowed: bool = True # guard for m4 activation
@ -792,7 +809,10 @@ class Viz(msgspec.Struct): # , frozen=True):
if not out:
log.warning(f'{self.name} failed to render!?')
return graphics
return (
(ivl, ivr),
graphics,
)
path, reset_cache = out
@ -843,7 +863,10 @@ class Viz(msgspec.Struct): # , frozen=True):
# track downsampled state
self._in_ds = r._in_ds
return graphics
return (
(ivl, ivr),
graphics,
)
def draw_last(
self,
@ -1054,7 +1077,7 @@ class Viz(msgspec.Struct): # , frozen=True):
if do_ds:
# view.interaction_graphics_cycle()
view.maybe_downsample_graphics()
view._set_yrange()
view._set_yrange(viz=self)
def incr_info(
self,