From 5bcd6ac494ac8ace8ad31862950eff2e7cfebb67 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 1 Apr 2022 13:47:24 -0400 Subject: [PATCH] Move px width log scaling into `ds_m4()` --- piker/ui/_compression.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/piker/ui/_compression.py b/piker/ui/_compression.py index 1fa9dcae..1e178036 100644 --- a/piker/ui/_compression.py +++ b/piker/ui/_compression.py @@ -199,25 +199,13 @@ def ohlc_to_m4_line( use_mxmn=pretrace, ) - if uppx: - # optionally log-scale down the "supposed pxs on screen" - # as the units-per-px (uppx) get's large. - scaler = round( - max( - # NOTE: found that a 16x px width brought greater - # detail, likely due to dpi scaling? - # px_width=px_width * 16, - 128 / (1 + math.log(uppx, 2)), - 1 - ) - ) - px_width *= scaler - if downsample: bins, x, y = ds_m4( xpts, flat, px_width=px_width, + uppx=uppx, + log_scale=bool(uppx) ) x = np.broadcast_to(x[:, None], y.shape) x = (x + np.array([-0.43, 0, 0, 0.43])).flatten() @@ -235,6 +223,8 @@ def ds_m4( # this is the width of the data in view # in display-device-local pixel units. px_width: int, + uppx: Optional[float] = None, + log_scale: bool = True, ) -> tuple[int, np.ndarray, np.ndarray]: ''' @@ -261,6 +251,22 @@ def ds_m4( # "i didn't show it in the sample code, but it's accounted for # in the start and end indices and number of bins" + # optionally log-scale down the "supposed pxs on screen" + # as the units-per-px (uppx) get's large. + if log_scale: + assert uppx, 'You must provide a `uppx` value to use log scaling!' + + scaler = round( + max( + # NOTE: found that a 16x px width brought greater + # detail, likely due to dpi scaling? + # px_width=px_width * 16, + 2**6 / (1 + math.log(uppx, 2)), + 1 + ) + ) + px_width *= scaler + assert px_width > 1 # width of screen in pxs? # NOTE: if we didn't pre-slice the data to downsample @@ -320,7 +326,7 @@ def ds_m4( @jit( nopython=True, - # nogil=True, + nogil=True, ) def _m4(