Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions smrf/distribute/albedo.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def distribute(
self.albedo_ir = utils.set_min_max(alb_ir, self.min, self.max)

else:
self.albedo_vis = np.zeros(storm_day.shape)
self.albedo_ir = np.zeros(storm_day.shape)
self.albedo_vis = None
self.albedo_ir = None

def date_method(
self,
Expand Down
26 changes: 26 additions & 0 deletions smrf/tests/distribute/test_albedo.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ def test_distribute_file_broadband(self, mock_read_netcdf):
npt.assert_equal(subject.albedo, values)
mock_source.load.assert_called_with("albedo", TIMESTEP)

@patch("smrf.distribute.variable_base.ReadNetCDF")
def test_distribute_file_broadband_after_sun_down(self, mock_read_netcdf):
# A night step must not set vis/ir values, as these take priority over the
# broadband albedo in the net solar calculation
values = np.array([0.9, 0.5])
mock_source = MagicMock()
mock_source.variables = ["albedo"]
mock_source.load.return_value = values
mock_read_netcdf.return_value = mock_source

config = self._copy_config(CONFIG)
config["albedo"]["source_files"] = "path/to/files"
subject = Albedo(config, topo_mock())
subject.initialize(pd.DataFrame())

# Sun is down
subject.distribute(TIMESTEP, None, STORM_DAYS)
self.assertIsNone(subject.albedo_vis)
self.assertIsNone(subject.albedo_ir)

# Sun is up
subject.distribute(TIMESTEP, COS_Z, STORM_DAYS)
npt.assert_equal(subject.albedo, values)
self.assertIsNone(subject.albedo_vis)
self.assertIsNone(subject.albedo_ir)

@patch("smrf.distribute.variable_base.ReadNetCDF")
def test_distribute_file_vis_ir(self, mock_read_netcdf):
values_vis = np.array([0.8, 0.7])
Expand Down
38 changes: 37 additions & 1 deletion smrf/tests/distribute/test_solar_hrrr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from unittest.mock import patch
from unittest.mock import MagicMock, patch

import numpy as np
import numpy.testing as npt
Expand Down Expand Up @@ -114,6 +114,42 @@ def test_distribute_with_vegetation(self, vegetation_mock):
diffuse, self.subject.veg_tau
)

@patch("smrf.distribute.variable_base.ReadNetCDF")
@patch("smrf.distribute.solar_hrrr.mask_for_shade")
def test_net_solar_broadband_albedo_after_sun_down(
self, shade_mock, mock_read_netcdf
):
shade_mock.return_value = ILLUMINATION_MOCK, np.array([1, 1])

broadband = np.array([[0.8, 0.5]], dtype=np.float32)
mock_source = MagicMock()
mock_source.variables = ["albedo"]
mock_source.load.return_value = broadband
mock_read_netcdf.return_value = mock_source

config = {
"time": {"start_date": "2025-10-01 00:00", "time_zone": "utc"},
"albedo": {"decay_method": None, "source_files": "path/to/files"},
"solar": {"correct_veg": False},
}
albedo = Albedo(config=config, topo=topo_mock())
albedo.initialize(pd.DataFrame())

# A night step precedes the first daylight step, like at the start of a run
storm_days = np.zeros_like(ILLUMINATION_MOCK)
albedo.distribute(DATETIME, None, storm_days)
albedo.distribute(DATETIME, COS_Z, storm_days)

self.subject.distribute(
DATETIME, DATA_MOCK, COS_Z, AZIMUTH, ILLUMINATION_MOCK, albedo
)

# Net solar is reduced by the broadband albedo and not passed through
npt.assert_allclose(
self.subject.net_solar, self.subject.hrrr_solar * (1 - broadband)
)
self.assertTrue(np.all(self.subject.net_solar < self.subject.hrrr_solar))

def test_distribute_sun_is_down(self):
self.subject.distribute(
DATETIME,
Expand Down
Loading