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

Hour angle filter #375

Merged
merged 24 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4082f9b
fixes for pandas 2.0.0 compatibility
kandersolar Mar 3, 2023
2dd0217
lint
kandersolar Mar 3, 2023
14137ee
temporarily add a pandas==2.0.0rc0 job
kandersolar Mar 3, 2023
1a416f8
fix broken yaml
kandersolar Mar 3, 2023
9473614
pin nbval for semicolon suppression issue
kandersolar Mar 3, 2023
c91defb
lint
kandersolar Mar 3, 2023
e06b65f
Add logos to repo
mdeceglie Mar 9, 2023
29a7ae9
remove pandas 2.0.0rc0 job
mdeceglie Apr 26, 2023
f523cd2
change log
mdeceglie Apr 27, 2023
6c3f434
Merge branch 'master' into pandas_200
cdeline May 16, 2023
8aa7733
Update change log date
mdeceglie May 16, 2023
d19fa83
Merge pull request #362 from NREL/pandas_200
mdeceglie May 16, 2023
563dff1
add hour angle filter
mdeceglie May 24, 2023
3bf7363
add hour angle filter to TrendAnalysis
mdeceglie May 24, 2023
04449bc
Merge branch 'master' into hour_angle_filter
mdeceglie May 25, 2023
aa4af78
Merge branch 'master' into aggregated_filters_for_trials
mdeceglie May 25, 2023
54b0423
add hour angle filter
mdeceglie May 24, 2023
ee13551
add hour angle filter to TrendAnalysis
mdeceglie May 24, 2023
9cbcb47
Merge branch 'hour_angle_filter' of https://github.com/NREL/rdtools i…
cdeline May 25, 2023
d94ccba
adjust error message
mdeceglie May 25, 2023
c9285fe
try updating arch version
mdeceglie May 25, 2023
e889ffe
try arch=5.5.0
mdeceglie May 25, 2023
2e689e4
fix broken self.pvlib_location checks.
cdeline May 25, 2023
13d0f9b
Merge branch 'hour_angle_filter' of https://github.com/NREL/rdtools i…
cdeline May 25, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
pip install ${{ matrix.env }}
- name: Test with pytest ${{ matrix.env }}
run: |
pytest
pytest
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RdTools Change Log
==================
.. include:: changelog/v2.2.0-beta.1.rst
.. include:: changelog/v2.1.5.rst
.. include:: changelog/v2.1.4.rst
.. include:: changelog/v2.2.0-beta.0.rst
.. include:: changelog/v2.1.3.rst
Expand Down
13 changes: 13 additions & 0 deletions docs/sphinx/source/changelog/v2.1.5.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*************************
v2.1.5 (May 16, 2023)
*************************

Bug Fixes
---------
* Add support for pandas 2.0 (:issue:`361`, :pull:`362`)


Contributors
------------
* Kevin Anderson (:ghuser:`kanderso-nrel`)
* Michael Deceglie (:ghuser:`mdeceglie`)
12 changes: 12 additions & 0 deletions rdtools/analysis_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,18 @@ def _call_clearsky_filter(filter_string):
f = filtering.clip_filter(
self.pv_power, **self.filter_params['clip_filter'])
filter_components['clip_filter'] = f
if 'hour_angle_filter' in self.filter_params:
if self.pvlib_location is None:
Copy link
Collaborator

@cdeline cdeline May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if undefined, self.pvlib_location won't be None, it'll actually return an AttributeError. I've got a fix for the handful of places this crops up. There's another bug of this nature on the check for tilt and azimuth too...

raise ValueError(
'The pvlib location must be provided using set_clearsky() '
'or by directly setting TrendAnalysis.pvlib_location '
'in order to use the hour_angle_filter')
loc = self.pvlib_location
f = filtering.hour_angle_filter(
energy_normalized, loc.latitude, loc.longitude,
**self.filter_params['hour_angle_filter'])
filter_components['hour_angle_filter'] = f

if case == 'clearsky':
filter_components['pvlib_clearsky_filter'] = _call_clearsky_filter('pvlib_clearsky_filter')
if 'sensor_pvlib_clearsky_filter' in self.filter_params:
Expand Down
6 changes: 3 additions & 3 deletions rdtools/degradation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def degradation_ols(energy_normalized, confidence_level=68.2):

# calculate a years column as x value for regression, ignoring leap years
day_diffs = (df.index - df.index[0])
df['days'] = day_diffs.astype('timedelta64[s]') / (60 * 60 * 24)
df['days'] = day_diffs / pd.Timedelta('1d')
df['years'] = df.days / 365.0

# add intercept-constant to the exogeneous variable
Expand Down Expand Up @@ -123,7 +123,7 @@ def degradation_classical_decomposition(energy_normalized,

# calculate a years column as x value for regression, ignoring leap years
day_diffs = (df.index - df.index[0])
df['days'] = day_diffs.astype('timedelta64[s]') / (60 * 60 * 24)
df['days'] = day_diffs / pd.Timedelta('1d')
df['years'] = df.days / 365.0

# Compute yearly rolling mean to isolate trend component using
Expand Down Expand Up @@ -292,7 +292,7 @@ def degradation_year_on_year(energy_normalized, recenter=True,
tolerance=pd.Timedelta('8D')
)

df['time_diff_years'] = (df.dt - df.dt_right).astype('timedelta64[h]') / 8760.0
df['time_diff_years'] = (df.dt - df.dt_right) / pd.Timedelta('365d')
df['yoy'] = 100.0 * (df.energy - df.energy_right) / (df.time_diff_years)
df.index = df.dt

Expand Down
23 changes: 19 additions & 4 deletions rdtools/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,9 @@ def logic_clip_filter(power_ac,
# series sampling frequency is less than 95% consistent.
_check_data_sampling_frequency(power_ac)
# Get the sampling frequency of the time series
time_series_sampling_frequency = power_ac.index.to_series().diff()\
.astype('timedelta64[m]').mode()[0]
time_series_sampling_frequency = (
power_ac.index.to_series().diff() / pd.Timedelta('60s')
).mode()[0]
# Make copies of the original inputs for the cases that the data is
# changes for clipping evaluation
original_time_series_sampling_frequency = time_series_sampling_frequency
Expand Down Expand Up @@ -754,8 +755,7 @@ def xgboost_clip_filter(power_ac,
# series sampling frequency is less than 95% consistent.
_check_data_sampling_frequency(power_ac)
# Get the most common sampling frequency
sampling_frequency = int(power_ac.index.to_series().diff()
.astype('timedelta64[m]').mode()[0])
sampling_frequency = int((power_ac.index.to_series().diff() / pd.Timedelta('60s')).mode()[0])
freq_string = str(sampling_frequency) + "T"
# Min-max normalize
# Resample the series based on the most common sampling frequency
Expand Down Expand Up @@ -948,3 +948,18 @@ def directional_tukey_filter(series, roll_period=pd.to_timedelta('7 Days'), k=1.
((backward_dif > backward_dif_lower) & (backward_dif < backward_dif_upper))
)
return mask


def hour_angle_filter(series, lat, lon, min_hour_angle=-30, max_hour_angle=30):
'''
Creates a filter based on the hour angle of the sun (15 degrees per hour)
'''

times = series.index
spa = pvlib.solarposition.get_solarposition(times, lat, lon)
eot = spa['equation_of_time']
hour_angle = pvlib.solarposition.hour_angle(times, lon, eot)
hour_angle = pd.Series(hour_angle, index=times)
mask = (hour_angle >= min_hour_angle) & (hour_angle <= max_hour_angle)

return mask
2 changes: 1 addition & 1 deletion rdtools/test/availability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def difficult_data():

# generate a plausible clear-sky power signal
times = pd.date_range('2019-01-01', '2019-01-06', freq='15min',
tz='US/Eastern', closed='left')
tz='US/Eastern')
location = pvlib.location.Location(40, -80)
clearsky = location.get_clearsky(times, model='haurwitz')
# just scale GHI to power for simplicity
Expand Down
2 changes: 1 addition & 1 deletion rdtools/test/degradation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_corr_energy(cls, rd, input_freq):
freq = input_freq

x = pd.date_range(start=start, end=end, freq=freq)
day_deltas = (x - x[0]).astype('timedelta64[s]') / (60.0 * 60.0 * 24)
day_deltas = (x - x[0]) / pd.Timedelta('1d')
noise = (np.random.rand(len(day_deltas)) - 0.5) / 1e3

y = 1 + daily_rd * day_deltas + noise
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pvlib==0.9.0
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2019.3
arch==4.11
arch==5.5.0
filterpy==1.4.5
requests==2.25.1
retrying==1.3.3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'pytest >= 3.6.3',
'coverage',
'flake8',
'nbval',
'nbval==0.9.6', # https://github.com/computationalmodelling/nbval/issues/194
'pytest-mock',
]

Expand Down