species.analysis package

Submodules

species.analysis.fit_model module

Module with functionalities for fitting atmospheric model spectra.

class species.analysis.fit_model.FitModel(object_name, filters, model, bounds=None, inc_phot=True, inc_spec=True)[source]

Bases: object

Class for fitting atmospheric model spectra to photometric and/or spectroscopic data.

For each photometric point and spectrum, the model grid is linearly interpolated at the required synthetic photometry and wavelength sampling before running the MCMC. Therefore, the computation time of this initial interpolation depends on the wavelength range and spectral resolution of the spectra that are stored in the database, and the prior boundaries that are chosen with bounds.

Parameters:
  • object_name (str) – Object name in the database as created with add_object() or add_companion().
  • filters (tuple(str, )) – Filter names for which the photometry is selected. All available photometry of the object is selected if set to None.
  • model (str) – Atmospheric model (e.g. ‘drift-phoenix’, ‘petitcode-cool-cloudy’, or ‘bt-settl’).
  • bounds (dict, None) – Parameter boundaries. The full range is used for each parameter if set to None. In that case, the radius range is set to 0.8-1.5 Rjup. It is also possible to specify the bounds for a subset of the parameters, for example, {'radius': (0.5, 10.)}. Restricting the boundaries will decrease the computation time with the interpolation prior to the MCMC sampling. An additional scaling parameter can be fitted for each spectrum in which case, the boundaries have to be provided with the database tag of the spectrum. For example, {'sphere_ifs': (0.5, 2.)} if the spectrum is stored as sphere_ifs with add_object().
  • inc_phot (bool) – Include photometric data in the fit.
  • inc_spec (bool) – Include spectroscopic data in the fit.
Returns:

None

Return type:

NoneType

run_mcmc(tag, guess, nwalkers=200, nsteps=1000, prior=None)[source]

Function to run the MCMC sampler of emcee.

Parameters:
  • tag (str) – Database tag where the samples will be stored.
  • guess (dict, None) – Guess for the parameter values. Random values between the boundary values are used if set to None.
  • nwalkers (int) – Number of walkers.
  • nsteps (int) – Number of steps per walker.
  • prior (tuple(str, float, float), None) – Gaussian prior on one of the parameters. Currently only possible for the mass, e.g. (‘mass’, 13., 3.) for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. Not used if set to None.
Returns:

None

Return type:

NoneType

run_multinest(tag, n_live_points=4000, output='multinest/')[source]

Function to run the PyMultiNest wrapper of the MultiNest sampler. While PyMultiNest can be installed with pip from the PyPI repository, MultiNest has to to be build manually. See the PyMultiNest documentation for details: http://johannesbuchner.github.io/PyMultiNest/install.html. Note that the library path of MultiNest should be set to the environmental variable LD_LIBRARY_PATH on a Linux machine and DYLD_LIBRARY_PATH on a Mac. Alternatively, the variable can be set before importing the species package, for example:

>>> import os
>>> os.environ['DYLD_LIBRARY_PATH'] = '/path/to/MultiNest/lib'
>>> import species
Parameters:
  • tag (str) – Database tag where the samples will be stored.
  • n_live_points (int) – Number of live points.
  • output (str) – Path that is used for the output files from MultiNest.
Returns:

None

Return type:

NoneType

species.analysis.fit_model.lnlike(param, modelpar, objphot, distance, spectrum, modelphot, modelspec)[source]

Internal function for the likelihood function.

Parameters:
  • param (numpy.ndarray) – Parameter values.
  • modelpar (list(str, )) – Parameter names.
  • objphot (list(tuple(float, float), )) – List with the fluxes and uncertainties of the object.
  • distance (tuple(float, float)) – Distance and uncertainty (pc).
  • spectrum (dict) – Dictionary with the spectrum stored as wavelength (um), flux (W m-2 um-1), and error (W m-2 um-1), and optionally the covariance matrix and the inverse of the covariance matrix.
  • modelphot (list(species.read.read_model.ReadModel, )) – List with the interpolated synthetic photometry.
  • modelspec (list(species.read.read_model.ReadModel, )) – List with the interpolated synthetic spectra.
Returns:

Log likelihood probability.

Return type:

float

species.analysis.fit_model.lnprior(param, bounds, modelpar, prior=None)[source]

Internal function for the prior probability.

Parameters:
  • param (numpy.ndarray) – Parameter values.
  • bounds (dict) – Parameter boundaries.
  • modelpar (list(str, )) – Parameter names.
  • prior (tuple(str, float, float), None) – Gaussian prior on one of the parameters. Currently only possible for the mass, e.g. (‘mass’, 13., 3.) for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. Not used if set to None.
Returns:

Log prior probability.

Return type:

float

species.analysis.fit_model.lnprob(param, bounds, modelpar, objphot, distance, prior, spectrum, modelphot, modelspec)[source]

Internal function for the posterior probability.

Parameters:
  • param (numpy.ndarray) – Parameter values.
  • bounds (dict) – Parameter boundaries.
  • modelpar (list(str, )) – Parameter names.
  • objphot (list(tuple(float, float), )) – List with the fluxes and uncertainties of the object.
  • distance (tuple(float, float)) – Distance and uncertainty (pc).
  • prior (tuple(str, float, float)) – Gaussian prior on one of the parameters. Currently only possible for the mass, e.g. (‘mass’, 13., 3.) for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. Not used if set to None.
  • spectrum (dict) – Wavelength (um), apparent flux (W m-2 um-1), and flux error (W m-2 um-1).
  • modelphot (list(species.read.read_model.ReadModel, )) – List with the interpolated synthetic fluxes.
  • modelspec (list(species.read.read_model.ReadModel, )) – List with the interpolated synthetic spectra.
Returns:

Log posterior probability.

Return type:

float

species.analysis.fit_planck module

Module with functionalities for fitting a Planck spectrum.

class species.analysis.fit_planck.FitPlanck(object_name, filters, bounds, inc_phot=True, inc_spec=True)[source]

Bases: object

Class for fitting Planck spectra to photometric and/or spectroscopic data.

Parameters:
  • object_name (str) – Object name in the database.
  • filters (tuple(str, )) – Filter names for which the photometry is selected. All available photometric data of the object are used if set to None.
  • bounds (dict) – Parameter boundaries for ‘teff’ and ‘radius’. The values should be provided either as float or as list of floats such that multiple Planck functions can be combined, e.g. {'teff': [(1000., 2000.), (500., 1500.)], 'radius': [(0.5, 1.5), (1.5, 2.0)]}.
  • inc_phot (bool) – Include photometric data with the fit.
  • inc_spec (bool) – Include spectroscopic data with the fit.
Returns:

None

Return type:

NoneType

run_mcmc(nwalkers, nsteps, guess, tag)[source]

Function to run the MCMC sampler.

Parameters:
  • nwalkers (int) – Number of walkers.
  • nsteps (int) – Number of steps per walker.
  • guess (dict, None) – Guess for the ‘teff’ and ‘radius’. Random values between the boundary values are used if a value is set to None. The values should be provided either as float or in a list of floats such that multiple Planck functions can be combined, e.g. {'teff': [1500., 1000.], 'radius': [1., 2.].
  • tag (str) – Database tag where the MCMC samples are stored.
Returns:

None

Return type:

NoneType

species.analysis.fit_planck.lnlike(param, bounds, objphot, synphot, distance, spectrum)[source]

Internal function for the likelihood function.

Parameters:
  • param (numpy.ndarray) – Parameter values.
  • bounds (dict) – Parameter boundaries for ‘teff’ and ‘radius’. The values should be provided in a list such that multiple Planck functions can be combined, e.g. {'teff': [(1000., 2000.), (500., 1500.)], 'radius': [(0.5, 1.5), (1.5, 2.0)]}.
  • objphot (list(tuple(float, float), )) – List with the photometric fluxes and uncertainties.
  • synphot (list(species.analysis.photometry.SyntheticPhotometry, )) – List with the SyntheticPhotometry objects for calculation of synthetic photometry from the model spectra.
  • distance (float) – Distance (pc).
  • spectrum (numpy.ndarray, None) – Spectrum array with the wavelength (um), flux (W m-2 um-1), and error (W m-2 um-1). Not used if set to None.
Returns:

Log likelihood probability.

Return type:

float

species.analysis.fit_planck.lnprior(param, bounds)[source]

Internal function for the prior probability.

Parameters:
  • param (numpy.ndarray) – Parameter values.
  • bounds (dict) – Parameter boundaries for ‘teff’ and ‘radius’. The values should be provided in a list such that multiple Planck functions can be combined, e.g. {'teff': [(1000., 2000.), (500., 1500.)], 'radius': [(0.5, 1.5), (1.5, 2.0)]}.
Returns:

Log prior probability.

Return type:

float

species.analysis.fit_planck.lnprob(param, bounds, objphot, synphot, distance, spectrum)[source]

Internal function for the posterior probability.

Parameters:
  • param (numpy.ndarray) – Parameter values.
  • bounds (dict) – Parameter boundaries for ‘teff’ and ‘radius’. The values should be provided in a list such that multiple Planck functions can be combined, e.g. {'teff': [(1000., 2000.), (500., 1500.)], 'radius': [(0.5, 1.5), (1.5, 2.0)]}.
  • objphot (list(tuple(float, float), )) – List with the photometric fluxes and uncertainties.
  • synphot (list(species.analysis.photometry.SyntheticPhotometry, )) – List with the SyntheticPhotometry objects for calculation of synthetic photometry from the model spectra.
  • distance (float) – Distance (pc).
  • spectrum (numpy.ndarray, None) – Spectrum array with the wavelength (um), flux (W m-2 um-1), and error (W m-2 um-1). Not used if set to None.
Returns:

Log posterior probability.

Return type:

float

species.analysis.fit_spectrum module

Module with functionalities for fitting a calibration spectrum.

class species.analysis.fit_spectrum.FitSpectrum(object_name, filters, spectrum, bounds)[source]

Bases: object

Class for fitting a calibration spectrum to photometric data.

Parameters:
  • object_name (str) – Object name in the database.
  • filters (tuple(str, )) – Filter IDs for which the photometry is selected. All available photometry of the object is selected if set to None.
  • spectrum (str) – Calibration spectrum.
  • bounds (dict) – Boundaries of the scaling parameter, as {‘scaling’:(min, max)}.
Returns:

Return type:

None

run_mcmc(nwalkers, nsteps, guess, tag, bands=False)[source]

Function to run the MCMC sampler.

Parameters:
  • nwalkers (int) – Number of walkers.
  • nsteps (int) – Number of steps per walker.
  • guess (dict) – Guess of the scaling parameter.
  • tag (str) – Database tag where the MCMC samples are stored.
  • bands (bool) – Use band-dependent scaling parameters in addition to the main scaling parameter which is used for the full spectrum.
Returns:

Return type:

None

species.analysis.fit_spectrum.lnprob(param, bounds, modelpar, objphot, specphot, bands)[source]

Internal function for the posterior probability.

Parameters:
  • param (numpy.ndarray) – Values of the main scaling parameter and optionally additional band-dependent scaling parameters.
  • bounds (dict) – Boundaries of the main scaling parameter.
  • modelpar (list(str, )) – Parameter names.
  • objphot (list(tuple(float, float), )) – Photometry of the object.
  • specphot (list(float, )) – Synthetic photometry of the calibration spectrum for the same filters as the photometry of the object.
  • bands (bool) – Use band-dependent scaling parameters in addition to the main scaling parameter which is used for the full spectrum.
Returns:

Log posterior probability.

Return type:

float

species.analysis.photometry module

Module with functionalities for calculating synthetic photometry.

class species.analysis.photometry.SyntheticPhotometry(filter_name)[source]

Bases: object

Class for calculating synthetic photometry from a spectrum.

Parameters:filter_name (str) – Filter ID as listed in the database. Filters from the SVO Filter Profile Service are downloaded and added to the database.
Returns:None
Return type:NoneType
flux_to_magnitude(flux, error=None, distance=None)[source]

Function for converting a flux into a magnitude.

Parameters:
  • flux (float, numpy.ndarray) – Flux (W m-2 um-1).
  • error (float, numpy.ndarray, None) – Uncertainty (W m-2 um-1). Not used if set to None.
  • distance (tuple(float, float), tuple(numpy.ndarray, numpy.ndarray)) – Distance and uncertainty (pc). The returned absolute magnitude is set to None in case distance is set to None. The error is not propagated into the error on the absolute magnitude in case the distance uncertainty is set to None, for example distance=(20., None)
Returns:

  • tuple(float, float), tuple(numpy.ndarray, numpy.ndarray) – Apparent magnitude and uncertainty (mag).
  • tuple(float, float), tuple(numpy.ndarray, numpy.ndarray) – Absolute magnitude and uncertainty (mag).

magnitude_to_flux(magnitude, error=None, zp_flux=None)[source]

Function for converting a magnitude to a flux.

Parameters:
  • magnitude (float) – Magnitude (mag).
  • error (float, None) – Error (mag). Not used if set to None.
  • zp_flux (float) – Zero-point flux (W m-2 um-1). The value is calculated if set to None.
Returns:

  • float – Flux (W m-2 um-1).
  • float – Error (W m-2 um-1).

spectrum_to_flux(wavelength, flux, error=None, threshold=0.05)[source]

Function for calculating the average flux from a spectrum and a filter profile. The error is propagated by sampling 200 random values from the error distributions.

Parameters:
  • wavelength (numpy.ndarray) – Wavelength points (um).
  • flux (numpy.ndarray) – Flux (W m-2 um-1).
  • error (numpy.ndarray) – Uncertainty (W m-2 um-1). Not used if set to None.
  • threshold (float, None) – Transmission threshold (value between 0 and 1). If the minimum transmission value is larger than the threshold, a NaN is returned. This will happen if the input spectrum does not cover the full wavelength range of the filter profile. Not used if set to None.
Returns:

  • float – Average flux (W m-2 um-1).
  • float, None – Uncertainty (W m-2 um-1).

spectrum_to_magnitude(wavelength, flux, error=None, distance=None, threshold=0.05)[source]

Function for calculating the apparent and absolute magnitude from a spectrum and a filter profile. The error is propagated by sampling 200 random values from the error distributions.

Parameters:
  • wavelength (numpy.ndarray) – Wavelength points (um).
  • flux (numpy.ndarray) – Flux (W m-2 um-1).
  • error (numpy.ndarray, list(numpy.ndarray), None) – Uncertainty (W m-2 um-1).
  • distance (tuple(float, float), None) – Distance and uncertainty (pc). No absolute magnitude is calculated if set to None. No error on the absolute magnitude is calculated if the uncertainty is set to None.
  • threshold (float, None) – Transmission threshold (value between 0 and 1). If the minimum transmission value is larger than the threshold, a NaN is returned. This will happen if the input spectrum does not cover the full wavelength range of the filter profile. Not used if set to None.
Returns:

  • tuple(float, float) – Apparent magnitude and uncertainty (mag).
  • tuple(float, float) – Absolute magnitude and uncertainty (mag).

zero_point()[source]

Internal function for calculating the zero point of the provided filter_name.

Returns:Zero-point flux (W m-2 um-1).
Return type:float

Module contents