easyspec.analysis package

class easyspec.analysis.analysis.analysis[source]

Bases: object

This class contains all the functions necessary to perform the analysis of calibrated spectral data.

BH_mass_CIV_VP2006(wavelengths, continuum_baseline, FWHM_CIV, par_values_CIV, H0=70)[source]

This function estimates the black hole mass based on Vestergaard & Peterson, 2006, ApJ, 641, “DETERMINING CENTRAL BLACK HOLE MASSES IN DISTANT ACTIVE GALAXIES AND QUASARS. II. IMPROVED OPTICAL AND UV SCALING RELATIONSHIPS”. As stated in this work, here we assume a cosmology with H0 = 70 km/s/Mpc, Omega_Lambda = 0.7, and Omega_matter = 0.3, although we allow the user to change the value of the Hubble constant (H0).

We assume a systematic error of 0.36 dex for the estimated black hole masses. This value is reported in Vestergaard & Peterson, 2006. Since this error is much higher than the errors in FWHM and integrated flux, we simply ignore the measured errors in these parameters.

Parameters:
  • wavelengths (numpy.ndarray (astropy.units Angstrom)) – The wavelength solution for the given spectrum.

  • continuum_baseline (numpy.ndarray (float)) – An array with the continuum density flux. Standard easyspec units are in erg/cm2/s/A. This variable is an output of the function analysis.find_lines().

  • FWHM_CIV (float (astropy.units Angstrom)) – The FWHM for the CIV line in Angstrom units.

  • par_values_CIV (list) – The list with the best fit values for the CIV line. This information is contained in the variable “par_values_list” returned from the function analysis.fit_lines().

  • H0 (float) – This is the Hubble constant value. Default is 70 km/s/Mpc.

Returns:

log10_BH_mass_CIV – The black hole mass in log10 scale and its corresponding error in dex computed based on Eq. 8 from Vestergaard & Peterson, 2006, ApJ, 641.

Return type:

float

BH_mass_Halpha_Shen2011(FWHM_Halpha, par_values_Halpha, integrated_flux_Halpha, H0=70)[source]

This function estimates the black hole mass based on Shen at al. 2011, ApJS, 194:45, “A CATALOG OF QUASAR PROPERTIES FROM SLOAN DIGITAL SKY SURVEY DATA RELEASE 7”. As stated in this work, here we assume a cosmology with H0 = 70 km/s/Mpc, Omega_Lambda = 0.7, and Omega_matter = 0.3, although we allow the user to change the value of the Hubble constant (H0).

We assume a systematic error of 0.18 dex for the estimated black hole masses. This value is reported in Shen et al. 2011. Since this error is much higher than the errors in FWHM and integrated flux, we simply ignore the measured errors in these parameters.

Parameters:
  • FWHM_Halpha (float (astropy.units Angstrom)) – The FWHM for the Halpha line in Angstrom units.

  • par_values_Halpha (list) – The list with the best fit values for the Halpha line. This information is contained in the variable “par_values_list” returned from the function analysis.fit_lines().

  • integrated_flux_Halpha (float (astropy.units Angstrom)) – The integrated flux for the Halpha line in erg/cm2/s units.

  • H0 (float) – This is the Hubble constant value. Default is 70 km/s/Mpc.

Returns:

log10_BH_mass_Halpha – The black hole mass in log10 scale and its corresponding error in dex computed based on Eq. 10 from Shen et al. 2011.

Return type:

float

BH_mass_Hbeta_VP2006(wavelengths, continuum_baseline, FWHM_Hbeta, par_values_Hbeta, integrated_flux_Hbeta, H0=70)[source]

This function estimates the black hole mass based on Vestergaard & Peterson, 2006, ApJ, 641, “DETERMINING CENTRAL BLACK HOLE MASSES IN DISTANT ACTIVE GALAXIES AND QUASARS. II. IMPROVED OPTICAL AND UV SCALING RELATIONSHIPS”. As stated in this work, here we assume a cosmology with H0 = 70 km/s/Mpc, Omega_Lambda = 0.7, and Omega_matter = 0.3, although we allow the user to change the value of the Hubble constant (H0).

We assume a systematic error of 0.43 dex for the estimated black hole masses. This value is reported in Vestergaard & Peterson, 2006. Since this error is much higher than the errors in FWHM and integrated flux, we simply ignore the measured errors in these parameters.

Parameters:
  • wavelengths (numpy.ndarray (astropy.units Angstrom)) – The wavelength solution for the given spectrum.

  • continuum_baseline (numpy.ndarray (float)) – An array with the continuum density flux. Standard easyspec units are in erg/cm2/s/A. This variable is an output of the function analysis.find_lines().

  • FWHM_Hbeta (float (astropy.units Angstrom)) – The FWHM for the Hbeta line in Angstrom units.

  • par_values_Hbeta (list) – The list with the best fit values for the Hbeta line. This information is contained in the variable “par_values_list” returned from the function analysis.fit_lines().

  • integrated_flux_Hbeta (float (astropy.units Angstrom)) – The integrated flux for the Hbeta line in erg/cm2/s units.

  • H0 (float) – This is the Hubble constant value. Default is 70 km/s/Mpc.

Returns:

  • log10_BH_mass_continuum (float) – The black hole mass in log10 scale and its corresponding error in dex computed based on Eq. 5 from Vestergaard & Peterson, 2006, ApJ, 641.

  • log10_BH_mass_line_lum (float) – The black hole mass in log10 scale and its corresponding error in dex computed based on Eq. 6 from Vestergaard & Peterson, 2006, ApJ, 641.

BH_mass_MgII_VO2009(wavelengths, continuum_baseline, FWHM_MgII, par_values_MgII, H0=70)[source]

This function estimates the black hole mass based on Vestergaard & Osmer, 2009, ApJ, 699, “MASS FUNCTIONS OF THE ACTIVE BLACK HOLES IN DISTANT QUASARS FROM THE LARGE BRIGHT QUASAR SURVEY, THE BRIGHT QUASAR SURVEY, AND THE COLOR-SELECTED SAMPLE OF THE SDSS FALL EQUATORIAL STRIPE”. As stated in this work, here we assume a cosmology with H0 = 70 km/s/Mpc, Omega_Lambda = 0.7, and Omega_matter = 0.3, although we allow the user to change the value of the Hubble constant (H0).

We assume a systematic error of 0.55 dex for the estimated black hole masses. This value is reported in Vestergaard & Osmer, 2009. Since this error is much higher than the errors in FWHM and integrated flux, we simply ignore the measured errors in these parameters.

Parameters:
  • wavelengths (numpy.ndarray (astropy.units Angstrom)) – The wavelength solution for the given spectrum.

  • continuum_baseline (numpy.ndarray (float)) – An array with the continuum density flux. Standard easyspec units are in erg/cm2/s/A. This variable is an output of the function analysis.find_lines().

  • FWHM_MgII (float (astropy.units Angstrom)) – The FWHM for the MgII line in Angstrom units.

  • par_values_MgII (list) – The list with the best fit values for the MgII line. This information is contained in the variable “par_values_list” returned from the function analysis.fit_lines().

  • H0 (float) – This is the Hubble constant value. Default is 70 km/s/Mpc.

Returns:

log10_BH_mass_MgII – The black hole mass in log10 scale and its corresponding error in dex computed based on Eq. 1 from Vestergaard & Osmer, 2009, ApJ, 699, taking the continuum luminosity at 3000 Angstroms. If the continuum at 3000 Angstroms is not available, it automatically uses the continuum at 2100 Angstroms.

Return type:

float

MCMC_spread(x, samples, model_name, nsamples=100, custom_function=None)[source]

Function to compute the median MCMC model and its standard deviation.

all_models(model_name, custom_function=None)[source]

This function is used to select a specific line model. E.g.: Gaussian, Lorentz, GaussianLorentzGaussian, and so on.

Parameters:
  • model_name (string) – The name of the line model, e.g. “Gaussian”.

  • custom_function (method) – Optional. You can input a custom model here.

Returns:

models[model_name] – returns a function with the desired line model.

Return type:

method

automatic_priors(which_model, observed_wavelength, peak_height, line_region_min, line_region_max)[source]

In this function we automatically set the priors, initial parameter values and select the line model.

Parameters:
  • which_models (string) – The models to be applied to the line. Options are “Gaussian”, “Lorentz” and “Voigt”.

  • observed_wavelength (float) – The wavelength corresponding to the peak position.

  • peak_height (flaot) – The height of the peak with respect to the continuum emission.

  • line_region_min (float) – The starting wavelength around the studied line.

  • line_region_max (float) – The final wavelength around the studied line.

Returns:

  • initial (numpy.array) – An array with the automatic initial parameter values for the MCMC.

  • priors (numpy.array) – An array containing three or four lists of two elements, i.e. one list for each parameter given in ‘initial’.

  • labels (list) – A list with the names of each parameter.

  • adopted_model (method) – A function with the adopted model, i.e., a “Gaussian”, “Lorentz” or “Voigt”.

continuum_fit(flux, wavelengths, continuum_regions, method='powerlaw', pl_order=2, smooth_window=111)[source]

This function fits the continuum emission with an spline or a power law.

Parameters:
  • flux (array (float)) – Array with the flux density to be fitted and (if spline is chosen) smoothed.

  • wavelengths (array (float)) – Wavelength must be in absolute values, i.e. without units.

  • continuum_regions (list (float)) – The continuum will be computed only within these wavelength regions and then extrapolated everywhere else. E.g.: continuum_regions = [[3000,6830],[6930,7500]]. If None, then all the wavelength range will be used.

  • method (string) – This is the desired method to compute the continuum. Options are ‘powerlaw’ (or ‘pl’) and “median_filter”. The ‘powerlaw’ method is better in case you have large emission/absorption lines. The method “median_filter” is excellent for extracting the continuum of a spectrum with narrow emission/absorption lines.

  • pl_order (int) – Polynomial order for the power law fit. Used only if input variable method=”powerlaw” (or “pl”).

  • smooth_window (int) – This is the size of the smooth window for the “median_filter” method. This number must be odd.

Returns:

  • continuum_selection (array (float)) – Array with the continuum flux density.

  • continuum_std_deviation (float) – The standard deviation for the continuum.

data_window_selection(wavelengths, spec_flux, spec_flux_err, line_region_min, line_region_max)[source]

Function to slice the data into a wavelength window.

Parameters:
  • wavelengths (numpy.array) – This variable must be in absolute values, i.e. without units.

  • spec_flux (numpy.array) – The spectral density array.

  • spec_flux_err (numpy.array) – The spectral density array.

  • line_region_min (float) – Inferior window limit.

  • line_region_max (float) – Superior window limit.

Returns:

x, y, yerr – New arrays containing data within the selected window.

Return type:

numpy.arrays

equiv_width_error(integrand, line_window, line_parameters, line_par_errors)[source]

In this function we estimate the modeled equivalent width error for a line based on a Monte Carlo simulation.

Parameters:
  • integrand (function) – The function to be integrated. See the details here: https://en.wikipedia.org/wiki/Equivalent_width

  • line_window (list) – A list containing the wavelength limits around the line.

  • line_parameters (list) – A list with the line best-fit parameters obtained with the MCMC method.

  • line_par_errors (list) – A list with the asymmetrical parameter errors.

Returns:

  • EQW_error_down (float) – The equivalent width lower error for a modeled line.

  • EQW_error_up (float) – The equivalent width upper error for a modeled line.

error_propagation_voigt(FWHM_Lorentz, FWHM_Gauss, error_lorentz, error_gauss)[source]

In this function we propagate the FWHM error for the Voigt model assuming independent variables.

Parameters:
  • FWHM_Lorentz (float) – The Lorentzian component FWHM.

  • FWHM_Gauss (float) – The Gaussian component FWHM.

  • error_lorentz (float) – The associated error to the Lorentzian FWHM.

  • error_gauss (float) – The associated error to the Gaussian FWHM.

Returns:

fwhm_error_voigt – The propagated uncertainty in FWHM for the Voigt model.

Return type:

float

estimate_norm_height(wavelengths, flux_density, continuum_baseline, wavelength_peak_position, peak_height)[source]

Funtion to estimate the normalized height of a peak to set the priors for the MCMC.

Parameters:
  • wavelengths (numpy.ndarray (astropy.units Angstrom)) – The wavelength solution for the given spectrum.

  • flux_density (numpy.ndarray (astropy.units erg/cm2/s/A)) – The calibrated spectrum in flux density.

  • continuum_baseline (numpy.ndarray (float)) – An array with the continuum density flux. Standard easyspec units are in erg/cm2/s/A. This variable is an output of the function analysis.find_lines().

  • wavelength_peak_position (astropy.units Angstrom) – The position of the peak in the wavelength axis in Angstroms.

  • peak_height (astropy.units erg/cm2/s/A) – The height of the peak in erg/cm2/s/A.

Returns:

norm_height – The estimated normalized height of the input peak. This value can be set to estimate priors for the MCMC.

Return type:

float

find_lines(wavelengths, flux_density, line_significance_sigma=5, peak_distance=30, peak_width=10, method='median_filter', continuum_regions=None, pl_order=2, smooth_window=111, plot_lines=True, plot_regions=True, save_plot=False)[source]

This function will find all emission/absorption lines with significance above ‘line_significance_sigma’ with respect to the local continuum.

Parameters:
  • wavelengths (numpy.ndarray (astropy.units Angstrom)) – The wavelength solution for the given spectrum.

  • flux_density (numpy.ndarray (astropy.units erg/cm2/s/A)) – The calibrated spectrum in flux density.

  • line_significance_sigma (float) – Defines how many standard deviations above the continuum the line peak must be in order to be detected.

  • peak_distance (float) – The minimal distance (data bins, not in Angstroms) between peaks (>=1).

  • peak_width (float) – Minimum required width of peaks in data bins. The number of data bins is equal to the number of pixels in the reduced spectral image.

  • method (string) – This is the desired method to compute the continuum. Options are ‘powerlaw’ (or ‘pl’) and “median_filter”. The ‘powerlaw’ method is better in case you have large emission/absorption lines. The method “median_filter” is excellent for extracting the continuum of a spectrum with narrow emission/absorption lines.

  • continuum_regions (list (float)) – The continuum will be computed only within these wavelength regions and then extrapolated everywhere else. E.g.: continuum_regions = [[3000,6830],[6930,7500]]. If None, then all the wavelength range will be used.

  • pl_order (int) – Polynomial order for the power law fit. Used only if input variable method=”powerlaw” (or “pl”).

  • smooth_window (int) – This is the size of the smooth window for the “median_filter” method. This number must be odd.

  • plot_lines (boolean) – If True, the spectrum and all detected lines will be shown.

  • plot_regions (boolean) – If True, the spectrum will be plotted in multiple regions (assuming continuum_regions is not None). For each one of these regions, the noise is independently estimated from the local continuum.

  • save_plot (boolean) – If True, the spectrum plot will be saved in the output directory defined in analysis.load_calibrated_data().

Returns:

  • continuum_baseline (numpy.ndarray (float)) – An array with the continuum density flux. Standard easyspec units are in erg/cm2/s/A.

  • line_std_deviation (numpy.ndarray (float)) – The standard deviation for the local continuum. Line significance is calculated with respect to this value.

  • wavelength_peak_positions (numpy.ndarray (astropy.units Angstrom)) – The position of each peak in Angstroms.

  • peak_heights (numpy.ndarray (astropy.units erg/cm2/s/A)) – The height of each peak in erg/cm2/s/A

  • line_significance (array (floats)) – The line significance with respect to the local continuum standard deviation.

fit_lines(wavelengths, flux_density, continuum_baseline, wavelength_peak_positions, rest_frame_line_wavelengths, peak_heights, line_std_deviation, blended_line_min_separation=50, which_models='Lorentz', line_names=None, overplot_archival_lines=['H'], priors=None, MCMC_walkers=250, MCMC_iterations=400, N_cores=1, plot_spec=True, plot_MCMC=False, overplot_median_model=False, save_results=True)[source]

This function uses a Markov-chain Monte Carlo to estimate the line parameters and their errors.

Parameters:
  • wavelengths (numpy.ndarray (astropy.units Angstrom)) – The wavelength solution for the given spectrum.

  • flux_density (numpy.ndarray (astropy.units erg/cm2/s/A)) – The calibrated spectrum in flux density.

  • continuum_baseline (numpy.ndarray (float)) – An array with the continuum density flux. Standard easyspec units are in erg/cm2/s/A. This variable is an output of the function analysis.find_lines().

  • wavelength_peak_positions (numpy.ndarray (astropy.units Angstrom)) – The position of each peak in Angstroms found with the function analysis.find_lines().

  • rest_frame_line_wavelengths (list) – A list with the rest frame wavelength values for each one of the input lines.

  • peak_heights (numpy.ndarray (astropy.units erg/cm2/s/A)) – The height of each peak in erg/cm2/s/A. This variable is an output of the function analysis.find_lines().

  • line_std_deviation (numpy.ndarray (float)) – The standard deviation for the local continuum. This variable is an output of the function analysis.find_lines().

  • blended_line_min_separation (float) – The minimum separation between blended line peaks in Angstrom. If the line peaks are closer than this value, a blended model will be adopted.

  • which_models (string or list of strings) – A list containing the models to be applied to each line, e.g.: if you are trying to model 2 lines, you can use which_models = [“Lorentz”,”Gaussian”]. If you wish to use the same model for all lines, you can use which_models = [“Gaussian”,”Gaussian”] or simply which_models = “Gaussian”. Options are “Gaussian”, “Lorentz” and “Voigt”.

  • line_names (list) – Optional. A list with line names, e.g.: if you are trying to model 2 lines, you can use line_names = [“Hbeta”,”Halpha”]. If the names are not provided, easyspec will call the lines line_0, line_1… and so on.

  • overplot_archival_lines (list) – List with the strings corresponding to different elements. E.g.: [“H”,”He”] will overplot all the Hydrogen and Helium lines redshifted based on the average redshift of the lines given in wavelength_peak_positions. If you don’t want to overplot lines, use overplot_archival_lines = None. If you use too many lines as input, they will very likely overlap in the plot. Be aware that this feature is meant only for guiding the user! There are several lines which are not included in our database, but we tried to select the most commonly seen lines in galaxy, quasar and stellar spectra.

  • priors (list or list of lists) – This parameter is complicated. It is better if you leave it as “None”. This parameter controls the priors used in the MCMC in the estimation of the line parameters. The initial parameters for the MCMC are always defined as wavelength_peak_positions (for the position of the line peak) and peak_heights (for the height of the peak). If priors = None, the priors are set to wavelength_peak_positions +- 100 Angstroms (or to half the distance to the closest line if this line is closer than 100 Angstroms), 0.1*peak_heights up to 10*peak_heights (normalized based on the continuum), and the std or fwhm are confined within 0.1 to 150. If you are e.g. analysing 4 lines with the Lorentz model and want to change the priors of the third line, you can set priors = [None, None,[[7496,7696],[0.1, 150],[2,150]], None], where the list of three ranges here represents the allowed sampling intervals, i.e. the position of the peak, the peak heigh in terms of the continuum level and the fwhm. For the Voigt model, the input variable would be priors = [None, None,[[7496,7696],[0.1, 150],[2,150],[1,150]], None]. Of course you can set up the ranges for all lines.

  • MCMC_walkers (int) – This is the number of walkers for the MCMC.

  • MCMC_iterations (int) – This is the number of iterations for the MCMC.

  • N_cores (int) – This is the number of cores in case you want to run this analysis in parallel.

  • plot_spec (boolean) – If True, a plot of the spectrum with the lines requested in the input variable overplot_archival_lines will be shown.

  • plot_MCMC (boolean) – If True, a series of diagnostic plots for the MCMC will be shown, as the corner plot, the evolution of the parameters over time, and the line fitted to the data.

  • overplot_median_model (boolean) – If True, the median model and model standard deviation will be overploted in the diagnostic plots.

  • save_results (boolean) – If True, the plots and fit information will be saved in the output directory defined in the function analysis.load_calibrated_data()

Returns:

  • par_values_list (list) – This is a list containing sublists with the best-fit values for each line model.

  • par_values_errors_list (list) – A list with the asymmetrical errors for each parameter listed in par_values_list.

  • par_names_list (list) – A list with the names of all the parameters used in each line model.

  • samples_list (list) – A list containing the MCMC posterior distributions.

  • line_windows (list) – A list containing the wavelength intervals around each line.

  • XXXXXXX_lines.csv – Optional. This file contains all the best-fit parameters for each line model and is saved in the output directory defined in the function analysis.load_calibrated_data(). “XXXXXXX” here stands for the target’s name.

line_MCMC(p0, priors, nwalkers, niter, initial, lnprob, data, model_name, custom_function=None, burn_in=100, ncores=1)[source]

This function runs a MCMC approach for one line (singular or blended) for a given a model.

line_dispersion_and_equiv_width(wavelengths_window, flux_density_window, continuum_baseline_window, line_std_deviation, line_name=None, plot=True)[source]

This function estimates the line dispersion (aka the rms width of the line), the profile equivalent width, and the FWHM. All measures are independent on the line model (i.e. Gaussian, Lorentz or Voigt) and dependent on the interpolated line profile.

Parameters:
  • wavelengths_window (numpy.ndarray) – The wavelength window for the given line.

  • flux_density_window (numpy.ndarray) – The flux density window for the given line.

  • continuum_baseline_window (numpy.ndarray) – An array with the continuum density flux window for the given line. Standard easyspec units are in erg/cm2/s/A.

  • line_std_deviation (numpy.ndarray (float)) – The standard deviation for the local continuum. This variable is an output of the function analysis.find_lines().

  • line_name (string) – The line name.

  • plot (boolean) – If True, the line and corresponding centroid and dispersion will be showed.

Returns:

  • line_dispersion (float) – The line dispersion is well defined for arbitrary line profiles. See Eqs. 4 and 5 in Peterson et al. 2004 for some guidance. You should avoid using the line dispersion in case of blended lines. The result here is given in the observed frame.

  • profile_equiv_width (float) – This is a model-independent estimate of the equivalent width and can be used with arbitrary line profiles. This is the integral of (Fc - F)/Fc over the wavelengths, where Fc is the continuum flux density and F is the interpolated flux density. The result is given in the observed frame.

  • profile_FWHM (float) – The model-independent FWHM.

  • line_disp_error (float) – The error on the line dispersion computed with a Monte Carlo simulation.

  • equiv_width_error (float) – The error on the equivalent width computed with a Monte Carlo simulation.

  • fwhm_error (float) – The error on the FWHM computed with a Monte Carlo simulation.

line_physics(wavelengths, flux_density, continuum_baseline, par_values_list, par_values_errors_list, par_names_list, line_windows, line_std_deviation, plot=True, save_file=True)[source]

In this function we compute several physical properties for the fitted lines.

OBS 1: For the Voigt model, we assume independent variables when propagating the FWHM error. If this is not the case (you can check this in the MCMC corner plots), we recommend that you use the Gaussian or Lorentzian models.

OBS 2: The integrated flux is computed by taking the equivalent width and multiplying it by the continuum value at the line center.

OBS 3: The line dispersion is well defined for arbitrary line profiles. See e.g. Eqs. 4 and 5 in Peterson et al. 2004. This method is not recommended in case of blended lines.

Parameters:
  • wavelengths (numpy.ndarray (astropy.units Angstrom)) – The wavelength solution for the given spectrum.

  • flux_density (numpy.ndarray (astropy.units erg/cm2/s/A)) – The calibrated spectrum in flux density.

  • continuum_baseline (numpy.ndarray (float)) – An array with the continuum density flux. Standard easyspec units are in erg/cm2/s/A. This variable is an output of the function analysis.find_lines().

  • par_values_list (list) – This is a list containing sublists with the best-fit values for each line model.

  • par_values_errors_list (list) – A list with the asymmetrical errors for each parameter listed in par_values_list.

  • par_names_list (list) – A list with the names of all the parameters used in each line model.

  • line_windows (list) – A list containing the wavelength intervals around each line.

  • line_std_deviation (numpy.ndarray (float)) – The standard deviation for the local continuum. This variable is an output of the function analysis.find_lines().

  • plot (boolean) – If True, the line and corresponding centroid and dispersion will be showed.

  • save_file (boolean) – If True, the results of this function will be saved in a .csv file in the output directory defined at analysis.load_calibrated_data().

Returns:

  • profile_equiv_width_rest_frame (list (astropy.units Angstrom)) – A list with the equivalent widths (and respective errors) for each line and their respective errors in the rest frame. The values here are obtained with the interpolation of the line profile and are therefore independent on the line model (i.e. Gaussian, Lorentzian or Voigt).

  • modeled_equiv_width_rest_frame (list (astropy.units Angstrom)) – A list with the model-dependent equivalent widths (and respective errors) for each line and their respective errors in the rest frame.

  • profile_integrated_flux (list (astropy.units erg/cm2/s)) – A list with the model-independent line fluxes and their respective errors.

  • modeled_integrated_flux (list (astropy.units erg/cm2/s)) – A list with the model-dependent line fluxes and their respective errors.

  • profile_rest_frame_disp_velocity (list (astropy.units km/s)) – A list with the model-independent dispersion velocities and their respective errors in the rest frame.

  • modeled_rest_frame_disp_velocity (list (astropy.units km/s)) – A list with the model-dependent dispersion velocities and their respective errors in the rest frame.

  • profile_line_dispersion_rest_frame (list (astropy.units Angstrom)) – A list with the line dispersions (from the line second moments) and their respective errors in the rest frame.

  • profile_rest_frame_fwhm (list (astropy.units Angstrom)) – A list with the model-independent line FWHMs and their respective errors in the rest frame.

  • modeled_rest_frame_fhwm (list (astropy.units Angstrom)) – A list with the model-dependent line FWHMs and their respective errors in the rest frame.

  • XXXXXXX_line_physics.csv – Optional. This file contains all physics parameters for each modeled line and is saved in the output directory defined in the function analysis.load_calibrated_data(). “XXXXXXX” here stands for the target’s name.

lnlike(theta, x, y, yerr, model)[source]

Here we compute the likelihood of the current model given the data.

lnprior(theta, priors)[source]

This function checks if the input parameters satisfy the prior conditions.

lnprob(theta, priors, x, y, yerr, model)[source]
load_calibrated_data(calibrated_spec_data, target_name=None, output_dir='./', plot=True)[source]

This function loads the spectral calibrated data. Preferentially, you should use the file ‘TARGETNAME_spec_X.dat’ generated with easyfermi function ‘extraction.target_flux_calibration()’.

Parameters:
  • calibrated_spec_data (string) – The path to the data ‘.dat’ file containing the calibrated spectrum.

  • target_name (string) – Optional. This name will be used in all subsequent plots.

  • output_dir (string) – A string with the path to the output directory.

  • plot (boolean) – If True, the spectrum will be shown.

Returns:

  • wavelengths (numpy.ndarray (astropy.units Angstrom)) – The wavelength solution for the given spectrum

  • flux_density (numpy.ndarray (astropy.units erg/cm2/s/A)) – The calibrated spectrum in flux density.

merge_fit_results(target_name, list_of_files=None, wavelength_systematic_error=None, output_dir='./')[source]

This function merges the individual data files for each line into a single merged data file.

model_Gauss(theta, x)[source]
model_Gauss_Gauss(theta, x)[source]
model_Gauss_Gauss_Gauss(theta, x)[source]
model_Gauss_Gauss_Lorentz(theta, x)[source]
model_Gauss_Gauss_Voigt(theta, x)[source]
model_Gauss_Lorentz(theta, x)[source]
model_Gauss_Lorentz_Gauss(theta, x)[source]
model_Gauss_Lorentz_Lorentz(theta, x)[source]
model_Gauss_Lorentz_Voigt(theta, x)[source]
model_Gauss_Voigt(theta, x)[source]
model_Gauss_Voigt_Gauss(theta, x)[source]
model_Gauss_Voigt_Lorentz(theta, x)[source]
model_Gauss_Voigt_Voigt(theta, x)[source]
model_Lorentz(theta, x)[source]
model_Lorentz_Gauss(theta, x)[source]
model_Lorentz_Gauss_Gauss(theta, x)[source]
model_Lorentz_Gauss_Lorentz(theta, x)[source]
model_Lorentz_Gauss_Voigt(theta, x)[source]
model_Lorentz_Lorentz(theta, x)[source]
model_Lorentz_Lorentz_Gauss(theta, x)[source]
model_Lorentz_Lorentz_Lorentz(theta, x)[source]
model_Lorentz_Lorentz_Voigt(theta, x)[source]
model_Lorentz_Voigt(theta, x)[source]
model_Lorentz_Voigt_Gauss(theta, x)[source]
model_Lorentz_Voigt_Lorentz(theta, x)[source]
model_Lorentz_Voigt_Voigt(theta, x)[source]
model_Voigt(theta, x)[source]
model_Voigt_Gauss(theta, x)[source]
model_Voigt_Gauss_Gauss(theta, x)[source]
model_Voigt_Gauss_Lorentz(theta, x)[source]
model_Voigt_Gauss_Voigt(theta, x)[source]
model_Voigt_Lorentz(theta, x)[source]
model_Voigt_Lorentz_Gauss(theta, x)[source]
model_Voigt_Lorentz_Lorentz(theta, x)[source]
model_Voigt_Lorentz_Voigt(theta, x)[source]
model_Voigt_Voigt(theta, x)[source]
model_Voigt_Voigt_Gauss(theta, x)[source]
model_Voigt_Voigt_Lorentz(theta, x)[source]
model_Voigt_Voigt_Voigt(theta, x)[source]
parameter_estimation(samples, model_name, air_wavelength_line=None, quantiles=[0.16, 0.5, 0.84], normalization=1, parlabels=None, line_names='', output_dir='.', savefile=True)[source]

In this function we estimate the parameter values and corresponding errors based on the 16%, 50%, and 84% quantiles of the MCMC posterior distributions of parameters.

Parameters:
  • samples (list) – A list containing the MCMC posterior distributions.

  • model_name (string) – The current model adopted in the fit.

  • air_wavelength_line (float) – The line rest-frame wavelength used to compute the redshift.

  • quantiles (list) – The quantiles adpted to compute the parameter values and corresponding errors. Default is quantiles=[0.16, 0.5, 0.84].

  • normalization (float) – The plot normalization.

  • parlabels (list) – This is a list with the names of the free parameters in the adopted model. If you use a model with two peaks, then parlabels needs two input lists, e.g.: parlabels=[[‘a’,’b’],[‘c’,’d’]]. If it has three peaks, parlabels must be parlabels=[[‘a’,’b’],[‘c’,’d’],[‘e’,’f’]] and so on.

  • line_names (string or list of strings) – The line names.

  • outputdir (string) – The output directory.

  • savefile (boolean) – If True, the data will be saved in the output directory.

Returns:

  • par_values (list) – A list with the parameter values recovered from the 50% quantiles of the MCMC posterior distributions of parameters.

  • par_values_errors (list) – A list with the parameter errors recovered from the 16% and 84% quantiles of the MCMC posterior distributions of parameters.

  • par_names (list) – A list with the parameter names.

parameter_time_series(initial, sampler, labels)[source]

This function plots the time series of the parameters running in the MCMC.

plotter(sampler, model_name, x, color='grey', normalization=1)[source]

In this function we plot the ‘hairs’ (i.e. alternative models) around the maximum likelihood model estimated with the MCMC method.

quick_plot(x, y, model_name, parlabels, sampler=None, best_fit_model=None, theta_max=None, normalization=1, hair_color='grey', title='', xlabel='Observed $\\lambda$ [$\\AA$]', ylabel='F$_{\\lambda}$ [erg cm$^{-2}$ s$^{-1}$ $\\AA^{-1}$ ]', overplot_median_model=True, savefig=True, outputdir='./')[source]

In this function we plot the data window together with the maximum likelihood and/or the median model.

Parameters:
  • x (numpy.arrays) – Arrays containing the data within the selected window.

  • y (numpy.arrays) – Arrays containing the data within the selected window.

  • model_name (string) – The current model adopted in the fit.

  • parlabels (list) – A list with the parameter names for the adopted model.

  • sampler – The MCMC sampler.

  • best_fit_model (numpy.array) – Array with the best-fit model.

  • theta_max (numpy.ndarray) – Array with the best-fit parameters.

  • normalization (float) – The plot normalization.

  • hair_color (string) – The color adopted for the MCMC hairs.

  • title (string) – The title of the plot.

  • xlabel (strings) – The axes labels.

  • ylabel (strings) – The axes labels.

  • overplot_median_model (boolean) – If True, the median model and model standard deviation will be overploted.

  • savefig (boolean) – If True, the figure will be saved in the output directory.

  • outputdir (string) – The output directory.

redshift_calculator(q_16, q_50, q_84, air_wavelength_line)[source]