def test_defaults(): rcalc = Rcalc() assert rcalc.command == 'rcalc' assert rcalc.options.to_radiance() == '' with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') rcalc.to_radiance() # verify a warning has been raised for empty scene. assert len(w) == 1 assert 'no inputs.' in str(w[0].message)
def test_assigning_inputs(): rcalc = Rcalc() rcalc.inputs = input_path assert rcalc.to_radiance() == 'rcalc %s' % input_path rcalc.inputs = [input_path] assert rcalc.to_radiance() == 'rcalc %s' % input_path rcalc.inputs = [input_path_1, input_path_2] assert rcalc.to_radiance() == 'rcalc %s %s' % (input_path_1, input_path_2)
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)
def test_to_radiance_piped(): rcalc = Rcalc() rcalc.inputs = input_path rcalc.output = output_path rcalc.options.e = '$1=(0.265*$1+0.67*$2+0.065*$3)*179/1000' if os.name == 'nt': assert rcalc.to_radiance(stdin_input=True) == \ 'rcalc -e "$1=(0.265*$1+0.67*$2+0.065*$3)*179/1000" > %s' % output_path else: assert rcalc.to_radiance(stdin_input=True) == \ 'rcalc -e \'$1=(0.265*$1+0.67*$2+0.065*$3)*179/1000\' > %s' % output_path
def test_updating_options(): rcalc = Rcalc() rcalc.inputs = input_path rcalc.output = output_path rcalc.options.e = '$1=(0.265*$1+0.67*$2+0.065*$3)*179/1000' if os.name == 'nt': assert rcalc.to_radiance() == \ 'rcalc -e "$1=(0.265*$1+0.67*$2+0.065*$3)*179/1000" %s > %s' % ( input_path, output_path ) else: assert rcalc.to_radiance() == \ 'rcalc -e \'$1=(0.265*$1+0.67*$2+0.065*$3)*179/1000\' %s > %s' % ( input_path, output_path )
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)
def test_assigning_output(): rcalc = Rcalc() rcalc.inputs = [input_path_1, input_path_2] rcalc.output = output_path assert rcalc.to_radiance() == \ 'rcalc %s %s > %s' % (input_path_1, input_path_2, output_path)
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) with open(full_ghi_res, 'r') as inf: ghi = inf.readlines()[0].strip()