Skip to content

Commit

Permalink
Merge pull request #437 from NREL/fix_issue_#370
Browse files Browse the repository at this point in the history
Fix issue #370 (energy_from_power returns incorrect index for shifted hourly data)
  • Loading branch information
mdeceglie authored Dec 30, 2024
2 parents 3721a4d + f15210c commit 4592eed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
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

0 comments on commit 4592eed

Please sign in to comment.