recipe_system.utils package Subpackages Submodules recipe_system.utils.decorators module recipe_system.utils.errors module

exception recipe_system.utils.errors.AstroDataError[source]

Bases: Exception

exception recipe_system.utils.errors.ContextError[source]

Bases: Exception

exception recipe_system.utils.errors.ModeError[source]

Bases: Exception

exception recipe_system.utils.errors.PrimitivesNotFound[source]

Bases: Exception

exception recipe_system.utils.errors.RecipeNotFound[source]

Bases: Exception

exception recipe_system.utils.errors.StackError[source]

Bases: OSError recipe_system.utils.findexe module


Function receives an executable name, ‘exe’, as a string, and returns a list of pids that match the name. Parameters


Name of a running executable. Returns

pids: list

a list of extant pids found running ‘exe’ Example

>>> findexe('autoredux')
>>> findexe('emacs')
[41273, 55557] recipe_system.utils.mapper_utils module

Utility functions for Mappers.

find_user_recipe – searches for a user specified recipe, if any. dotpath() – build a python import path for dr packages.


Build an import path from args.


args (<list>, implied by *) – a set of arguments of arbitrary length


a dot path to an importable module

Return type:



Function receives the value of the reduce [-r, –recipe] flag, if passed. This will be a path to a recipe file and a dotted recipe name, which exists as a function in the recipe file. A properly specified user recipe shall contain one, and only one, dot operator.

If the recipefile.recipename cannot be found on the path, whether specified or implied (as cwd), then None is returned.

The string value of dashr will look like,

-r ‘/path/to/users/recipes/recipefile.recipe_function’

-r ‘recipefile.recipe_function’ – recipe file in cwd.

A recipe name with no dot operator implies a recipe name in the system recipe library.


dashr (<str>) – a path to a recipe file dotted with a recipe function name.


imported recipe function OR None

Return type:

<type ‘function’> or None recipe_system.utils.md5 module


Generates the md5sum of the data in filename, returns the hex string.


Generates the md5sum and size of the data returned by the file-like object fobj, returns a tuple containing the hex string md5 and the size in bytes. f must be open. It will not be closed. We will read from it until we encounter EOF. No seeks will be done, fobj will be left at eof recipe_system.utils.reduceActions module

This module provides a number “action” classes, subclassed from the argparse.Action class. These classes only override the __call__() method. This actions class library supplies ad hoc functionality to DPDG requirements on the reduce command line interface.

Action classes provided:

PosArgAction - positional argument BooleanAction - optional switches UnitaryArgumentAction - single value options ParameterAction - user parameters (-p, –param) CalibrationAction - user calibration services (–user_cal)

Becuase of requirements on the reduce interface, any new reduce options should specify one of these actions in the add_argument() call. But only one (1) PosArgAction should occur in a given parser.

These actions may be used in the add_argument() method call, such as,

parser.add_argument(‘-f’, ‘–foo’, action=BooleanAction,

help=”Switch on foo.”)

class recipe_system.utils.reduceActions.BooleanAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

class recipe_system.utils.reduceActions.CalibrationAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

class recipe_system.utils.reduceActions.ParameterAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

class recipe_system.utils.reduceActions.PosArgAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

class recipe_system.utils.reduceActions.UnitaryArgumentAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action recipe_system.utils.reduce_utils module

class recipe_system.utils.reduce_utils.ReduceArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)[source]

Bases: ArgumentParser

Converts an argument line from a user param file into an actual argument, yields to the calling parser.

class recipe_system.utils.reduce_utils.ReduceHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Bases: RawDescriptionHelpFormatter

ReduceHelpFormatter class overrides default help formatting on customized reduce actions.

recipe_system.utils.reduce_utils.get_option_flags(parser, option)[source]
recipe_system.utils.reduce_utils.insert_option_value(parser, args, option, value)[source]

Convert argparse argument lists to single string values.


args (<Namespace>) – argparse Namespace object or equivalent


Same with converted types.

Return type:



When a user passes a –user_cal argument of the form,

–user_cal processed_bias:/path/to/foo.fits

The parser produces a user calibrations list like,


This list would pass to the Reduce __init__ as such, but, this function will translate into a dict and confirm that the provided file exists and is of the correct type.

{‘processed_bias’: ‘/path/to/foo.fits’}

User calibrations always take precedence over nominal calibration retrieval. User calibrations are not cached because they are not retrieved from fitsstore and are presumably on disk. Parameters


A list of strings like, ‘caltype:calfilepath’. Returns


a dictionary of the cal types applied to input files.


For Recipe System v2.0, upload shall now be a list of things to send to fitsstore. E.g., $ reduce –upload metrics <file.fits> <file2.fits> $ reduce –upload metrics, calibs <file.fits> <file2.fits> $ reduce –upload metrics, calibs, science <file.fits> <file2.fits>

Result in

upload == [‘metrics’] upload == [‘metrics’, ‘calibs’] upload == [‘metrics’, ‘calibs’, ‘science’]


upload (<list>) – upload argument received by the reduce command line.


list of coerced or defaulted upload instructions.

Return type:


recipe_system.utils.reduce_utils.parser_has_option(parser, option)[source]

All cmd line args are delivered as strings. Find any user parameters that should be other python types and set them to those actual corresponding types.


‘None’ –> None ‘True’ –> True ‘False’ –> False

Parameters userparams:

user parameters (if any) passed on the command line.


A tuple of same parameters with converted None and boolean types. preserved with any specified primitive name. E.g., [(‘foo’,’bar’), (‘tileArrays:par1’,’val1’)]

Return type:

<list> of tuples.

recipe_system.utils.reduce_utils.show_parser_options(parser, args)[source] recipe_system.utils.rs_utilities module

Set of functions in support of the recipe_system.

recipe_system.utils.rs_utilities.makedrpkg(pkgname, instruments, modes=None)[source]

Create the basic structure for a data reduction package that the recipe system will recognize. Parameters

pkgname: str

Name of the new dr-package.

instruments: list of str

Name of the instrument(s) for which to create a directory structure.

modes: list of str

Name of the recipe modes that will be supported. Eg. modes = [‘sq’, ‘qa’] Default: [‘sq’] (‘sq’=science quality, ‘qa’=quality assessement)