From 42e582ab3dc10ef94d6eb483840eadbdfae4ba61 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Wed, 10 Apr 2024 09:36:45 -0600 Subject: [PATCH] add tests --- pvanalytics/features/snow.py | 4 +-- pvanalytics/tests/features/test_snow.py | 48 ++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/pvanalytics/features/snow.py b/pvanalytics/features/snow.py index 4bdee425..fbde2b5f 100644 --- a/pvanalytics/features/snow.py +++ b/pvanalytics/features/snow.py @@ -132,9 +132,9 @@ def get_transmission(measured_e_e, modeled_e_e, i_mp): 50th Photovoltaic Specialists Conference (PVSC), San Juan, PR, USA, 2023, pp. 1-5. :doi:`10.1109/PVSC48320.2023.10360065` """ - + # TODO only works with Series T = modeled_e_e/measured_e_e - T[T.isna()] = np.nan + T[T.isna()] = np.nan # TODO what does this accomplish T[i_mp == 0] = 0 T[T < 0] = np.nan T[T > 1] = 1 diff --git a/pvanalytics/tests/features/test_snow.py b/pvanalytics/tests/features/test_snow.py index e2074a4b..e36e787a 100644 --- a/pvanalytics/tests/features/test_snow.py +++ b/pvanalytics/tests/features/test_snow.py @@ -7,10 +7,11 @@ import numpy as np import pandas as pd from numpy.testing import assert_array_equal +from pandas.testing import assert_series_equal from pvanalytics.features import snow -def test_horizon_mask(): +def test_get_horizon_mask(): horizon = pd.Series(index=range(0, 360), data=0) horizon[5:10] = 10 result = snow.get_horizon_mask(horizon, azimuth=np.array([4, 5, 7]), @@ -19,6 +20,51 @@ def test_horizon_mask(): assert_array_equal(result, expected) +def test_get_irradiance_sapm(): + # solve Ee^2 + 2 Ee - 3 = 0 + c0, c1 = (2, 1) + imp0 = 6. + alpha_imp = -2. / 3 + temp_cell = 26. + # effective irradiance = i_mp / factor + i_mp = np.array([6., 0., np.nan]) + result = snow.get_irradiance_sapm(temp_cell, i_mp, imp0, c0, c1, alpha_imp) + expected = np.array([1000., 0., np.nan]) # from suns to W/m2 + assert_array_equal(result, expected) + # test with Series + i_mp = pd.Series(data=i_mp) + temp_cell = pd.Series(index=i_mp.index, data=26.) + result = snow.get_irradiance_sapm(temp_cell, i_mp, imp0, c0, c1, alpha_imp) + assert_series_equal(result, pd.Series(index=i_mp.index, data=expected)) + + +def test_get_irradiance_imp(): + # solve Ee = Imp / Imp0 + imp0 = 6. + i_mp = np.array([6., 0., np.nan]) + result = snow.get_irradiance_imp(i_mp, imp0) + expected = np.array([1000., 0, np.nan]) + assert_array_equal(result, expected) + # test with Series + i_mp = pd.Series(data=i_mp) + result = snow.get_irradiance_imp(i_mp, imp0) + assert_series_equal(result, pd.Series(index=i_mp.index, data=expected)) + + +def test_get_transmission(): + # solve modeled_ee / measured_ee, subject to i_mp>0, with bounds + # T[T.isna()] = np.nan + # T[i_mp == 0] = 0 + # T[T < 0] = np.nan + # T[T > 1] = 1 + measured_ee = pd.Series(data=[1., 0.5, 1., -1., np.nan]) + modeled_ee = pd.Series(data=[1., 1., 1., 1., 1.]) + i_mp = pd.Series(data=[1., 1., 0., 1., 1.]) + result = snow.get_transmission(measured_ee, modeled_ee, i_mp) + expected = pd.Series(data=[1., 1., 0., np.nan, np.nan]) + assert_series_equal(result, expected) + + def test_categorize(): vmp_ratio = np.array([np.nan, 0.9, 0.1, 0.6, 0.7, 0.9, 0.9]) voltage = np.array([400., 400., 400., 400., 400., 400., 200.])