Skip to content

Commit

Permalink
Add support for specifying the beam width of error bars
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWrigley committed Aug 12, 2022
1 parent f7dd194 commit ab9acf4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions extra_foam/special_suite/correlator_w.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,15 @@ def handle_rich_output():
if label in self._errors:
error_data = self._errors[label].data()

# Set a default beam width
beam_width = self.xbinning_resolution if self.xbinning_enabled else 1

# But override it if the user set it manually
for data in data_list:
if isinstance(data, xr.DataArray):
if label in data.attrs["series_errors_beam_widths"]:
beam_width = data.attrs["series_errors_beam_widths"][label]

if label not in self._error_plots:
self._error_plots[label] = self._plot_widget.plotStatisticsBar(pen=self._plots[label]._pen,
beam=beam_width)
Expand Down
6 changes: 5 additions & 1 deletion extra_foam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ def get_available_port(default_port):
#: :param float/np.ndarray data: The series data for the current train.
#: :param str name: The name of the series, to be displayed in a legend (optional).
#: :param float/np.ndarray error: The error of :code:`data`, shown as ± :code:`error` (optional).
Series = namedtuple("Series", ["data", "name", "error"], defaults=[None, None])
#: :param float/np.ndarray error_beam_width: The
Series = namedtuple("Series", ["data", "name", "error", "error_beam_width"], defaults=[None, None, None])


def rich_output(x, xlabel="x", ylabel="y", title=None, max_points=None, **kwargs):
Expand Down Expand Up @@ -356,6 +357,7 @@ def rich_output(x, xlabel="x", ylabel="y", title=None, max_points=None, **kwargs
"ylabel": ylabel,
"y_series_labels": [],
"series_errors": { },
"series_errors_beam_widths": { }
}

# Copy optional arguments without a default value
Expand All @@ -375,6 +377,8 @@ def rich_output(x, xlabel="x", ylabel="y", title=None, max_points=None, **kwargs

if data.error is not None:
xr_attrs["series_errors"][label] = data.error
if data.error_beam_width is not None:
xr_attrs["series_errors_beam_widths"][label] = data.error_beam_width
else:
y_series_labels.append(key)
full_data.append(data)
Expand Down

0 comments on commit ab9acf4

Please sign in to comment.