示例#1
0
def test_updating_values():
    sp = Sunpath(location)
    assert sp.north == 0
    sp.north = 10
    assert sp.north == 10
    sp.north = 0
    assert sp.north == 0
示例#2
0
def sunpath_from_wea(wea, north, folder, name, log_file, leap_year,
                     reverse_vectors):
    """Generate a climate-based sunpath from a Wea 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.

    wea: Path to a wea file.
    """
    try:
        wea = Wea.from_file(wea)
        sp = Sunpath(wea.location, north)
        hoys = wea.hoys
        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)
示例#3
0
def test_write_to_fie():
    sp = Sunpath(location)
    lb_sp = LBSunpath.from_location(location)
    folder = './tests/assets/temp'
    filename = 'sunpath_annual'
    sp.to_file(folder, filename)
    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
    lb_tot = [
        i for i in range(8760) if lb_sp.calculate_sun_from_hoy(i).is_during_day
    ]
    assert count == len(lb_tot) - 1  # number of suns - 1
    with open(sp_file) as inf:
        for count, _ in enumerate(inf):
            pass
    assert count == len(lb_tot) - 1  # 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'
    assert data[-1] == '0.533'
    assert float(data[-2]) < 0  # z vector is looking down
示例#4
0
def sunpath_from_location(
    lat, lon, tz, north, folder, name, log_file, start_date, start_time, end_date,
        end_time, timestep, leap_year, reverse_vectors):
    """Generate a non climate-based sunpath for a location.

    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.
    """
    location = Location()
    location.latitude = lat
    location.longitude = lon
    location.time_zone = tz
    try:
        sp = Sunpath(location, north)
        hoys = get_hoys(start_date, start_time, end_date, end_time, timestep, leap_year)
        sp_files = sp.to_file(
            folder, name, 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)
示例#5
0
def test_write_to_file_timestep():
    ap = AnalysisPeriod(12, 21, 0, 12, 21, 23, timestep=4)
    sp = Sunpath(location)
    folder = './tests/assets/temp'
    filename = 'sunpath_dec_21_timestep'
    sp.to_file(folder, filename, hoys=ap.hoys)
    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 == 36  # number of suns - 1
    with open(sp_file) as inf:
        for count, _ in enumerate(inf):
            pass
    assert count == 36  # number of suns - 1
示例#6
0
def test_split_modifiers():
    ap = AnalysisPeriod(timestep=4)
    sp = Sunpath(location)
    lb_sp = LBSunpath.from_location(location)
    folder = './tests/assets/temp'
    filename = 'sunpath_timestep_4'
    sp.to_file(folder, filename, hoys=ap.hoys)
    sp_file = os.path.join(folder, '%s.rad' % filename)
    sp_mod_files = [
        os.path.join(folder, '%s_%d.mod' % (filename, count))
        for count in range(2)
    ]
    assert os.path.isfile(sp_file)

    lb_tot = [
        i for i in ap.hoys if lb_sp.calculate_sun_from_hoy(i).is_during_day
    ]
    sun_count = [int(len(lb_tot) / 2) - 1, int(len(lb_tot) / 2)]
    for sp_count, sp_mod_file in enumerate(sp_mod_files):
        assert os.path.isfile(sp_mod_file)
        with open(sp_mod_file) as inf:
            for count, _ in enumerate(inf):
                pass
        assert count == sun_count[sp_count]
示例#7
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'
示例#8
0
def test_invalid_input():
    with pytest.raises(AssertionError):
        Sunpath('Denver')
示例#9
0
def test_creation():
    sp = Sunpath(location, 10)
    assert sp.location == location
    assert sp.north == 10