def test_shade_azimuth_value_error(self): with self.assertRaises(Exception) as context: shade(0, 0, 360, zenith=10) self.assertTrue('Azimuth must be between -180 and 180 degrees' in str(context.exception)) # noqa
def test_shade_aspect_degrees_error(self): with self.assertRaises(Exception) as context: shade(0, 100, 0, zenith=10) self.assertTrue( 'Aspect is not in radians from south' in str(context.exception))
def test_shade_zenith_cosz_not_specified_error(self): with self.assertRaises(Exception) as context: shade(0, 0, 0) self.assertTrue( 'Must specify either cosz or zenith' in str(context.exception))
def test_shade_zenith_bounds_error(self): with self.assertRaises(Exception) as context: shade(0, 0, 0, zenith=-10) self.assertTrue( 'Zenith must be >= 0 and < 90' in str(context.exception))
def test_shade_east(self): # test east slope and aspect dem = np.fliplr(np.tile(range(10), (10, 1))) slope, asp = self.calc_slope(dem) zenith = 45 mu = shade(slope, asp, 0, zenith=zenith) mu_cos = shade(slope, asp, 0, cosz=np.cos(zenith * np.pi / 180)) self.assertAlmostEqual(np.mean(mu), 0.43769265754174774, places=7) np.testing.assert_allclose(mu, mu_cos)
def test_shade_north(self): # test north slope and aspect dem = np.tile(range(10), (10, 1)).transpose() slope, asp = self.calc_slope(dem) zenith = 45 mu = shade(slope, asp, 0, zenith=zenith) mu_cos = shade(slope, asp, 0, cosz=np.cos(zenith * np.pi / 180)) self.assertAlmostEqual(np.mean(mu), 0.0, places=7) np.testing.assert_allclose(mu, mu_cos)
def shade_thread(queue, date, sin_slope, aspect, zenith=None): """ See shade for input argument descriptions Args: queue: queue with illum_ang, cosz, azimuth date_time: loop through dates to accesss sin_slope: numpy array of sine of slope angles sin(S) aspect: numpy array of aspect in radians from south azimuth: azimuth in degrees to the sun -180..180 (comes from sunang) zenith: the solar zenith angle 0..90 degrees """ for v in ['cosz', 'azimuth', 'illum_ang']: if v not in queue.keys(): raise ValueError('Queue must have {} key'.format(v)) log = logging.getLogger(__name__) for t in date: log.debug('%s Calculating illumination angle' % t) mu = None cosz = queue['cosz'].get(t) if cosz > 0: azimuth = queue['azimuth'].get(t) mu = shade(sin_slope, aspect, azimuth, cosz, zenith) queue['illum_ang'].put([t, mu])
def setUpClass(cls): super().setUpClass() date_time = pd.to_datetime('2/15/1990 20:30') cls.date_time = date_time.tz_localize('UTC') cls.tau_elevation = 100.0 cls.tau = 0.2 cls.omega = 0.85 cls.scattering_factor = 0.3 cls.surface_albedo = 0.5 cls.solar_irradiance = irradiance.direct_solar_irradiance( cls.date_time, w=[0.28, 2.8]) topo_config = { 'filename': os.path.join(cls.basin_dir, 'topo/topo.nc'), 'northern_hemisphere': True, 'gradient_method': 'gradient_d8', 'sky_view_factor_angles': 72 } cls.topo = Topo(topo_config) cls.dem = cls.topo.dem # inputs for toporad and stoporad cls.cosz, cls.azimuth, rad_vec = sunang( cls.date_time, cls.topo.basin_lat, cls.topo.basin_long) cls.elevrad = toporad.Elevrad( cls.dem, cls.solar_irradiance, cls.cosz) cls.illum_ang = shade( cls.topo.sin_slope, cls.topo.aspect, cls.azimuth, cls.cosz)
def distribute_single_timestep(self, t): self._logger.info('Distributing time step {}'.format(t)) if self.hrrr_data_timestep: self.data.load_class.load_timestep(t) self.data.set_variables() # 0.1 sun angle for time step cosz, azimuth, rad_vec = sunang.sunang(t.astimezone(pytz.utc), self.topo.basin_lat, self.topo.basin_long) # 0.2 illumination angle illum_ang = None if cosz > 0: illum_ang = shade(self.topo.sin_slope, self.topo.aspect, azimuth, cosz) # 1. Air temperature self.distribute['air_temp'].distribute(self.data.air_temp.loc[t]) # 2. Vapor pressure self.distribute['vapor_pressure'].distribute( self.data.vapor_pressure.loc[t], self.distribute['air_temp'].air_temp) # 3. Wind_speed and wind_direction self.distribute['wind'].distribute(self.data.wind_speed.loc[t], self.data.wind_direction.loc[t], t) # 4. Precipitation self.distribute['precipitation'].distribute( self.data.precip.loc[t], self.distribute['vapor_pressure'].dew_point, self.distribute['vapor_pressure'].precip_temp, self.distribute['air_temp'].air_temp, t, self.data.wind_speed.loc[t], self.data.air_temp.loc[t], self.distribute['wind'].wind_direction, self.distribute['wind'].wind_model.dir_round_cell, self.distribute['wind'].wind_speed, self.distribute['wind'].wind_model.cellmaxus) # 5. Albedo self.distribute['albedo'].distribute( t, illum_ang, self.distribute['precipitation'].storm_days) # 6. cloud_factor self.distribute['cloud_factor'].distribute( self.data.cloud_factor.loc[t]) # 7. Solar self.distribute['solar'].distribute( t, self.distribute["cloud_factor"].cloud_factor, illum_ang, cosz, azimuth, self.distribute['albedo'].albedo_vis, self.distribute['albedo'].albedo_ir) # 8. thermal radiation self.distribute['thermal'].distribute( t, self.distribute['air_temp'].air_temp, self.distribute['vapor_pressure'].vapor_pressure, self.distribute['vapor_pressure'].dew_point, self.distribute['cloud_factor'].cloud_factor) # 9. Soil temperature self.distribute['soil_temp'].distribute()
def test_shade_cosz_bounds_error(self): with self.assertRaises(Exception) as context: shade(0, 0, 0, cosz=1.5) self.assertTrue('cosz must be > 0 and <= 1' in str(context.exception))