.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/weather/module-temperature-check.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_gallery_weather_module-temperature-check.py: Module Temperature Check ======================== Test whether the module temperature is correlated with irradiance. .. GENERATED FROM PYTHON SOURCE LINES 9-18 Testing the correlation between module temperature and irradiance measurements can help identify if there are issues with the module temperature sensor. In this example, we demonstrate how to use :py:func:`pvanalytics.quality.weather.module_temperature_check`, which runs a linear regression model of module temperature vs. irradiance. Model performance is then assessed by the Pearson correlation coefficient. If it meets a minimum threshold, function outputs a True boolean. If not, it outputs a False boolean. .. GENERATED FROM PYTHON SOURCE LINES 18-27 .. code-block:: default import pvanalytics from pvanalytics.quality.weather import module_temperature_check from pvanalytics.features.daytime import power_or_irradiance import matplotlib.pyplot as plt import pandas as pd from scipy.stats import linregress import pathlib .. GENERATED FROM PYTHON SOURCE LINES 28-33 First, we read in example data from the NREL SERF West system, which contains data for module temperature and irradiance under the 'module_temp_1__781' and 'poa_irradiance__771' columns, respectively. This data set contains 15-minute averaged measurements, and is available via the NREL PVDAQ database as system 51. .. GENERATED FROM PYTHON SOURCE LINES 33-40 .. code-block:: default pvanalytics_dir = pathlib.Path(pvanalytics.__file__).parent serf_east_file = pvanalytics_dir / 'data' / 'serf_west_15min.csv' data = pd.read_csv(serf_east_file, index_col=0, parse_dates=True) print(data[['module_temp_1__781', 'poa_irradiance__771']].head(10)) .. rst-class:: sphx-glr-script-out .. code-block:: none module_temp_1__781 poa_irradiance__771 2022-01-02 00:01:00 -6.4187 -1.9775 2022-01-02 00:16:00 -6.2204 -2.0451 2022-01-02 00:31:00 -6.1505 -2.1464 2022-01-02 00:46:00 -5.9059 -2.1463 2022-01-02 01:01:00 -5.7022 -1.8083 2022-01-02 01:16:00 -5.4755 -1.9941 2022-01-02 01:31:00 -5.3714 -2.0109 2022-01-02 01:46:00 -4.4072 -1.7236 2022-01-02 02:01:00 -4.1609 -1.6221 2022-01-02 02:16:00 -3.9174 -1.6390 .. GENERATED FROM PYTHON SOURCE LINES 41-42 Plot the module temperature to visualize it. .. GENERATED FROM PYTHON SOURCE LINES 42-50 .. code-block:: default data['module_temp_1__781'].plot() plt.xlabel("Date") plt.ylabel("Module Temperature (deg C)") plt.xticks(rotation=25) plt.tight_layout() plt.show() .. image-sg:: /generated/gallery/weather/images/sphx_glr_module-temperature-check_001.png :alt: module temperature check :srcset: /generated/gallery/weather/images/sphx_glr_module-temperature-check_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 51-52 Plot the POA irradiance to visualize it. .. GENERATED FROM PYTHON SOURCE LINES 52-60 .. code-block:: default data['poa_irradiance__771'].plot() plt.xlabel("Date") plt.ylabel("POA irradiance (W/m^2)") plt.xticks(rotation=25) plt.tight_layout() plt.show() .. image-sg:: /generated/gallery/weather/images/sphx_glr_module-temperature-check_002.png :alt: module temperature check :srcset: /generated/gallery/weather/images/sphx_glr_module-temperature-check_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 61-63 We mask the irradiance time series into day-night periods, and remove any nighttime data to clean up the future regression. .. GENERATED FROM PYTHON SOURCE LINES 63-68 .. code-block:: default predicted_day_night_mask = power_or_irradiance( series=data['poa_irradiance__771'], freq='15T') # Filter out nighttime periods data = data[predicted_day_night_mask] .. GENERATED FROM PYTHON SOURCE LINES 69-72 We then use :py:func:`pvanalytics.quality.weather.module_temperature_check` to regress module temperature against irradiance POA, and check if the relationship meets the minimum correlation coefficient criteria. .. GENERATED FROM PYTHON SOURCE LINES 72-77 .. code-block:: default corr_coeff_bool = module_temperature_check(data['module_temp_1__781'], data['poa_irradiance__771']) print("Passes correlation coeff threshold? " + str(corr_coeff_bool)) .. rst-class:: sphx-glr-script-out .. code-block:: none Passes correlation coeff threshold? True .. GENERATED FROM PYTHON SOURCE LINES 78-80 We then plot module temperature against irradiance to illustrate the relationship. .. GENERATED FROM PYTHON SOURCE LINES 80-97 .. code-block:: default data.plot(x='module_temp_1__781', y='poa_irradiance__771', style='o', legend=None) data_reg = data[['module_temp_1__781', 'poa_irradiance__771']].dropna() # Add the linear regression line reg = linregress(data_reg['module_temp_1__781'].values, data_reg['poa_irradiance__771'].values) plt.axline(xy1=(0, reg.intercept), slope=reg.slope, linestyle="--", color="k") plt.xlabel("Module Temperature (deg C)") plt.ylabel("POA irradiance (W/m^2)") plt.xticks(rotation=25) plt.tight_layout() plt.show() # Print the Pearson correlation coefficient associated with the regression. print("Pearson Correlation Coefficient: ") print(reg.rvalue) .. image-sg:: /generated/gallery/weather/images/sphx_glr_module-temperature-check_003.png :alt: module temperature check :srcset: /generated/gallery/weather/images/sphx_glr_module-temperature-check_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Pearson Correlation Coefficient: 0.6836377995026489 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.537 seconds) .. _sphx_glr_download_generated_gallery_weather_module-temperature-check.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: module-temperature-check.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: module-temperature-check.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_