recipe_system.cal_service package


Read the path of the local database specified in the config file. An error will be raised if there is no such database, or more than one. This function is used by the “caldb” script and the set_local_database() function here. Parameters

config: str

name of the configuration file Returns


the path to the local database file

recipe_system.cal_service.init_calibration_databases(inst_lookups=None, procmode=None, ucals=None, upload=None)[source]

Initialize the calibration databases for a PrimitivesBASE object. Parameters


local of the instrument lookups package (for the MDF lookup table)


user calibrations


things to upload (we’re concerned about “calibs” and “science”) Returns

A UserDB object, possibly linked to additional CalDB objects


Parse the databases listed in the global config file. This returns a list provided information on how to build the cascase of databases, but does not instantiate any CalDB objects, so it can be used by the caldb script efficiently. Parameters


default name of database file (if only a directory is listed in the config file) Returns

list of tuples (class, database name, kwargs)


User helper function to define a local calibration database based on the “dragonsrc” config file. Returns

A LocalDB object Subpackages Submodules recipe_system.cal_service.caldb module

class recipe_system.cal_service.caldb.CalDB(name=None, get_cal=True, store_cal=False, valid_caltypes=None, procmode=None, log=None)[source]

Bases: object

The parent class for all types of calibration database handlers. Attributes


a name for this database (gets reported with the calibration, so there is some provenance)

loglogger object

the logger object to report to


allow retrievals from this database?


allow new calibrations to be stored to this database?


directory under which calibrations will be stored (either when createed, or when retrieved from a RemoteDB)


the default processing mode that retrieved calibrations must be suitable for

nextdbCalDB object/None

a place to send unfulfilled calibration requests

_valid_caltypeslist of str

valid calibration types for retrieval/storage


Adds a database to the end of the cascade. It does this recursively, calling this method on the next database in the casecade, until it gets to the end. Parameters

dbCalDB instance

the database to add to the end of this cascade

clear_calibrations(*args, **kwargs)[source]
get_calibrations(adinputs, caltype=None, procmode=None, howmany=1)[source]

Returns the requested calibration type for the list of files provided. Parameters

adinputslist of AstroData objects

the files requiring calibrations


the type of calibration required


minimum quality of processing needed for the calibration


maximum number of calibrations to return (for backwards compat). Use howmany>1 at your own risk! Returns

CalReturnthe calibration filenames and the databases which

provided them

set_calibrations(*args, **kwargs)[source]
store_calibration(cal, caltype=None)[source]

Handle storage of calibrations. For all types of calibration (NOT processed_science) this saves the file to disk in the appropriate calibrations/ subdirectory (if store=True) and then passes the filename down the chain. For processed_science files, it passes the AstroData object. Parameters


the calibration or its filename


type of calibration

unset_calibrations(*args, **kwargs)[source]
class recipe_system.cal_service.caldb.CalReturn(*args)[source]

Bases: object

A simple class to store files and origins (i.e., which CalDB instance provided the calibration) for calibration requests. The class can be instantiated with either a list of files and a list of origins, or a single list of 2-tuples (file, origin), where a single None can be used in place of (None, None).

Public attributes are: files : list of files (or list of lists of files) origins : list of origins

There is also an items() method that returns these lists as zipped pairs, like the dict.items() method. Iteration is set up to return first the complete list of files, then the complete list of origins, which helps with coding the cheeseCorrect() primitives.


Decorates methods such that, after execution, the method with the same name is called on the next CalDB instance in the cascade, with the same arguments. recipe_system.cal_service.calrequestlib module

class recipe_system.cal_service.calrequestlib.CalibrationRequest(ad, caltype=None, procmode=None)[source]

Bases: object

Request objects are passed to a calibration_search() function

recipe_system.cal_service.calrequestlib.get_cal_requests(inputs, caltype, procmode=None, is_local=True)[source]

Builds a list of CalibrationRequest objects, one for each ad input. Parameters

inputs: <list>

A list of input AstroData instances.

caltype: <str>

Calibration type, eg., ‘processed_bias’, ‘flat’, etc. Returns

rq_events: <list>

A list of CalibrationRequest instances, one for each passed

‘ad’ instance in ‘inputs’.

recipe_system.cal_service.calrequestlib.get_request(url, filename)[source] recipe_system.cal_service.calurl_dict module recipe_system.cal_service.file_getter module

exception recipe_system.cal_service.file_getter.GetterError(messages)[source]

Bases: Exception

recipe_system.cal_service.file_getter.requests_getter(url)[source] recipe_system.cal_service.localdb module

class recipe_system.cal_service.localdb.LocalDB(dbfile, name=None, valid_caltypes=None, procmode=None, get_cal=True, store_cal=True, log=None, force_init=False)[source]

Bases: CalDB

The class handling a calibration database stored on disk, via the LocalManager class. In addition to the methods required to interface with DRAGONS data reduction pipelines, other methods are used to provide a full API and effect actions of the “caldb” script.

An attempt to create an instance of this class without the LocalManager being importable will result in an error. Attributes


name of the file on disk holding the database

_calmgrLocalManager instance

the local calibration manager that will handle the requests

add_directory(path, walk=False)[source]

Ingest one or more files from a given directory, optionally searching all subdirectories. This is not used by primitives in the DRAGONS data reduction pipelines. Parameters


directory containing files to be ingested


add files from all subdirectories?


Initialize a calibration database. Callers will usually only want to do this once. But if called again, it will wipe the old database. Parameters

wipe<bool>, optional

If the database exists and this parameter is True, the file will be removed and recreated before initializing Raises


If the file exists and there a system error when trying to remove it (eg. lack of permissions).


If the file exists and wipe was False


List all files in the local calibration database. This is not used by primitives in the DRAGONS data reduction pipelines. Returns

LocalManager.list_files: <generator>.

(See class docstring for example of how to use this generator.) Raises


Raised when unable to read database.


Removes a calibration file from the database. Note that only the filename is relevant. All duplicate copies in the database will be removed. Parameters


Path to the file. It can be either absolute or relative recipe_system.cal_service.localmanager module recipe_system.cal_service.remotedb module

class recipe_system.cal_service.remotedb.RemoteDB(server, name=None, valid_caltypes=None, get_cal=True, store_cal=False, store_science=False, procmode=None, log=None, upload_cookie=None)[source]

Bases: CalDB

The class for remote calibration databases. It inherits from CalDB, but also has the following attributes: Attributes


URL of the server


whether processed science images should be uploaded


the cookie to send when uploading files


the URL for making requests to the remote calibration manager

_proccal_url, _science_urlstr

the URLs for uploading processed calibrations and processed science images, respectively.

recipe_system.cal_service.remotedb.retrieve_calibration(rqurl, rq, howmany=1)[source] recipe_system.cal_service.userdb module

class recipe_system.cal_service.userdb.UserDB(name=None, get_cal=True, mdf_dict=None, user_cals=None, valid_caltypes=None, log=None)[source]

Bases: CalDB

The class handling the User-defined database, which can contain:

  1. a filename for each caltype that should be returned whenever that caltype is requested, irrespective of the AD “making” the request

  2. a filename to be returned for a given caltype for a specific AD (actually, a specific ad.calibration_key(), which is normally just the data label)

This class also handles the standard MDFs when a “mask” is requested. Attributes


A dict of {caltype: filename} as described in (a) above


A dict of {(calibration_key, caltype): filename} as described in (b) This is cached to disk as a pickle.


A dict of {mdf_key: filename} for the standard focal plane masks