distroi.data.sed module#

A module to handle spectral energy distributions (SEDs).

class distroi.data.sed.SED(dictionary: dict[str, ndarray])#

Bases: object

Contains information on an SED.

Parameters:

dictionary (dict) – Dictionary containing keys and values representing several instance variables described below. Should include ‘wavelengths’, ‘flam’, and ‘flam_err’. The other required instance variables are set automatically through add_freq_vars.

wavelengths#

1D array containing the wavelengths in micron.

Type:

np.ndarray

frequencies#

1D array containing the frequencies in Hz.

Type:

np.ndarray

flam#

1D array containing the flux in F_lam format, the unit is erg s^-1 cm^-2 micron^-1.

Type:

np.ndarray

flam_err#

1D array containing the errors on flam_err (set to 0 if reading in a model SED).

Type:

np.ndarray

fnu#

1D array containing the flux in F_nu format, the unit is Jansky (Jy).

Type:

np.ndarray

fnu_err#

1D array containing the error on F_nu.

Type:

np.ndarray

bands#

Optional list of strings containing the names of the associated photometric bands. Mostly useful when reading in observed SED data tables from e.g. VizieR.

Type:

list of str or None

sources#

Similar to the ‘bands’ attribute, but listing the source catalogue.

Type:

list of str or None

add_freq_vars() None#

Calculate and set frequency-based attributes from the wavelength-based ones.

Return type:

None

get_flux(x: ndarray | float, flux_form: str = 'flam', interp_method: str = 'linear') ndarray | float#

Get the flux at specified wavelengths or frequencies.

Retrieve the flux at certain wavelengths/frequencies by interpolating the contained SED data.

Parameters:
  • x (np.ndarray or float) – Wavelengths/frequencies (in micron/Hz) at which to calculate the flux.

  • flux_form (str, optional) – The format of the flux to be calculated. Options are ‘flam’ (default) and ‘lam_flam’, as well as their frequency analogues ‘fnu’ and ‘nu_fnu’. In case flux_form = 'flam' or 'lam_flam', x is assumed to represent wavelengths, while in case of 'fnu' and 'nu_fnu', x is assumed to be frequencies.

  • interp_method (str, optional) – Interpolation method used by scipy’s interp1d method. Default is ‘linear’. Can support ‘linear’, ‘nearest’, ‘nearest-up’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘previous’, or ‘next’.

Returns:

flux – The flux calculated at x using the reference wavelength/frequency and reference flux value. In case of flux_form='flam', output will be in units erg s^-1 cm^-2 micron^-1. In case of flux_form='fnu', output will be in units Jansky. In case of flux_form='lam_flam', units will be in erg s^-1 cm^-2. In case of flux_form='nu_fnu', units will be Jy Hz.

Return type:

np.ndarray or float

Warning

This method throws an error if you try to retrieve fluxes outside the wavelength/frequency bounds.

plot(fig_dir: str | None = None, flux_form: str = 'lam_flam', log_plot: bool = True, show_plots: bool = True) None#

Make a scatter plot of the SED.

Parameters:
  • fig_dir (str, optional) – Directory to store plots in.

  • flux_form (str, optional) – Format for the flux. By default, it is set to ‘lam_flam’, meaning we represent the flux in lam*F_lam format (units erg s^-1 cm^-2). Analogously, other options are ‘flam’ (erg s^-1 cm^-2 micron^-1), ‘fnu’ (Jy) and ‘nu_fnu’ (Jy Hz).

  • log_plot (bool, optional) – Set to False if you want the plot axes to be in linear scale.

  • show_plots (bool, optional) – Set to False if you do not want the plots to be shown during your script run. Note that if True, this freezes further code execution until the plot windows are closed.

Return type:

None

redden(ebminv: float, reddening_law: str = '/home/docs/checkouts/readthedocs.org/user_builds/distroi/checkouts/latest/utils/ISM_reddening/ISMreddening_law_Cardelli1989.dat') None#

Redden the SED.

Further reddens the SED according to the appropriate E(B-V) and a corresponding reddening law.

Parameters:
  • ebminv (float) – E(B-V) reddening factor to be applied.

  • reddening_law (str, optional) – Path to the reddening law to be used. Defaults to the ISM reddening law by Cardelli (1989) in DISTROI’s ‘utils/ISM_reddening folder’. See this file for the expected formatting of your own reddening laws.

Return type:

None

distroi.data.sed.read_sed_mcfost(sed_path: str, star_only: bool = False) SED#

Retrieve SED data from an MCFOST model SED.

Parameters:
  • sed_path (str) – Path to an MCFOST output sed_rt.fits.gz model SED file.

  • star_only (bool, optional) – Set to True if you only want to read in the flux from the star.

Returns:

sedSED instance containing the information on the MCFOST model SED. Note that the errors on the flux flam_err are set to zero (since this is a model SED).

Return type:

SED

distroi.data.sed.read_sed_repo_phot(sed_path: str, wave_lims: tuple[float, float] | None = None) SED#

Retrieve SED data from a KU Leuven Insitute of Astronomy SED repository .phot file.

Retrieve observed SED data stored in a .phot file as presented in e.g. the SED catalog presented in Kluska et al. 2022 (A&A, 658 (2022) A36). Such files are stored in the local system of KU Leuven’s Institute of Astronomy.

Parameters:
  • sed_path (str) – Path to an MCFOST output sed_rt.fits.gz model SED file.

  • wave_lims (tuple of float, optional) – The lower and upper wavelength limits in micron used when reading in data.

Returns:

sedSED instance containing the information on the MCFOST model SED.

Return type:

SED

distroi.data.sed.sed_chi2reddened(sed_obs: SED, sed_mod: SED, ebminv: float, reddening_law: str = '/home/docs/checkouts/readthedocs.org/user_builds/distroi/checkouts/latest/utils/ISM_reddening/ISMreddening_law_Cardelli1989.dat') float#

Get the chi2 between a data SED and a reddened model SED.

Returns the chi2 between an RT model SED and an observed SED under a certain amount of additional reddening. Note that this doesn’t actually redden any of the SED object class instances, only calculates the chi2 assuming the model SED were to be reddened.

Parameters:
  • sed_obs (SED) – Observed SED.

  • sed_mod (SED) – RT model SED.

  • ebminv (float) – E(B-V) reddening factor to be applied.

  • reddening_law (str, optional) – Path to the reddening law to be used. Defaults to the ISM reddening law by Cardelli (1989) in DISTROI’s ‘utils/ISM_reddening folder’. See this file for the expected formatting of your own reddening laws.

Returns:

chi2 – The chi2 value between the reddened model SED and the observed SED.

Return type:

float

distroi.data.sed.sed_plot_data_vs_model(sed_dat: SED, sed_mod: SED, fig_dir: str | None = None, flux_form: str = 'lam_flam', log_plot: bool = True, show_plots: bool = True) None#

Plot an observed SED against a model SED.

Plots the data (observed) SED against the model SED.

Parameters:
  • sed_dat (SED) – Data SED. Typically corresponds to observations.

  • sed_mod (SED) – RT model SED.

  • fig_dir (str, optional) – Directory to store plots in.

  • flux_form (str, optional) – Format for the flux. By default, it is set to ‘lam_flam’, meaning we represent the flux in lam*F_lam format (units erg s^-1 cm^-2). Analogously, other options are ‘flam’ (erg s^-1 cm^-2 micron^-1), ‘fnu’ (Jy) and ‘nu_fnu’ (Jy Hz).

  • log_plot (bool, optional) – Set to False if you want the plot axes to be in linear scale.

  • show_plots (bool, optional) – Set to False if you do not want the plots to be shown during your script run. Note that if True, this freezes further code execution until the plot windows are closed.

Return type:

None

distroi.data.sed.sed_reddening_fit(sed_obs: SED, sed_mod: SED, ebminv_guess: float, redden_mod: bool = True, reddening_law: str = '/home/docs/checkouts/readthedocs.org/user_builds/distroi/checkouts/latest/utils/ISM_reddening/ISMreddening_law_Cardelli1989.dat') tuple[float, float]#

Fits an additional reddening to make a model SED match an observed SED.

Fits an additional reddening E(B-V) value to make a model SED match up to an observed SED as much as possible. In case of a successful fit, the model SED is subsequently reddened according to the fitted value of E(B-V) and the chi2 value between model and observations is returned.

Parameters:
  • sed_obs (SED) – Observed SED.

  • sed_mod (SED) – Model SED.

  • ebminv_guess (float) – Initial guess for the E(B-V) reddening factor.

  • redden_mod (bool, optional) – Redden the model SED according to the fitted value. Set to True by default.

  • reddening_law (str, optional) – Path to the reddening law to be used. Defaults to the ISM reddening law by Cardelli (1989) in DISTROI’s ‘utils/ISM_reddening folder’. See this file for the expected formatting of your own reddening laws.

Returns:

The optimal E(B-V) and corresponding chi2 value between the reddened model SED and the observed SED.

Return type:

tuple of float