From 563dff13bdcccb4d6c36047f600b37c4aefce32b Mon Sep 17 00:00:00 2001 From: Michael Deceglie Date: Wed, 24 May 2023 15:49:06 -0600 Subject: [PATCH 1/8] add hour angle filter --- rdtools/filtering.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rdtools/filtering.py b/rdtools/filtering.py index 8f70510d..5b3dac05 100644 --- a/rdtools/filtering.py +++ b/rdtools/filtering.py @@ -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 From 3bf7363c2a493b28be0c731bbbd01b845483533a Mon Sep 17 00:00:00 2001 From: Michael Deceglie Date: Wed, 24 May 2023 16:49:12 -0600 Subject: [PATCH 2/8] add hour angle filter to TrendAnalysis --- rdtools/analysis_chains.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rdtools/analysis_chains.py b/rdtools/analysis_chains.py index 76011e77..024a33e3 100644 --- a/rdtools/analysis_chains.py +++ b/rdtools/analysis_chains.py @@ -464,6 +464,17 @@ 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: + raise ValueError( + 'pvlib location must be provided using set_clearsky() ' + '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: From 54b0423f2d80f96b118464dab15527be89b5debe Mon Sep 17 00:00:00 2001 From: Michael Deceglie Date: Wed, 24 May 2023 15:49:06 -0600 Subject: [PATCH 3/8] add hour angle filter --- rdtools/filtering.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rdtools/filtering.py b/rdtools/filtering.py index bb274f2b..40ef08a3 100644 --- a/rdtools/filtering.py +++ b/rdtools/filtering.py @@ -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 From ee1355161b4c7946eacf14c67567826acf680182 Mon Sep 17 00:00:00 2001 From: Michael Deceglie Date: Wed, 24 May 2023 16:49:12 -0600 Subject: [PATCH 4/8] add hour angle filter to TrendAnalysis --- rdtools/analysis_chains.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rdtools/analysis_chains.py b/rdtools/analysis_chains.py index 76011e77..024a33e3 100644 --- a/rdtools/analysis_chains.py +++ b/rdtools/analysis_chains.py @@ -464,6 +464,17 @@ 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: + raise ValueError( + 'pvlib location must be provided using set_clearsky() ' + '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: From d94ccbad5c2acda3f9fb5c0581fe96482096e2d8 Mon Sep 17 00:00:00 2001 From: Michael Deceglie Date: Thu, 25 May 2023 09:51:44 -0600 Subject: [PATCH 5/8] adjust error message --- rdtools/analysis_chains.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rdtools/analysis_chains.py b/rdtools/analysis_chains.py index 024a33e3..6c479a18 100644 --- a/rdtools/analysis_chains.py +++ b/rdtools/analysis_chains.py @@ -467,7 +467,8 @@ def _call_clearsky_filter(filter_string): if 'hour_angle_filter' in self.filter_params: if self.pvlib_location is None: raise ValueError( - 'pvlib location must be provided using set_clearsky() ' + '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( From c9285fea7e39ffc09d82029367746d122d2471ef Mon Sep 17 00:00:00 2001 From: Michael Deceglie Date: Thu, 25 May 2023 13:49:40 -0600 Subject: [PATCH 6/8] try updating arch version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b0bfb519..30fdf1bd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ pvlib==0.9.0 pyparsing==2.4.7 python-dateutil==2.8.1 pytz==2019.3 -arch==4.11 +arch==6.0.1 filterpy==1.4.5 requests==2.25.1 retrying==1.3.3 From e889ffedd4101740650036551ef8dd14afa9786d Mon Sep 17 00:00:00 2001 From: Michael Deceglie Date: Thu, 25 May 2023 14:04:51 -0600 Subject: [PATCH 7/8] try arch=5.5.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 30fdf1bd..4910f6ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ pvlib==0.9.0 pyparsing==2.4.7 python-dateutil==2.8.1 pytz==2019.3 -arch==6.0.1 +arch==5.5.0 filterpy==1.4.5 requests==2.25.1 retrying==1.3.3 From 2e689e4e50810ecc18e8adca0a58e6e1a3c2ce1b Mon Sep 17 00:00:00 2001 From: cdeline Date: Thu, 25 May 2023 14:24:22 -0600 Subject: [PATCH 8/8] fix broken self.pvlib_location checks. --- rdtools/analysis_chains.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rdtools/analysis_chains.py b/rdtools/analysis_chains.py index 6c479a18..8ffa750e 100644 --- a/rdtools/analysis_chains.py +++ b/rdtools/analysis_chains.py @@ -236,10 +236,10 @@ def _calc_clearsky_poa(self, times=None, rescale=True, **kwargs): freq='1min') aggregate = True - if self.pvlib_location is None: + if not hasattr(self, 'pvlib_location'): raise ValueError( 'pvlib location must be provided using set_clearsky()') - if self.pv_tilt is None or self.pv_azimuth is None: + if not hasattr(self, 'pv_tilt') or not hasattr(self, 'pv_azimuth'): raise ValueError( 'pv_tilt and pv_azimuth must be provided using set_clearsky()') @@ -332,9 +332,9 @@ def _calc_clearsky_tamb(self): Calculate clear-sky ambient temperature and store in self.temperature_ambient_clearsky ''' times = self.poa_global_clearsky.index - if self.pvlib_location is None: + if not hasattr(self, 'pvlib_location'): raise ValueError( - 'pvlib location must be provided using set_clearsky()') + 'pvlib_location must be provided using set_clearsky()') loc = self.pvlib_location cs_amb_temp = clearsky_temperature.get_clearsky_tamb( @@ -465,7 +465,7 @@ def _call_clearsky_filter(filter_string): 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: + if not hasattr(self, 'pvlib_location'): raise ValueError( 'The pvlib location must be provided using set_clearsky() ' 'or by directly setting TrendAnalysis.pvlib_location '