species.analysis package

Submodules

species.analysis.compare_spectra module

Module with functionalities for comparing a spectrum with a library of empirical or model spectra.

class species.analysis.compare_spectra.CompareSpectra(object_name: str, spec_name: Union[str, List[str]], spec_library: Optional[str] = None)[source]

Bases: object

Class for comparing a spectrum of an object with a library of empirical or model spectra.

Parameters:
  • object_name (str) – Object name as stored in the database with add_object() or add_companion().
  • spec_name (str, list(str)) – Name of the spectrum or list with spectrum names that are stored at the object data of object_name. The argument can be either a string or a list of strings.
  • spec_library (str, None) – DEPRECATED: Name of the spectral library (‘irtf’, ‘spex’, or ‘kesseli+2017).
Returns:

None

Return type:

NoneType

compare_model(tag: str, model: str, av_points: Union[List[float], numpy.array, None] = None, fix_logg: Optional[float] = None, scale_spec: Optional[List[str]] = None, weights: bool = True, inc_phot: Optional[List[str]] = None) → None[source]

Method for finding the best fitting spectrum from a grid of atmospheric model spectra by evaluating the goodness-of-fit statistic from Cushing et al. (2008). Currently, this method only supports model grids with only \(T_\mathrm{eff}\) and \(\log(g)\) as free parameters (e.g. BT-Settl). Please create an issue on Github if support for models with more than two parameters is required.

Parameters:
  • tag (str) – Database tag where for each spectrum from the spectral library the best-fit parameters will be stored. So when testing a range of values for av_ext and rad_vel, only the parameters that minimize the goodness-of-fit statistic will be stored.
  • model (str) – Name of the atmospheric model grid with synthetic spectra.
  • av_points (list(float), np.array, None) – List of \(A_V\) extinction values for which the goodness-of-fit statistic will be tested. The extinction is calculated with the relation from Cardelli et al. (1989).
  • fix_logg (float, None) – Fix the value of \(\log(g)\), for example if estimated from gravity-sensitive spectral features. Typically, \(\log(g)\) can not be accurately determined when comparing the spectra over a broad wavelength range.
  • scale_spec (list(str), None) – List with names of observed spectra to which a flux scaling is applied to best match the spectral templates.
  • weights (bool) – Apply a weighting based on the widths of the wavelengths bins.
  • inc_phot (list(str), None) – Filter names of the photometry to include in the comparison. Photometry points are weighted by the FWHM of the filter profile. No photometric fluxes will be used if the argument is set to None.
Returns:

None

Return type:

NoneType

spectral_type(tag: str, spec_library, wavel_range: Optional[Tuple[Optional[float], Optional[float]]] = None, sptypes: Optional[List[str]] = None, av_ext: Union[List[float], numpy.array, None] = None, rad_vel: Union[List[float], numpy.array, None] = None) → None[source]

Method for finding the best fitting empirical spectra from a selected library by evaluating the goodness-of-fit statistic from Cushing et al. (2008).

Parameters:
  • tag (str) – Database tag where for each spectrum from the spectral library the best-fit parameters will be stored. So when testing a range of values for av_ext and rad_vel, only the parameters that minimize the goodness-of-fit statistic will be stored.
  • spec_library (str) – Name of the spectral library (‘irtf’, ‘spex’, ‘kesseli+2017’, ‘bonnefoy+2014’).
  • wavel_range (tuple(float, float), None) – Wavelength range (um) that is used for the empirical comparison.
  • sptypes (list(str), None) – List with spectral types to compare with. The list should only contains types, for example sptypes=['M', 'L']. All available spectral types in the spec_library are compared with if set to None.
  • av_ext (list(float), np.array, None) – List of A_V extinctions for which the goodness-of-fit statistic is tested. The extinction is calculated with the empirical relation from Cardelli et al. (1989).
  • rad_vel (list(float), np.array, None) – List of radial velocities (km s-1) for which the goodness-of-fit statistic is tested.
Returns:

None

Return type:

NoneType

species.analysis.emission_line module

Module with functionalities for the analysis of emission lines.

class species.analysis.emission_line.EmissionLine(object_name: str, spec_name: str, lambda_rest: float, wavel_range: Optional[Tuple[float, float]] = None)[source]

Bases: object

Class for the analysis of emission lines.

Parameters:
  • object_name (str) – Object name as stored in the database with add_object() or add_companion().
  • spec_name (str) – Name of the spectrum that is stored at the object data of object_name.
  • lambda_rest (float, None) – Rest wavelength (um) of the emission line. The parameter is used for calculating the radial velocity and its uncertainty.
  • wavel_range (tuple(float, float), None) – Wavelength range (um) that is cropped from the spectrum. The full spectrum is used if the argument is set to None.
Returns:

None

Return type:

NoneType

fit_gaussian(tag: str, min_num_live_points: float = 400, bounds: Dict[str, Tuple[float, float]] = None, output: str = 'ultranest/', plot_filename: str = 'line_fit.pdf', show_status: bool = True, double_gaussian: bool = False) → None[source]

Method for fitting a Gaussian profile to an emission line and using UltraNest for sampling the posterior distributions and estimating the evidence.

Parameters:
  • tag (str) – Database tag where the posterior samples will be stored.
  • min_num_live_points (int) – Minimum number of live points (see https://johannesbuchner.github.io/UltraNest/issues.html).
  • bounds (dict(str, tuple(float, float)), None) – The boundaries that are used for the uniform priors of the 3 Gaussian parameters (gauss_amplitude, gauss_mean, and gauss_sigma). Conservative prior boundaries will be estimated from the spectrum if the argument is set to None or if any of the required parameters is missing in the bounds dictionary.
  • output (str) – Path that is used for the output files from UltraNest.
  • plot_filename (str) – Filename for the plot with the best-fit line profile.
  • show_status (bool) – Print information about the convergence.
  • double_gaussian (bool) – Set to True for fitting a double instead of a single Gaussian. In that case, the bounds dictionary may also contain 'gauss_amplitude_2', 'gauss_mean_2', and 'gauss_sigma_2' (otherwise conservative parameter boundaries are estimated from the data).
Returns:

None

Return type:

NoneType

integrate_flux(wavel_int: Tuple[float, float], interp_kind: str = 'linear', plot_filename: str = 'int_line.pdf') → numpy.float64[source]

Method for calculating the integrated line flux and error. The spectrum is first interpolated to \(R = 100000\) and then integrated across the specified wavelength range with the composite trapezoidal rule of np.trapz. The error is estimated with a Monte Carlo approach from 1000 samples.

Parameters:
  • wavel_int (tuple(float, float)) – Wavelength range (um) across which the flux will be integrated.
  • interp_kind (str) – Kind of interpolation kind for scipy.interpolate.interp1d (default: ‘linear’).
  • plot_filename (str) – Filename for the plot with the interpolated line profile.
Returns:

  • float – Integrated line flux (W m-2).
  • float – Flux error (W m-2).

subtract_continuum(poly_degree: int = 3, plot_filename: str = 'continuum.pdf', spec_filename: Optional[str] = None) → None[source]

Method for fitting the continuum with a polynomial function of the following form: \(P = \sum_{i=0}^{i=n}C_{i} * x^{i}\). The spectrum is first smoothed with a median filter and then fitted with a linear least squares algorithm.

Parameters:
  • poly_degree (int) – Degree of the polynomial series.
  • plot_filename (str) – Filename for the plots with the continuum fit and the continuum-subtracted spectrum.
  • spec_filename (str, None) – Output text file for writing the continuum-subtracted spectrum. The file will not be created if the argument is set to None.
Returns:

None

Return type:

NoneType

species.analysis.fit_model module

Module with functionalities for fitting atmospheric model spectra.

class species.analysis.fit_model.FitModel(object_name: str, model: str, bounds: Dict[str, Union[Tuple[float, float], Tuple[Optional[Tuple[float, float]], Optional[Tuple[float, float]]], List[Tuple[float, float]]]], inc_phot: Union[bool, List[str]] = True, inc_spec: Union[bool, List[str]] = True, fit_corr: Optional[List[str]] = None, weights: Optional[Dict[str, float]] = None)[source]

Bases: object

Class for fitting atmospheric model spectra to spectroscopic and/or photometric data, and using Bayesian inference (UltraNest, MultiNest, or emcee) to estimate posterior distributions and marginalized likelihoods (i.e. “evidence”).

The grid of spectra is linearly interpolated for each photometric point and spectrum while taking into account the filter profile, spectral resolution, and wavelength sampling. Therefore, when fitting spectra from a model grid, the computation time of the interpolation will depend on the wavelength range, spectral resolution, and parameter space of the spectra that are stored in the database.

Parameters:
  • object_name (str) – Object name as stored in the database with add_object() or add_companion().
  • model (str) – Atmospheric model (e.g. ‘bt-settl’, ‘exo-rem’, ‘planck’, or ‘powerlaw’).
  • bounds (dict(str, tuple(float, float)), None) –

    The boundaries that are used for the uniform priors. Fixing a parameter is possible by providing the same value as lower and upper boundary of the parameter, for example, bounds={'logg': (4., 4.).

    Atmospheric model parameters (e.g. model='bt-settl'):

    • Boundaries are provided as tuple of two floats. For example, bounds={'teff': (1000, 1500.), 'logg': (3.5, 5.), 'radius': (0.8, 1.2)}.
    • The grid boundaries are used if set to None. For example, bounds={'teff': None, 'logg': None}. The radius range is set to 0.8-1.5 Rjup if the boundary is set to None.

    Blackbody emission parameters (model='planck'):

    • Parameter boundaries have to be provided for ‘teff’ and ‘radius’.
    • For a single blackbody component, the values are provided as a tuple with two floats. For example, bounds={'teff': (1000., 2000.), 'radius': (0.8, 1.2)}.
    • For multiple blackbody component, the values are provided as a list with tuples. For example, bounds={'teff': [(1000., 1400.), (1200., 1600.)], 'radius': [(0.8, 1.5), (1.2, 2.)]}.
    • When fitting multiple blackbody components, a prior is used which restricts the temperatures and radii to decreasing and increasing values, respectively, in the order as provided in bounds.

    Power-law spectrum (model='powerlaw'):

    • Parameter boundaries have to be provided for ‘log_powerlaw_a’, ‘log_powerlaw_b’, and ‘log_powerlaw_c’. For example, bounds={'log_powerlaw_a': (-20., 0.), 'log_powerlaw_b': (-20., 5.), 'log_powerlaw_c': (-20., 5.)}.
    • The spectrum is parametrized as log10(flux) = a + b*log10(wavelength)^c, where a = log_powerlaw_a, b = log_powerlaw_b, and c = log_powerlaw_c.
    • Only implemented for fitting photometric fluxes, for example the IR fluxes of a star with disk. In that way, synthetic photometry can be calculated afterwards for a different filter. Note that this option assumes that the photometric fluxes are dominated by continuum emission while spectral lines are ignored.
    • The plot_photometry() function can be used to calculate synthetic photometry and error bars from the posterior distribution.
    • Only supported by run_ultranest and run_multinest.

    Calibration parameters:

    • For each spectrum/instrument, two optional parameters can be fitted to account for biases in the calibration: a scaling of the flux and a constant inflation of the uncertainties.
    • For example, bounds={'SPHERE': ((0.8, 1.2), (0., 1.))} if the scaling is fitted between 0.8 and 1.2, and the error is inflated (relative to the sampled model fluxes) with a value between 0 and 1.
    • The dictionary key should be equal to the database tag of the spectrum. For example, {'SPHERE': ((0.8, 1.2), (0., 1.))} if the spectrum is stored as 'SPHERE' with add_object().
    • Each of the two calibration parameters can be set to None in which case the parameter is not used. For example, bounds={'SPHERE': ((0.8, 1.2), None)}.
    • The errors of the photometric fluxes can be inflated to account for underestimated error bars. The error inflation is relative to the actual flux and is fitted separately for different filters. The keyword in the bounds dictionary should be provided in the following format: 'Paranal/NACO.Mp_error': (0., 1.). In this case, the error of the NACO Mp flux is inflated up to 100 percent of the actual flux.
    • No calibration parameters are fitted if the spectrum name is not included in bounds.

    ISM extinction parameters:

    • There are three approaches for fitting extinction. The first is with the empirical relation from Cardelli et al. (1989) for ISM extinction.
    • The extinction is parametrized by the V band extinction, A_V (ism_ext), and optionally the reddening, R_V (ism_red). If ism_red is not provided, its value is fixed to 3.1 and not fitted.
    • The prior boundaries of ism_ext and ext_red should be provided in the bounds dictionary, for example bounds={'ism_ext': (0., 10.), 'ism_red': (0., 20.)}.
    • Only supported by run_ultranest and run_multinest.

    Log-normal size distribution:

    • The second approach is fitting the extinction of a log-normal size distribution of grains with a crystalline MgSiO3 composition, and a homogeneous, spherical structure.
    • The size distribution is parameterized with a mean geometric radius (lognorm_radius in um) and a geometric standard deviation (lognorm_sigma, dimensionless). The grid of cross sections has been calculated for mean geometric radii between 0.001 and 10 um, and geometric standard deviations between 1.1 and 10.
    • The extinction (lognorm_ext) is fitted in the V band (A_V in mag) and the wavelength-dependent extinction cross sections are interpolated from a pre-tabulated grid.
    • The prior boundaries of lognorm_radius, lognorm_sigma, and lognorm_ext should be provided in the bounds dictionary, for example bounds={'lognorm_radius': (0.001, 10.), 'lognorm_sigma': (1.1, 10.), 'lognorm_ext': (0., 5.)}.
    • A uniform prior is used for lognorm_sigma and lognorm_ext, and a log-uniform prior for lognorm_radius.
    • Only supported by run_ultranest and run_multinest.

    Power-law size distribution:

    • The third approach is fitting the extinction of a power-law size distribution of grains, again with a crystalline MgSiO3 composition, and a homogeneous, spherical structure.
    • The size distribution is parameterized with a maximum radius (powerlaw_max in um) and a power-law exponent (powerlaw_exp, dimensionless). The minimum radius is fixed to 1 nm. The grid of cross sections has been calculated for maximum radii between 0.01 and 100 um, and power-law exponents between -10 and 10.
    • The extinction (powerlaw_ext) is fitted in the V band (A_V in mag) and the wavelength-dependent extinction cross sections are interpolated from a pre-tabulated grid.
    • The prior boundaries of powerlaw_max, powerlaw_exp, and powerlaw_ext should be provided in the bounds dictionary, for example {'powerlaw_max': (0.01, 100.), 'powerlaw_exp': (-10., 10.), 'powerlaw_ext': (0., 5.)}.
    • A uniform prior is used for powerlaw_exp and powerlaw_ext, and a log-uniform prior for powerlaw_max.
    • Only supported by run_ultranest and run_multinest.

    Blackbody disk emission:

    • Additional blackbody emission can be added to the atmospheric spectrum to account for thermal emission from a disk.
    • Parameter boundaries have to be provided for ‘disk_teff’ and ‘disk_radius’. For example, bounds={'teff': (2000., 3000.), 'radius': (1., 5.), 'logg': (3.5, 4.5), 'disk_teff': (100., 2000.), 'disk_radius': (1., 100.)}.
    • Only supported by run_ultranest and run_multinest.
  • inc_phot (bool, list(str)) – Include photometric data in the fit. If a boolean, either all (True) or none (False) of the data are selected. If a list, a subset of filter names (as stored in the database) can be provided.
  • inc_spec (bool, list(str)) – Include spectroscopic data in the fit. If a boolean, either all (True) or none (False) of the data are selected. If a list, a subset of spectrum names (as stored in the database with add_object()) can be provided.
  • fit_corr (list(str), None) – List with spectrum names for which the correlation length and fractional amplitude are fitted (see Wang et al. 2020).
  • weights (dict(str, float), None) – Weights to be applied to the log-likelihood components of the different spectroscopic and photometric data that are provided with inc_spec and inc_phot. This parameter can for example be used to bias the weighting of the photometric data points. An equal weighting is applied if the argument is set to None. Only supported by run_ultranest and run_multinest.
Returns:

None

Return type:

NoneType

lnlike_func(params, prior: Optional[Dict[str, Tuple[float, float]]] = None) → numpy.float64[source]

Function for calculating the log-likelihood for the sampled parameter cube.

Parameters:
  • params (np.ndarray, pymultinest.run.LP_c_double) – Cube with physical parameters.
  • prior (dict(str, tuple(float, float)), None) – Dictionary with Gaussian priors for one or multiple parameters. The prior can be set for any of the atmosphere or calibration parameters, e.g. prior={'teff': (1200., 100.)}. Additionally, a prior can be set for the mass, e.g. prior={'mass': (13., 3.)} for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. The parameter is not used if set to None.
Returns:

Log-likelihood.

Return type:

float

run_mcmc(tag: str, guess: Optional[Dict[str, Union[float, None, List[Optional[float]], Tuple[Optional[float], Optional[float]]]]], nwalkers: int = 200, nsteps: int = 1000, prior: Optional[Dict[str, Tuple[float, float]]] = None) → None[source]

Function to run the MCMC sampler of emcee. The functionalities of run_mcmc are more limited than run_ultranest() and run_multinest(). Furthermore, run_ultranest run_multinest provide more robust results when sampling multimodal posterior distributions and have the additional advantage of returning the marginal likelihood (i.e. “evidence”). Therefore, it is recommended to use run_ultranest or run_multinest instead of run_mcmc.

Parameters:
  • tag (str) – Database tag where the samples will be stored.
  • guess (dict, None) – Guess for each parameter to initialize the walkers. Random values between the bounds are used is set to None.
  • nwalkers (int) – Number of walkers.
  • nsteps (int) – Number of steps per walker.
  • prior (dict(str, tuple(float, float)), None) – Dictionary with Gaussian priors for one or multiple parameters. The prior can be set for any of the atmosphere or calibration parameters, e.g. prior={'teff': (1200., 100.)}. Additionally, a prior can be set for the mass, e.g. prior={'mass': (13., 3.)} for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. The parameter is not used if set to None.
Returns:

None

Return type:

NoneType

run_multinest(tag: str, n_live_points: int = 1000, output: str = 'multinest/', prior: Optional[Dict[str, Tuple[float, float]]] = None) → None[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.
  • prior (dict(str, tuple(float, float)), None) – Dictionary with Gaussian priors for one or multiple parameters. The prior can be set for any of the atmosphere or calibration parameters, e.g. prior={'teff': (1200., 100.)}. Additionally, a prior can be set for the mass, e.g. prior={'mass': (13., 3.)} for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. The parameter is not used if set to None.
Returns:

None

Return type:

NoneType

run_ultranest(tag: str, min_num_live_points=400, output: str = 'ultranest/', prior: Optional[Dict[str, Tuple[float, float]]] = None) → None[source]

Function to run UltraNest for constructing the posterior probability distributions on model parameters and computing the marginal likelihood (i.e. “evidence”).

Parameters:
  • tag (str) – Database tag where the samples will be stored.
  • min_num_live_points (int) – Minimum number of live points. The default of 400 is a reasonable number (see https://johannesbuchner.github.io/UltraNest/issues.html). In principle, choosing a very low number allows nested sampling to make very few iterations and go to the peak quickly. However, the space will be poorly sampled, giving a large region and thus low efficiency, and potentially not seeing interesting modes. Therefore, a value above 100 is typically useful.
  • output (str) – Path that is used for the output files from UltraNest.
  • prior (dict(str, tuple(float, float)), None) – Dictionary with Gaussian priors for one or multiple parameters. The prior can be set for any of the atmosphere or calibration parameters, e.g. prior={'teff': (1200., 100.)}. Additionally, a prior can be set for the mass, e.g. prior={'mass': (13., 3.)} for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. The parameter is not used if set to None.
Returns:

None

Return type:

NoneType

species.analysis.fit_model.lnlike(param: numpy.ndarray, bounds: dict, param_index: Dict[str, int], model: str, objphot: List[Optional[numpy.ndarray]], distance: Tuple[float, float], spectrum: Optional[dict], modelphot: Union[List[species.read.read_model.ReadModel], List[species.analysis.photometry.SyntheticPhotometry], None], modelspec: Optional[List[species.read.read_model.ReadModel]], n_planck: int, fit_corr: List[str])[source]

Internal function for calculating the log likelihood.

Parameters:
  • param (np.ndarray) – Parameter values.
  • bounds (dict) – Dictionary with the parameter boundaries.
  • param_index (dict(str, int)) – Dictionary with the parameter indices of param.
  • model (str) – Atmosphere model (e.g. ‘bt-settl’, ‘exo-rem’, or ‘planck).
  • objphot (list(np.ndarray, )) – List with the photometric fluxes and uncertainties of the object. Not photometric data is fitted if an empty list is provided.
  • distance (tuple(float, float)) – Distance and uncertainty (pc).
  • spectrum (dict(str, tuple(np.ndarray, np.ndarray, np.ndarray, float)), None) – Dictionary with the spectra stored as wavelength (um), flux (W m-2 um-1), and error (W m-2 um-1). Optionally the covariance matrix, the inverse of the covariance matrix, and the spectral resolution are included. Each of these three elements can be set to None. No spectroscopic data is fitted if spectrum=None.
  • modelphot (list(species.read.read_model.ReadModel, ),) – list(species.analysis.photometry.SyntheticPhotometry, ), None List with the interpolated synthetic fluxes or list with the SyntheticPhotometry objects for calculation of synthetic photometry for Planck spectra. No photometry is fitted if set to None.
  • modelspec (list(species.read.read_model.ReadModel, ), None) – List with the interpolated synthetic spectra.
  • n_planck (int) – Number of Planck components. The argument is set to zero if model is not 'planck'.
  • fit_corr (list(str)) – List with spectrum names for which the correlation length and fractional amplitude are fitted (see Wang et al. 2020).
Returns:

Log likelihood.

Return type:

float

species.analysis.fit_model.lnprior(param: numpy.ndarray, bounds: dict, param_index: Dict[str, int], prior: Optional[Dict[str, Tuple[float, float]]] = None)[source]

Internal function for calculating the log prior.

Parameters:
  • param (np.ndarray) – Parameter values.
  • bounds (dict) – Dictionary with the parameter boundaries.
  • param_index (dict(str, int)) – Dictionary with the parameter indices of param.
  • prior (dict(str, tuple(float, float)), None) – Dictionary with Gaussian priors for one or multiple parameters. The prior can be set for any of the atmosphere or calibration parameters, e.g. prior={'teff': (1200., 100.)}. Additionally, a prior can be set for the mass, e.g. prior={'mass': (13., 3.)} for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. The parameter is not used if set to None.
Returns:

Log prior.

Return type:

floats

species.analysis.fit_model.lnprob(param: numpy.ndarray, bounds: dict, model: str, param_index: Dict[str, int], objphot: List[Optional[numpy.ndarray]], distance: Tuple[float, float], prior: Optional[Dict[str, Tuple[float, float]]], spectrum: Optional[dict], modelphot: Union[List[species.read.read_model.ReadModel], List[species.analysis.photometry.SyntheticPhotometry], None], modelspec: Optional[List[species.read.read_model.ReadModel]], n_planck: int, fit_corr: List[str]) → numpy.float64[source]

Internal function for calculating the log posterior.

Parameters:
  • param (np.ndarray) – Parameter values.
  • bounds (dict) – Parameter boundaries.
  • model (str) – Atmosphere model (e.g. ‘bt-settl’, ‘exo-rem’, or ‘planck).
  • param_index (dict(str, int)) – Dictionary with the parameter indices of param.
  • objphot (list(np.ndarray, ), None) – List with the photometric fluxes and uncertainties. No photometric data is fitted if the parameter is set to None.
  • distance (tuple(float, float)) – Distance and uncertainty (pc).
  • prior (dict(str, tuple(float, float)), None) – Dictionary with Gaussian priors for one or multiple parameters. The prior can be set for any of the atmosphere or calibration parameters, e.g. prior={'teff': (1200., 100.)}. Additionally, a prior can be set for the mass, e.g. prior={'mass': (13., 3.)} for an expected mass of 13 Mjup with an uncertainty of 3 Mjup. The parameter is not used if set to None.
  • spectrum (dict(str, tuple(np.ndarray, np.ndarray, np.ndarray, float)), None) – Dictionary with the spectra stored as wavelength (um), flux (W m-2 um-1), and error (W m-2 um-1). Optionally the covariance matrix, the inverse of the covariance matrix, and the spectral resolution are included. Each of these three elements can be set to None. No spectroscopic data is fitted if spectrum=None.
  • modelphot (list(species.read.read_model.ReadModel, ),) – list(species.analysis.photometry.SyntheticPhotometry, ), None List with the interpolated synthetic fluxes or list with the SyntheticPhotometry objects for calculation of synthetic photometry for Planck spectra. No photometry is fitted if set to None.
  • modelspec (list(species.read.read_model.ReadModel, ), None) – List with the interpolated synthetic spectra. The parameter is set to None when no spectroscopic data is included or when model='planck'.
  • n_planck (int) – Number of Planck components. The argument is set to zero if model is not 'planck'.
  • fit_corr (list(str)) – List with spectrum names for which the correlation amplitude and length are fitted.
Returns:

Log posterior.

Return type:

float

species.analysis.fit_spectrum module

Module with functionalities for photometric and spectroscopic calibration. The fitting routine can be used to fit photometric data with a calibration spectrum (e.g. extracted with get_model()) by simply fitting a scaling parameter.

class species.analysis.fit_spectrum.FitSpectrum(object_name: str, filters: Optional[List[str]], spectrum: str, bounds: Dict[str, Tuple[float, float]])[source]

Bases: object

Class for fitting a calibration spectrum to photometric data.

Parameters:
  • object_name (str) – Object name in the database.
  • filters (list(str)) – Filter names for which the photometry is selected. All available photometry of the object is selected if set to None.
  • spectrum (str) – Calibration spectrum as labelled in the database. The calibration spectrum can be stored in the database with add_calibration().
  • bounds (dict) – Boundaries of the scaling parameter, as {'scaling':(min, max)}.
Returns:

None

Return type:

NoneType

run_mcmc(nwalkers: int, nsteps: int, guess: Union[Dict[str, float], Dict[str, None]], tag: str) → None[source]

Function to run the MCMC sampler.

Parameters:
  • nwalkers (int) – Number of walkers.
  • nsteps (int) – Number of steps per walker.
  • guess (dict(str, float), dict(str, None)) – Guess of the scaling parameter.
  • tag (str) – Database tag where the MCMC samples will be stored.
Returns:

None

Return type:

NoneType

species.analysis.fit_spectrum.lnprob(param: numpy.ndarray, bounds: Dict[str, Tuple[float, float]], modelpar: List[str], objphot: List[numpy.ndarray], specphot: Union[List[float], List[Tuple[species.analysis.photometry.SyntheticPhotometry, Tuple[numpy.float64, numpy.float64]]]]) → float[source]

Internal function for calculating the posterior probability.

Parameters:
  • param (np.ndarray) – Value of the scaling parameter.
  • 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), photometry.SyntheticPhotometry) – Synthetic photometry of the calibration spectrum for the same filters as the photometry of the object.
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: str)[source]

Bases: object

Class for calculating synthetic photometry from a spectrum and also for conversion between magnitudes and fluxes. Note that depending on the detector type (energy- or photon-counting) the integral for the filter-weighted flux contains an additional wavelength factor.

Parameters:filter_name (str) – Filter name as listed in the database. Filters from the SVO Filter Profile Service are automatically downloaded and added to the database.
Returns:None
Return type:NoneType
flux_to_magnitude(flux: float, error: Union[float, numpy.ndarray, None] = None, distance: Union[Tuple[float, Optional[float]], Tuple[numpy.ndarray, Optional[numpy.ndarray]], None] = None) → Tuple[Union[Tuple[float, Optional[float]], Tuple[numpy.ndarray, Optional[numpy.ndarray]]], Union[Tuple[float, Optional[float]], Tuple[numpy.ndarray, Optional[numpy.ndarray]]]][source]

Function for converting a flux into a magnitude.

Parameters:
  • flux (float, np.ndarray) – Flux (W m-2 um-1).
  • error (float, np.ndarray, None) – Uncertainty (W m-2 um-1). Not used if set to None.
  • distance (tuple(float, float), tuple(np.ndarray, np.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(np.ndarray, np.ndarray) – Apparent magnitude and uncertainty.
  • tuple(float, float), tuple(np.ndarray, np.ndarray) – Absolute magnitude and uncertainty.

magnitude_to_flux(magnitude: float, error: Optional[float] = None, zp_flux: Optional[float] = None) → Tuple[numpy.float64, numpy.float64][source]

Function for converting a magnitude to a flux.

Parameters:
  • magnitude (float) – Magnitude.
  • error (float, None) – Error on the magnitude. Not used if set to None.
  • zp_flux (float, None) – 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: numpy.ndarray, flux: numpy.ndarray, error: Optional[numpy.ndarray] = None, threshold: Optional[float] = 0.05) → Tuple[Union[numpy.float32, numpy.float64], Union[numpy.float32, None, numpy.float64]][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 (np.ndarray) – Wavelength points (um).
  • flux (np.ndarray) – Flux (W m-2 um-1).
  • error (np.ndarray, None) – 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: numpy.ndarray, flux: numpy.ndarray, error: Union[numpy.ndarray, List[numpy.ndarray], None] = None, distance: Optional[Tuple[float, Optional[float]]] = None, threshold: Optional[float] = 0.05) → Tuple[Tuple[float, Optional[float]], Optional[Tuple[Optional[float], Optional[float]]]][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 (np.ndarray) – Wavelength points (um).
  • flux (np.ndarray) – Flux (W m-2 um-1).
  • error (np.ndarray, list(np.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.
  • tuple(float, float) – Absolute magnitude and uncertainty.

zero_point() → numpy.float64[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