Interface

class sofia_redux.pipeline.interface.Interface(configuration=None)[source]

Bases: object

Interface to Redux reduction objects.

Parent object to both command-line and graphical interfaces.

Attributes:
reduction: Reduction

A Redux reduction object for the currently loaded data

chooser: Chooser

A Redux chooser object that selects reduction objects for new data

configuration: Configuration

A Redux configuration object that selects a chooser and sets any necessary parameters for the reduction.

viewers: list of Viewer

List of Redux Viewer objects associated with the reduction.

Initialize the interface, with an optional configuration.

Parameters:
configurationConfiguration, optional

Configuration items to be used for all reductions.

Methods Summary

clear_reduction()

Clear reduction variables.

close_viewers()

Close any open viewers.

has_embedded_viewers()

Check for associated embedded viewers.

is_input_manifest(data)

Test if input data list is actually an input manifest file.

load_configuration()

Set reduction chooser from configuration.

load_data_id()

Load the input file description from the reduction.

load_files(data)

Load input files from a list of file names.

load_parameters([param_file])

Load reduction parameters.

read_input_manifest(data)

Read an input manifest and return input filenames.

reduce()

Call the reduce method of the current reduction.

register_viewers([parent])

Retrieve and start viewers defined by the reduction object.

reset_log([loglevel])

Reset astropy log to standard settings.

reset_reduction(data)

Reset the current reduction to its initial state.

reset_viewers()

Reset viewers to default state.

save_configuration([filename])

Save configuration values.

save_input_manifest([filename, absolute_paths])

Save input manifest to disk.

save_output_manifest([filename, absolute_paths])

Save the output manifest.

save_parameters([filename])

Save current reduction parameters.

set_log_file([filename])

Set a log file handler for the reduction.

set_output_directory([dirname])

Set the output directory for the reduction.

set_recipe([recipe, step_to])

Set a non-default processing recipe for the reduction.

start(data)

Start a new reduction from an input data set.

step()

Run a reduction step.

tidy_log([loglevel])

Tidy up log printing for easier human readability at INFO level.

unset_log_file()

Remove any existing log file handlers.

update_configuration(config_file)

Update top-level configuration.

update_viewers()

Update all viewers associated with the current reduction.

Methods Documentation

clear_reduction()[source]

Clear reduction variables.

Resets the reduction and viewers attributes. Removes any existing log file handlers.

close_viewers()[source]

Close any open viewers.

has_embedded_viewers()[source]

Check for associated embedded viewers.

Returns:
bool

True if associated viewers are intended to be embedded in the main GUI; False otherwise

is_input_manifest(data)[source]

Test if input data list is actually an input manifest file.

Parameters:
datalist of str

List of input file names.

Returns:
bool

True if data is a single plain text file; False otherwise.

load_configuration()[source]

Set reduction chooser from configuration.

All other configuration items are accessed as needed.

load_data_id()[source]

Load the input file description from the reduction.

load_files(data)[source]

Load input files from a list of file names.

The reduction object is assigned by the chooser, then an output directory and log file are set, and the data is loaded into the reduction object.

Parameters:
datalist of str or str

Lists the input file names to be reduced.

load_parameters(param_file=None)[source]

Load reduction parameters.

Default reduction parameters may optionally be overridden by a parameter file in INI format with reduction step names as section headers, and parameters specified in key, value pairs.

Parameters:
param_filestr, optional

Parameter file name

read_input_manifest(data)[source]

Read an input manifest and return input filenames.

Input manifests are assumed to be plain text files that list one input file per line. Only file names that exist on disk as files are returned.

Parameters:
datastr or list of str

File name for the input manifest.

Returns:
list of str

List of input file names.

reduce()[source]

Call the reduce method of the current reduction.

register_viewers(parent=None)[source]

Retrieve and start viewers defined by the reduction object.

Calls the Reduction.register_viewers() method, to retrieve Viewer objects, then calls the Viewer.start() method to initialize them. If configuration.update_display is False, no viewers will be registered.

Parameters:
parent: object, optional

A parent widget for the viewer. May be any type that the viewer understands (e.g. a Qt frame widget).

static reset_log(loglevel=None)[source]

Reset astropy log to standard settings.

Removes any TidyLogHandlers, and resets filters for any astropy LogHandlers.

Parameters:
loglevelstr or int, optional

Logging level to use for the terminal log. May be any of the values accepted by the logging module (CRITICAL, ERROR, WARNING, INFO, DEBUG). If not specified, log levels will not be modified.

reset_reduction(data)[source]

Reset the current reduction to its initial state.

Calls the Reduction.load() method on the input data. Also resets a non-standard recipe if necessary.

Parameters:
datalist of str or str

Input data filenames.

reset_viewers()[source]

Reset viewers to default state.

Calls the Viewer.reset() method

save_configuration(filename=None)[source]

Save configuration values.

If a file name is provided, this function writes a plain text file in INI format, containing top-level configuration values.

Parameters:
filenamestr, optional

File path to write to.

Returns:
None or list of str

The return value depends on the filename parameter.

save_input_manifest(filename=None, absolute_paths=None)[source]

Save input manifest to disk.

Writes a plain text file containing one file name per line. Input files are specified in the reduction.raw_files attribute.

Parameters:
filenamestr, optional

Output file path to write to. Default may be set in the configuration.input_manifest attribute. If configuration.input_manifest is not an absolute path, it will be joined with the reduction.output_directory attribute.

absolute_pathsbool, optional

If True, input file names will be written as absolute paths. If False, they will be written as relative paths. If None, the default value specified in configuration.absolute_paths will be used if present; otherwise, absolute_paths defaults to True.

save_output_manifest(filename=None, absolute_paths=None)[source]

Save the output manifest.

Writes a plain text file containing one file name per line. Output files are specified in the reduction.out_files attribute.

Parameters:
filenamestr, optional

Output file path to write to. Default may be set in the configuration.output_manifest attribute. If configuration.output_manifest is not an absolute path, it will be joined with the reduction.output_directory attribute.

absolute_pathsbool or None

If True, output file names will be written as absolute paths. If False, they will be written as relative paths. If None, the default value specified in configuration.absolute_paths will be used if present; otherwise, absolute_paths defaults to True

save_parameters(filename=None)[source]

Save current reduction parameters.

If a file name is provided, this function writes a plain text file in INI format. Reduction step index and names are used as section headers, followed by key-value pairs for all currently defined parameters.

If no filename is provided, this function will return a list of strings containing the parameters pretty-printed to INI format.

Parameters:
filenamestr, optional

File path to write to.

Returns:
None or list of str

The return value depends on the filename parameter.

set_log_file(filename=None)[source]

Set a log file handler for the reduction.

If the provided file name is not an absolute path, it will be joined with reduction.output_directory. When called, any existing file handlers will be removed. If a log file has already been written, it will be moved to the new file name; any further log messages will be appended to the existing log file.

Parameters:
filenamestr, optional

Log file path name. If not provided, the configuration.log_file attribute will be used. If this value is None, no action will be taken.

set_output_directory(dirname=None)[source]

Set the output directory for the reduction.

Makes the directory if it does not yet exist. The directory name is stored in the reduction.output_directory attribute.

Parameters:
dirnamestr, optional

Path to the output directory. If not provided, the configuration.output_directory attribute will be used. If this value is None, no action is taken.

set_recipe(recipe=None, step_to=None)[source]

Set a non-default processing recipe for the reduction.

All specified processing steps must be known to the current reduction object. The reduction is not reset after setting the new recipe.

Parameters:
recipelist of str, optional

List of processing step names to use in place of the default reduction. If not provided, the configuration.recipe attribute will be used. If this value is also None, no action will be taken.

step_tostr, optional

A processing step name after which the recipe is terminated. If not provided, the configuration.step_to attribute will be used. If this value is also None, no action will be taken.

start(data)[source]

Start a new reduction from an input data set.

Parameters:
datalist of str or str

Input data.

step()[source]

Run a reduction step.

Calls the current reduction’s Reduction.step method.

Returns:
str

Empty string if step was successful; an error message otherwise.

static tidy_log(loglevel='INFO')[source]

Tidy up log printing for easier human readability at INFO level.

INFO messages to the terminal will be printed directly. Messages at all other levels will use astropy.log format. Log file formatting is unaffected.

Parameters:
loglevelstr or int, optional

Logging level to use for the terminal log. May be any of the values accepted by the logging module (CRITICAL, ERROR, WARNING, INFO, DEBUG).

unset_log_file()[source]

Remove any existing log file handlers.

update_configuration(config_file)[source]

Update top-level configuration.

Default configuration parameters may optionally be overridden by a parameter file in INI format, specified in key, value pairs.

Parameters:
config_filestr, dict, or ConfigObj

Configuration to update with.

update_viewers()[source]

Update all viewers associated with the current reduction.

Calls the current viewers’ Viewer.update method with the current reduction’s reduction.display_data. If configuration.update_display is False, the update will not be performed.