phot_class.utils

A collection of general utilities used across the parent package.

phot_class.utils.calc_model_chisq(data, result, model)[source]

Calculate the chi-squared for a given data table and model

Chi-squareds are calculated using parameter values from model. Degrees of freedom are calculated using the number of varied parameters specified is the result object.

Parameters:
  • data (Table) – An sncosmo input table
  • model (Model) – An sncosmo Model
  • result (Result) – sncosmo fitting result
Returns:

The un-normalized chi-squared The number of data points used in the calculation

phot_class.utils.classification_filter_factory(classifications, ftype='exclude')[source]
Returns function to determine whether data should be skipped/kept in an
iterator based on its classification

The function returned by this factory has signature returned_function(table: astropy.Table) -> boolean. The boolean indicates whether the data should kept (i.e. not skipped). The class of each object is determined from table.meta['classification']. If there is no ‘classification’ key in the meta data, the return is True.

Parameters:
  • classifications (list[str]) – A list of classifications to allow
  • ftype (str) – ‘exclude’ or ‘include’ the given classes
Returns:

A filter function for sndata

phot_class.utils.parse_config_dict(obj_id, config_dict)[source]

Return the priors and kwargs for a given object from a config file

Parameters:
  • obj_id (str) – The object id in the dictionary
  • config_dict (dict) – A dictionary with data from a config file
Returns:

  • A dictionary with object priors for the hsiao_x1 model
  • A dictionary of fitting kwargs for the hsiao_x1 model
  • A dictionary with object priors for the sn91bg model
  • A dictionary of fitting kwargs for the sn91bg model

phot_class.utils.split_bands(bands, lambda_eff, redshift=0)[source]

Split band-passes into collections of blue and red bands

Blue bands have an rest frame effective wavelength < 5500 Ang. Red bands have a rest frame effective wavelength >= 5500 Ang.

Parameters:
  • bands (array[str]) – Name of band-passes
  • lambda_eff (array[float]) – Effective wavelength of band-passes
  • redshift (float) – The redshift of the rest frame
Returns:

An array of blue filter names An array of red filter names

phot_class.utils.split_data(data_table, band_names, lambda_eff, z, cutoff=700)[source]

Split a data table into blue and red data (by rest frame)

Wavelengths are expected to be in angstroms. Split data by keeping filters that are red-ward or blue-ward of 5500 Ang. If the closest rest frame filter for an observation is more than cutoff angstroms away, drop the observation.

Parameters:
  • data_table (Table) – An SNCosmo input table with column ‘band’
  • band_names (iter) – List of all bands available in the survey
  • lambda_eff (iter) – The effective wavelength of each band in band_names
  • z (float) – The redshift of the observed target
  • cutoff (float) – The cutoff distance for dropping an observation
Returns:

A SNCosmo input table with only blue bands A SNCosmo input table with only red bands

class phot_class.utils.timeout(seconds=1, error_message='Timeout')[source]

A timeout context manager