Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ratapi/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _extract_plot_data(event_data: PlotEventData, q4: bool, show_error_bar: bool
show_error_bar : bool, default: True
Controls whether the error bars are shown
shift_value : float
A value between 1 and 100 that controls the spacing between the reflectivity plots for each of the contrasts
A value between 0 and 100 that controls the spacing between the reflectivity plots for each of the contrasts

Returns
-------
Expand All @@ -46,14 +46,14 @@ def _extract_plot_data(event_data: PlotEventData, q4: bool, show_error_bar: bool
"""
results = {"ref": [], "error": [], "sld": [], "sld_resample": []}

if shift_value < 1 or shift_value > 100:
raise ValueError("Parameter `shift_value` must be between 1 and 100")
if shift_value < 0 or shift_value > 100:
raise ValueError("Parameter `shift_value` must be between 0 and 100")

for i, (r, data, sld) in enumerate(
zip(event_data.reflectivity, event_data.shiftedData, event_data.sldProfiles, strict=False)
):
# Calculate the divisor
div = 1 if i == 0 and not q4 else 10 ** ((i + 1) / 100 * shift_value)
div = 10 ** (i / 100 * shift_value)
q4_data = 1 if not q4 or not event_data.dataPresent[i] else data[:, 0] ** 4
mult = q4_data / div

Expand Down Expand Up @@ -137,7 +137,7 @@ def plot_ref_sld_helper(
show_legend : bool, default: True
Controls whether the legend is shown
shift_value : float, default: 100
A value between 1 and 100 that controls the spacing between the reflectivity plots for each of the contrasts
A value between 0 and 100 that controls the spacing between the reflectivity plots for each of the contrasts
animated : bool, default: False
Controls whether the animated property of foreground plot elements should be set.

Expand Down Expand Up @@ -168,7 +168,7 @@ def plot_ref_sld_helper(
# Plot confidence intervals if required
if confidence_intervals is not None:
# Calculate the divisor
div = 1 if i == 0 and not q4 else 10 ** ((i / 100) * shift_value)
div = 10 ** (i / 100 * shift_value)
ref_min, ref_max = confidence_intervals["reflectivity"][i]
mult = (1 if not q4 else plot_data["ref"][i][0] ** 4) / div
ref_plot.fill_between(plot_data["ref"][i][0], ref_min * mult, ref_max * mult, alpha=0.6, color="grey")
Expand Down Expand Up @@ -277,7 +277,7 @@ def plot_ref_sld(
show_legend : bool, default: True
Controls whether the legend is shown
shift_value : float, default: 100
A value between 1 and 100 that controls the spacing between the reflectivity plots for each of the contrasts
A value between 0 and 100 that controls the spacing between the reflectivity plots for each of the contrasts

Returns
-------
Expand Down Expand Up @@ -387,7 +387,7 @@ class BlittingSupport:
show_legend : bool, default: True
Controls whether the legend is shown
shift_value : float, default: 100
A value between 1 and 100 that controls the spacing between the reflectivity plots for each of the contrasts
A value between 0 and 100 that controls the spacing between the reflectivity plots for each of the contrasts
"""

def __init__(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ def test_extract_plot_data(data) -> None:
assert len(plot_data["ref"]) == len(data.reflectivity)
assert len(plot_data["sld"]) == len(data.shiftedData)

with pytest.raises(ValueError, match=r"Parameter `shift_value` must be between 1 and 100"):
RATplot._extract_plot_data(data, False, True, 0)
with pytest.raises(ValueError, match=r"Parameter `shift_value` must be between 0 and 100"):
RATplot._extract_plot_data(data, False, True, -0.1)

with pytest.raises(ValueError, match=r"Parameter `shift_value` must be between 1 and 100"):
with pytest.raises(ValueError, match=r"Parameter `shift_value` must be between 0 and 100"):
RATplot._extract_plot_data(data, False, True, 100.5)
Loading