Exemplo n.º 1
0
def test_write_wea():
    """Test the write Wea file capability."""
    stat_path = './tests/assets/stat/chicago.stat'
    wea_from_stat = Wea.from_stat_file(stat_path)

    wea_path = './tests/assets/wea/chicago_stat.wea'
    hrs_path = './tests/assets/wea/chicago_stat.hrs'
    wea_from_stat.write(wea_path, True)

    assert os.path.isfile(wea_path)
    assert os.stat(wea_path).st_size > 1
    assert os.path.isfile(hrs_path)
    assert os.stat(hrs_path).st_size > 1

    # check the order of the data in the file
    with open(wea_path) as wea_f:
        lines = wea_f.readlines()
        assert float(lines[6].split(' ')[-2]) == \
            pytest.approx(
                wea_from_stat.direct_normal_irradiance[0], rel=1e-1)
        assert int(lines[6].split(' ')[-1]) == \
            wea_from_stat.diffuse_horizontal_irradiance[0]
        assert float(lines[17].split(' ')[-2]) == \
            pytest.approx(
                wea_from_stat.direct_normal_irradiance[11], rel=1e-1)
        assert float(lines[17].split(' ')[-1]) == \
            pytest.approx(
                wea_from_stat.diffuse_horizontal_irradiance[11], rel=1e-1)

    os.remove(wea_path)
    os.remove(hrs_path)
Exemplo n.º 2
0
def test_global_and_direct_horizontal():
    """Test the global horizontal irradiance on method."""
    stat_path = './tests/assets/stat/chicago.stat'
    wea_from_stat = Wea.from_stat_file(stat_path)

    diffuse_horiz_rad = wea_from_stat.diffuse_horizontal_irradiance
    direct_horiz_rad = wea_from_stat.direct_horizontal_irradiance
    glob_horiz_rad = wea_from_stat.global_horizontal_irradiance

    assert [x for x in glob_horiz_rad] == pytest.approx(
        [x + y for x, y in zip(diffuse_horiz_rad, direct_horiz_rad)], rel=1e-3)
Exemplo n.º 3
0
    def test_import_stat(self):
        """Test to compare import from stat with its json version."""
        stat_path = './tests/stat/chicago.stat'
        wea_from_stat = Wea.from_stat_file(stat_path)

        wea_json = wea_from_stat.to_json()
        wea_from_json = Wea.from_json(wea_json)
        assert wea_from_json.direct_normal_radiation.values == \
            wea_from_stat.direct_normal_radiation.values
        assert wea_from_json.diffuse_horizontal_radiation.values == \
            wea_from_stat.diffuse_horizontal_radiation.values
Exemplo n.º 4
0
def test_import_stat():
    """Test to compare import from stat with its dict version."""
    stat_path = './tests/assets/stat/chicago.stat'
    wea_from_stat = Wea.from_stat_file(stat_path)

    wea_dict = wea_from_stat.to_dict()
    wea_from_dict = Wea.from_dict(wea_dict)
    assert wea_from_dict.direct_normal_irradiance.values == \
        wea_from_stat.direct_normal_irradiance.values
    assert wea_from_dict.diffuse_horizontal_irradiance.values == \
        wea_from_stat.diffuse_horizontal_irradiance.values
Exemplo n.º 5
0
    def test_global_and_direct_horizontal(self):
        """Test the global horizontal radiation on method."""
        stat_path = './tests/stat/chicago.stat'
        wea_from_stat = Wea.from_stat_file(stat_path)

        diffuse_horiz_rad = wea_from_stat.diffuse_horizontal_radiation
        direct_horiz_rad = wea_from_stat.direct_horizontal_radiation
        glob_horiz_rad = wea_from_stat.global_horizontal_radiation

        assert [x.value for x in glob_horiz_rad] == pytest.approx(
            [x + y for x, y in zip(diffuse_horiz_rad, direct_horiz_rad)],
            rel=1e-3)
Exemplo n.º 6
0
def test_directional_irradiance():
    """Test the directional irradiance method."""
    stat_path = './tests/assets/stat/chicago.stat'
    wea_from_stat = Wea.from_stat_file(stat_path)

    srf_total, srf_direct, srf_diffuse, srf_reflect = \
        wea_from_stat.directional_irradiance(90)
    diffuse_horiz_rad = wea_from_stat.diffuse_horizontal_irradiance
    direct_horiz_rad = wea_from_stat.direct_horizontal_irradiance
    glob_horiz_rad = wea_from_stat.global_horizontal_irradiance

    assert srf_total.values == pytest.approx(glob_horiz_rad.values, rel=1e-3)
    assert srf_direct.values == pytest.approx(direct_horiz_rad.values, rel=1e-3)
    assert srf_diffuse.values == pytest.approx(diffuse_horiz_rad.values, rel=1e-3)
    assert srf_reflect.values == pytest.approx([0] * 8760, rel=1e-3)
Exemplo n.º 7
0
def test_from_stat():
    """Test import from stat"""
    stat_path = './tests/assets/stat/chicago.stat'
    wea_from_stat = Wea.from_stat_file(stat_path)

    assert wea_from_stat.location.city == 'Chicago Ohare Intl Ap'
    assert wea_from_stat.timestep == 1
    assert wea_from_stat.diffuse_horizontal_irradiance[0] == \
        pytest.approx(0, rel=1e-3)
    assert wea_from_stat.direct_normal_irradiance[0] == \
        pytest.approx(0, rel=1e-3)
    assert wea_from_stat.diffuse_horizontal_irradiance[12] == \
        pytest.approx(87.44171, rel=1e-3)
    assert wea_from_stat.direct_normal_irradiance[12] == \
        pytest.approx(810.693919, rel=1e-3)
Exemplo n.º 8
0
    def test_directional_radiation(self):
        """Test the directinal radiation method."""
        stat_path = './tests/stat/chicago.stat'
        wea_from_stat = Wea.from_stat_file(stat_path)

        srf_total, srf_direct, srf_diffuse, srf_reflect = \
            wea_from_stat.directional_radiation(90)
        diffuse_horiz_rad = wea_from_stat.diffuse_horizontal_radiation
        direct_horiz_rad = wea_from_stat.direct_horizontal_radiation
        glob_horiz_rad = wea_from_stat.global_horizontal_radiation

        assert [x.value for x in srf_total
                ] == pytest.approx([x.value for x in glob_horiz_rad], rel=1e-3)
        assert [x.value for x in srf_direct
                ] == pytest.approx([x.value for x in direct_horiz_rad],
                                   rel=1e-3)
        assert [x.value for x in srf_diffuse
                ] == pytest.approx([x.value for x in diffuse_horiz_rad],
                                   rel=1e-3)
        assert [x.value for x in srf_reflect] == pytest.approx([0] * 8760,
                                                               rel=1e-3)
Exemplo n.º 9
0
    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):
    stat_obj = STAT(_stat_file)

    # output location and climate zone
    location = stat_obj.location
    ashrae_zone = stat_obj.ashrae_climate_zone
    koppen_zone = stat_obj.koppen_climate_zone

    # output clear sky radiation
    try:  # first see if we can get the values from monthly optical depths
        wea = Wea.from_stat_file(_stat_file)
    except:  # no optical data was found; use the original clear sky
        wea = Wea.from_ashrae_clear_sky(location)
    clear_dir_norm_rad = wea.direct_normal_irradiance
    clear_diff_horiz_rad = wea.diffuse_horizontal_irradiance

    # output design day objects
    ann_heat_dday_996 = stat_obj.annual_heating_design_day_996
    ann_heat_dday_990 = stat_obj.annual_heating_design_day_990
    ann_cool_dday_004 = stat_obj.annual_cooling_design_day_004
    ann_cool_dday_010 = stat_obj.annual_cooling_design_day_010
    monthly_ddays_050 = stat_obj.monthly_cooling_design_days_050
    monthly_ddays_100 = stat_obj.monthly_cooling_design_days_100

    # output extreme and typical weeks
    extreme_cold_week = stat_obj.extreme_cold_week
Exemplo n.º 10
0
def test_from_stat_missing_optical():
    """Test import from a stat file that is missing optical data"""
    stat_path = './tests/assets/stat/santamonica.stat'
    with pytest.raises(ValueError, match='Stat file contains no optical data.'):
        Wea.from_stat_file(stat_path)
-

    Args:
        _stat_file = Full path to .stat file (typically next to the epw file).
        timestep_: An integer representing the timestep with which to make the 
            WEA object.  Default is set to 1 for 1 step per hour of the year.
    Returns:
        readMe!: Reports, errors, warnings, etc.
        wea: A wea object from stat file. This wea object represents an ASHRAE Revised 
            Clear Sky ("Tau Model"), which is intended to determine peak solar load 
            and sizing parmeters for HVAC systems. The "Tau Model" uses monthly 
            optical depths found within a .stat file.
"""

ghenv.Component.Name = "HoneybeePlus_Tau Clear Sky from STAT"
ghenv.Component.NickName = 'TauClearSky'
ghenv.Component.Message = 'VER 0.0.06\nJUL_07_2020'
ghenv.Component.Category = "HoneybeePlus"
ghenv.Component.SubCategory = '02 :: Daylight :: Light Sources'
ghenv.Component.AdditionalHelpFromDocStrings = "3"

try:
    from ladybug.wea import Wea
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

if _stat_file:
    timestep_ = 1 if timestep_ is None else timestep_
    wea = Wea.from_stat_file(_stat_file, timestep_)