Skip to content

Commit

Permalink
Merge pull request #354 from NREL/version_2.1.4
Browse files Browse the repository at this point in the history
Version 2.1.4
  • Loading branch information
mdeceglie authored Dec 1, 2022
2 parents aab642c + c78cd42 commit 996f843
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/flake8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
- name: List changed files
run: |
git diff --compact-summary "origin/$GITHUB_BASE_REF"
- name: Run linter on changed files
- name: Run linter
run: |
git diff "origin/$GITHUB_BASE_REF" -- "*.py" | flake8 . --config=.flake8 --diff --count --statistics --show-source
flake8 . --config=.flake8 --count --statistics --show-source
2 changes: 1 addition & 1 deletion docs/sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RdTools Change Log
==================
.. include:: changelog/pending.rst
.. include:: changelog/v2.1.4.rst
.. include:: changelog/v2.1.3.rst
.. include:: changelog/v2.1.2.rst
.. include:: changelog/v2.1.1.rst
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
************************
Pending
************************
*************************
v2.1.4 (December 1, 2022)
*************************

Bug Fixes
---------
* :py:func:`~rdtools.degradation.degradation_year_on_year` no longer raises
an error for inputs exactly two years long (:pull:`339`)
* :py:func:`~rdtools.plotting.soiling_interval_plot` no longer ignores the optional
``point_color``, ``profile_color``, ``point_alpha``, and ``profile_alpha`` parameters.
(:issue:`343`, :pull:`345`)

Testing
-------
Expand All @@ -18,3 +26,10 @@ Requirements
* Bump ``sphinx`` version from 3.2 to 4.5 and ``nbsphinx`` version
from 0.8.5 to 0.8.8 in the optional ``[doc]`` requirements (:pull:`317`, :pull:`325`)
* A number of other requirements updates (:pull:`337`)

Contributors
------------
* Sandra Villamar (:ghuser:`SandraVillamar`)
* Michael Deceglie (:ghuser:`mdeceglie`)
* Chris Deline (:ghuser:`cdeline`)
* Kevin Anderson (:ghuser:`kanderso-nrel`)
1 change: 1 addition & 0 deletions docs/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def setup(app):
# based on
# https://gist.github.com/flying-sheep/b65875c0ce965fbdd1d9e5d0b9851ef1


def get_obj_module(qualname):
"""
Get a module/class/attribute and its original module by qualname.
Expand Down
19 changes: 14 additions & 5 deletions rdtools/degradation.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,19 @@ def degradation_year_on_year(energy_normalized, recenter=True,
raise ValueError('energy_normalized must not be '
'more frequent than daily')

# Detect less than 2 years of data
if energy_normalized.index[-1] - energy_normalized.index[0] < \
pd.Timedelta('730d'):
raise ValueError('must provide at least two years of '
'normalized energy')
# Detect less than 2 years of data. This is complicated by two things:
# - leap days muddle the precise meaning of "two years of data".
# - can't just check the number of days between the first and last
# index values, since non-daily (e.g. weekly) inputs span
# a longer period than their index values directly indicate.
# See the unit tests for several motivating cases.
if energy_normalized.index.inferred_freq is not None:
step = pd.tseries.frequencies.to_offset(energy_normalized.index.inferred_freq)
else:
step = energy_normalized.index.to_series().diff().median()

if energy_normalized.index[-1] < energy_normalized.index[0] + pd.DateOffset(years=2) - step:
raise ValueError('must provide at least two years of normalized energy')

# Auto center
if recenter:
Expand Down Expand Up @@ -263,6 +271,7 @@ def degradation_year_on_year(energy_normalized, recenter=True,
df.index = df.dt

yoy_result = df.yoy.dropna()

df_right = df.set_index(df.dt_right).drop_duplicates('dt_right')
df['usage_of_points'] = df.yoy.notnull().astype(int).add(
df_right.yoy.notnull().astype(int), fill_value=0)
Expand Down
4 changes: 2 additions & 2 deletions rdtools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def soiling_interval_plot(soiling_info, normalized_yield, point_alpha=0.5,
sratio = soiling_info['soiling_ratio_perfect_clean']
fig, ax = plt.subplots()
renormalized = normalized_yield / soiling_info['renormalizing_factor']
ax.plot(renormalized.index, renormalized, 'o')
ax.plot(sratio.index, sratio, 'o')
ax.plot(renormalized.index, renormalized, 'o', c=point_color, alpha=point_alpha)
ax.plot(sratio.index, sratio, 'o', c=profile_color, alpha=profile_alpha)
ax.set_ylim(ymin, ymax)
ax.set_ylabel('Renormalized energy')

Expand Down
27 changes: 27 additions & 0 deletions rdtools/test/degradation_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Degradation Module Tests. """

import unittest
import pytest
import sys

import pandas as pd
Expand Down Expand Up @@ -164,6 +165,32 @@ def test_usage_of_points(self):
self.assertTrue((np.sum(rd_result[2]['usage_of_points'])) == 1462)


@pytest.mark.parametrize('start,end,freq', [
('2014-01-01', '2015-12-31', 'D'), # no leap day
('2015-01-01', '2016-12-31', 'D'), # leap day included in index
('2015-01-01', '2016-12-29', '7D'), # leap day in period but not in index
('2016-06-01', '2018-05-31', 'D'), # leap year, but no leap day in period
# ('2016-02-29', '2018-02-28', 'd'), # starts on leap day (doesn't work)
('2014-03-01', '2016-02-29', 'D'), # ends on leap day
('2015-01-01', '2016-12-31', 'M'), # month end
('2015-01-01', '2016-12-31', 'MS'), # month start
])
def test_yoy_two_years_error(start, end, freq):
# GH 339
times = pd.date_range(start, end, freq=freq)
series = pd.Series(1, index=times)
# introduce NaN at the end to ensure that the 2 year requirement applies to
# timestamps, not non-nan values:
series.iloc[-5:] = np.nan
# should not raise an error
_ = degradation_year_on_year(series)
# but if we shorten it by one element, then it should:
with pytest.raises(ValueError, match='must provide at least two years'):
_ = degradation_year_on_year(series.iloc[:-1])
with pytest.raises(ValueError, match='must provide at least two years'):
_ = degradation_year_on_year(series.iloc[1:])


if __name__ == '__main__':
# Initialize logger when run as a module:
# python -m tests.degradation_test
Expand Down

0 comments on commit 996f843

Please sign in to comment.