Skip to content

Commit 1bb9804

Browse files
committed
Merge branch '455_degradation_timeseries' into multi_YoY_integration
2 parents fd16332 + 8451499 commit 1bb9804

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

rdtools/plotting.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import plotly.express as px
66
import numpy as np
77
import warnings
8+
import datetime
89

910

1011
def degradation_summary_plots(yoy_rd, yoy_ci, yoy_info, normalized_yield,
@@ -475,8 +476,6 @@ def degradation_timeseries_plot(yoy_info, rolling_days=365, include_ci=True, lab
475476
matplotlib.figure.Figure
476477
'''
477478

478-
import datetime
479-
480479
def _bootstrap(x, percentile, reps):
481480
# stolen from degradation_year_on_year
482481
n1 = len(x)

rdtools/test/plotting_test.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,45 @@ def test_availability_summary_plots_empty(availability_analysis_object):
254254
def test_degradation_timeseries_plot(degradation_info):
255255
power, yoy_rd, yoy_ci, yoy_info = degradation_info
256256

257-
# test defaults
258-
result = degradation_timeseries_plot(yoy_info)
259-
assert_isinstance(result, plt.Figure)
260-
assert (result.get_axes()[0].get_xlim()[0] == 17685.55)
261-
# test other label options
262-
result = degradation_timeseries_plot(yoy_info=yoy_info, include_ci=False,
263-
label='center', fig=result)
264-
assert_isinstance(result, plt.Figure)
265-
assert (result.get_axes()[0].get_xlim()[0] == 17304.4)
266-
result = degradation_timeseries_plot(yoy_info=yoy_info, include_ci=False, label='left')
267-
assert_isinstance(result, plt.Figure)
268-
assert (result.get_axes()[0].get_xlim()[0] == 17130.5)
269-
result = degradation_timeseries_plot(yoy_info=yoy_info, include_ci=False, label=None)
270-
assert_isinstance(result, plt.Figure)
257+
# test defaults (label='right')
258+
result_right = degradation_timeseries_plot(yoy_info)
259+
assert_isinstance(result_right, plt.Figure)
260+
xlim_right = result_right.get_axes()[0].get_xlim()[0]
261+
262+
# test label='center'
263+
result_center = degradation_timeseries_plot(yoy_info=yoy_info, include_ci=False,
264+
label='center', fig=result_right)
265+
assert_isinstance(result_center, plt.Figure)
266+
xlim_center = result_center.get_axes()[0].get_xlim()[0]
267+
268+
# test label='left'
269+
result_left = degradation_timeseries_plot(yoy_info=yoy_info, include_ci=False, label='left')
270+
assert_isinstance(result_left, plt.Figure)
271+
xlim_left = result_left.get_axes()[0].get_xlim()[0]
272+
273+
# test label=None (should default to 'right')
274+
result_none = degradation_timeseries_plot(yoy_info=yoy_info, include_ci=False, label=None)
275+
assert_isinstance(result_none, plt.Figure)
276+
xlim_none = result_none.get_axes()[0].get_xlim()[0]
277+
278+
# Check that the xlim values are offset as expected
279+
# right > center > left (since offset_days increases)
280+
assert xlim_right > xlim_center > xlim_left
281+
assert xlim_right == xlim_none # label=None defaults to 'right'
282+
283+
# The expected difference from right to left is 548 days (1.5 yrs), allow 5% tolerance
284+
expected_diff = 548
285+
actual_diff = (xlim_right - xlim_left)
286+
tolerance = expected_diff * 0.05
287+
assert abs(actual_diff - expected_diff) <= tolerance, \
288+
f"difference of right-left xlim {actual_diff} not within 5% of 1.5 yrs."
289+
290+
# The expected difference from right to center is 365 days, allow 5% tolerance
291+
expected_diff2 = 365
292+
actual_diff2 = (xlim_right - xlim_center)
293+
tolerance2 = expected_diff2 * 0.05
294+
assert abs(actual_diff2 - expected_diff2) <= tolerance2, \
295+
f"difference of right-center xlim {actual_diff2} not within 5% of 1 yr."
271296

272297
with pytest.raises(KeyError):
273298
degradation_timeseries_plot({'a': 1}, include_ci=False)

0 commit comments

Comments
 (0)