From e45bc4c619cbc493a97cd8915cbda97a749a6a6f Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 24 Nov 2022 16:22:20 -0500 Subject: [PATCH] Move `ui._compression`/`._pathops` to `.data` subpkg Since these modules no longer contain Qt specific code we might as well include them in the data sub-package. Also, add `IncrementalFormatter.index_field` as single point to def the indexing field that should be used for all x-domain graphics-data rendering. --- piker/{ui => data}/_compression.py | 0 piker/{ui => data}/_pathops.py | 31 +++++++++--------------------- piker/ui/_render.py | 10 +++++----- 3 files changed, 14 insertions(+), 27 deletions(-) rename piker/{ui => data}/_compression.py (100%) rename piker/{ui => data}/_pathops.py (97%) diff --git a/piker/ui/_compression.py b/piker/data/_compression.py similarity index 100% rename from piker/ui/_compression.py rename to piker/data/_compression.py diff --git a/piker/ui/_pathops.py b/piker/data/_pathops.py similarity index 97% rename from piker/ui/_pathops.py rename to piker/data/_pathops.py index 77928c1d..62a8a8da 100644 --- a/piker/ui/_pathops.py +++ b/piker/data/_pathops.py @@ -32,7 +32,7 @@ from msgspec import field # from PyQt5 import QtGui # from PyQt5.QtCore import QLineF, QPointF -from ..data._sharedmem import ( +from ._sharedmem import ( ShmArray, ) # from .._profile import pg_profile_enabled, ms_slower_then @@ -42,26 +42,11 @@ from ._compression import ( if TYPE_CHECKING: from ._render import ( - Renderer, Viz, ) from .._profile import Profiler -def by_index_and_key( - renderer: Renderer, - array: np.ndarray, - array_key: str, - vr: tuple[int, int], - -) -> tuple[ - np.ndarray, - np.ndarray, - np.ndarray, -]: - return array['index'], array[array_key], 'all' - - class IncrementalFormatter(msgspec.Struct): ''' Incrementally updating, pre-path-graphics tracking, formatter. @@ -74,6 +59,7 @@ class IncrementalFormatter(msgspec.Struct): ''' shm: ShmArray viz: Viz + index_field: str = 'index' # last read from shm (usually due to an update call) _last_read: tuple[ @@ -407,7 +393,6 @@ class IncrementalFormatter(msgspec.Struct): self, src_shm: ShmArray, data_field: str, - index_field: str = 'index', ) -> tuple[ np.ndarray, # x @@ -421,7 +406,7 @@ class IncrementalFormatter(msgspec.Struct): ''' y_nd = src_shm._array[data_field].copy() - x_nd = src_shm._array[index_field].copy() + x_nd = src_shm._array[self.index_field].copy() return x_nd, y_nd # XXX: was ``.update_xy()`` @@ -478,7 +463,7 @@ class IncrementalFormatter(msgspec.Struct): ''' return ( - array['index'], + array[self.index_field], array[array_key], # 1d connection array or style-key to @@ -512,7 +497,7 @@ class OHLCBarsFmtr(IncrementalFormatter): # generate an flat-interpolated x-domain x_nd = ( np.broadcast_to( - ohlc_shm._array['index'][:, None], + ohlc_shm._array[self.index_field][:, None], ( ohlc_shm._array.size, # 4, # only ohlc @@ -543,6 +528,7 @@ class OHLCBarsFmtr(IncrementalFormatter): data: np.ndarray, start: int64, bar_gap: float64 = 0.43, + index_field: str = 'index', ) -> tuple[ np.ndarray, @@ -574,7 +560,7 @@ class OHLCBarsFmtr(IncrementalFormatter): high = q['high'] low = q['low'] close = q['close'] - index = float64(q['index']) + index = float64(q[index_field]) istart = i * 6 istop = istart + 6 @@ -631,6 +617,7 @@ class OHLCBarsFmtr(IncrementalFormatter): array, start, bar_gap=w, + index_field=self.index_field, ) return x, y, c @@ -723,7 +710,7 @@ class StepCurveFmtr(IncrementalFormatter): for use by path graphics generation. ''' - i = shm._array['index'].copy() + i = shm._array[self.index_field].copy() out = shm._array[data_field].copy() x_out = np.broadcast_to( diff --git a/piker/ui/_render.py b/piker/ui/_render.py index 97abca94..e44251e1 100644 --- a/piker/ui/_render.py +++ b/piker/ui/_render.py @@ -37,17 +37,17 @@ from ..data._sharedmem import ( ShmArray, ) from ..data.feed import Flume -from .._profile import ( - pg_profile_enabled, - # ms_slower_then, -) -from ._pathops import ( +from ..data._pathops import ( IncrementalFormatter, OHLCBarsFmtr, # Plain OHLC renderer OHLCBarsAsCurveFmtr, # OHLC converted to line StepCurveFmtr, # "step" curve (like for vlm) xy_downsample, ) +from .._profile import ( + pg_profile_enabled, + # ms_slower_then, +) from ._ohlc import ( BarItems, # bar_from_ohlc_row,