def rtrace_command(octree, sensor_grid, rad_params, rad_params_locked, output,
                   dry_run):
    """Run rtrace command for an input octree and a sensor grid.

    octree: Path to octree file.
    sensor-grid: Path to sensor grid file.
    """
    try:
        options = RtraceOptions()
        # parse input radiance parameters
        if rad_params:
            options.update_from_string(rad_params.strip())
        # overwrite input values with protected ones
        if rad_params_locked:
            options.update_from_string(rad_params_locked.strip())

        # create command.
        rtrace = Rtrace(options=options,
                        output=output,
                        octree=octree,
                        sensors=sensor_grid)

        if dry_run:
            click.echo(rtrace)
        else:
            env = None
            if folders.env != {}:
                env = folders.env
            env = dict(os.environ, **env) if env else None
            rtrace.run(env=env)
    except Exception:
        _logger.exception('Failed to run ray-tracing command.')
        sys.exit(1)
    else:
        sys.exit(0)
示例#2
0
def test_defaults():
    rtrace = Rtrace()
    assert rtrace.command == 'rtrace'
    assert rtrace.options.to_radiance() == ''
    with pytest.raises(exceptions.MissingArgumentError):
        # missing octree
        rtrace.to_radiance()
示例#3
0
def rtrace_with_pit_post_process(octree, sensor_grid, rad_params,
                                 rad_params_locked, metric, output, dry_run):
    """Run rtrace command with rcalc post-processing for point-in-time studies.

    \b
    Args:
        octree: Path to octree file.
        sensor_grid: Path to sensor grid file.
    """
    try:
        options = RtraceOptions()
        # parse input radiance parameters
        if rad_params:
            options.update_from_string(rad_params.strip())
        # overwrite input values with protected ones
        if rad_params_locked:
            options.update_from_string(rad_params_locked.strip())
        # overwrite the -I attribute depending on the metric to be calculated
        if metric in ('illuminance', 'irradiance'):
            options.I = True
        elif metric in ('luminance', 'radiance'):
            options.I = False
        else:
            raise ValueError('Metric "{}" is not recognized.'.format(metric))

        # create command.
        rtrace = Rtrace(options=options, octree=octree, sensors=sensor_grid)

        # add rcalc post-procing
        rcalc = Rcalc(output=output)
        rcalc.options.e = '$1=(0.265*$1+0.67*$2+0.065*$3)*179' if metric in \
            ('illuminance', 'luminance') else '$1=(0.265*$1+0.67*$2+0.065*$3)'
        rtrace.pipe_to = rcalc

        if dry_run:
            click.echo(rtrace)
        else:
            env = None
            if folders.env != {}:
                env = folders.env
            env = dict(os.environ, **env) if env else None
            rtrace.run(env=env)
    except Exception:
        _logger.exception('Failed to run point-in-time ray-tracing.')
        sys.exit(1)
    else:
        sys.exit(0)
示例#4
0
def test_validation():
    rtrace = Rtrace()
    with pytest.raises(exceptions.MissingArgumentError):
        # missing octree
        rtrace.to_radiance()

    rtrace.octree = 'input.oct'
    with pytest.raises(exceptions.MissingArgumentError):
        # missing sensors
        rtrace.to_radiance()

    rtrace.sensors = 'sensors.pts'
    assert rtrace.to_radiance() == 'rtrace input.oct < sensors.pts'
示例#5
0
def test_assignment():
    rtrace = Rtrace()  
    rtrace.octree = 'input.oct'
    assert rtrace.octree == 'input.oct'
    rtrace.sensors = 'sensors.pts'
    assert rtrace.sensors == 'sensors.pts'
    assert rtrace.to_radiance() == 'rtrace input.oct < sensors.pts'
    rtrace.output = 'results.dat'
    assert rtrace.output == 'results.dat'
    assert rtrace.to_radiance() == 'rtrace input.oct < sensors.pts > results.dat'
示例#6
0
def rtrace_with_df_post_process(octree, sensor_grid, rad_params,
                                rad_params_locked, sky_illum, output, dry_run):
    """Run rtrace command with rcalc post-processing for daylight factor studies.

    \b
    Args:
        octree: Path to octree file.
        sensor_grid: Path to sensor grid file.
    """
    try:
        options = RtraceOptions()
        # parse input radiance parameters
        if rad_params:
            options.update_from_string(rad_params.strip())
        # overwrite input values with protected ones
        if rad_params_locked:
            options.update_from_string(rad_params_locked.strip())

        # create command.
        rtrace = Rtrace(options=options, octree=octree, sensors=sensor_grid)

        # add rcalc post-procing
        rcalc = Rcalc(output=output)
        rcalc.options.e = '$1=(0.265*$1+0.67*$2+0.065*$3)*17900/{}'.format(
            sky_illum)
        rtrace.pipe_to = rcalc

        if dry_run:
            click.echo(rtrace)
        else:
            env = None
            if folders.env != {}:
                env = folders.env
            env = dict(os.environ, **env) if env else None
            rtrace.run(env=env)
    except Exception:
        _logger.exception('Failed to run daylight-factor ray-tracing.')
        sys.exit(1)
    else:
        sys.exit(0)
示例#7
0
def test_stdin():
    rtrace = Rtrace()  
    rtrace.octree = 'input.oct'
    rtrace.sensors = 'sensors.pts'
    rtrace.output = 'results.dat'
    assert rtrace.to_radiance(stdin_input=True) == 'rtrace input.oct > results.dat'
示例#8
0
    rpict.options.y = _size_
    rpict.options.vt = 'h'
    rpict.options.vp = (0, 0, 0)
    rpict.options.vd = (0, 0, 1)
    rpict.options.vu = (0, 1, 0)
    rpict.options.vh = 180
    rpict.options.vv = 180

    pflip = Pflip(input=init_hdr, output=final_hdr)
    pflip.options.h = True

    # add the command to get the horizontal irradiance of the sky
    grid = SensorGrid.from_position_and_direction('up_sensor', [(0, 0, 0)],
                                                  [(0, 0, 1)])
    grid.to_file(sky_dir, 'up_sensor.pts')
    rtrace = Rtrace(octree=sky_oct, sensors='up_sensor.pts')
    rtrace.options.I = True
    rtrace.options.w = True
    rtrace.options.h = True
    rtrace.options.ab = 1
    rcalc = Rcalc(output=ghi_res)
    rcalc.options.e = '$1=(0.265*$1+0.67*$2+0.065*$3)'
    rtrace.pipe_to = rcalc

    # run the commands in series and load the global horizontal irradiance
    env = None
    if rad_folders.env != {}:
        env = rad_folders.env
    env = dict(os.environ, **env) if env else None
    for r_cmd in (oconv, rpict, pflip, rtrace):
        r_cmd.run(env, cwd=sky_dir)