Configuration

class specsim.config.Configuration(config)[source] [edit on github]

Bases: Node

Configuration parameters container and utilities.

This class specifies the required top-level keys and delegates the interpretation and validation of their values to other functions.

Parameters:
configdict

Dictionary of configuration parameters, normally obtained by parsing a YAML file with load().

Attributes:
wavelengthastropy.units.Quantity

Array of linearly increasing wavelength values used for all simulation calculations. Determined by the wavelength_grid configuration parameters.

abs_base_pathstr

Absolute base path used for loading tabulated data. Determined by the basepath configuration parameter.

Raises:
ValueError

Missing required top-level configuration key.

Methods Summary

get_constants(parent[, required_names, ...])

Interpret a constants node in this configuration.

get_sky(parent)

Create a sky coordinate from a configuration node.

get_timestamp(parent)

Create a timestamp from a configuration node.

load_fits2d(filename, xy_unit, **hdus)

Load the specified FITS file.

load_table(parent, column_names[, ...])

Load and interpolate tabular data from one or more files.

load_table2d(node, y_column_name, ...)

Read values for some quantity tabulated along 2 axes.

update()

Update this configuration.

Methods Documentation

get_constants(parent, required_names=None, optional_names=None)[source] [edit on github]

Interpret a constants node in this configuration.

Constant values are parsed by parse_quantity().

Parameters:
parentNode

Parent node in this configuration whose constants child will be processed.

required_namesiterable or None

List of constant names that are required to be present for this method to succeed. If None, then no specific names are required. When specified, exactly these names are required and any other names will raise a RuntimeError.

optional_namesiterable or None

List of constant names that are optional for the parent node. When specified, all non-required names must be listed here or else a RuntimeError will be raised.

Returns:
dict

Dictionary of (name, value) pairs where each value is an astropy.units.Quantity. When required_names is specified, they are guaranteed to be present as keys of the returned dictionary.

Raises:
RuntimeError

Constants present in the node do not match the required or optional names.

get_sky(parent)[source] [edit on github]

Create a sky coordinate from a configuration node.

Parameters:
parentNode

Parent node in this configuration whose sky child will be processed.

Returns:
astropy.coordinates.SkyCoord

Sky coordinates object constructed from node parameters.

get_timestamp(parent)[source] [edit on github]

Create a timestamp from a configuration node.

Parameters:
parentNode

Parent node in this configuration whose timestamp child will be processed.

Returns:
astropy.time.Time

Timestamp object constructed from node parameters.

load_fits2d(filename, xy_unit, **hdus)[source] [edit on github]

Load the specified FITS file.

The data in each image HDU is interpreted with x mapped to columns (NAXIS1) and y mapped to rows (NAXIS2). The x, y coordinates are inferred from each image HDUs basic WCS parameters.

The returned interpolators expect parameter with units and return interpolated values with units. Units for x, y are specified via a parameter and assumed to be the same for all HDUs. Units for the interpolated data are taken from the BUNIT header keyword, and must be interpretable by astropy.

Parameters:
filenamestr

Name of the file to read using astropy.table.Table.read().

xy_unitastropy.units.Unit

Unit of x, y coordinates.

hdusdict

Dictionary of name, hdu mappings where each hdu is specified by its integer offset or its name.

Returns:
dict

Dictionary of 2D linear interpolators corresponding to each hdu, with the same keys that appear in the hdus input parameter.

load_table(parent, column_names, interpolate=True, as_dict=False)[source] [edit on github]

Load and interpolate tabular data from one or more files.

Reads a single file if parent.table.path exists, or else reads multiple files if parent.table.paths exists (and returns a dictionary). If as_dict is True, always return a dictionary using the ‘default’ key when only a single parent.table.path is present.

load_table2d(node, y_column_name, x_column_prefix)[source] [edit on github]

Read values for some quantity tabulated along 2 axes.

Parameters:
filenamestr

Name of the file to read using astropy.table.Table.read().

y_column_namestr

Name of the column containing y coordinate values.

x_column_prefixstr

Prefix for column names at different values of the x coordinate. The remainder of the column name must be interpretable by specsim.config.parse_quantity() as the x coordinate value. Values in each column correspond to data[:, x].

formatstr

A table format supported by astropy.table.Table.read().

Returns:
scipy.interpolate.RectBivariateSpline

A 2D linear interpolator in (x,y) that handles units correctly.

update()[source] [edit on github]

Update this configuration.

Updates the wavelength and abs_base_path attributes based on the current settings of the wavelength_grid and base_path nodes.