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

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
1 change: 1 addition & 0 deletions docs/sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RdTools Change Log
==================
.. include:: changelog/pending.rst
.. include:: changelog/v3.0.0-beta.0.rst
.. include:: changelog/v2.2.0-beta.2.rst
.. include:: changelog/v2.2.0-beta.1.rst
Expand Down
15 changes: 15 additions & 0 deletions docs/sphinx/source/changelog/pending.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**************************
v3.0.0 (December XX, 2024)
**************************

Enhancements
------------
* Add `CITATION.cff` file for citation information (:pull:`434`)
* Added checks to TrendAnalysis for `filter_params` and `filter_params_aggregated`. Raises an error if unkown filter is supplied. (:pull:`436`)


Bug fixes
---------
* 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`)

2 changes: 1 addition & 1 deletion docs/sphinx/source/changelog/v3.0.0-beta.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Enhancements
* Added codecov.yml configuration file (:pull:`420`)
* Availability module no longer considered experimental (:pull:`429`)
* Add capability to seed the CircularBlockBootstrap (:pull:`429`)
* Allow sub-daily aggregation in :py:func:`~rdtools.degradation.degradation_year_on_year` (:pull:`390`)
* Allow sub-daily aggregation in :py:func:`~rdtools.degradation.degradation_year_on_year` (:pull:`390`)

Bug fixes
---------
Expand Down
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 @@ -740,3 +740,21 @@ def test_plot_degradation_timeseries(sensor_analysis, clearsky_analysis):
assert_isinstance(
clearsky_analysis.plot_degradation_timeseries("clearsky"), plt.Figure
)


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)
Loading