Skip to content

Commit

Permalink
move check for snow depth
Browse files Browse the repository at this point in the history
  • Loading branch information
cwhanse committed Dec 22, 2024
1 parent 0ef3d7a commit 57f5eef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
22 changes: 15 additions & 7 deletions pvlib/snow.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def coverage_nrel(snowfall, poa_irradiance, temp_air, surface_tilt,
# don't slide in the interval preceding the snowfall data
slide_amt.iloc[0] = 0

if snow_depth is not None:
# all slides off if there is no snow on the ground
# described in [2] to avoid non-sliding snow for low-tilt systems.
# default threshold_depth of 1cm is from SAM's implementation and
# is different than the value of 0cm implied in [2].
# https://github.com.mcas-gov.ms/NREL/ssc/issues/1265
slide_amt[snow_depth < threshold_depth] = 1.

# build time series of cumulative slide amounts
sliding_period_ID = new_snowfall.cumsum()
cumulative_sliding = slide_amt.groupby(sliding_period_ID).cumsum()
Expand All @@ -166,13 +174,13 @@ def coverage_nrel(snowfall, poa_irradiance, temp_air, surface_tilt,
snow_coverage.ffill(inplace=True)
snow_coverage -= cumulative_sliding

if snow_depth is not None:
# no coverage when there's no snow on the ground
# described in [2] to avoid non-sliding snow for low-tilt systems.
# default threshold_depth of 1cm is from SAM's implementation and
# is different than the value of 0cm implied in [2].
# https://github.com.mcas-gov.ms/NREL/ssc/issues/1265
snow_coverage[snow_depth < threshold_depth] = 0.
# if snow_depth is not None:
# # no coverage when there's no snow on the ground
# # described in [2] to avoid non-sliding snow for low-tilt systems.
# # default threshold_depth of 1cm is from SAM's implementation and
# # is different than the value of 0cm implied in [2].
# # https://github.com.mcas-gov.ms/NREL/ssc/issues/1265
# snow_coverage[snow_depth < threshold_depth] = 0.
# clean up periods where row is completely uncovered
return snow_coverage.clip(lower=0)

Expand Down
13 changes: 7 additions & 6 deletions pvlib/tests/test_snow.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ def test_coverage_nrel_hourly_with_snow_depth():
surface_tilt = 45
slide_amount_coefficient = 0.197
threshold_depth = 0.5
dt = pd.date_range(start="2019-1-1 10:00:00", end="2019-1-1 17:00:00",
dt = pd.date_range(start="2019-1-1 10:00:00", end="2019-1-1 18:00:00",
freq='1h')
poa_irradiance = pd.Series([400, 200, 100, 1234, 134, 982, 100, 100],
poa_irradiance = pd.Series([400, 200, 100, 1234, 134, 982, 100, 100, 100],
index=dt)
temp_air = pd.Series([10, 2, 10, 1234, 34, 982, 10, 10], index=dt)
snowfall_data = pd.Series([1, .5, .6, .4, .23, -5, .1, .1], index=dt)
snow_depth = pd.Series([1, 1, 1, 1, 0, 1, 0, .1], index=dt)
temp_air = pd.Series([10, 2, 10, 1234, 34, 982, 10, 10, 10], index=dt)
# restarts with new snow on 5th time step
snowfall_data = pd.Series([1, .5, .6, .4, .23, 5., .1, .1, 0.], index=dt)
snow_depth = pd.Series([1, 1, 1, 1, 0, 1, 1, 0, .1], index=dt)
snow_coverage = snow.coverage_nrel(
snowfall_data, poa_irradiance, temp_air, surface_tilt,
snow_depth=snow_depth, threshold_snowfall=0.6,
threshold_depth=threshold_depth)

slide_amt = slide_amount_coefficient * sind(surface_tilt)
covered = 1.0 - slide_amt * np.array([0, 1, 2, 3, 4, 5, 6, 7])
covered = 1.0 - slide_amt * np.array([0, 1, 2, 3, 0, 0, 1, 0, 0])
expected = pd.Series(covered, index=dt)
expected[snow_depth < threshold_depth] = 0
assert_series_equal(expected, snow_coverage)
Expand Down

0 comments on commit 57f5eef

Please sign in to comment.