-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for selecting a TOA range in detector plots #304
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
from ..core.handler import ( | ||
Accumulator, | ||
Config, | ||
ConfigValueAccessor, | ||
Handler, | ||
HandlerFactory, | ||
PeriodicAccumulatingHandler, | ||
|
@@ -135,9 +136,29 @@ class DetectorCounts(Accumulator[sc.DataArray, sc.DataArray]): | |
def __init__(self, config: Config, detector_view: raw.RollingDetectorView): | ||
self._config = config | ||
self._det = detector_view | ||
self._toa_range = ConfigValueAccessor( | ||
config, 'toa_range', default=None, convert=self._convert_toa_range | ||
) | ||
self._current_toa_range = None | ||
|
||
def _convert_toa_range(self, value: dict[str, Any] | None) -> None: | ||
self.clear() | ||
if value is None: | ||
return None | ||
return ( | ||
sc.scalar(value['low'], unit=value['unit']).to(unit='ns'), | ||
sc.scalar(value['high'], unit=value['unit']).to(unit='ns'), | ||
) | ||
|
||
def apply_toa_range(self, data: sc.DataArray) -> sc.DataArray: | ||
if (toa_range := self._toa_range()) is None: | ||
return data | ||
low, high = toa_range | ||
return data.bins.assign_coords(toa=data.bins.data).bins['toa', low:high] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need some explanation here 😄
|
||
|
||
def add(self, timestamp: int, data: sc.DataArray) -> None: | ||
_ = timestamp | ||
data = self.apply_toa_range(data) | ||
self._det.add_events(data) | ||
|
||
def get(self) -> sc.DataArray: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,23 @@ def _setup_layout(self) -> None: | |
value=[45, 55], | ||
marks={i: str(i) for i in range(0, 101, 20)}, | ||
), | ||
html.Label('Time-of-arrival range (us)'), | ||
dcc.Checklist( | ||
id='toa-checkbox', | ||
options=[ | ||
{'label': 'Filter by time-of-arrival [μs]', 'value': 'enabled'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems it's microseconds here and nanoseconds above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The text in the Unless this is not the same time as in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant was that on L149-150 in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is wrong with converting microseconds to nanoseconds? The dashboard uses microseconds, since nanoseconds are a bit unwieldy for a user to think about. |
||
], | ||
value=[], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (minor) checklist is slightly odd for what seems to be a "toggle" on/off, maybe consider https://dash.plotly.com/dash-daq/booleanswitch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That appears to be from a different library ( |
||
style={'margin': '10px 0'}, | ||
), | ||
dcc.RangeSlider( | ||
id='toa-range', | ||
min=0, | ||
max=71_000, | ||
step=100, | ||
value=[0, 71_000], | ||
marks={i: str(i) for i in range(0, 71_001, 10_000)}, | ||
), | ||
html.Button('Clear', id='clear-button', n_clicks=0), | ||
] | ||
self._app.layout = html.Div( | ||
|
@@ -204,6 +221,17 @@ def _setup_callbacks(self) -> None: | |
Input('roi-y', 'value'), | ||
)(self.update_roi) | ||
|
||
self._app.callback( | ||
Output('toa-range', 'disabled'), | ||
Input('toa-checkbox', 'value'), | ||
)(lambda value: len(value) == 0) | ||
|
||
self._app.callback( | ||
Output('toa-range', 'value'), | ||
Input('toa-range', 'value'), | ||
Input('toa-checkbox', 'value'), | ||
)(self.update_toa_range) | ||
|
||
def update_roi(self, roi_x, roi_y): | ||
if roi_x is not None: | ||
self._config_service.update_config( | ||
|
@@ -236,6 +264,15 @@ def update_roi(self, roi_x, roi_y): | |
|
||
return roi_x, roi_y | ||
|
||
def update_toa_range(self, toa_range, toa_enabled): | ||
if len(toa_enabled) == 0: | ||
self._config_service.update_config('toa_range', None) | ||
else: | ||
self._config_service.update_config( | ||
'toa_range', {'low': toa_range[0], 'high': toa_range[1], 'unit': 'us'} | ||
) | ||
return toa_range | ||
|
||
@staticmethod | ||
def create_monitor_plot(key: str, data: sc.DataArray) -> go.Figure: | ||
fig = go.Figure() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the unit always be 'ns', or should we instead just store floats and use the units of
data.bins.coords['toa']
inapply_toa_range
below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bounds come via a message from Kafka. It is essential to send to unit with this (or you will waste hours debugging). Not sure what is the benefit from your suggestion, recreating the
low
andhigh
variables in every single call below? It is just making it a bit slower?