Ejemplo n.º 1
0
def sunpath_from_epw(
    epw, north, folder, name, log_file, start_date, start_time, end_date, end_time,
        timestep, leap_year, reverse_vectors):
    """Generate a climate-based sunpath from an epw weather file.

    This command also generates a mod file which includes all the modifiers in sunpath.
    mod file is usually used with rcontrib command to indicate the list of modifiers.
    Since rcontrib command has a hard limit of 10,000 modifiers in a single run the files
    will be broken down into multiple files if number of modifiers is more than 10000
    modifiers.

    epw: Path to a epw file.
    """
    try:
        wea = Wea.from_epw_file(epw)
        sp = Sunpath(wea.location, north)
        hoys = get_hoys(start_date, start_time, end_date, end_time, timestep, leap_year)
        sp_files = sp.to_file(
            folder, name, wea=wea, hoys=hoys, leap_year=leap_year,
            reverse_vectors=reverse_vectors
        )

        files = [
            {'path': os.path.relpath(path, folder), 'full_path': path}
            for path in sp_files['suns']
        ]

        log_file.write(json.dumps(files))
    except Exception:
        _logger.exception('Failed to generate sunpath.')
        sys.exit(1)
    else:
        sys.exit(0)
Ejemplo n.º 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)
Ejemplo n.º 3
0
def test_filter_by_pattern():
    """Test the filter_by_pattern method"""
    epw_path = './tests/assets/epw/chicago.epw'
    wea_from_epw = Wea.from_epw_file(epw_path)

    pattern = [False] * 8 + [True] * 8 + [False] * 8
    filtered_wea = wea_from_epw.filter_by_pattern(pattern)
    assert len(filtered_wea) == int(8760 / 3)
Ejemplo n.º 4
0
 def from_epw_file(cls,
                   epw_file,
                   north=0,
                   hoys=None,
                   output_type=0,
                   suffix=None):
     """Create sun matrix from an epw file."""
     return cls(Wea.from_epw_file(epw_file), north, hoys, output_type,
                suffix)
Ejemplo n.º 5
0
def test_dict_methods():
    """Test JSON serialization methods"""
    # test first with a continuous annual Wea
    epw_path = './tests/assets/epw/chicago.epw'
    wea = Wea.from_epw_file(epw_path)
    assert wea.to_dict() == Wea.from_dict(wea.to_dict()).to_dict()

    # then test with a filtered Wea including datetimes in the dict
    wea_file = './tests/assets/wea/chicago_filtered.wea'
    wea = Wea.from_file(wea_file)
    assert wea.to_dict() == Wea.from_dict(wea.to_dict()).to_dict()
Ejemplo n.º 6
0
def test_import_epw():
    """Test to compare import from epw with its dict version."""
    epw_path = './tests/assets/epw/chicago.epw'
    wea_from_epw = Wea.from_epw_file(epw_path)

    wea_dict = wea_from_epw.to_dict()
    wea_from_dict = Wea.from_dict(wea_dict)
    assert wea_from_dict.direct_normal_irradiance.values == \
        wea_from_epw.direct_normal_irradiance.values
    assert wea_from_dict.diffuse_horizontal_irradiance.values == \
        wea_from_epw.diffuse_horizontal_irradiance.values
Ejemplo n.º 7
0
    def test_import_epw(self):
        """Test to compare import from epw with its json version."""
        epw_path = './tests/epw/chicago.epw'

        wea_from_epw = Wea.from_epw_file(epw_path)

        wea_json = wea_from_epw.to_json()
        wea_from_json = Wea.from_json(wea_json)
        assert wea_from_json.direct_normal_radiation.values == \
            wea_from_epw.direct_normal_radiation.values
        assert wea_from_json.diffuse_horizontal_radiation.values == \
            wea_from_epw.diffuse_horizontal_radiation.values
Ejemplo n.º 8
0
def test_filter_by_hoys_and_moys():
    """Test the filter_by_hoys and the filter_by_moys method"""
    epw_path = './tests/assets/epw/chicago.epw'
    wea_from_epw = Wea.from_epw_file(epw_path)

    hoys = list(range(24))
    filtered_wea = wea_from_epw.filter_by_hoys(hoys)
    assert len(filtered_wea) == len(hoys)

    moys = list(range(0, 24 * 60, 60))
    filtered_wea = wea_from_epw.filter_by_moys(moys)
    assert len(filtered_wea) == len(moys)
Ejemplo n.º 9
0
def test_filter_by_sun_up():
    """Test the filter_by_sun_up method"""
    epw_path = './tests/assets/epw/chicago.epw'
    wea_from_epw = Wea.from_epw_file(epw_path)

    wea = wea_from_epw.filter_by_sun_up()
    assert isinstance(wea.direct_normal_irradiance, HourlyDiscontinuousCollection)
    assert isinstance(wea.diffuse_horizontal_irradiance, HourlyDiscontinuousCollection)
    assert not wea.is_annual
    assert not wea.is_continuous
    assert len(wea) == 4427
    assert wea.datetimes[0].hour == 7
Ejemplo n.º 10
0
def test_from_epw_fine_timestep():
    """Test import from epw"""
    epw_path = './tests/assets/epw/chicago.epw'
    wea_from_epw = Wea.from_epw_file(epw_path, 2)

    assert wea_from_epw.location.city == 'Chicago Ohare Intl Ap'
    assert wea_from_epw.timestep == 2
    assert wea_from_epw.direct_normal_irradiance[15] == 22
    assert wea_from_epw.direct_normal_irradiance.datetimes[15].hour == 7
    assert wea_from_epw.direct_normal_irradiance.datetimes[15].minute == 30
    assert wea_from_epw.direct_normal_irradiance[17] == 397
    assert wea_from_epw.direct_normal_irradiance.datetimes[17].hour == 8
    assert wea_from_epw.direct_normal_irradiance.datetimes[17].minute == 30
Ejemplo n.º 11
0
 def from_epw_file(cls,
                   epw_file,
                   sky_density=1,
                   north=0,
                   hoys=None,
                   mode=0,
                   suffix=None):
     """Create sky from an epw file."""
     return cls(Wea.from_epw_file(epw_file),
                sky_density,
                north,
                hoys,
                mode,
                suffix=suffix)
Ejemplo n.º 12
0
def test_estimate_illuminance():
    """Test the directional irradiance method."""
    epw_path = './tests/assets/epw/chicago.epw'
    epw = EPW(epw_path)
    wea = Wea.from_epw_file(epw_path)

    glob_ill, dir_ill, diff_ill, zen_lum = \
        wea.estimate_illuminance_components(epw.dew_point_temperature)

    assert glob_ill.bounds[0] == pytest.approx(0, rel=1e-3)
    assert 100000 < glob_ill.bounds[1] < 125000
    assert dir_ill.bounds[0] == pytest.approx(0, rel=1e-3)
    assert 75000 < dir_ill.bounds[1] < 125000
    assert diff_ill.bounds[0] == pytest.approx(0, rel=1e-3)
    assert 50000 < diff_ill.bounds[1] < 100000
    assert zen_lum.bounds[0] == pytest.approx(0, rel=1e-3)
    assert zen_lum.bounds[1] < 35000
Ejemplo n.º 13
0
def test_filter_by_analysis_period():
    """Test the filter_by_analysis_period method"""
    epw_path = './tests/assets/epw/chicago.epw'
    wea_from_epw = Wea.from_epw_file(epw_path)

    a_period = AnalysisPeriod(12, 21, 0, 3, 21, 23)
    filtered_wea = wea_from_epw.filter_by_analysis_period(a_period)
    assert len(filtered_wea) == len(filtered_wea.diffuse_horizontal_irradiance.values) \
        == len(a_period)
    assert not filtered_wea.is_annual
    assert filtered_wea.is_continuous

    wea_path = './tests/assets/wea/chicago_winter.wea'
    filtered_wea.write(wea_path)
    assert os.path.isfile(wea_path)
    assert os.stat(wea_path).st_size > 1
    os.remove(wea_path)
Ejemplo n.º 14
0
def test_body_dir_from_dir_normal():
    """Test body_solar_flux_from_parts gainst its horizontal counterpart."""
    wea_obj = Wea.from_epw_file('./tests/epw/chicago.epw')
    diff_hr = wea_obj.diffuse_horizontal_irradiance.values
    dir_nr = wea_obj.direct_normal_irradiance.values
    dir_hr = wea_obj.direct_horizontal_irradiance.values
    dts = wea_obj.datetimes
    sp = Sunpath.from_location(wea_obj.location)

    for i in xrange(8760):
        sun = sp.calculate_sun_from_date_time(dts[i])
        alt, az = sun.altitude, sun.azimuth
        sharp = sharp_from_solar_and_body_azimuth(az, 180)
        sflux1 = body_solar_flux_from_parts(diff_hr[i], dir_nr[i], alt, sharp)
        sflux2 = body_solar_flux_from_horiz_solar(diff_hr[i], dir_hr[i], alt,
                                                  sharp)
        assert sflux1 == pytest.approx(sflux2, rel=1e-2)
Ejemplo n.º 15
0
def epw_to_wea(epw_file, analysis_period, timestep, output_file):
    """Translate an .epw file to a .wea file.

    \b
    Args:
        epw_file: Path to an .epw file.
    """
    try:
        wea_obj = Wea.from_epw_file(epw_file, timestep)
        analysis_period = _load_analysis_period_str(analysis_period)
        if analysis_period is not None:
            wea_obj = wea_obj.filter_by_analysis_period(analysis_period)
        output_file.write(wea_obj.to_file_string())
    except Exception as e:
        _logger.exception('Wea translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Ejemplo n.º 16
0
def test_from_epw():
    """Test import from epw"""
    epw_path = './tests/epw/chicago.epw'
    wea_from_epw = Wea.from_epw_file(epw_path)

    assert wea_from_epw.location.city == 'Chicago Ohare Intl Ap'
    assert wea_from_epw.timestep == 1
    assert wea_from_epw.direct_normal_irradiance[7] == 22
    assert wea_from_epw.direct_normal_irradiance.datetimes[7].hour == 7
    assert wea_from_epw.direct_normal_irradiance.datetimes[7].minute == 0
    assert wea_from_epw.direct_normal_irradiance[8] == 397
    assert wea_from_epw.direct_normal_irradiance.datetimes[8].hour == 8
    assert wea_from_epw.direct_normal_irradiance.datetimes[8].minute == 0
    # diffuse horizontal irradiance
    assert wea_from_epw.diffuse_horizontal_irradiance[7] == 10
    assert wea_from_epw.diffuse_horizontal_irradiance.datetimes[7].hour == 7
    assert wea_from_epw.diffuse_horizontal_irradiance.datetimes[7].minute == 0
    assert wea_from_epw.diffuse_horizontal_irradiance[8] == 47
    assert wea_from_epw.diffuse_horizontal_irradiance.datetimes[8].hour == 8
    assert wea_from_epw.diffuse_horizontal_irradiance.datetimes[8].minute == 0
Ejemplo n.º 17
0
def test_write_to_file_wea():
    wea = Wea.from_epw_file(epw_file, timestep=1)
    ap = AnalysisPeriod(12, 21, 0, 12, 21, 23, timestep=1)
    sp = Sunpath(location)
    folder = './tests/assets/temp'
    filename = 'sunpath_dec_21_climate_based'
    sp.to_file(folder, filename, hoys=ap.hoys, wea=wea)
    sp_file = os.path.join(folder, '%s.rad' % filename)
    sp_mod_file = os.path.join(folder, '%s.mod' % filename)
    assert os.path.isfile(sp_file)
    assert os.path.isfile(sp_mod_file)
    with open(sp_mod_file) as inf:
        for count, _ in enumerate(inf):
            pass
    assert count == 8  # number of suns - 1
    with open(sp_file) as inf:
        for count, _ in enumerate(inf):
            pass
    assert count == 8  # number of suns - 1
    # check line info
    with open(sp_file) as inf:
        data = inf.readline().split()

    assert data[6] == data[6] == data[6] != '1000000.0'
Ejemplo n.º 18
0
# assign inputs
_epwFile = IN[0]
wea = None

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

if _epwFile:
    wea = Wea.from_epw_file(_epwFile)

# assign outputs to OUT
OUT = (wea, )
Ejemplo n.º 19
0
def test_dict_methods():
    """Test JSON serialization methods"""
    epw_path = './tests/epw/chicago.epw'
    wea = Wea.from_epw_file(epw_path)

    assert wea.to_dict() == Wea.from_dict(wea.to_dict()).to_dict()
Ejemplo n.º 20
0
 def from_epw_file(cls, epw_file, north=0, hoys=None, output_type=0, suffix=None):
     """Create sun matrix from an epw file."""
     return cls(Wea.from_epw_file(epw_file), north, hoys, output_type, suffix)
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>

"""
Create a WEA object from an EPW.

-

    Args:
        _epw_file = Fullpath to epw weather 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:
        wea: A wea object from epw file.
"""

ghenv.Component.Name = "HoneybeePlus_WEA From EPW"
ghenv.Component.NickName = 'WEA'
ghenv.Component.Message = 'VER 0.0.05\nOCT_22_2018'
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 _epw_file:
    timestep_ = 1 if timestep_ is None else timestep_
    wea = Wea.from_epw_file(_epw_file, timestep_)
Ejemplo n.º 22
0
    def test_json_methods(self):
        """Test JSON serialization methods"""
        epw_path = './tests/epw/chicago.epw'
        wea = Wea.from_epw_file(epw_path)

        assert wea.to_json() == Wea.from_json(wea.to_json()).to_json()
Ejemplo n.º 23
0
 def from_epw_file(cls, epw_file, sky_density=1, north=0,
                   hoys=None, mode=0, suffix=None):
     """Create sky from an epw file."""
     return cls(Wea.from_epw_file(epw_file), sky_density, north, hoys, mode,
                suffix=suffix)