Esempio n. 1
0
def test_from_zhang_huang():
    """Test from zhang huang solar model"""
    path = './tests/assets/epw/chicago.epw'
    epw = EPW(path)

    # test it first without pressure values
    wea_from_zh = Wea.from_zhang_huang_solar(
        epw.location, epw.total_sky_cover, epw.relative_humidity,
        epw.dry_bulb_temperature, epw.wind_speed)

    # include EPW pressure values
    wea_from_zh = Wea.from_zhang_huang_solar(
        epw.location, epw.total_sky_cover, epw.relative_humidity,
        epw.dry_bulb_temperature, epw.wind_speed, epw.atmospheric_station_pressure)

    assert wea_from_zh.location.city == 'Chicago Ohare Intl Ap'
    assert wea_from_zh.timestep == 1
    assert wea_from_zh.global_horizontal_irradiance[0] == \
        pytest.approx(0, rel=1e-1)
    assert wea_from_zh.global_horizontal_irradiance[12] == \
        pytest.approx(417.312, rel=1e-1)
    assert wea_from_zh.direct_normal_irradiance[12] == \
        pytest.approx(654.52, rel=1e-1)
    assert wea_from_zh.diffuse_horizontal_irradiance[12] == \
        pytest.approx(144.51, rel=1e-1)
Esempio n. 2
0
def test_zhang_huang_accuracy():
    """Test zhang huang solar model to ensure that average error is within
    25% of actual solar."""
    path = './tests/assets/epw/chicago.epw'
    epw = EPW(path)

    wea = Wea.from_zhang_huang_solar(
        epw.location, epw.total_sky_cover, epw.relative_humidity,
        epw.dry_bulb_temperature, epw.wind_speed, epw.atmospheric_station_pressure)

    # test global horizontal radiation
    glob_horiz_error = [abs(i - j) for i, j in zip(
        epw.global_horizontal_radiation,
        wea.global_horizontal_irradiance)]
    avg_glob_horiz_error = sum(glob_horiz_error) / sum(
        epw.global_horizontal_radiation)
    assert (sum(glob_horiz_error) / 8760) < 50
    assert avg_glob_horiz_error < 0.5

    # test direct normal radiation
    dir_normal_error = [abs(i - j) for i, j in zip(
        epw.direct_normal_radiation, wea.direct_normal_irradiance)]
    avg_dir_normal_error = sum(dir_normal_error) / sum(
        epw.direct_normal_radiation)
    assert sum(dir_normal_error) / 8760 < 100
    assert avg_dir_normal_error < 0.5

    # test diffuse horizontal radiation
    dif_horiz_error = [abs(i - j) for i, j in zip(
        epw.diffuse_horizontal_radiation,
        wea.diffuse_horizontal_irradiance)]
    avg_dif_horiz_error = sum(dif_horiz_error) / sum(
        epw.diffuse_horizontal_radiation)
    assert sum(dif_horiz_error) / 8760 < 50
    assert avg_dif_horiz_error < 0.5
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try:
    from ladybug.wea import Wea
    from ladybug.datacollection import HourlyContinuousCollection
    from ladybug.header import Header
    from ladybug.datatype.pressure import AtmosphericStationPressure
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):
    # perform checks.
    assert isinstance(_cloud_cover, HourlyContinuousCollection), \
        'Data Collections must be Continuous Hourly.'
    if _atmos_pressure_ is None:
        header = Header(AtmosphericStationPressure(), 'Pa',
                        _cloud_cover.header.analysis_period,
                        _cloud_cover.header.metadata)
        _atmos_pressure_ = HourlyContinuousCollection(
            header,
            [101325] * 8760 * _cloud_cover.header.analysis_period.timestep)

    # build the Wea
    wea = Wea.from_zhang_huang_solar(_location, _cloud_cover, _rel_humidity,
                                     _dry_bulb_temp, _wind_speed,
                                     _atmos_pressure_)