5.1.1.2. recipe_system.cal_service package

recipe_system.cal_service.get_calconf()[source]
recipe_system.cal_service.get_db_path_from_config()[source]

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.

config: str
name of the configuration file
db_path : str
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.

inst_lookups : str
local of the instrument lookups package (for the MDF lookup table)
ucals : dict
user calibrations
upload : list
things to upload (we’re concerned about “calibs” and “science”)

A UserDB object, possibly linked to additional CalDB objects

recipe_system.cal_service.parse_databases(default_dbname='cal_manager.db')[source]

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.

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

list of tuples (class, database name, kwargs)

recipe_system.cal_service.set_local_database()[source]

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

A LocalDB object

5.1.1.2.2. Submodules

5.1.1.2.3. 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.

name : str
a name for this database (gets reported with the calibration, so there is some provenance)
log : logger object
the logger object to report to
get_cal : bool
allow retrievals from this database?
store_cal : bool
allow new calibrations to be stored to this database?
caldir : str
directory under which calibrations will be stored (either when createed, or when retrieved from a RemoteDB)
procmode : str
the default processing mode that retrieved calibrations must be suitable for
nextdb : CalDB object/None
a place to send unfulfilled calibration requests
_valid_caltypes : list of str
valid calibration types for retrieval/storage
add_database(db)[source]

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.

db : CalDB 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.

adinputs : list of AstroData objects
the files requiring calibrations
caltype : str
the type of calibration required
procmode : str/None
minimum quality of processing needed for the calibration
howmany : int
maximum number of calibrations to return (for backwards compat). Use howmany>1 at your own risk!
CalReturn : the 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.

cals : str/AstroData
the calibration or its filename
caltype : str
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.

items()[source]
recipe_system.cal_service.caldb.cascade(fn)[source]

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.

5.1.1.2.4. 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

as_dict()[source]
recipe_system.cal_service.calrequestlib.generate_md5_digest(filename)[source]
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.

inputs: <list>
A list of input AstroData instances.
caltype: <str>
Calibration type, eg., ‘processed_bias’, ‘flat’, etc.
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]

5.1.1.2.5. recipe_system.cal_service.calurl_dict module

5.1.1.2.6. 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.get_file_iterator(url)[source]
recipe_system.cal_service.file_getter.plain_file_getter(url)[source]
recipe_system.cal_service.file_getter.requests_getter(url)[source]

5.1.1.2.7. 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: recipe_system.cal_service.caldb.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.

dbfile : str
name of the file on disk holding the database
_calmgr : LocalManager instance
the local calibration manager that will handle the requests
add_cal(calfile)[source]
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.

path : str
directory containing files to be ingested
walk : bool
add files from all subdirectories?
init(wipe=False)[source]

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

wipe : <bool>, optional
If the database exists and this parameter is True, the file will be removed and recreated before initializing
IOError
If the file exists and there a system error when trying to remove it (eg. lack of permissions).
LocalManagerError
If the file exists and wipe was False
list_files()[source]

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

LocalManager.list_files: <generator>.
(See class docstring for example of how to use this generator.)
LocalManagerError
Raised when unable to read database.
remove_cal(calfile)[source]

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

calfile : <str>
Path to the file. It can be either absolute or relative

5.1.1.2.8. recipe_system.cal_service.localmanager module

5.1.1.2.9. 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: recipe_system.cal_service.caldb.CalDB

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

server : str
URL of the server
store_science : bool
whether processed science images should be uploaded
_upload_cookie : str
the cookie to send when uploading files
_calmgr : str
the URL for making requests to the remote calibration manager
_proccal_url, _science_url : str
the URLs for uploading processed calibrations and processed science images, respectively.
recipe_system.cal_service.remotedb.retrieve_calibration(rqurl, rq, howmany=1)[source]

5.1.1.2.10. 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: recipe_system.cal_service.caldb.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.

user_cals : dict
A dict of {caltype: filename} as described in (a) above
user_cache : dict
A dict of {(calibration_key, caltype): filename} as described in (b) This is cached to disk as a pickle.
mdf_dict : dict
A dict of {mdf_key: filename} for the standard focal plane masks
load_cache()[source]
save_cache()[source]