Exemplo n.º 1
0
def test_to_file():
    sky = CIE(38.186734, 270.410387)
    sky_file = sky.to_file('./tests/assets/temp', mkdir=True)
    assert os.path.isfile(sky_file)
    with open(sky_file, 'r') as skyf:
        content = skyf.read()

    assert sky.to_radiance() in str(content)
Exemplo n.º 2
0
def test_to_and_from_string():
    sky_string = 'cie 21 Jun 12:00 -lat 41.78 -lon -87.75 -type 2'
    sky = CIE.from_string(sky_string)

    sky_from_str = CIE.from_string(str(sky))
    if (sys.version_info >= (3, 7)):
        assert sky == sky_from_str

    sky_string = 'cie -alt 35 -az 185 -type 0'
    sky = CIE.from_string(sky_string)
Exemplo n.º 3
0
def test_check_defaults():
    sky = CIE(38.186734, 270.410387)
    assert sky.altitude == 38.186734
    assert sky.azimuth == 270.410387
    assert sky.ground_reflectance == 0.2
    sky_radiance = sky.to_radiance()
    assert '!gensky -ang 38.186734 90.410387 +s -g 0.200' in sky_radiance
    assert sky.ground_hemisphere.to_radiance() in sky_radiance
    assert sky.sky_hemisphere.to_radiance() in sky_radiance
    assert sky.is_climate_based is False
    assert sky.is_point_in_time is True
Exemplo n.º 4
0
def test_from_location():
    latitude = 37.815214
    longitude = -122.040010
    time_zone = -8
    location = Location(latitude=latitude,
                        longitude=longitude,
                        time_zone=time_zone)
    sky = CIE.from_location(location, 7, 4, 14.5)
    assert round(sky.altitude, 1) == 57.0
    assert round(sky.azimuth -
                 180) == 73  # ladybug's sun position is more accurate
    assert sky.ground_reflectance == 0.2
    sky_radiance = sky.to_radiance()
    assert '!gensky -ang 57.042579 72.808289 +s -g 0.200' in sky_radiance
    assert sky.ground_hemisphere.to_radiance() in sky_radiance
    assert sky.sky_hemisphere.to_radiance() in sky_radiance
Exemplo n.º 5
0
def test_from_lat_long():
    latitude = 37.815214
    longitude = -122.040010
    time_zone = -8
    sky = CIE.from_lat_long(latitude, longitude, time_zone, 7, 4, 14.5)
    # Radiance output
    # gensky 7 4 14:30 +s
    # Local solar time: 14.30
    # Solar altitude and azimuth: 57.0 73.1
    assert round(sky.altitude, 1) == 57.0
    assert round(sky.azimuth -
                 180) == 73  # ladybug's sun position is more accurate
    assert sky.ground_reflectance == 0.2
    sky_radiance = sky.to_radiance()
    assert '!gensky -ang 57.042579 72.808289 +s -g 0.200' in sky_radiance
    assert sky.ground_hemisphere.to_radiance() in sky_radiance
    assert sky.sky_hemisphere.to_radiance() in sky_radiance
Exemplo n.º 6
0
def test_sky_types():
    sky = CIE(0, 0, 0)
    assert sky.sky_type == 0
    assert sky.sky_type_radiance == '+s'
    sky.sky_type = 1
    assert sky.sky_type == 1
    assert sky.sky_type_radiance == '-s'
    sky.sky_type = 2
    assert sky.sky_type == 2
    assert sky.sky_type_radiance == '+i'
    sky.sky_type = 3
    assert sky.sky_type == 3
    assert sky.sky_type_radiance == '-i'
    sky.sky_type = 4
    assert sky.sky_type == 4
    assert sky.sky_type_radiance == '-c'
    sky.sky_type = 5
    assert sky.sky_type == 5
    assert sky.sky_type_radiance == '-u'
Exemplo n.º 7
0
def test_dict_to_object_cie_sky():
    """Test the dict_to_object method with Sky objects."""
    sky_obj = CIE(38.186734, 270.410387)
    sky_dict = sky_obj.to_dict()
    new_sky = dict_to_object(sky_dict)
    assert isinstance(new_sky, CIE)
Exemplo n.º 8
0
def test_to_and_from_dict():
    sky = CIE(38.186734, 270.410387)
    sky_from_dict = CIE.from_dict(sky.to_dict())

    assert sky == sky_from_dict
try:
    from honeybee_radiance.lightsource.sky import CIE
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))

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

import math

if all_required_inputs(ghenv.Component):
    # process the north input
    north_ = north_ or 0
    try:  # it's a vector
        north_ = math.degrees(
            to_vector2d(north_).angle_clockwise(Vector2D(0, 1)))
    except AttributeError:  # north angle instead of vector
        north_ = float(north_)

    # set default values if they are not set
    _type_ = 0 if _type_ is None else _type_
    _month_ = 6 if _month_ is None else _month_
    _day_ = 21 if _day_ is None else _day_
    _hour_ = 12 if _hour_ is None else _hour_

    # create the sky object
    sky = CIE.from_location(_location, _month_, _day_, _hour_, _type_, north_)
Exemplo n.º 10
0
def sky_cie(directory):
    sky = CIE(38.186734, 270.410387)
    dest_file = os.path.join(directory, 'sky_cie.json')
    with open(dest_file, 'w') as fp:
        json.dump(sky.to_dict(), fp, indent=4)