def test_defaults():
    gendaymtx = Gendaymtx()
    assert gendaymtx.command == 'gendaymtx'
    assert gendaymtx.options.to_radiance() == ''
    with pytest.raises(exceptions.MissingArgumentError):
        # missing wea
        gendaymtx.to_radiance()
Example #2
0
def sunpath_from_wea_rad(wea, north, sky_type, sky_density, output_format,
                         hourly, visible, all_hours, folder, name, log_file,
                         dry_run):
    """Generate a climate-based sky matrix from a Wea file using radiance's gendaymtx.

    \b
    Args:
        wea: Path to a wea file.
    """
    try:
        if not os.path.exists(folder):
            os.makedirs(folder)
        output = os.path.join(folder, '%s.mtx' % name)
        opt = GendaymtxOptions()
        opt.r = north
        opt.O = '0' if visible else '1'
        if sky_type == 'total':
            pass
        elif sky_type == 'sun-only':
            opt.d = True
        elif sky_type == 'no-sun':
            opt.s = True

        if output_format == 'ASCII':
            pass
        elif output_format == 'float':
            opt.o = 'f'
        elif output_format == 'double':
            opt.o = 'd'

        if not hourly:
            opt.A = True

        if not all_hours:
            opt.u = True
        if sky_density > 1:
            opt.m = sky_density

        cmd = Gendaymtx(wea=wea, options=opt, output=output)
        if dry_run:
            print(cmd.to_radiance())
            sys.exit(0)

        try:
            run_command(cmd.to_radiance(), env=folders.env)
        except RuntimeError as e:  # likely a nighttime Wea; write blank .mtx file
            with open(output, 'w') as wf:
                wf.write('')
        files = [{
            'path': os.path.relpath(output, folder),
            'full_path': output
        }]
        log_file.write(json.dumps(files))

    except Exception:
        _logger.exception('Failed to generate sunpath.')
        sys.exit(1)
    else:
        sys.exit(0)
Example #3
0
def sunpath_from_wea_rad(wea, north, folder, name, visible, log_file, dry_run):
    """Generate a climate-based sunpath from a Wea file using radiance's gendaymtx.

    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.

    \b
    Args:
        wea: Path to a wea file.

    """
    try:
        if not os.path.exists(folder):
            os.makedirs(folder)
        opt = GendaymtxOptions()
        opt.n = True
        opt.D = os.path.join(folder, name + '.mtx').replace('\\', '//')
        opt.M = os.path.join(folder, name + '.mod').replace('\\', '//')
        opt.r = north
        opt.O = '0' if visible else '1'

        cmd = Gendaymtx(wea=wea, options=opt)

        if dry_run:
            print(cmd.to_radiance())
            sys.exit(0)

        run_command(cmd.to_radiance(), env=folders.env)
        files = [{
            'path': os.path.relpath(path, folder),
            'full_path': path
        } for path in (opt.D.value, opt.M.value)]

        log_file.write(json.dumps(files))
    except Exception:
        _logger.exception('Failed to generate sunpath.')
        sys.exit(1)
    else:
        sys.exit(0)
def test_validation():
    gendaymtx = Gendaymtx()
    with pytest.raises(exceptions.MissingArgumentError):
        # missing wea
        gendaymtx.to_radiance()

    gendaymtx.wea = 'input.wea'
    assert gendaymtx.to_radiance() == 'gendaymtx input.wea'
def test_assignment():
    gendaymtx = Gendaymtx()
    gendaymtx.wea = 'input.wea'
    assert gendaymtx.wea == 'input.wea'
    assert gendaymtx.to_radiance() == 'gendaymtx input.wea'
    gendaymtx.output = 'sky.mtx'
    assert gendaymtx.output == 'sky.mtx'
    assert gendaymtx.to_radiance() == 'gendaymtx input.wea > sky.mtx'