mangadap.par.parset module

Define a utility base class used to hold parameters.

License:
Copyright (c) 2015, SDSS-IV/MaNGA Pipeline Group
Licensed under BSD 3-clause license - see LICENSE.rst
Class usage examples:
to be added

Todo

  • Add range and length parameters allowing one to define the range allowed for the parameter values and number of elements required (if the parameter is an array)
  • Allow for a from_par_file classmethod to initialize the parameter set based on a yanny parameter file.
  • Save the defaults and allow for a revert_to_default function.
  • Write an __add__ function that will all you to add multiple parameter sets.
Revision history:
16 Jun 2015: Original implementation by K. Westfall (KBW)
18 Mar 2016: (KBW) Change dtype checking
23 Mar 2016: (KBW) Changed initialization type checking of lists to use isinstance.
02 Apr 2016: (KBW) Allow input parameters to be callable functions.
05 Apr 2018: (KBW) Added to pypit repo
18 Apr 2018: (KBW) Add parameter descriptions; keep default values as attributes
19 Apr 2018: (KBW) Spruce up the __repr__ function and add the info function. Add to_config function to write to a configuration file.
class mangadap.par.parset.ParDatabase(inp)[source]

Bases: object

Class used as a list of ParSets in a glorified structured numpy array.

Very similar to yanny when converted to a numpy array.

Can be initialized using a list of ParSet objects, or an SDSS parameter file.

Todo

  • Check that the data types are the same for all ParSet objects in the list
  • Better handle the NaN values when converting None to a float type
  • Add from_par_file classmethod?
static _set_dtypes(inp, i)[source]
append(pdb)[source]
class mangadap.par.parset.ParSet(pars, values=None, defaults=None, options=None, dtypes=None, can_call=None, descr=None, cfg_section=None, cfg_comment=None)[source]

Bases: object

Generic base class to handle and manipulate a list of operational parameters. A glorified dictionary that constrains and types its components.

Parameters:
  • pars (list) – A list of keywords for a list of parameter values.
  • values (list, optional) – Initialize the parameters to these values. If not provided, all parameters are initialized to None or the provided default.
  • defaults (list, optional) – For any parameters not provided in the values list, use these default values. If not provided, no defaults are assumed.
  • options (list, optional) – Force the parameters to be one of a list of options. Each element in the list can be a list itself. If not provided, all parameters are allowed to take on any value within the allowed data type.
  • dtypes (list, optional) – Force the parameter to be one of a list of data types. Each element in the list can be a list itself. If not provided, all parameters are allowed to have any data type.
  • can_call (list, optional) – Flag that the parameters are callable operations. Default is False.
  • descr (list, optional) – A list of parameter descriptions. Empty strings by default.
  • cfg_section (str, optional) – The top-level designation for a configuration section written based on the contents of this parameter set.
  • cfg_comment (str, optional) – Comment to be placed at the top-level of the configuration section written based on the contents of this parameter set.
Raises:
  • TypeError – Raised if the input parameters are not lists or if the input keys are not strings.
  • ValueError – Raised if any of the optional arguments do not have the same length as the input list of parameter keys.
npar

Number of parameters

Type:int
data

Dictionary with the parameter values

Type:dict
default

Dictionary with the default values

Type:dict
options

Dictionary with the allowed options for the parameter values

Type:dict
dtype

Dictionary with the allowed data types for the parameters

Type:dict
can_call

Dictionary with the callable flags

Type:dict
descr

Dictionary with the description of each parameter.

Type:dict
cfg_section

The top-level designation for a configuration section written based on the contents of this parameter set.

Type:str
cfg_comment

Comment to be placed at the top-level of the configuration section written based on the contents of this parameter set.

Type:str
static _config_comment(comment, indent, full_width=72)[source]
_config_lines(section_name=None, section_comment=None, section_level=0)[source]

Recursively generate the lines of a configuration file based on this ParSet and its ParSet members.

static _data_string(data)[source]
static _data_table_string(data_table)[source]
_output_string(header=None)[source]
_types_list(key)[source]
_wrap_print(head, output, tcols)[source]
add(key, value, default=None, options=None, dtype=None, can_call=None, descr=None)[source]

Add a new parameter.

Parameters:
  • key (str) – Key for new parameter
  • value (dtype) – Parameter value, must have a type in the list provided by :arg:`dtype`, if the list is provided
  • default (dtype, optional) – Define a default value for the parameter, must have a type in the list provided by :arg:`dtype`, if the list is provided. No default if not provided.
  • options (list, optional) – List of discrete values that the parameter is allowed to have. Allowed to be anything if not provided.
  • dtype (list, optional) – List of allowed data types that the parameter can have. Allowed to be anything if not provided.
  • can_call (bool, optional) – Flag that the parameters are callable operations. Default is False.
info(basekey=None)[source]

A long-form version of __repr__ that includes the parameter descriptions.

keys()[source]
to_config(cfg_file, section_name=None, section_comment=None, section_level=0, append=False, quiet=False)[source]

Write/Append the parameter set to a configuration file.

Parameters:
  • cfg_file (str) – The name of the file to write/append to.
  • section_name (str, optional) – The top-level name for the config section. This must be provided if cfg_section is None or any of the parameters are not also ParSet instances themselves.
  • section_comment (str, optional) – The top-level comment for the config section based on this ParSet.
  • section_level (int, optional) – The top level of this ParSet. Used for recursive output of nested ParSets.
  • append (bool, optional) – Append this configuration output of this ParSet to the file. False by default. If not appending and the file exists, the file is automatically overwritten.
  • quiet (bool, optional) – Suppress all standard output from the function.
Raises:

ValueError – Raised if there are types other than ParSet in the parameter list, cfg_section is None, and no section_name argument was provided.