def test_stdin(): """Test stdin.""" getinfo = Getinfo() getinfo.input = ['image1.hdr', 'image2.hdr'] getinfo.output = 'combined.hdr' assert getinfo.to_radiance(stdin_input=True) == ('getinfo > combined.hdr')
def test_assignment_options(): """Test assigning options.""" getinfo = Getinfo() getinfo.input = ['image1.hdr', 'image2.hdr'] getinfo.options.d = True assert getinfo.to_radiance() == 'getinfo -d image1.hdr image2.hdr'
def test_assignment_options_append(): """Test assigning options.""" getinfo = Getinfo() getinfo.input = ['image1.hdr', 'image2.hdr'] getinfo.options.a = 'This is some Text to append to the header' assert getinfo.to_radiance() == \ 'getinfo -a "This is some Text to append to the header" image1.hdr image2.hdr' \ or getinfo.to_radiance() == \ "getinfo -a 'This is some Text to append to the header' image1.hdr image2.hdr"
def test_validation(): """Validate error for missing argument.""" getinfo = Getinfo() with pytest.raises(exceptions.MissingArgumentError): getinfo.to_radiance() getinfo.input = ['image1.hdr', 'image2.hdr'] assert getinfo.to_radiance() == 'getinfo image1.hdr image2.hdr'
def test_assignment(): """Test assignment.""" getinfo = Getinfo() getinfo.input = ['image1.hdr', 'image2.hdr'] assert getinfo.input == 'image1.hdr image2.hdr' assert getinfo.to_radiance() == 'getinfo image1.hdr image2.hdr' getinfo.output = 'combined.hdr' assert getinfo.output == 'combined.hdr' assert getinfo.to_radiance( ) == 'getinfo image1.hdr image2.hdr > combined.hdr'
def three_phase_rmtxop(view_matrix, t_matrix, daylight_matrix, sky_vector, output_matrix, output_format, illuminance, remove_header, dry_run): """Matrix multiplication for view matrix, transmission matrix, daylight matrix and sky matrix.""" try: options = RmtxopOptions() options.f = output_format matrices = [view_matrix, t_matrix, daylight_matrix, sky_vector] if illuminance: # rmtxop concatenation calc = Rmtxop(matrices=matrices) cmd = Rmtxop(options=options) cmd.transforms = [['47.4', '119.9', '11.6']] cmd.matrices = calc else: cmd = Rmtxop(options=options, matrices=matrices) if remove_header: getinfo = Getinfo.remove_header(output=output_matrix) cmd.pipe_to = getinfo else: cmd.output = output_matrix if dry_run: click.echo(cmd) else: run_command(cmd.to_radiance(), env=folders.env) except OSError: os.system(cmd.to_radiance()) except Exception: _logger.exception( 'Failed to run matrix multiplication calculations with rmtxop') sys.exit(1) else: sys.exit(0)
def merge_view(input_folder, base_name, extension, scale_factor, folder, name): """Merge several radiance HDR image files into a single file. This command will also perform an anti-aliasing operation on the output and replace the view information in the header of the merged file if a single .vf file is found within the root of the input-folder. \b Args: input_folder: Input folder. base_name: File base name. All of the files must start with base name and continue with _ and an integer values. extension: File extention. [Default: .unf] """ try: # get all of the files in the folder with the given extension pattern = r'{}_\d+{}'.format(base_name, extension) images = sorted(f for f in os.listdir(input_folder) if re.match(pattern, f)) if len(images) == 0: raise ValueError('Found no files to merge.') name = name or base_name # get the new dir name as view name might be group/name dirname = os.path.dirname(os.path.normpath(os.path.join(folder, name))) if dirname and not os.path.exists(dirname): os.makedirs(dirname) temp_output = os.path.join(dirname, name + '_temp.HDR') output_file = os.path.join(dirname, name + '.HDR') # set up the pcompos command in_dirname = os.path.normpath(input_folder) pcompos = Pcompos(output=temp_output) pcompos.input = [os.path.join(in_dirname, img) for img in images] pcompos.options.a = 1 # setup the pfilt command to perform anti-aliasing on the output pfilt = Pfilt(input=temp_output) pfilt.options.r = 0.6 if scale_factor != 1: pfilt.options.x = '/{}'.format(scale_factor) pfilt.options.y = '/{}'.format(scale_factor) # search for a single .vf in the folder and, if it's found, grab the info views = sorted(f for f in os.listdir(input_folder) if f.endswith('.vf')) if len(views) == 1: # replace the header with the info in the view view_obj = View.from_file(os.path.join(input_folder, views[0])) getinfo = Getinfo(output=output_file) getinfo.options.a = 'VIEW= {}'.format(view_obj) pfilt.pipe_to = getinfo else: # just let the output of pfilt be the final output pfilt.output = output_file # run the commands in series env = None if folders.env != {}: env = folders.env env = dict(os.environ, **env) if env else None for r_cmd in (pcompos, pfilt): r_cmd.run(env) except Exception: _logger.exception('Failed to merge image files.') sys.exit(1) else: sys.exit(0)
def test_defaults(): """Test command.""" getinfo = Getinfo() assert getinfo.command == 'getinfo' assert getinfo.options.to_radiance() == ''