From aec1a46071769b7b397b1c73fa0ab179391f6bff Mon Sep 17 00:00:00 2001 From: Will Vining Date: Mon, 22 Jun 2020 13:01:19 -0600 Subject: [PATCH 1/5] Add module temperature/irradiance correlation check --- pvanalytics/quality/weather.py | 29 +++++++++++++++++++++++ pvanalytics/tests/quality/test_weather.py | 19 +++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/pvanalytics/quality/weather.py b/pvanalytics/quality/weather.py index caa7d888..157ac265 100644 --- a/pvanalytics/quality/weather.py +++ b/pvanalytics/quality/weather.py @@ -1,5 +1,6 @@ """Quality control functions for weather data.""" from pvanalytics.quality import util +from scipy import stats def temperature_limits(air_temperature, limits=(-35.0, 50.0)): @@ -97,3 +98,31 @@ def wind_limits(wind_speed, limits=(0.0, 50.0)): upper_bound=limits[1], inclusive_lower=True ) + + +def module_temperature_check(module_temperature, irradiance, + correlation_min=0.5): + """Test whether the module temperature is correlated with irradiance. + + Parameters + ---------- + module_temperature : Series + Time series of module temperature. + irradiance : Series + Time series of irradiance with the same index as + `module_temperature`. This should be of relatively high + quality (outliers and other problems removed). + correlation_min : float, default 0.5 + Minimum correlation between `module_temperature` and + `irradiance` for the module temperature sensor to 'pass' + + Returns + ------- + bool + True if the `module_temperature` is correlated with + `irradiance`. + + """ + _, _, r, _, _ = stats.linregress(module_temperature, irradiance) + return r > correlation_min + diff --git a/pvanalytics/tests/quality/test_weather.py b/pvanalytics/tests/quality/test_weather.py index c2807e30..2293d0de 100644 --- a/pvanalytics/tests/quality/test_weather.py +++ b/pvanalytics/tests/quality/test_weather.py @@ -2,6 +2,7 @@ import pytest import pandas as pd import numpy as np +from pvlib import location from pandas.util.testing import assert_series_equal from pvanalytics.quality import weather @@ -87,3 +88,21 @@ def test_wind_limits(weather_data): weather_data['extreme_wind_flag'], check_names=False ) + + +def test_module_temperatuew(): + """Module temperature is correlated with GHI.""" + albuquerque = location.Location(35.0844, -106.6504, altitude=5312, tz='MST') + times = pd.date_range( + start='01/01/2020', + end='03/01/2020', + freq='H', + tz='MST' + ) + clearsky = albuquerque.get_clearsky(times, model='simplified_solis') + assert weather.module_temperature_check( + clearsky['ghi']*0.6, clearsky['ghi'] + ) + assert not weather.module_temperature_check( + clearsky['ghi']*(-0.6), clearsky['ghi'] + ) From 666ccb6d9d1a1b3326e4f27e1962f6c174bd3f02 Mon Sep 17 00:00:00 2001 From: Will Vining Date: Mon, 22 Jun 2020 13:12:11 -0600 Subject: [PATCH 2/5] Shorten lines --- pvanalytics/quality/weather.py | 1 - pvanalytics/tests/quality/test_weather.py | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pvanalytics/quality/weather.py b/pvanalytics/quality/weather.py index 157ac265..10de92fc 100644 --- a/pvanalytics/quality/weather.py +++ b/pvanalytics/quality/weather.py @@ -125,4 +125,3 @@ def module_temperature_check(module_temperature, irradiance, """ _, _, r, _, _ = stats.linregress(module_temperature, irradiance) return r > correlation_min - diff --git a/pvanalytics/tests/quality/test_weather.py b/pvanalytics/tests/quality/test_weather.py index 2293d0de..147365c0 100644 --- a/pvanalytics/tests/quality/test_weather.py +++ b/pvanalytics/tests/quality/test_weather.py @@ -92,7 +92,9 @@ def test_wind_limits(weather_data): def test_module_temperatuew(): """Module temperature is correlated with GHI.""" - albuquerque = location.Location(35.0844, -106.6504, altitude=5312, tz='MST') + albuquerque = location.Location( + 35.0844, -106.6504, altitude=5312, tz='MST' + ) times = pd.date_range( start='01/01/2020', end='03/01/2020', From 80d8f477c3220eaabcda749b8318094cc335023e Mon Sep 17 00:00:00 2001 From: Will Vining Date: Mon, 22 Jun 2020 14:56:31 -0600 Subject: [PATCH 3/5] Add API documentation for the module temperature check --- docs/api.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index e6b92faf..261990b8 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -134,6 +134,20 @@ Quality checks for weather data. quality.weather.temperature_limits quality.weather.wind_limits +In addition to validating temperature limits, module-temperature can +be validated by testing whether it is correlated with irradiance. Poor +correlation could indicate that the sensor has become detached from +the module, for example. Unlike other functions in the +:py:mod:`quality` module which return Boolean masks over the input +series, this function returns a single Boolean value indicating +whether the entire series has passed (``True``) or failed (``False``) +the quality check. + +.. autosummary:: + :toctree: generated/ + + quality.weather.module_temperature_check + Features ======== From cbfed195b053d74710e11aabb62f255bf7b9b10e Mon Sep 17 00:00:00 2001 From: Will Vining Date: Mon, 13 Jul 2020 12:13:14 -0600 Subject: [PATCH 4/5] Fix test name spelling --- pvanalytics/tests/quality/test_weather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvanalytics/tests/quality/test_weather.py b/pvanalytics/tests/quality/test_weather.py index 147365c0..a32138e4 100644 --- a/pvanalytics/tests/quality/test_weather.py +++ b/pvanalytics/tests/quality/test_weather.py @@ -90,7 +90,7 @@ def test_wind_limits(weather_data): ) -def test_module_temperatuew(): +def test_module_temperature(): """Module temperature is correlated with GHI.""" albuquerque = location.Location( 35.0844, -106.6504, altitude=5312, tz='MST' From c438e2ee0c185ecc46cb19e4306a322fa5c0b284 Mon Sep 17 00:00:00 2001 From: Will Vining Date: Tue, 21 Jul 2020 10:56:47 -0600 Subject: [PATCH 5/5] Reword documentation Co-authored-by: Cliff Hansen --- docs/api.rst | 4 ++-- pvanalytics/quality/weather.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 261990b8..9d3c6499 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -134,8 +134,8 @@ Quality checks for weather data. quality.weather.temperature_limits quality.weather.wind_limits -In addition to validating temperature limits, module-temperature can -be validated by testing whether it is correlated with irradiance. Poor +In addition to validating temperature by comparing with limits, module +temperature should be positively correlated with irradiance. Poor correlation could indicate that the sensor has become detached from the module, for example. Unlike other functions in the :py:mod:`quality` module which return Boolean masks over the input diff --git a/pvanalytics/quality/weather.py b/pvanalytics/quality/weather.py index 10de92fc..5e331bab 100644 --- a/pvanalytics/quality/weather.py +++ b/pvanalytics/quality/weather.py @@ -119,8 +119,8 @@ def module_temperature_check(module_temperature, irradiance, Returns ------- bool - True if the `module_temperature` is correlated with - `irradiance`. + True if the correlation between `module_temperature` and + `irradiance` exceeds `correlation_min`. """ _, _, r, _, _ = stats.linregress(module_temperature, irradiance)