Skip to content
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

Fix issue #370 (energy_from_power returns incorrect index for shifted hourly data) #437

Merged
merged 15 commits into from
Dec 30, 2024
Merged
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
4 changes: 2 additions & 2 deletions docs/sphinx/source/changelog/pending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Enhancements

Bug fixes
---------
* Set marker linewidth to zero in :py:func:`~rdtools.plotting.degradation_summary_plots` (:pull:`433`)

* Set marker linewidth to zero in `rdtools.plotting.degradation_summary_plots` (:pull:`433`)
* Fix :py:func:`~rdtools.normalization.energy_from_power` returns incorrect index for shifted hourly data (:issue:`370`, :pull:`437`)
16 changes: 8 additions & 8 deletions rdtools/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ def _aggregate(time_series, target_frequency, max_timedelta, series_type):
'''

# series that has same index as desired output
output_dummy = time_series.resample(target_frequency,
closed='right',
label='right').sum()
output_dummy = time_series.resample(
target_frequency, closed="right", label="right", origin="start"
).sum()

union_index = time_series.index.union(output_dummy.index)
time_series = time_series.dropna()
Expand Down Expand Up @@ -521,13 +521,13 @@ def _aggregate(time_series, target_frequency, max_timedelta, series_type):
raise ValueError("series_type must be either 'instantaneous' or 'right_labeled', "
"not '{}'".format(series_type))

series_sum = pd.Series(data=series_sum, index=time_series.index[1:])
series_sum = pd.Series(data=np.insert(series_sum, 0, np.nan), index=time_series.index)

aggregated = series_sum.resample(target_frequency,
closed='right',
label='right').sum(min_count=1)
aggregated = series_sum.resample(
target_frequency, closed="right", label="right", origin="start"
).sum(min_count=1)

return aggregated
return aggregated[1:]


def _interpolate_series(time_series, target_index, max_timedelta=None,
Expand Down
18 changes: 18 additions & 0 deletions rdtools/test/analysis_chains_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,24 @@ def test_plot_degradation_timeseries(sensor_analysis, clearsky_analysis):
)


def test_energy_from_power_hourly_data():

times = pd.date_range("2019-01-01 00:00:00", periods=3, freq="h")
pv = pd.Series([1.2, 2.8, 2.0], index=times)

energy = normalization.energy_from_power(pv)
pd.testing.assert_series_equal(energy, pv[1:], check_names=False)


def test_energy_from_power_shifted_hourly_data():

times = pd.date_range("2019-01-01 00:30:00", periods=3, freq="h")
pv = pd.Series([1.2, 2.8, 2.0], index=times)

energy = normalization.energy_from_power(pv)
pd.testing.assert_series_equal(energy, pv[1:], check_names=False)


def test_validated_filter_dict_initialization():
valid_keys = ["key1", "key2"]
filter_dict = ValidatedFilterDict(valid_keys, key1="value1", key2="value2")
Expand Down
Loading