Exemple #1
0
def test_error_1():
    """Test if errors are being raised when incompatible options are assigned."""
    rpict1 = Rpict()

    rpict1.octree = 'input.oct'
    rpict1.view = 'view.vf'
    rpict1.options.aI = 'mod'
    with pytest.raises(ValueError):
        rpict1.options.aE = 'mod'
Exemple #2
0
def test_warning_0():
    """Test if warnings are being raised when incompatible options are assigned."""
    rpict = Rpict()

    rpict.octree = 'input.oct'
    rpict.view = 'view.vf'
    rpict.options.ps = -1
    assert rpict.to_radiance() == 'rpict -ps -1 -vf view.vf input.oct'
    with pytest.warns(Warning):
        rpict.options.dj = 0.0
def test_warning_1():
    """Test if warnings are being raised when incompatible options are assigned."""
    rpict = Rpict()

    rpict.octree = 'input.oct'
    rpict.view = 'view.vf'
    rpict.options.i = True
    assert rpict.to_radiance() == 'rpict -i input.oct < view.vf'
    with pytest.warns(Warning):
        rpict.options.dv = True
def test_validation():
    """Test for errors in case of missing arguments."""
    rpict = Rpict()

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

    with pytest.raises(exceptions.MissingArgumentError):
        # missing view file
        rpict.to_radiance()

    rpict.view = 'view.vf'
    assert rpict.to_radiance() == 'rpict input.oct < view.vf'
Exemple #5
0
def test_assignment():
    """Test assignment."""
    rpict = Rpict()

    rpict.octree = 'input.oct'
    assert rpict.octree == 'input.oct'
    rpict.view = 'view.vf'
    assert rpict.view == 'view.vf'
    assert rpict.to_radiance() == 'rpict -vf view.vf input.oct'
    rpict.output = 'results.dat'
    assert rpict.output == 'results.dat'
    assert rpict.to_radiance() == 'rpict -vf view.vf input.oct > results.dat'
Exemple #6
0
def test_stdin():
    """Test stdin."""
    rpict = Rpict()

    rpict.octree = 'input.oct'
    rpict.view = 'view.vf'
    rpict.output = 'results.dat'
    assert rpict.to_radiance(
        stdin_input=True) == ('rpict input.oct > results.dat')
Exemple #7
0
def test_assignment_options():
    """Test assignment of a few options."""
    rpict = Rpict()

    rpict.octree = 'input.oct'
    rpict.view = 'view.vf'
    rpict.options.vt = 'v'
    assert rpict.to_radiance() == 'rpict -vtv -vf view.vf input.oct'
    with pytest.raises(exceptions.InvalidValueError):
        rpict.options.vt = 'k'
    rpict.options.av = (0.0, 0.0, 0.0)
    assert rpict.to_radiance(
    ) == 'rpict -av 0.0 0.0 0.0 -vtv -vf view.vf input.oct'
    rpict.options.x = 512
    assert rpict.to_radiance(
    ) == 'rpict -av 0.0 0.0 0.0 -vtv -x 512 -vf view.vf input.oct'
Exemple #8
0
def test_defaults():
    """Test command."""
    rpict = Rpict()

    assert rpict.command == 'rpict'
    assert rpict.options.to_radiance() == ''
Exemple #9
0
def rpict_command(octree, view, rad_params, rad_params_locked, metric,
                  resolution, scale_factor, output, dry_run):
    """Run rpict command for an input octree and a view file.

    Note that, if an ambient cache file (.amb) is found next to the view file,
    and it is determined to be valid (with a non-zero size) it will be
    automatically used within the rpict command.

    \b
    Args:
        octree: Path to octree file.
        view: Path to view file.

    """
    try:
        options = RpictOptions()
        # 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))
        # overwrite the -x and -y attribute depending on the input resolution
        if resolution:
            options.x = int(resolution * scale_factor)
            options.y = int(resolution * scale_factor)
        # sense wether there is an ambient cache file next to the view
        for base_file in os.listdir(os.path.dirname(view)):
            if base_file.endswith('.amb'):
                full_amb_path = os.path.join(os.path.dirname(view), base_file)
                if os.stat(full_amb_path).st_size != 0:
                    options.af = os.path.join(os.path.dirname(view), base_file)
                    break

        # write the metric type into the view name such that it's in the HDR header
        metric_view = os.path.basename(view).replace('.vf',
                                                     '_{}.vf'.format(metric))
        full_metric_view = os.path.join(os.path.dirname(view), metric_view)
        shutil.copyfile(view, full_metric_view)

        # create command.
        rpict = Rpict(options=options,
                      output=output,
                      octree=octree,
                      view=full_metric_view)

        if dry_run:
            click.echo(rpict)
        else:
            env = None
            if folders.env != {}:
                env = folders.env
            env = dict(os.environ, **env) if env else None
            rpict.run(env=env)
        os.remove(full_metric_view)
    except Exception:
        _logger.exception('Failed to run rpict command.')
        sys.exit(1)
    else:
        sys.exit(0)
Exemple #10
0
def split_view(view, count, skip_overture, octree, rad_params, folder,
               log_file):
    """Split a radiance view file into smaller views based on count.

    \b
    Args:
        view: Full path to input sensor view file.
        count: Maximum number of sensors in new files. The number will be rounded to
            closest round number for each file. For example if the input file has 21
            sensors and input count is set to 5 this command will generate 4 files where
            the first three files will have 5 sensors and the last file will have 6.
    """
    try:
        # split the view into smaller views
        view_obj = View.from_file(view)
        views = view_obj.grid(y_div_count=count)
        views_info = []
        for c, v in enumerate(views):
            name = '%s_%04d' % (view_obj.identifier, c)
            path = '%s.vf' % name
            full_path = os.path.join(folder, path)
            v.to_file(folder, path, mkdir=True)
            views_info.append({
                'name': name,
                'path': path,
                'full_path': full_path
            })

        # create the ambient cache file if specified
        amb_file = os.path.basename(view).replace('.vf', '.amb')
        if not skip_overture:
            options = RpictOptions()
            if rad_params:
                options.update_from_string(rad_params.strip())
            # overwrite default image size to be small for the ambient cache (64 x 64)
            options.x = 64
            options.y = 64
            options.af = amb_file

            # create command and run it to get the .amb file
            assert octree is not None, \
                'Octree  must be specified for an overture calculation.'
            out_file = os.path.basename(view).replace('.vf', '.unf')
            rpict = Rpict(options=options,
                          output=out_file,
                          octree=octree,
                          view=view)
            env = None
            if folders.env != {}:
                env = folders.env
            env = dict(os.environ, **env) if env else None
            rpict.run(env=env, cwd=folder)
            os.remove(os.path.join(folder, out_file))
        else:  # write a dummy ambient file so that queenbee does not crash
            write_to_file_by_name(folder, amb_file, '')

        # record all of the view files that were generated
        log_file.write(json.dumps(views_info))
    except Exception:
        _logger.exception('Failed to split view file.')
        sys.exit(1)
    else:
        sys.exit(0)
Exemple #11
0
    # set up the paths for the various files used in translation
    sky_dir = os.path.join(folders.default_simulation_folder,
                           'sky_visualiztion')
    sky_file, sky_oct = 'weather.sky', 'sky_visual.oct'
    write_to_file_by_name(sky_dir, sky_file, sky_content, mkdir=True)
    ghi_res, full_ghi_res = 'ghi.res', os.path.join(sky_dir, 'ghi.res')
    init_hdr, final_hdr = 'sky_init.HDR', 'sky.HDR'
    hdr = os.path.join(sky_dir, final_hdr)
    if os.path.isfile(hdr):
        os.remove(hdr)

    # build up the commands to render the image of the sky
    oconv = Oconv(inputs=[sky_file], output=sky_oct)
    oconv.options.f = True

    rpict = Rpict(octree=sky_oct, output=init_hdr)
    rpict.options.i = True
    rpict.options.t = 10
    rpict.options.ab = 1
    rpict.options.ad = 1000
    rpict.options.as_ = 20
    rpict.options.ar = 300
    rpict.options.aa = 0.1
    rpict.options.x = _size_
    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