4.1.1.2. recipe_system.cal_service package

class recipe_system.cal_service.CalibrationService[source]

Bases: object

The CalibrationService class provides a limited API on the LocalManager class. The CalibrationService is meant for public use, as opposed to the lower level LocalManager class, and provides limited access to let users/callers easy configuration and use of the local calibration database.

config(db_dir=None, verbose=True, config_file=STANDARD_REDUCTION_CONF)[source]

configure a session with the database via the rsys.conf file.

init(wipe=True)[source]

initialize a calibration database.

add_cal(path)[source]

Add a calibration file to the database.

remove_cal(path)[source]

Delete a calibration from the database.

list_files()[source]

List files in the database. Returns a generator object.

E.g.,
>>> from recipe_system.cal_service import CalibrationService
>>> caldb = CalibrationService()
>>> caldb.config()
Using configuration file: ~/.geminidr/rsys.cfg
The active database directory is: ~/.geminidr
The database file to be used: ~/.geminidr/cal_manager.db
The 'standalone' flag is active; local calibrations will be used.
>>> caldb.add_cal('calibrations/processed_bias/S20141013S0163_bias.fits')
>>> for f in caldb.list_files():

f

FileData(name='N20120212S0073_flat.fits', path='NIRI/calibrations/processed_flat')
FileData(name='N20131214S0097_dark.fits', path='NIRI')
FileData(name='N20150419S0224_flat.fits', path='GMOS_N_TWILIGHT_FLATS')
FileData(name='S20141013S0020_stackd_flat.fits', path='gband_demo')
FileData(name='S20141013S0163_bias.fits', path='gband_demo')
FileData(name='S20141013S0163_flats_bias.fits', path='../gband_demo')
FileData(name='S20141103S0123_image_bias.fits', path='../gband_demo')
>>> caldb.remove_cal('N20120212S0073_flat.fits')
>>> for f in caldb.list_files():

f

FileData(name='N20131214S0097_dark.fits', path='NIRI')
FileData(name='N20150419S0224_flat.fits', path='GMOS_N_TWILIGHT_FLATS')
FileData(name='S20141013S0020_stackd_flat.fits', path='gband_demo')
FileData(name='S20141013S0163_bias.fits', path='gband_demo')
FileData(name='S20141013S0163_flats_bias.fits', path='../gband_demo')
FileData(name='S20141103S0123_image_bias.fits', path='../gband_demo')
add_cal(path)[source]

Registers a calibration file specified by ‘apath’ into the database

Parameters:path (<str>) – Path to the file. It can be either absolute or relative.
config(db_dir=None, verbose=False, config_file='~/.geminidr/rsys.cfg')[source]

Configure the Calibration Service and database.

Parameters:
  • db_dir (<str>) – Path to the local calibration database. If the database has not been initialized, call this method and then init() the database. If not passed (None), the path specified in a user’s rsys.conf file is used.
  • verbose (<bool>) – Configuration information will be displayed to stdout. Default is True.
  • config_file (str) – Path to the configuration file.
config_info()[source]
init(wipe=True)[source]

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

Parameters:

wipe (<bool>, optional) – If the database exists and this parameter is True (default value), the file will be removed and recreated before initializing.

Raises:
  • 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.

Parameters:<void>
Returns:LocalManager.list_files – (See class docstring for example of how to use this generator.)
Return type:<generator>.
Raises:LocalManagerError – Raised when unable to read database.
remove_cal(path)[source]

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 (<str>) – Path to the file. It can be either absolute or relative
recipe_system.cal_service.cal_search_factory()[source]

This function returns the proper calibration search function, depending on the user settings.

Defaults to prsproxyutil.calibration_search if there is missing calibs setup, or if the [calibs].`standalone` option is turned off.

Returns:calibration_search – The appropriate (local or fitsstore) search function indicated by a given configuration.
Return type:<func>
recipe_system.cal_service.get_calconf()[source]
recipe_system.cal_service.handle_returns_factory()[source]
recipe_system.cal_service.is_local()[source]
recipe_system.cal_service.load_calconf(conf_path='~/.geminidr/rsys.cfg')[source]

Load the configuration from the specified path to file (or files), and initialize it with some defaults.

Parameters:conf_path (<str>, Path of configuration file. Default is) – STANDARD_REDUCTION_CONF -> ‘~/.geminidr/rsys.cfg’
Returns:
Return type:<ConfigObject>
recipe_system.cal_service.set_calservice(local_db_dir=None, config_file='~/.geminidr/rsys.cfg')[source]

Update the calibration service global configuration stored in recipe_system.config.globalConf by changing the path to the configuration file and to the data base directory.

Parameters:
  • local_db_dir (<str>) – Name of the directory where the database will be stored.
  • config_file (<str>) – Name of the configuration file that will be loaded.
recipe_system.cal_service.update_calconf(items)[source]

4.1.1.2.2. Submodules

4.1.1.2.3. 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)[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 – A list of CalibrationRequest instances, one for each passed ‘ad’ instance in ‘inputs’.

Return type:

<list>

recipe_system.cal_service.calrequestlib.get_request(url, filename)[source]
recipe_system.cal_service.calrequestlib.process_cal_requests(cal_requests, howmany=None)[source]

Conduct a search for calibration files for the passed list of calibration requests. This passes the requests to the calibration_search() function, and then examines the search results to see if a matching file, if any, is cached. If not, then the calibration file is retrieved from the archive.

If a calibration match is found by the calibration manager, a URL is returned. This function will perform a cache inspection to see if the matched calibraiton file is already present. If not, the calibration will be downloaded and written to the cache. It is this path that is returned in the dictionary structure. A path of ‘None’ indicates that no calibration match was found.

Parameters:
  • cal_requests (<list>) – A list of CalibrationRequest objects
  • howmany (<int>, optional) – Maximum number of calibrations to return per request (not passed to the server-side request but trims the returned list)
Returns:

calibration_records – A set of science frames and matching calibrations.

Return type:

<dict>

Example

The returned dictionary has the form:

{(ad): <filename_of_calibration_including_path>,
    ...
}

4.1.1.2.4. recipe_system.cal_service.calurl_dict module

4.1.1.2.5. 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]

4.1.1.2.6. recipe_system.cal_service.localmanager module

4.1.1.2.7. recipe_system.cal_service.transport_request module

Receives a CalibrationRequest object, encodes the data and make the request on the appropriate server. Returns a URL, if any, and the MD5 hash checksum.

Parameters:
  • rq (<instance>, CalibrationRequest obj) –
  • howmany (<int>) – Maxinum number of calibrations to return
  • return_xml (<bool>) – Return the xml message to the caller when no URL is returned from the calibration server.
Returns:

calurlel, calurlmd5 – A tuple of the matching URLs and md5 hash checksums

Return type:

<list>, <list>

recipe_system.cal_service.transport_request.handle_returns(dv)[source]
recipe_system.cal_service.transport_request.upload_calibration(filename, is_science=False)[source]

Uploads a calibration file to the FITS Store.

Parameters:filename (<str>, File to be uploaded) –
Returns:
Return type:<void>