DataParent

class sofia_redux.instruments.hawc.dataparent.DataParent(config=None)[source]

Bases: object

Pipeline data object.

This object stores a config file, header, and data.

Initialize data object and variables.

Parameters:
configconfigobj.ConfigObj, dict, str, or list of str, optional

If specified, the configuration will be loaded.

Attributes Summary

pipever

str : Pipeline version.

Methods Summary

copy()

Return a copy of the current object.

date_override_config(date)

Retrieve an override configuration for a particular date.

default_config()

Set default configuration from config/pipeconf.cfg.

delheadval(key)

Delete one or more keywords from the header.

get_pipe_mode()

Get the pipeline mode.

getheadval(key[, errmsg])

Get header value.

load([filename])

Load the data from the file.

mergeconfig([config, date, mode])

Merge configuration into the existing configuration.

mergehead(other)

Merge a data object header into the current object's header.

mode_override_config(mode)

Retrieve an override configuration for an observation mode.

save([filename])

Save the data in the object to the specified file.

setconfig([config, date])

Set configuration for the pipe data.

setheadval(key, value[, comment])

Set a keyword value in the header.

Attributes Documentation

pipever = '3.2.0'

str : Pipeline version.

Methods Documentation

copy()[source]

Return a copy of the current object.

Returns:
DataParent
date_override_config(date)[source]

Retrieve an override configuration for a particular date.

Parameters:
datedatetime

The date of the observation.

Returns:
configobj.ConfigObj

Any non-default parameters associated with the observation date.

default_config()[source]

Set default configuration from config/pipeconf.cfg.

Returns:
configobj.ConfigObj
delheadval(key)[source]

Delete one or more keywords from the header.

Keywords are deleted from self.header, which defaults to the first header in the data object.

If the keyword is HISTORY or COMMENT, then all HISTORY or COMMENT entries will be removed.

Parameters:
keystr or list of str

The header keyword(s) to delete.

get_pipe_mode()[source]

Get the pipeline mode.

Searches for an appropriate pipeline mode in the config file, given the header values in the passed data. Tries to mach all key=value pairs in the datakeys value of the mode entries in the config file. Returns name of the first pipeline mode that matches the data. Returns None if no matching pipeline mode found.

Returns:
str or None

The pipeline mode name, or None if not found.

getheadval(key, errmsg=True)[source]

Get header value.

Returns the value of the requested key from the header.

If the key is present in the [header] section of the configuration, that value is returned instead. The following entries are possible in the configuration file:

  • KEY = VALUE : VALUE is returned. The system checks if value is an int or a float, else a string is returned.

  • KEY = NEWKEY : The value under header[NEWKEY] is returned.

  • KEY = ?_ALTKEY : If the keyword KEY is present, header[KEY] is returned, else header[ALTKEY] is returned.

If the key can not be found in either the header or the configuration, a KeyError is produced and a warning is issued.

Parameters:
keystr

The keyword value to return.

errmsgbool, optional

Flag indicating if a log error message should be issued if the keyword is not found. A KeyError will still be raised if errmsg is False.

Returns:
int, float, or str

The header value.

Raises:
KeyError

If the keyword is not found.

load(filename='')[source]

Load the data from the file.

This function is not implemented for the parent class. It should be overridden by child classes.

mergeconfig(config=None, date=None, mode=None)[source]

Merge configuration into the existing configuration.

All values from the new configuration are used, overwriting old values if they are already in the old configuration.

The order is:

  • load the default configuration (data/config/pipeconf.cfg)

  • load any overrides for the observation date

  • load any overrides for the pipeline mode

  • load any user overrides from the config parameter

Parameters:
configconfigobj.ConfigObj, dict, str or list of str, optional

Configuration to merge into the default.

datedatetime, optional

If specified, additional override configurations will be loaded for this date, if they exist, prior to loading configurations from config.

modestr, optional

The pipeline mode to retrieve. Should be specified in the config file with ‘mode_’ prepended.

mergehead(other)[source]

Merge a data object header into the current object’s header.

Parameters:
otherDataParent

The other object.

mode_override_config(mode)[source]

Retrieve an override configuration for an observation mode.

Parameters:
modestr

The pipeline mode to retrieve. Should be specified in the config file with ‘mode_’ prepended.

Returns:
configobj.ConfigObj

Any non-default parameters associated with the observation date.

save(filename='')[source]

Save the data in the object to the specified file.

This function is not implemented for the parent class. It should be overridden by child classes.

setconfig(config=None, date=None)[source]

Set configuration for the pipe data.

The configuration object is returned. The config parameter can be one of these:

  • A ConfigObj object

  • A path string containing the filename of a valid config file

  • A list of path strings to valid config files. In this case, each file is merged in order.

A default configuration will be loaded first, then the config parameter will be merged into it.

Parameters:
configconfigobj.ConfigObj, str, or list of str, optional

Configuration to merge into the default.

datedatetime, optional

If specified, additional override configurations will be loaded for this date, if they exist, prior to loading configurations from config.

Returns:
configobj.ConfigObj

The merged configuration.

setheadval(key, value, comment='')[source]

Set a keyword value in the header.

Parameters:
keystr

The keyword to set.

valuestr, int, float, or bool

The value to set.

commentstr, optional

If provided, will be set in the value of the COMMENT keyword in the header.