From 2af3fa0dc6f397d636345068a003ee6bb3622412 Mon Sep 17 00:00:00 2001 From: Cliff Hansen Date: Wed, 10 Apr 2024 12:39:26 -0600 Subject: [PATCH] handle equals --- docs/examples/snow-detection/snow-mode.py | 2 ++ pvanalytics/features/snow.py | 24 +++++++++++------------ pvanalytics/tests/features/test_snow.py | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/examples/snow-detection/snow-mode.py b/docs/examples/snow-detection/snow-mode.py index 56705f67..016533db 100644 --- a/docs/examples/snow-detection/snow-mode.py +++ b/docs/examples/snow-detection/snow-mode.py @@ -374,6 +374,7 @@ def wrapper(voltage, current, temp_cell, effective_irradiance, 2. Calculate transmission 3. Uses transmission to model voltage with the SAPM. # TODO How is this voltage different than measured (snow-affected voltage)? + # Answer: All cells are modeled to get the incoming irradiance 4. Determine the snow mode for each point. Parameters @@ -652,6 +653,7 @@ def wrapper(voltage, current, temp_cell, effective_irradiance, modeled_line = Line2D([0], [0], label='Modeled', color='k', ls='--') measured_line = Line2D([0], [0], label='Measured', color='k') +# TODO don't mark offline periods as Mode 0 red_patch = mpatches.Patch(color='r', alpha=0.05, label='Mode 0') blue_patch = mpatches.Patch(color='b', alpha=0.05, label='Mode 1') yellow_patch = mpatches.Patch(color='y', alpha=0.05, label='Mode 2') diff --git a/pvanalytics/features/snow.py b/pvanalytics/features/snow.py index fbde2b5f..474abe52 100644 --- a/pvanalytics/features/snow.py +++ b/pvanalytics/features/snow.py @@ -4,8 +4,7 @@ def get_horizon_mask(horizon, azimuth, elevation): """ - Determines if a given (azimuth, elevation) pair is above or - below a horizon profile + Determines if a given (azimuth, elevation) pair is above a horizon profile. Parameters ---------- @@ -22,7 +21,7 @@ def get_horizon_mask(horizon, azimuth, elevation): out : bool or NaN """ yp = np.interp(azimuth, horizon.index, horizon.values) - out = elevation >= yp # TODO or strictly > + out = elevation >= yp return out @@ -106,9 +105,9 @@ def get_transmission(measured_e_e, modeled_e_e, i_mp): measured irradiance. Measured irradiance should be in the array's plane and represent snow-free - conditions. When possible, the irradiance should be adjusted for - reflections and spectral content. For example, the measured irradiance - could be obtained with a heated plane-of-array pyranometer. + conditions. For example, the measured irradiance could be obtained with a + heated plane-of-array pyranometer. When necessary, the irradiance should be + adjusted for reflections and spectral content. Parameters ---------- @@ -123,7 +122,7 @@ def get_transmission(measured_e_e, modeled_e_e, i_mp): Returns ------- T : array - Effective transmission. [unitless] + Effective transmission. [unitless] # TODO describe when expect nan, 0 References ---------- @@ -133,8 +132,9 @@ def get_transmission(measured_e_e, modeled_e_e, i_mp): 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 # TODO what does this accomplish + T = modeled_e_e / measured_e_e + # no transmission if no current + T[i_mp.isna()] = np.nan T[i_mp == 0] = 0 T[T < 0] = np.nan T[T > 1] = 1 @@ -262,9 +262,9 @@ def categorize(vmp_ratio, transmission, voltage, min_dcv, 50th Photovoltaic Specialists Conference (PVSC), San Juan, PR, USA, 2023, pp. 1-5, :doi:`10.1109/PVSC48320.2023.10360065`. """ - umin = voltage > min_dcv # necessary for all modes except 0 - uvr = np.where(vmp_ratio > threshold_vratio, 3, 1) - utrans = np.where(transmission > threshold_transmission, 1, 0) + umin = voltage >= min_dcv # necessary for all modes except 0 + uvr = np.where(vmp_ratio >= threshold_vratio, 3, 1) + utrans = np.where(transmission >= threshold_transmission, 1, 0) mode = np.where(np.isnan(vmp_ratio) | np.isnan(transmission), None, umin * (uvr + utrans)) diff --git a/pvanalytics/tests/features/test_snow.py b/pvanalytics/tests/features/test_snow.py index e36e787a..6e8ca834 100644 --- a/pvanalytics/tests/features/test_snow.py +++ b/pvanalytics/tests/features/test_snow.py @@ -75,7 +75,7 @@ def test_categorize(): # np.nan, vrthres, vr>thres, vrthres, vo>thres, vo>thres, vo>thres, vo>thres, vo>thres, vothres, trthres - expected = np.array([None, None, 2, 2, 2, 4, 0]) + expected = np.array([None, None, 2, 2, 3, 4, 0]) result = snow.categorize(vmp_ratio, transmission, voltage, min_dcv, threshold_vratio, threshold_transmission) assert_array_equal(result, expected)