Пример #1
0
def test_init_horizontal_solarcal_collection():
    """Test the initialization of the HorizontalSolarCal collection."""
    calc_length = 24
    irr_header = Header(Irradiance(), 'W/m2',
                        AnalysisPeriod(end_month=1, end_day=1))
    dir_norm = HourlyContinuousCollection(irr_header, [300] * calc_length)
    diff_horiz = HourlyContinuousCollection(irr_header, [100] * calc_length)
    solarcal_obj = HorizontalSolarCal(Location(), dir_norm, diff_horiz, 24)

    assert solarcal_obj.comfort_model == 'Horizontal SolarCal'
    assert solarcal_obj.calc_length == calc_length
    str(solarcal_obj)  # test that the string representaiton is ok

    assert isinstance(solarcal_obj.direct_horizontal_solar,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.direct_horizontal_solar.values) == calc_length
    assert solarcal_obj.direct_horizontal_solar[12] == 300
    assert isinstance(solarcal_obj.diffuse_horizontal_solar,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.diffuse_horizontal_solar.values) == calc_length
    assert solarcal_obj.diffuse_horizontal_solar[12] == 100

    assert isinstance(solarcal_obj.effective_radiant_field,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.effective_radiant_field.values) == calc_length
    assert solarcal_obj.effective_radiant_field[12] == pytest.approx(79.35027,
                                                                     rel=1e-3)
    assert isinstance(solarcal_obj.mrt_delta, HourlyContinuousCollection)
    assert len(solarcal_obj.mrt_delta.values) == calc_length
    assert solarcal_obj.mrt_delta[12] == pytest.approx(18.20503, rel=1e-3)
    assert isinstance(solarcal_obj.mean_radiant_temperature,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.mean_radiant_temperature.values) == calc_length
    assert solarcal_obj.mean_radiant_temperature[12] == pytest.approx(42.20503,
                                                                      rel=1e-3)
Пример #2
0
def test_init_horizontal_solarcal_collection_epw():
    """Test the initialization of the HorizontalSolarCal collection with EPW input."""
    calc_length = 8760
    wea_obj = Wea.from_epw_file('./tests/epw/chicago.epw')
    diff_hr = wea_obj.diffuse_horizontal_irradiance
    dir_hr = wea_obj.direct_horizontal_irradiance
    solarcal_obj = HorizontalSolarCal(wea_obj.location, dir_hr, diff_hr, 24)

    assert isinstance(solarcal_obj.direct_horizontal_solar,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.direct_horizontal_solar.values) == calc_length
    assert solarcal_obj.direct_horizontal_solar[12] == pytest.approx(62.9354,
                                                                     rel=1e-3)
    assert isinstance(solarcal_obj.diffuse_horizontal_solar,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.diffuse_horizontal_solar.values) == calc_length
    assert solarcal_obj.diffuse_horizontal_solar[12] == pytest.approx(168,
                                                                      rel=1e-3)

    assert isinstance(solarcal_obj.effective_radiant_field,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.effective_radiant_field.values) == calc_length
    assert solarcal_obj.effective_radiant_field[12] == pytest.approx(82.80573,
                                                                     rel=1e-3)
    assert isinstance(solarcal_obj.mrt_delta, HourlyContinuousCollection)
    assert len(solarcal_obj.mrt_delta.values) == calc_length
    assert solarcal_obj.mrt_delta[12] == pytest.approx(18.997806, rel=1e-3)
    assert isinstance(solarcal_obj.mean_radiant_temperature,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.mean_radiant_temperature.values) == calc_length
    assert solarcal_obj.mean_radiant_temperature[12] == pytest.approx(
        42.997806, rel=1e-3)
Пример #3
0
def test_horizontal_solarcal_collection_defaults():
    """Test the default inputs assigned to the HorizontalSolarCal collection."""
    calc_length = 24
    irr_header = Header(Irradiance(), 'W/m2',
                        AnalysisPeriod(end_month=1, end_day=1))
    dir_norm = HourlyContinuousCollection(irr_header, [500] * calc_length)
    diff_horiz = HourlyContinuousCollection(irr_header, [200] * calc_length)
    solarcal_obj = HorizontalSolarCal(Location(), dir_norm, diff_horiz, 24)

    assert isinstance(solarcal_obj.fraction_body_exposed,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.fraction_body_exposed.values) == calc_length
    assert solarcal_obj.fraction_body_exposed[12] == 1

    assert isinstance(solarcal_obj.floor_reflectance,
                      HourlyContinuousCollection)
    assert len(solarcal_obj.floor_reflectance.values) == calc_length
    assert solarcal_obj.floor_reflectance[12] == 0.25

    assert isinstance(solarcal_obj.solarcal_body_parameter, SolarCalParameter)
    default_par = SolarCalParameter()
    assert solarcal_obj.solarcal_body_parameter.posture == default_par.posture
    assert solarcal_obj.solarcal_body_parameter.sharp == default_par.sharp
    assert solarcal_obj.solarcal_body_parameter.body_azimuth == default_par.body_azimuth
    assert solarcal_obj.solarcal_body_parameter.body_absorptivity == default_par.body_absorptivity
    assert solarcal_obj.solarcal_body_parameter.body_emissivity == default_par.body_emissivity
Пример #4
0
def test_horizontal_solarcal_collection_full_input():
    """Test the initialization of the HorizontalSolarCal collection will all inputs."""
    calc_length = 24
    irr_header = Header(Irradiance(), 'W/m2',
                        AnalysisPeriod(end_month=1, end_day=1))
    dir_norm = HourlyContinuousCollection(irr_header, [500] * calc_length)
    diff_horiz = HourlyContinuousCollection(irr_header, [200] * calc_length)
    custom_par = SolarCalParameter('seated', None, 45, 0.65, 0.97)
    solarcal_obj = HorizontalSolarCal(Location(), dir_norm, diff_horiz, 24,
                                      0.6, 0.35, custom_par)

    assert solarcal_obj.fraction_body_exposed[12] == 0.6
    assert solarcal_obj.floor_reflectance[0] == 0.35
    assert solarcal_obj.solarcal_body_parameter.posture == 'seated'
    assert solarcal_obj.solarcal_body_parameter.sharp is None
    assert solarcal_obj.solarcal_body_parameter.body_azimuth == 45
    assert solarcal_obj.solarcal_body_parameter.body_absorptivity == 0.65
    assert solarcal_obj.solarcal_body_parameter.body_emissivity == 0.97
Пример #5
0
def mean_radiant_temperature(
        epw_file: str,
        direct_horizontal_solar: HourlyContinuousCollection = None,
        diffuse_horizontal_solar: HourlyContinuousCollection = None,
        ground: Ground = None,
        is_shaded: bool = False):
    """
    Calculate the Mean Radiant Temperature from solar and ground radiation components
    :param epw_file: Weather-file with location and climatic conditions for simulation
    :param direct_horizontal_solar: Radiation from the sun
    :param diffuse_horizontal_solar: Radiation from the sky
    :param ground: Ground object
    :param is_shaded: Calculate MRT under shaded or unshaded conditions
    :return mean_radiant_temperature: Mean Radiant Temperature
    """

    # Check that the ground is shaded/unshaded in the same way for both the surface temperature calculation and this calculation
    if (ground is not None) & (ground.is_shaded != is_shaded):
        raise ValueError(
            "Ground surface temperature calculation {} shaded but this calculation {}. These should match!"
            .format("is" if ground.is_shaded else "isn't",
                    "is" if is_shaded else "isn't"))

    # Factor the visible surface temperature based on exposure to ground (50% in open field)
    ground.surface_temperature.values = [
        i * 0.5 for i in ground.surface_temperature.values
    ]

    mrt = HorizontalSolarCal(
        location=EPW(epw_file).location,
        direct_horizontal_solar=direct_horizontal_solar,
        diffuse_horizontal_solar=diffuse_horizontal_solar,
        longwave_mrt=ground.surface_temperature,
        fraction_body_exposed=0 if is_shaded else 1,
        floor_reflectance=ground.reflectivity).mean_radiant_temperature

    print("Mean radiant temperature calculation completed")

    return mrt
        erf: Data collection of effective radiant field (ERF) in W/m2.
        dmrt: Data collection of mean radiant temperature delta in C.
        mrt: Data collection of mean radiant temperature in C.
"""

ghenv.Component.Name = 'LB Solar MRT from Solar Components'
ghenv.Component.NickName = 'ComponentSolarMRT'
ghenv.Component.Message = '1.0.0'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '1 :: Analyze Data'
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try:
    from ladybug_comfort.collection.solarcal import HorizontalSolarCal
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component) and _run is True:
    solar_mrt_obj = HorizontalSolarCal(_location, _dir_horiz_rad,
                                       _diff_horiz_rad, _longwave_mrt,
                                       fract_body_exp_, _ground_ref_,
                                       _solar_body_par_)

    erf = solar_mrt_obj.effective_radiant_field
    dmrt = solar_mrt_obj.mrt_delta
    mrt = solar_mrt_obj.mean_radiant_temperature