SEDA

Archival Data

Spitzer IRS

Access Spitzer IRS archival spectra for one or multiple targets.

class seda.archival_data.IRS[source]

Bases: object

Interface to access Spitzer IRS archival spectra.

Use this class to retrieve spectra for one or multiple targets from the Spitzer IRS archival dataset.

data_path

Path to the observations_aux folder.

Type:

pathlib.Path

spectra_folder

Path to the spitzer_irs_spectra folder containing spectrum files.

Type:

pathlib.Path

table

Metadata table loaded from Suarez_Metchev_2022_tables.dat.

Type:

astropy.table.Table

get_spectra(targets)[source]

Retrieve spectra for one or multiple targets.

Examples

>>>
>>> import seda
>>>
>>> # create an instance of the IRS class
>>> irs = seda.archival_data.IRS()
>>> # example targets
>>> target_name = ['0355+1133', '1821+1414']
>>> # get spectrum and metadata
>>> spectra = irs.get_spectra(target_name)
>>>
>>> # extract a few attributes for the first spectrum
>>> spectra[0].wavelength # wavelengths in microns
>>> spectra[0].flux       # fluxes in Jy
>>> spectra[0].Name       # Object name via attribute
>>> spectra[0]['Name']    # Object name via dictionary-style
>>> spectra[0].plot()     # plot spectrum
>>> for s in spectra:
...      print(s.Name, s.spt_adop)

Author: Genaro Suárez

Date: 2026-02-18

get_spectra(targets)[source]

Retrieve spectra for one or multiple targets.

Parameters:

targets (str or list of str) – Target names in the format “0000+2554”.

Returns:

List of Spectrum objects, one per target.

Return type:

list of Spectrum

Spectrum

Represents individual spectra and provides plotting and analysis methods.

class seda.archival_data.Spectrum(target, wavelength, flux, eflux, meta_row)[source]

Bases: object

Represents a single spectrum with wavelength, flux, flux error, and all metadata columns from the table as direct attributes.

Provides both attribute-style access (e.g., spectrum.SName) and dict-style access (e.g., spectrum[‘SName’]).

Parameters:
  • target (str) – Target short name.

  • wavelength (array-like) – Wavelength numpy array in microns.

  • flux (array-like) – Flux numpy array in Jy.

  • eflux (array-like) – Flux uncertainty numpy array in Jy.

  • meta_row (astropy.table.Row) – Metadata row from the table; all columns are promoted as attributes.

plot(show=True, \*\*kwargs)[source]

Quick plot of the spectrum.

Examples

>>>
>>> import seda
>>>
>>> # create an instance of the IRS class
>>> irs = seda.archival_data.IRS()
>>> # get spectrum and metadata
>>> spectrum = irs.get_spectra('0355+1133')[0]
>>>
>>> # extract a few attributes
>>> spectrum.wavelength # wavelengths in microns
>>> spectrum.flux       # fluxes in Jy
>>> spectrum.Name       # Object name via attribute
>>> spectrum['Name']    # Object name via dictionary-style
>>> spectrum.plot()     # plot spectrum

Author: Genaro Suárez

Date: 2026-02-18

plot(show=True, **kwargs)[source]

Quick plot of the spectrum.

Parameters:
  • show (bool, default True) – Whether to call plt.show() immediately.

  • kwargs – Additional keyword arguments passed to plt.plot().

Returns:

  • self (Spectrum) – Returns self to allow method chaining.

  • Author (Genaro Suárez)

  • Date (2026-02-18)

Bayesian Sampling

seda.bayes_fit.bayes(my_bayes)[source]

Description:

Estimate Bayesian posteriors using dynesty dynamic nested sampling

Parameters:

  • my_bayes : dictionary with returned parameters from seda.BayesOptions, which also includes the parameters from seda.InputData and seda.ModelOptions.

Returns:

  • model_bayesian_sampling.pickle’dictionary
    Dictionary with:
    • 'my_bayes' input dictionary returned by input_parameters.BayesOptions.

    • Dynesty output, which is an initialized instance of the chosen sampler using dynamic_sampling in seda.BayesOptions.

Example:

>>> import seda
>>>
>>> # load input data
>>> wl_spectra = wl_input # in um
>>> flux_spectra = flux_input # in erg/cm^2/s/A
>>> eflux_spectra = eflux_input # in erg/cm^2/s/A
>>> my_data = seda.InputData(wl_spectra=wl_spectra, flux_spectra=flux_spectra,
>>>                          eflux_spectra=eflux_spectra)
>>>
>>> # load model options
>>> model = 'Sonora_Elf_Owl'
>>> model_dir = ['my_path/output_575.0_650.0/',
>>>              'my_path/output_700.0_800.0/'] # folders to seek model spectra
>>> # set ranges for some (Teff and logg) free parameters to select only a grid subset
>>> params_ranges = {'Teff': [700, 900], 'logg': [4.0, 5.0]}
>>> my_model = seda.ModelOptions(model=model, model_dir=model_dir,
>>>                              params_ranges=params_ranges)
>>>
>>> # load Bayesian options
>>> R_range = np.array((0.6, 1.0)) # R range in Rjup
>>> fit_wl_range = [value1, value2] # to make the fit between value1 and value2
>>> my_bayes = seda.Chi2FitOptions(my_data=my_data, my_model=my_model,
>>>                                fit_wl_range=fit_wl_range, R_range=R_range)
>>>
>>> # run Bayesian sampling
>>> out_bayes = seda.bayes(my_bayes)
    Bayesian sampling ran successfully

Author: Genaro Suárez

Chi-square Fit

seda.chi2_fit.chi2(my_chi2)[source]

Description:

Minimize the chi-square statistic to find the best model fits.

Parameters:

  • my_chi2 : return parameters from seda.Chi2Options, which also includes the parameters from seda.InputData and seda.ModelOptions.

Returns:

  • model_chi2_minimization.dat’ascii table

    Table with the names of all model spectra fits sorted by chi square and including the information: spectrum name, chi square, reduced chi square, scaling, scaling error, extinction, extinction error, model free parameters, radius and error (if distance and ``edistance are provided), and iterations to minimize chi-square.

  • model_chi2_minimization.pickle’dictionary
    Dictionary with the results from the chi-square minimization, namely:
    • my_chi2 input dictionary returned by input_parameters.Chi2Options.

    • iterations_fit: number of iterations to minimize chi-square.

    • Av_fit: visual extinction (in mag) that minimizes chi-square.

    • eAv_fit: visual extinction uncertainty (in mag).

    • scaling_fit: scaling factor that minimizes chi-square.

    • escaling_fit: scaling factor uncertainty.

    • chi2_wl_fit: chi-square as a function of wavelength.

    • chi2_red_wl_fit: reduced chi-square as a function of wavelength.

    • chi2_fit: total chi-square.

    • chi2_red_fit: total reduced chi-square.

    • radius: (if distance is provided) radius (in Rjup) considering the scaling_fit and input distance.

    • eradius: (if edistance is provided) radius uncertainty (in Rjup).

    • params: model free parameters for each model spectrum.

    • flux_array_model_conv_resam_scaled: (if fit spectra) input flux_array_model_conv_resam fluxes multiplied by the scaling factor scaling_fit.

    • flux_array_model_conv_resam_scaled_fit: (if fit spectra) input flux_array_model_conv_resam_fit fluxes multiplied by the scaling factor scaling_fit.

    • flux_residuals_spec: (if fit spectra) linear flux residual (in erg/cm2/s/A) between observed spectra and model spectra in fit_wl_range.

    • logflux_residuals_spec: (if fit spectra) logarithm flux residual (in erg/cm2/s/A) between observed spectra and model spectra in fit_wl_range.

    • flux_syn_array_model_scaled_fit: (if fit photometry) input flux_syn_array_model_fit fluxes multiplied by the scaling factor scaling_fit.

    • flux_residuals_phot: (if fit photometry) linear flux residual (in erg/cm2/s/A) between observed photometry and model spectra in fit_phot_range.

    • logflux_residuals_phot: (if fit photometry) logarithm flux residual (in erg/cm2/s/A) between observed photometry and model spectra in fit_phot_range.

Example:

>>> import seda
>>>
>>> # load input data
>>> wl_spectra = wl_input # in um
>>> flux_spectra = flux_input # in erg/cm^2/s/A
>>> eflux_spectra = eflux_input # in erg/cm^2/s/A
>>> my_data = seda.InputData(wl_spectra=wl_spectra, flux_spectra=flux_spectra,
>>>                          eflux_spectra=eflux_spectra)
>>>
>>> # load model options
>>> model = 'Sonora_Elf_Owl'
>>> model_dir = ['my_path/output_700.0_800.0/',
>>>              'my_path/output_850.0_950.0/'] # folders to seek model spectra
>>> params_ranges = {'Teff': [700, 900, 'logg': [4.0, 5.0]
>>> my_model = seda.ModelOptions(model=model, model_dir=model_dir,
>>>                              params_ranges=params_ranges)
>>>
>>> # load chi-square options
>>> fit_wl_range = np.array([value1, value2]) # to make the fit between value1 and value2
>>> my_chi2 = seda.Chi2FitOptions(my_data=my_data, my_model=my_model,
>>>                               fit_wl_range=fit_wl_range)
>>>
>>> # run chi-square fit
>>> out_chi2 = seda.chi2(my_chi2)
    Chi square fit ran successfully

Author: Genaro Suárez

seda.chi2_fit.save_params(out_chi2)[source]

Description:

Create table with model spectra names sorted by chi square along with relevant parameters.

Parameters:

  • out_chi2dictionary
    Dictionary with the following parameters:
    • spectra_name : spectrum name

    • chi2_fit : chi-square

    • chi2_red_fit : reduced chi-square

    • scaling_fit : scaling factor

    • e_scaling_fit : scaling factor uncertainty

    • Av_fit : extinction

    • eAv_fit : extinction uncertainty

    • params : fundamental parameters provided by model.

    • R : radius, when a distance was provided.

    • eR : radius error, when distance and edistance were provided.

    • iterations_fit : iterations to minimize chi square.

Returns:

  • chi2_table_fileascii table

    ASCII table with input parameters sorted according to reduced chi-square. Table named chi2_table_file, as specified in seda.Chi2Options.

Author: Genaro Suárez

Input Parameters

Input Data

class seda.input_parameters.InputData(fit_spectra=True, fit_photometry=False, wl_spectra=None, flux_spectra=None, eflux_spectra=None, flux_unit=None, res=None, lam_res=None, phot=None, ephot=None, filters=None, phot_unit=None, distance=None, edistance=None)[source]

Bases: object

Description:

Define input data for fitting (spectra and/or photometry).

Parameters:

  • fit_spectra{True, False}, optional (default True)

    Include (True) or do not include (False) spectra.

  • fit_photometry{True, False}, optional (default False)

    Include (True) or do not include (False) photometry.

  • wl_spectrafloat array or list, optional (required if fit_spectra)

    Wavelength in micron of the spectra for model comparisons. For multiple spectra, provide them as a list (e.g., wl_spectra = [wl_spectrum1, wl_spectrum2]).

  • flux_spectrafloat array or list, optional (required if fit_spectra)

    Fluxes for the input spectra in units indicated by flux_unit. Use a list for multiple spectra (similar to wl_spectra).

  • eflux_spectrafloat array or list, optional (required if fit_spectra)

    Fluxes uncertainties in units indicated by flux_unit. Use a list for multiple spectra (similar to wl_spectra).

  • flux_unitstr, optional (default 'erg/s/cm2/A')

    Units of flux_spectra and eflux_spectra: 'Jy', 'erg/s/cm2/A', or erg/s/cm2/um.

  • photfloat array, optional (required if fit_photometry)

    Magnitudes or photometric fluxes for the fit

  • ephotfloat array, optional (required if fit_photometry)

    Magnitude or photometric flux uncertainties for the fit. Magnitudes or fluxes with uncertainties equal to zero are excluded from the fit.

  • filtersfloat array, optional (required if fit_photometry)

    Filters associated to the input photometry following SVO filter IDs http://svo2.cab.inta-csic.es/theory/fps/

  • phot_unitstr, optional (default 'mag')

    Units of phot and ephot: 'mag', 'Jy', 'erg/s/cm2/A', or erg/s/cm2/um.

  • resfloat, list or array, optional (required if fit_spectra)

    Resolving power (R=lambda/delta(lambda) at lam_res) of input spectra to smooth model spectra. For multiple input spectra, res should be a list or array with a value for each spectrum.

  • lam_resfloat, list or array, optional

    Wavelength of reference at which res is given (because resolution may change with wavelength). For multiple input spectra, lam_res should be a list or array with a value for each spectrum. Default is the integer closest to the median wavelength for each input spectrum. If lam_res is provided, the values are also rounded to the nearest integer. This will facilitate managing (saving and reading) convolved model spectra in seda.ModelOptions.

  • distancefloat, optional

    Target distance (in pc) used to derive radii from scaling factors for models.

  • edistancefloat, optional

    Distance error (in pc).

Attributes:

Input parameters.

All input parameters are stored as attributes with their default values if not specified. Units: - flux_spectra, eflux_spectra, Phot, and ephot attributes are stored in erg/s/cm2/A.

Other parameters
N_spectraint

Number of input spectra (if fit_spectra).

lambda_eff_SVOfloat array

Effective wavelengths from the SVO for filters (if fit_photometry).

width_eff_SVOfloat array

Effective widths from the SVO for filters (if fit_photometry).

Example:

>>> import seda
>>>
>>> # input spectrum wl_input, flux_input, eflux_input
>>> wl_spectra = wl_input # in um
>>> flux_spectra = flux_input # in erg/cm^2/s/A
>>> eflux_spectra = eflux_input # in erg/cm^2/s/A
>>> res = 100 # input spectrum resolution
>>> my_data = seda.InputData(wl_spectra=wl_spectra, flux_spectra=flux_spectra,
>>>                          eflux_spectra=eflux_spectra, res=res)
    Input data loaded successfully

Author: Genaro Suárez

Model Options

class seda.input_parameters.ModelOptions(model=None, model_dir=None, params_ranges=None, wl_model=None, flux_model=None, path_save_spectra_conv=None, skip_convolution=False, path_save_syn_phot=None, skip_syn_phot=False)[source]

Description:

Define model options.

Parameters:

  • modelstr, optional (required if a model spectrum is not provided via wl_model and flux_model or for nested sampling)

    Label for any of the available atmospheric models. See more info in seda.models.Models.

  • model_dirstr, list, or array, optional (required if a model spectrum is not provided via wl_model and flux_model or for nested sampling)

    Path to the directory (str, list, or array) or directories (as a list or array) containing the model spectra (e.g., model_dir = ['path_1', 'path_2']). Avoid using paths with null spaces.

  • params_rangesdictionary, optional

    Minimum and maximum values for any free model parameters to select a model grid subset. E.g., params_ranges = {'Teff': [1000, 1200], 'logg': [4., 5.]} to consider spectra within those Teff and logg ranges. If a parameter range is not provided, the full range in model_dir is considered.

  • wl_modelarray, optional (required if model_dir is not provided)

    Wavelengths in micron of model spectrum.

  • flux_modelarray, optional (required if model_dir is not provided)

    Fluxes in erg/s/cm2/A of model spectrum.

  • path_save_spectra_conv: str, optional

    Directory path to store convolved model spectra. If not provided (default), the convolved spectra will not be saved. If the directory does not exist, it will be created. Otherwise, the spectra will be added to the existing folder. The convolved spectra will keep the same original names along with the res and lam_res parameters, e.g. ‘original_spectrum_name_R100at1um.nc’ for res=100 and lam_res=1. They will be saved as netCDF with xarray (it produces lighter files compared to normal ASCII files).

  • skip_convolution{True, False}, optional (default False)

    Convolution of model spectra (the slowest process when fitting spectra) can (True) or cannot (False) be avoided. Once the code has be run and the convolved spectra were stored in path_save_spectra_conv, the convolved grid can be reused for other input data with the same resolution as the convolved spectra. If ‘True’, model_dir should include the previously convolved spectra for res at lam_res in input_parameters.InputData.

  • path_save_syn_phot: str, optional

    Directory path to store the synthetic fluxes (in erg/s/cm2/A). If not provided (default), the synthetic photometry will not be saved. If the directory does not exist, it will be created. Otherwise, the photometry will be added to the existing folder. The synthetic photometry for different filters derived from the same model spectrum will be saved in a single ASCII table, named after the model with the suffix “_syn_phot.dat”. If a synthetic photometry file for a given model spectrum already exists, it will be updated to include photometry for any new filters as needed.

  • skip_syn_phot{True, False}, optional (default False)

    Synthetic photometry calculation (the lowest process when fitting photometry) can (True) or cannot (False) be avoided. Once the code has be run and the synthetic photometry was stored in path_save_syn_phot, the synthetic values can be reused for other input photometric SEDs that use the same set of filters. If ‘True’, model_dir should correspond to the directory with the synthetic photometry for filters in input_parameters.InputData.

Attributes:

Input parameters.

All input parameters are stored as attributes with their default values if not specified.

Example:

>>> import seda
>>>
>>> # models
>>> model = 'Sonora_Elf_Owl'
>>> model_dir = ['my_path/output_700.0_800.0/',
>>>              'my_path/output_850.0_950.0/'] # folders to seek model spectra
>>>
>>> # some parameter ranges to read a model grid subset
>>> params_ranges = {'Teff': [700, 900, 'logg': [4.0, 5.0]
>>>
>>> # load model options
>>> my_model = seda.ModelOptions(model=model, model_dir=model_dir,
>>>                              params_ranges=params_ranges)
    Model options loaded successfully

Author: Genaro Suárez

Chi-square Options

class seda.input_parameters.Chi2Options(my_data, my_model, fit_wl_range=None, disp_wl_range=None, model_wl_range=None, fit_phot_range=None, weight_label='dataset', extinction_free_param=False, scaling_free_param=True, scaling=None, avoid_IR_excess=False, IR_excess_limit=3, save_results=True, chi2_pickle_file=None, chi2_table_file=None)[source]

Description:

Define chi-square fit options.

Parameters:

  • my_datadictionary

    Output dictionary by input_parameters.InputData with input data.

  • my_modeldictionary

    Output dictionary by input_parameters.ModelOptions with model options.

  • fit_wl_rangefloat array or list, optional

    Minimum and maximum wavelengths (in micron) where each input spectrum will be compared to the models. E.g., fit_wl_range = np.array([[fit_wl_min1, fit_wl_max1], [fit_wl_min2, fit_wl_max2]]). This parameter is used if fit_spectra but ignored if only fit_photometry. Default values are the minimum and the maximum wavelengths of each input spectrum.

  • disp_wl_rangefloat array, optional

    Minimum and maximum wavelengths (in micron) to compute the median wavelength dispersion of model spectra to convolve them. It can take a set of values for each input spectrum e.g. disp_wl_range = np.array([[disp_wl_min1, disp_wl_max1], [disp_wl_min2, disp_wl_max2]]). Default values are fit_wl_range.

  • model_wl_rangearray or list, optional

    Minimum and maximum wavelength (in microns) to cut model spectra to keep only wavelengths of interest. Default values are the minimum and maximum wavelengths covered by the input spectra with a padding to avoid the point below. CAVEAT: the selected wavelength range of model spectra must cover the spectrophotometry used in the fit and a bit more (to avoid errors when resampling synthetic spectra using spectres).

  • fit_phot_rangefloat array or list, optional

    Minimum and maximum wavelengths (in micron) where photometry will be compared to the models. E.g., fit_phot_range = np.array([fit_phot_min1, fit_phot_max1]). This parameter is used if fit_photometry but ignored if only fit_spectra. Default values are the minimum and the maximum of the filter effective wavelengths from SVO.

  • weight_labelstr, optional (default dataset)

    Weight applied to each input data point (photometric and spectroscopic) during data fitting. This parameter is different from the weighting derived from the observed flux uncertainties, which typically appears as the denominator in the fit statistic. weight_label allows assigning different relative weights to photometry and spectra (when fit_spectra and fit_photometry are enabled), ensuring that photometric measurements do not have a negligible contribution to the fit, considering that photometric SEDs typically contain far fewer data points than spectroscopic SEDs.

    Available options are:

    • 'dataset' (default): each dataset, whether photometric or spectroscopic, is assigned a weight equal to the inverse of its total number of data points. All data contribute the same, even if they have very different numbers of points.

    • 'width': each spectroscopic data point is weighted by its wavelength resolution (wavelength step), and each photometric data point is weighted by the filter effective width. Broader filters receive larger weights, but the overall contribution of photometry may still differ from that of spectra.

    • 'none': apply the same weight to all input data points, which is equivalent to using no weighting at all (beyond the uncertainty-based weighting). Large datasets such as high-resolution spectra will dominate.

  • extinction_free_param{True, False}, optional (default False)
    Extinction as a free parameter:
    • 'False': null extinction is assumed and it will not change.

    • 'True': null extinction is assumed and it varies to minimize chi-square.

  • scaling_free_param{True, False}, optional (default True)
    Scaling as a free parameter:
    • 'True': to find the scaling that minimizes chi square for each model.

    • 'False': to fix scaling if radius and distance are known.

  • scaling: float, optional (required if scaling_free_param='False')

    Fixed scaling factor ((R/d)^2, R: object’s radius, d: distance to the object) to be applied to model spectra.

  • avoid_IR_excess{True, False}, optional (default False)

    Wavelengths longer than IR_excess_limit will ('True') or will not ('False') be avoided in the fit in case infrared excesses are expected.

  • IR_excess_limitfloat, optional (default 3 um).

    Shortest wavelength at which IR excesses are expected.

  • save_results{True, False}, optional (default True)

    Save (True) or do not save (False) seda.chi2_fit results.

  • chi2_pickle_filestr, optional

    Filename for the output dictionary stored as a pickle file, if save_results. Default name is ‘model_chi2_minimization.pickle’.

  • chi2_table_filestr, optional

    Filename for an output ascii table (if save_results) with relevant information from the fit. Default name is ‘model_chi2_minimization.dat’.

Attributes:

Input parameters either from this class or attributes from the InputData and ModelOptions classes.

All input parameters are stored as attributes with their default values if not specified.

Other parameters
spectra_namenumpy array

File names of selected model spectra

spectra_name_fullnumpy array

File names of selected model spectra with full absolute path.

if fit_spectra:
wl_spectra_minfloat

Minimum wavelength from the input spectra.

wl_spectra_maxfloat

Maximum wavelength from the input spectra.

N_datapointsint

Total number of data points in all input spectra.

N_model_spectraint

Number of model spectra selected within fit_wl_range.

wl_array_obs_fitlist

Nested list input spectra wavelengths within fit_wl_range for each selected model spectrum. This is convenient because model spectra do not necessary all have the same wavelength coverage.

flux_array_obs_fitlist

Nested list with input spectra fluxes (in erg/s/cm2/A) within fit_wl_range for each selected model spectrum.

eflux_array_obs_fitlist

Nested list with input spectra flux uncertainties (in erg/s/cm2/A) within fit_wl_range for each selected model spectrum.

wl_array_model_conv_resamlist

Nested list with wavelengths for the selected model spectra convolved using res and lam_res and resampled (based on the input wavelengths) within model_wl_range.

flux_array_model_conv_resamlist

Nested list with fluxes (in erg/s/cm2/A) for the selected model spectra convolved using res and lam_res and resampled (based on the input wavelengths) within model_wl_range.

wl_array_model_conv_resam_fitlist

Same as wl_array_model_conv_resam but within fit_wl_range.

flux_array_model_conv_resam_fit :

Same as flux_array_model_conv_resam but within fit_wl_range.

weight_spec_fitlist

Nested list with the weights assigned to each spectroscopic data point within the fit range considering the equation chi2 = weight * (data-model)^2 / edata^2.

if fit_photometry:
phot_fitnumpy array

Input photometry phot (in erg/s/cm2/A) within fit_phot_range and the model wavelength coverage.

ephot_fitnumpy array

Input photometry errors ephot (in erg/s/cm2/A) within fit_phot_range and the model wavelength coverage.

filters_fitnumpy array

Input filters filters within fit_phot_range and the model wavelength coverage.

lambda_eff_SVO_fitnumpy array

Effective wavelengths from SVO for filters_fit.

width_eff_SVO_fitnumpy array

Effective widths from SVO for filters_fit.

flux_syn_array_model_fitlist

Nested list with synthetic fluxes (in erg/s/cm2/A) for filters_fit for each selected model spectrum.

lambda_eff_array_model_fitnumpy array

Effective wavelengths (in micron) from the spectrum for filters_fit for each selected model spectrum.

width_eff_array_model_fitnumpy array

Effective width (in micron) from the spectrum for filters_fit for each selected model spectrum.

weight_phot_fitlist

Nested list with the weights assigned to each photometric data point within the fit range considering the equation chi2 = weight * (data-model)^2 / edata^2.

Example:

>>> import seda
>>>
>>> # input spectrum wl_input, flux_input, eflux_input
>>> fit_wl_range = np.array([value1, value2]) # to make the fit between value1 and value2
>>> my_chi2 = seda.Chi2FitOptions(my_data=my_data, my_model=my_model,
>>>                               fit_wl_range=fit_wl_range)
    Chi2 fit options loaded successfully

Author: Genaro Suárez

Bayesian Options

class seda.input_parameters.BayesOptions(my_data, my_model, fit_wl_range=None, disp_wl_range=None, model_wl_range=None, fit_phot_range=None, weight_label='dataset', R_range=None, chi2_pickle_file=None, bayes_pickle_file=None, grid=None, dynamic_sampling=True, nlive=500, save_results=True)[source]

Description:

Define Bayesian sampling options.

Parameters:

  • my_datadictionary

    Output dictionary by input_parameters.InputData with input data.

  • my_modeldictionary

    Output dictionary by input_parameters.ModelOptions with model options.

  • fit_wl_rangefloat array, optional

    Minimum and maximum wavelengths (in microns) where model spectra will be compared to the data. This parameter is used if fit_spectra but ignored if only fit_photometry. Default values are the minimum and the maximum wavelengths of each input spectrum. E.g., fit_wl_range = np.array([bayes_wl_min, bayes_wl_max]).

  • disp_wl_rangefloat array, optional

    Minimum and maximum wavelengths (in micron) to compute the median wavelength dispersion of model spectra to convolve them. It can take a set of values for each input spectrum e.g. disp_wl_range = np.array([[disp_wl_min1, disp_wl_max1], [disp_wl_min2, disp_wl_max2]]). Default values are fit_wl_range.

  • model_wl_rangearray or list, optional

    Minimum and maximum wavelength (in microns) to cut model spectra (to make the code faster). Default values are the same as fit_wl_range with a padding to avoid the point below. CAVEAT: the selected wavelength range of model spectra must cover the spectrophotometry used in the fit and a bit more (to avoid errors when resampling synthetic spectra using spectres)

  • fit_phot_rangefloat array or list, optional

    Minimum and maximum wavelengths (in micron) where photometry will be compared to the models. E.g., fit_phot_range = np.array([fit_phot_min1, fit_phot_max1]). This parameter is used if fit_photometry but ignored if only fit_spectra. Default values are the minimum and the maximum of the filter effective wavelengths from SVO.

  • weight_labelstr, optional (default dataset)

    Weight applied to each input data point (photometric and spectroscopic) during data fitting. This parameter is different from the weighting derived from the observed flux uncertainties, which typically appears as the denominator in the fit statistic. weight_label allows assigning different relative weights to photometry and spectra (when fit_spectra and fit_photometry are enabled), ensuring that photometric measurements do not have a negligible contribution to the fit, considering that photometric SEDs typically contain far fewer data points than spectroscopic SEDs.

    Available options are:

    • 'dataset' (default): each dataset, whether photometric or spectroscopic, is assigned a weight equal to the inverse of its total number of data points. All data contribute the same, even if they have very different numbers of points.

    • 'width': each spectroscopic data point is weighted by its wavelength resolution (wavelength step), and each photometric data point is weighted by the filter effective width. Broader filters receive larger weights, but the overall contribution of photometry may still differ from that of spectra.

    • 'none': apply the same weight to all input data points, which is equivalent to using no weighting at all (beyond the uncertainty-based weighting). Large datasets such as high-resolution spectra will dominate.

  • R_range: float array, optional (used in bayes_fit)

    Minimum and maximum radius values to sample the posterior for radius. It requires the parameter distance in input_parameters.InputData.

  • ‘chi2_pickle_file’dictionary, optional

    Pickle file with a dictionary with the results from the chi-square minimization by chi2_fit.chi2. If given, the grid nodes around the best fit will be used as params_ranges to select a grid subset and as sampling priors. Otherwise, params_ranges provided in ModelOptions will be considered.

  • grid: dictionary, optional

    Model grid ('wavelength' and 'flux') generated by seda.utils.read_grid to interpolate model spectra. If not provided (default), then the grid is read (model and model_dir must be provided). If provided, the code will skip reading the grid, which will save some time (a few minutes).

  • dynamic_sampling: {True, False}, optional (default True).

    Consider dynamic (True) or static (False) nested sampling. Read dynesty documentation for more info. Dynamic nested sampling is slower (~20-30%) than static nested sampling.

  • nlive: float, optional (default 500).

    Number of nested sampling live points.

  • save_results{True, False}, optional (default True)

    Save (True) or do not save (False) seda.bayes_fit results

  • bayes_pickle_filestr, optional

    Filename for the output dictionary stored as a pickle file, if save_results. Default name is ‘model_bayesian_sampling.pickle’.

Attributes:

Input parameters either from this class or attributes from the InputData and ModelOptions classes.

All input parameters are stored as attributes with their default values if not specified.

Other parameters
gridlist

Nested list of dictionaries containing the selected model spectra grid and their associated unique free-parameter values. If fit_spectra, a dictionary including the selected model spectra convolved using res and lam_res and resampled (based on the input wavelengths) within fit_wl_range. If fit_photometry, a dictionary containing synthetic model fluxes (in erg/s/cm2/A) for filters_fit computed from the selected model spectra.

ndimint

Number of free parameters in the model fit equal to the number of free parameters plus radius (if a distance is provided).

filename_patternlist

String as a list with a common pattern in model spectra filenames.

params_uniquedictionary

Dictionary with unique values for each free parameters in the selected models.

params_priorsdictionary

Dictionary with the prior ranges for each model free parameter.

if fit_spectra:
wl_spectra_minfloat

Minimum wavelength from the input spectra.

wl_spectra_maxfloat

Maximum wavelength from the input spectra.

N_datapointsint

Total number of data points in all input spectra.

wl_spectra_fitlist

Nested list input spectra wavelengths within fit_wl_range for each selected model spectrum. This is convenient because model spectra do not necessary all have the same wavelength coverage.

flux_spectra_fitlist

Nested list with input spectra fluxes (in erg/s/cm2/A) within fit_wl_range for each selected model spectrum.

eflux_spectra_fitlist

Nested list with input spectra flux uncertainties (in erg/s/cm2/A) within fit_wl_range for each selected model spectrum.

weight_spec_fitlist

Nested list with the weights assigned to each spectroscopic data point within the fit range considering the equation chi2 = weight * (data-model)^2 / edata^2.

if fit_photometry:
phot_fitnumpy array

Input photometry phot (in erg/s/cm2/A) within fit_phot_range and the model wavelength coverage.

ephot_fitnumpy array

Input photometry errors ephot (in erg/s/cm2/A) within fit_phot_range and the model wavelength coverage.

filters_fitnumpy array

Input filters filters within fit_phot_range and the model wavelength coverage.

lambda_eff_SVO_fitnumpy array

Effective wavelengths from SVO for filters_fit.

width_eff_SVO_fitnumpy array

Effective widths from SVO for filters_fit.

weight_phot_fitlist

Nested list with the weights assigned to each photometric data point within the fit range considering the equation chi2 = weight * (data-model)^2 / edata^2.

Example:

>>> import seda
>>>
>>> fit_wl_range = np.array([value1, value2]) # to make the fit between value1 and value2
>>> my_bayes = seda.Chi2FitOptions(my_data=my_data, my_model=my_model,
>>>                               fit_wl_range=fit_wl_range)
    Bayes fit options loaded successfully

Author: Genaro Suárez

Models

class seda.models.Models(model=None)[source]

Description:

See available atmospheric models and get basic parameters from a desired model grid.

Parameters:

  • modelstr, optional.

    Atmospheric models for which basic information will be read. See available models with seda.models.Models().available_models.

Attributes:

  • available_models (list) : Atmospheric models available on SEDA.

  • ref (str) : Reference to model (if provided).

  • name (str) : Name of model (if provided).

  • bibcode (str) : bibcode identifier for model (if provided).

  • ADS (str) : ADS links to model (if provided) reference.

  • download (str) : link to download model (if provided).

  • filename_pattern (str)common pattern in all spectra filenames in model (if provided).

    It is used to avoid other potential files in the same directory with model spectra.

  • filename_trim (list) : start and end indices of filenames to trim, selecting only the relevant part for display.

  • free_params (list) : free parameters in model (if provided).

  • params (dict) : values (including repetitions) for each free parameter in model (if provided).

  • params_unique (dict) : unique (no repetitions) values for each free parameter in model (if provided).

Returns:

NoneType

Example:

>>> import seda
>>>
>>> # see available atmospheric models
>>> seda.Models().available_models
    ['BT-Settl',
     'ATMO2020',
     'Sonora_Elf_Owl',
     'SM08',
     'Sonora_Bobcat',
     'Sonora_Diamondback',
     'Sonora_Cholla',
     'LB23']
>>>
>>> # see link to the reference paper
>>> seda.Models('Sonora_Elf_Owl').ADS
    'https://ui.adsabs.harvard.edu/abs/2024ApJ...963...73M/abstract'
>>>
>>> # see free parameters in one of the models
>>> seda.Models('Sonora_Elf_Owl').free_params
    ['Teff', 'logg', 'logKzz', 'Z', 'CtoO']

Author: Genaro Suárez

get_parameters(return_type='dict', include_values=True)[source]

Return all user-facing attributes (exclude __dunder__ names).

model_ranges()[source]

Read coverage of model free parameters.

Author: Genaro Suárez

seda.models.read_PT_profile(filename, model)[source]

Description:

Read a PT profile from atmospheric models

Parameters:

  • modelstr

    Atmospheric models. See available models in input_parameters.ModelOptions.

  • filename: str

    Spectrum file name with full path.

Returns:

Dictionary with model spectrum:
  • 'pressure' : pressure in bars

  • 'temperature' : temperature in K

Example:

>>> import seda
>>>
>>> # desired models and PT profile file
>>> model = 'Sonora_Diamondback'
>>> filename = 'my_path/Sonora_Diamondback/pressure-temperature_profiles/t1000g100f1_m-0.5_co1.0.pt' # change my_path accordingly
>>>
>>> # read PT profile
>>> out = seda.read_PT_profile(filename=filename, model=model)
>>> P = out['pressure'] # pressure in bar
>>> T = out['temperature'] # temperature in K

Author: Genaro Suárez

seda.models.read_model_spectrum(spectrum_name_full, model, model_wl_range=None)[source]

Description:

Read a desired model spectrum.

Parameters:

  • modelstr

    Atmospheric models. See available models in input_parameters.ModelOptions.

  • spectrum_name_full: str

    Spectrum file name with full path.

  • model_wl_rangefloat array, optional

    Minimum and maximum wavelength (in microns) to cut the model spectrum.

Returns:

Dictionary with model spectrum:
  • 'wl_model' : wavelengths in microns

  • 'flux_model' : fluxes in erg/s/cm2/A

  • 'flux_model_Jy' : fluxes in Jy

Author:

Genaro Suárez

Date:

Created: 2021-05-12 Last Modified: 2026-03-25

seda.models.separate_params(model, spectra_name, save_results=False, out_file=None)[source]

Description:

Extract parameters from the file names for model spectra.

Parameters:

  • modelstr

    Atmospheric models. See available models in input_parameters.ModelOptions.

  • spectra_namearray or list

    Model spectra names (without full path).

  • save_results{True, False}, optional (default False)

    Save (True) or do not save (False) the output as a pickle file named ‘model_free_parameters.pickle’.

  • out_filestr, optional

    File name to save the results as a pickle file (it can include a path e.g. my_path/free_params.pickle). Default name is ‘model_free_parameters.pickle’ and is stored at the notebook location.

Returns:

Dictionary with parameters for each model spectrum.
  • spectra_name : model spectra names.

  • params: model free parameters for the spectra.

Example:

>>> import seda
>>>
>>> model = 'Sonora_Elf_Owl'
>>> spectra_name = np.array(['spectra_logzz_4.0_teff_750.0_grav_178.0_mh_0.0_co_1.0.nc',
>>>                          'spectra_logzz_2.0_teff_800.0_grav_316.0_mh_0.0_co_1.0.nc'])
>>> seda.models.separate_params(spectra_name=spectra_name, model=model)
    {'spectra_name': array(['spectra_logzz_4.0_teff_750.0_grav_178.0_mh_0.0_co_1.0.nc',
            'spectra_logzz_2.0_teff_800.0_grav_316.0_mh_0.0_co_1.0.nc'],
           dtype='<U56'),
     'params': {'Teff': array([750., 800.]),
      'logg': array([4.25, 4.5 ]),
      'logKzz': array([4., 2.]),
      'Z': array([0., 0.]),
      'CtoO': array([1., 1.])}}
Author:

Genaro Suárez

Date:

Created: 2021-05-12 Last Modified: 2026-03-25

Physical Parameters

seda.phy_params.bol_lum(output_fit=None, wl_spectra=None, flux_spectra=None, eflux_spectra=None, distance=None, edistance=None, flux_unit=None, wl_model=None, flux_model=None, params=None, scale_model=True, convolve_model=True, res=None, lam_res=None, complement_SED=True)[source]

Description:

Calculate bolometric luminosity by integrated the input SED complemented with the best model fit.

Parameters:

  • output_fitdictionary or str, optional (required if no input model spectrum is provided)

    Output dictionary with the results from chi2 or bayes. It can be either the name of the pickle file or simply the output dictionary.

  • wl_spectrafloat array or list, optional (require if output_chi2 is not provided)

    Wavelength in micron of the spectra to construct an SED. For multiple spectra, provide them as a list (e.g., wl_spectra = [wl_spectrum1, wl_spectrum2]).

  • flux_spectrafloat array or list, optional (require if output_chi2 is not provided)

    Fluxes for the input spectra in units indicated by flux_unit. Use a list for multiple spectra (similar to wl_spectra).

  • eflux_spectrafloat array or list, optional (require if output_chi2 is not provided)

    Fluxes uncertainties in units indicated by flux_unit. Use a list for multiple spectra (similar to wl_spectra).

  • flux_unitstr, optional (default 'erg/s/cm2/A')

    Units of flux: 'Jy', 'erg/s/cm2/A', or erg/s/cm2/um.

  • distancefloat, optional (require if output_chi2 is not provided)

    Target distance (in pc) used to obtain luminosity from total flux.

  • edistancefloat, optional (require if output_chi2 is not provided)

    Distance error (in pc).

  • wl_modelarray, optional (required if model_dir is not provided)

    Wavelengths in micron of model spectrum to complement the input observed SED.

  • flux_modelarray, optional (required if model_dir is not provided)

    Fluxes in erg/s/cm2/A of model spectrum to complement the input observed SED.

  • paramsdictionary, optional (require if output_chi2 is not provided)

    Value for each free parameter for the model spectrum used in the hybrid SED.

  • scale_model{True, False}, optional (default True)

    Label to indicate if the input model spectrum needs to be scaled (True) by minimizing chi-square or it was already scaled (False).

  • convolve_model{True, False}, optional (default True)

    Label to indicate if the input model spectrum needs (True) or does not need (False) to be convolved.

  • resfloat, list or array, optional (required if convolve_model)

    Resolving power (R=lambda/delta(lambda) at lam_res) of input spectra to smooth model spectra. For multiple input spectra, res should be a list or array with a value for each spectrum.

  • lam_resfloat, list or array, optional

    Wavelength of reference at which res is given (because resolution may change with wavelength). For multiple input spectra, lam_res should be a list or array with a value for each spectrum. Default is the integer closest to the median wavelength for each input spectrum. If lam_res is provided, the values are also rounded to the nearest integer. This will facilitate managing (saving and reading) convolved model spectra in seda.ModelOptions.

  • complement_SED{True, False}, optional (default True)

    Label indicating if the input spectra will (True) or will not (False) be complemented with a model spectrum.

Returns:

Dictionary with derived parameters:
  • 'flux_tot' : total flux (in erg/s/cm2/A) by integrating the hybrid SED.

  • 'eflux_tot' : uncertainty (in erg/s/cm2/A) associated to total flux.

  • 'Lbol_tot' : bolometric luminosity (in Lsun) from the total flux.

  • 'eLbol_tot' : bolometric luminosity uncertainty (in Lsun).

  • 'logLbol_tot' : logarithmic bolometric luminosity.

  • 'elogLbol_tot' : logarithmic bolometric luminosity uncertainty.

  • 'flux_tot_obs' : total flux (in erg/s/cm2/A) by integrating the observed SED (if complement_SED).

  • 'eflux_tot_obs' : uncertainty (in erg/s/cm2/A) associated to the observed flux (if complement_SED).

  • 'Lbol_tot_obs' : bolometric luminosity (in Lsun) from the observed flux (if complement_SED).

  • 'eLbol_tot_obs' : bolometric luminosity uncertainty (in Lsun) from the observed flux (if complement_SED).

  • 'logLbol_tot_obs' : logarithmic bolometric luminosity from the observed flux (if complement_SED).

  • 'elogLbol_tot_obs' : logarithmic bolometric luminosity uncertainty from the observed flux (if complement_SED).

  • 'contribution_percentage' : contribution (in percentage) of each input spectrum to the total flux or luminosity (if complement_SED).

  • 'contribution_percentage_obs' : contribution (in percentage) of each input spectrum to the observed flux or luminosity (if complement_SED).

  • 'N_spectra' : number of input spectra (if complement_SED).

  • 'completeness_obs' : completeness of the observed SED with respect to the hybrid SED (if complement_SED).

  • 'wl_SED' : wavelengths in micron of the hybrid SED (if complement_SED).

  • 'flux_SED' : fluxes in erg/s/cm2/A the hybrid SED (if complement_SED).

  • 'eflux_SED' : fluxes uncertainties in erg/s/cm2/A the hybrid SED (if complement_SED).

  • 'params' : dictionary with free parameter values for the model spectrum used in the hybrid SED (if complement_SED).

  • 'wl_spectra' : input wl_spectra (if complement_SED).

  • 'flux_spectra' : input flux_spectra (if complement_SED).

  • 'eflux_spectra' : input eflux_spectra (if complement_SED).

  • 'wl_model' : input wl_model (if complement_SED).

  • 'flux_model' : input flux_model (if complement_SED).

Author: Genaro Suárez

Date: 2025-04-20

seda.phy_params.teff(Lbol, eLbol, R, eR, n_mc=10000, central='median', error='percentile', percentiles=(16, 84))[source]

Description:

Calculate effective temperature using the Stefan–Boltzmann law considering a known bolometric luminosity and radius.

Parameters:

  • Lbolfloat

    Bolometric luminosity in units of L_sun.

  • eLbolfloat

    Uncertainty in luminosity (L_sun).

  • Rfloat

    Radius in units of R_jup.

  • eRfloat

    Uncertainty in radius (R_jup).

  • n_mcint, optional (default 10000)

    Number of Monte Carlo samples for uncertainties.

  • centralstr, optional (default “median”)

    “mean” or “median” for central value.

  • errorstr, optional (default “percentile”)

    “std” or “percentile”.

  • percentilestuple or list, optional (default [16, 84])

    Lower and upper percentiles for uncertainty.

Returns:

  • Tefffloat

    Effective temperature in K.

  • eTefffloat or tuple
    • Effective temperature uncertainty in K.

    • If error=”std”: error is a scalar

    • If error=”percentile”: error is a tuple (lower_err, upper_err)

Example:

>>> import seda
>>>
>>> # input parameters
>>> Lbol, eLbol = 6.324e-5, 6.978e-6 # in Lsun
>>> R, eR = 1.018, 0.059 # in Rjup
>>>
>>> # derive Teff (in K) from Stefan–Boltzmann law
>>> seda.phy_params.teff(Lbol=Lbol, eLbol=eLbol, R=R, eR=eR)
    (1592.0020910445828, (57.98628122105015, 65.18365052510921))

Author: Genaro Suárez

Date: 2026-05-25

Plots

seda.plots.plot_bayes_fit(output_bayes, xlog=False, ylog=True, xrange=None, yrange=None, ori_res=False, res=None, lam_res=None, model_dir_ori=None, out_file=None, save=True)[source]

Description:

Plot the spectra and best model fit from the Bayesian sampling.

Parameters:

  • output_bayesstr

    Output dictionary with the results from the nested sampling by bayes. It can be either the name of the pickle file or simply the output dictionary.

  • xlog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale to plot the horizontal axis.

  • ylog{True, False}, optional (default True)

    Use logarithmic (True) or linear (False) scale to plot the vertical axis.

  • xrangelist or array, optional (default is full range in the input spectra)

    Horizontal range of the plot.

  • yrangelist or array, optional (default is full range in xrange)

    Vertical range of the plot.

  • ori_res{True, False}, optional (default False)

    Plot (True) or do not plot (False) the best model spectrum with its original resolution.

  • model_dir_oristr, list, or array

    Path to the directory (str, list, or array) or directories (as a list or array) containing the model spectra with the original resolution. This parameter is needed to plot the original resolution spectra (if ori_res is True) when seda.chi2 was run skipping the model spectra convolution (if skip_convolution is True).

  • resfloat, optional

    Spectral resolution (at lam_res) desired to smooth model spectra with original resolution. It is needed when only photometry is fit.

  • lam_resfloat, optional

    Wavelength of reference at which res is given. Default is the integer closest to the median wavelength of the spectrum.

  • out_filestr, optional

    File name to save the figure (it can include a path e.g. my_path/figure.pdf). Note: use a supported format by savefig() such as pdf, ps, eps, png, jpg, or svg. Default name is ‘SED_``model``_bayes.pdf’, where model is read from output_bayes.

  • save{True, False}, optional (default True)

    Save ('True') or do not save ('False') the resulting figure.

Returns:

Plot of the spectra and best model fit from the Bayesian sampling that will be stored if save with the name out_file.

Example:

>>> import seda
>>>
>>> # plot and save the best model fit from the Bayesian sampling to Sonora Elf Owl models
>>> # 'Sonora_Elf_Owl_bayesian_sampling.pickle' is the output by ``bayes_fit.bayes``.
>>> seda.plot_bayes_fit(output_bayes='Sonora_Elf_Owl_bayesian_sampling.pickle')

Author: Genaro Suárez

seda.plots.plot_calibrate_spectrum(dic, xrange=None, yrange=None)[source]

Description:

Plot flux-calibrated spectrum with observed photometry used as a reference.

Parameters:

  • dicdictionary

    Output dictionary from synthetic_photometry.calibrate_spectrum.

  • xrangelist or array, optional (default is full range in the input spectra)

    Horizontal range of the plot.

  • yrangelist or array, optional (default is full range in xrange)

    Vertical range of the plot.

Returns:

Plot showing a flux-calibrated spectrum, the observed photometry used as a reference, and synthetic photometry for comparison.

Example:

>>> import seda
>>>
>>> # Plot of the flux-calibrated spectrum with synthetic photometry and observed photometry.
>>> # 'dic' is the output dictionary from `synthetic_photometry.calibrate_spectrum``.
>>> # Show spectrum between 1 and 2.5 microns, as an example.
>>> seda.plot_calibrate_spectrum(dic=dic, xrange=[1, 2.5])

Author: Genaro Suárez

Date: 2026-05-06

seda.plots.plot_chi2_fit(output_chi2, N_best_fits=1, xlog=False, ylog=True, xrange=None, yrange=None, plot_title=None, ori_res=False, res=None, lam_res=None, model_dir_ori=None, out_file=None, save=True)[source]

Description:

Plot spectra with the best model fits from the chi-square minimization.

Parameters:

  • output_chi2dictionary or str

    Output dictionary with the results from the chi-square minimization by chi2. It can be either the name of the pickle file or simply the output dictionary.

  • N_best_fitsint

    Number (default 1) of best model fits for plotting.

  • xlog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale to plot the horizontal axis.

  • ylog{True, False}, optional (default True)

    Use logarithmic (True) or linear (False) scale to plot the vertical axis.

  • xrangelist or array, optional (default is full range in the input spectra)

    Horizontal range of the plot.

  • yrangelist or array, optional (default is full range in xrange)

    Vertical range of the plot.

  • set_titlestr, optional

    Title for the plot which, if not provided, will be ‘models.Models(model).name Atmospheric Models’.

  • ori_res{True, False}, optional (default False)

    Plot (True) or do not plot (False) model spectra with the original resolution.

  • model_dir_oristr, list, or array

    Path to the directory (str, list, or array) or directories (as a list or array) containing the model spectra with the original resolution. This parameter is needed to plot the original resolution spectra (if ori_res is True) when seda.chi2 was run skipping the model spectra convolution (if skip_convolution is True).

  • resfloat, optional

    Spectral resolution (at lam_res) desired to smooth model spectra with original resolution. It is needed when only photometry is fit.

  • lam_resfloat, optional

    Wavelength of reference at which res is given. Default is the integer closest to the median wavelength of the spectrum.

  • out_filestr, optional

    File name to save the figure (it can include a path e.g. my_path/figure.pdf). Note: use a supported format by savefig() such as pdf, ps, eps, png, jpg, or svg. Default name is ‘SED_``model``_chi2.pdf’, where model is read from output_chi2.

  • save{True, False}, optional (default True)

    Save ('True') or do not save ('False') the resulting figure.

Returns:

Plot of the spectra and best model fits from the chi-square minimization that will be stored if save with the name out_file.

Example:

>>> import seda
>>>
>>> # plot and save the best three model fits from the model comparison to the ATMO 2020 models
>>> # 'ATMO2020_chi2_minimization.pickle' is the output by ``chi2_fit.chi2``.
>>> seda.plot_chi2_fit(output_chi2='ATMO2020_chi2_minimization.pickle', N_best_fits=3)

Author: Genaro Suárez

Date: 2024-10, 2025-09-06

seda.plots.plot_chi2_red(output_chi2, N_best_fits=1, xlog=False, ylog=False, out_file=None, save=True)[source]

Description:

Plot reduced chi square as a function of wavelength for the best model fits form the chi-square minimization.

Parameters:

  • output_chi2dictionary or str

    Output dictionary with the results from the chi-square minimization by chi2. It can be either the name of the pickle file or simply the output dictionary.

  • N_best_fitsint

    Number (default 1) of best model fits for plotting.

  • xlog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale to plot the horizontal axis.

  • ylog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale to plot the vertical axis.

  • out_filestr, optional

    File name to save the figure (it can include a path e.g. my_path/figure.pdf). Note: use file formats (pdf, eps, or ps). Image formats do not work because the figure is saved in several pages, according to N_best_fits. Default name is ‘SED_``model``_chi2.pdf’, where model is read from output_chi2.

  • save{True, False}, optional (default True)

    Save ('True') or do not save ('False') the resulting figure.

Returns:

Plot of reduced chi-square against wavelength for the best model fits indicated by N_best_fits that will be stored if save with the name out_file.

Example:

>>> import seda
>>>
>>> # plot and save the best three model fits from the model comparison to the ATMO 2020 models
>>> # 'ATMO2020_chi2_minimization.pickle' is the output by ``chi2_fit.chi2``.
>>> seda.plot_chi2_red(output_chi2='ATMO2020_chi2_minimization.pickle', N_best_fits=3)

Author: Genaro Suárez

Date: 2024-10, 2025-09-07

seda.plots.plot_full_SED(out_bol_lum, xlog=True, ylog=True, xrange=None, yrange=None, spectra_label=None, model_label=None, out_file=None, save=True)[source]

Description:

Plot full SED considering observed data completed with a model spectrum.

Parameters:

  • out_bol_lumdictionary

    Output dictionary from bol_lum.

  • xlog{True, False}, optional (default True)

    Use logarithmic (True) or linear (False) scale to plot the horizontal axis.

  • ylog{True, False}, optional (default True)

    Use logarithmic (True) or linear (False) scale to plot the vertical axis.

  • xrangelist or array, optional (default is full hybrid SED range)

    Horizontal range of the plot.

  • yrangelist or array, optional (default is full hybrid SED range)

    Vertical range of the plot.

  • spectra_labellist, optional

    List of strings to label each input spectrum in the SED. Default is ‘Observed spectrum #i’.

  • model_labelstr, optional

    String to label the model spectrum in the SED. Default is ‘Model spectrum’.

  • out_filestr, optional

    File name to save the figure (it can include a path e.g. my_path/figure.pdf). Note: use a supported format by savefig() such as pdf, ps, eps, png, jpg, or svg. Default name is ‘Hybrid_SED.pdf’.

  • save{True, False}, optional (default True)

    Save ('True') or do not save ('False') the resulting figure.

Returns:

Plot of full SED from observations complemented with a model that will be stored if save with the name out_file.

Example:

>>> import seda
>>>
>>> # plot and save a hybrid SED using observation and models
>>> # 'out_bol_lum' is the output of ``bol_lum``
>>> seda.plot_full_SED(out_bol_lum=out_bol_lum)

Author: Genaro Suárez

Date: 2025-06-01

seda.plots.plot_model_coverage(model, xparam, yparam, model_dir=None, params_ranges=None, xrange=None, yrange=None, xlog=False, ylog=False, out_file=None, save=False)[source]

Description:

Plot model grid coverage for two desired parameters.

Parameters:

  • modelstr

    Atmospheric models. See available models in seda.Models().available_models.

  • xparamstr

    Parameter in model to be plotted in the horizontal axis. seda.Models('model').params_unique provides more details about available parameters for model.

  • yparamstr

    Parameter in model to be plotted in the vertical axis. seda.Models('model').params_unique provides more details about available parameters for model.

  • model_dirstr or list, optional

    Path to the directory (str or list) or directories (as a list) containing model spectra (e.g., model_dir = ['path_1', 'path_2']) to display their parameters coverage. If not provided, the code will read pre-saved pickle files the full coverage of model.

  • params_rangesdictionary, optional

    Minimum and maximum values for any model free parameters to select a model grid subset. E.g., params_ranges = {'Teff': [1000, 1200], 'logg': [4., 5.]} to consider spectra within those Teff and logg ranges. If a parameter range is not provided, the full range in model_dir or the pre-saved pickle files is considered.

  • xrangelist or array, optional (default is full range in the input spectra)

    Horizontal range of the plot.

  • yrangelist or array, optional (default is full range in xrange)

    Vertical range of the plot.

  • xlog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale to plot the horizontal axis.

  • ylog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale to plot the vertical axis.

  • out_filestr, optional

    File name to save the figure (it can include a path e.g. my_path/figure.pdf). Note: use a supported format by savefig() such as pdf, ps, eps, png, jpg, or svg. Default name is ‘model``_``xparam``_``yparam.pdf’.

  • save{True, False}, optional (default True)

    Save ('True') or do not save ('False') the resulting figure.

Returns:

Plot of yparam versus xparam for model that will be stored if save with the name out_file.

Example:

>>> import seda
>>>
>>> # plot logg vs. Teff for the ATMO 2020 models
>>> model = 'ATMO2020'
>>> model_dir = ['my_path/CEQ_spectra/',
>>>              'my_path/NEQ_weak_spectra/',
>>>              'my_path/NEQ_strong_spectra/']
>>> seda.plot_chi2_fit(model=model, model_dir=model_dir, xparam='Teff', yparam='logg')

Author: Genaro Suárez

seda.plots.plot_model_resolution(model, spectra_name_full, xlog=True, ylog=False, xrange=None, yrange=None, delta_wl_log=False, resolving_power=True, out_file=None, save=False)[source]

Description:

Plot model grid spectral resolution or resolving power as a function of wavelength.

Parameters:

  • modelstr

    Atmospheric models. See available models in seda.Models().available_models.

  • spectra_name_full: str, list, or array

    Spectra file names with full path.

  • xlog{True, False}, optional (default True)

    Use logarithmic (True) or linear (False) scale for wavelength range.

  • ylog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale for resolution range.

  • xrangelist or array, optional (default is full range in the input spectra)

    Horizontal range of the plot.

  • yrangelist or array, optional (default is full range in xrange)

    Vertical range of the plot.

  • delta_wl_log{True, False}, optional (default False)

    Consider wavelength steps in linear (False) or logarithmic (True) scale.

  • resolving_power{True, False}, optional (default True)

    Calculate resolving power (True; R=lambda/Delta(lambda)) or spectral resolution (False, Delta(lambda)).

  • save{True, False}, optional (default True)

    Save ('True') or do not save ('False') the resulting figure.

  • out_filestr, optional

    File name to save the figure (it can include a path e.g. my_path/figure.pdf). Note: use a supported format by savefig() such as pdf, ps, eps, png, jpg, or svg. Default name is ‘model_resolution.pdf’.

Returns:

Plot of the resolution of the input model spectra that will be stored if save with the name out_file.

Example:

>>> import seda
>>>
>>> # plot and save the resolving power of a Sonora Diamondback model spectrum
>>> model = 'Sonora_Diamondback'
>>> spectra_name_full = 'my_path/t1000g1000f1_m0.0_co1.0.spec'
>>> seda.plot_model_resolution(model, spectra_name_full, save=True)

Author: Genaro Suárez

seda.plots.plot_synthetic_photometry(out_synthetic_photometry, xlog=False, ylog=False, out_file=None, save=False, spectrum_kwargs=None, phot_kwargs=None)[source]

Description:

Plot synthetic fluxes and input SED.

Parameters:

  • out_synthetic_photometrydictionary

    Output dictionary by synthetic_photometry.

  • xlog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale to plot wavelengths.

  • ylog{True, False}, optional (default False)

    Use logarithmic (True) or linear (False) scale to plot fluxes.

  • out_filestr, optional

    File name to save the figure (it can include a path e.g. my_path/figure.pdf). Note: use a supported format by savefig() such as pdf, ps, eps, png, jpg, or svg. Default name is ‘SED_synthetic_photometry.pdf’, where model is read from out_synthetic_photometry.

  • save{True, False}, optional (default True)

    Save ('True') or do not save ('False') the resulting figure.

  • sed_kwargsdict, optional

    Keyword arguments to customize the spectrum line plot (e.g., color, linewidth).

  • phot_kwargsdict, optional

    Keyword arguments to customize synthetic photometry points (errorbar) plot.

Returns:

Plot of the synthetic fluxes over the SED used to calculate the fluxes that will be stored if save with the name out_file.

Example:

>>> import seda
>>>
>>> # plot and save the data with derived synthetic fluxes
>>> # 'out_synthetic_photometry' is the output of ``synthetic_photometry.synthetic_photometry``
>>> seda.plot_synthetic_photometry(out_synthetic_photometry=out_synthetic_photometry, save=True)

Author: Genaro Suárez

Spectral Indices

seda.spectral_indices.spectral_indices.ammonia_index(wl, flux, eflux, reference='SM22', ammonia_wl=None, ammonia_window=None, continuum_wl=None, continuum_window=None, plot=False, plot_title=None, plot_xrange=None, plot_yrange=None, plot_save=False, plot_name=False)[source]

Description:

Measure the strength of the mid-infrared ammonia absorption considering the defined ammonia index in Cushing et al. (2006) and modified in Suárez & Metchev (2022).

Parameters:

  • wlarray

    Spectrum wavelengths in microns.

  • fluxarray

    Spectrum fluxes in Jy.

  • efluxarray

    Spectrum flux errors in Jy.

  • reference{SM22, C06}, optional (default SM22)

    Reference to set default parameters to measure the ammonia index. SM22 (default) for Suárez & Metchev (2022) or C08 for Cushing et al (2006).

  • ammonia_wlfloat, optional (default 10.6 um)

    Wavelength reference of the feature. Note: the default value is slightly smaller than the 10.8 um value in Suárez & Metchev (2022) to be centered better within the feature.

  • ammonia_windowfloat, optional (default 0.6 um)

    Wavelength window around ammonia_wl and continuum_wl used to calculate average fluxes.

  • continuum_wlfloat, optional (default 9.9 um)

    Wavelength reference of the feature continuum. Note: the default value is slightly smaller than the 10 um value in Suárez & Metchev (2022) to avoid including fluxes at the beginning of the ammonia feature.

  • continuum_windowfloat, optional (default 0.6 um)

    Wavelength window around continuum_wl used to calculate the average continuum flux.

  • plot{True, False}, optional (default False)

    Plot (True) or do not plot (False) the ammonia index measurement.

  • plot_titlestr, optional

    Plot title (default 'Ammonia Index Measurement'.

  • plot_xrangelist or array, optional

    Wavelength range (in microns) of the plot (default [5.2, 14] um).

  • plot_yrangelist or array, optional

    Flux range (in Jy) of the plot (default is the flux range in plot_xrange).

  • plot_save{True, False}, optional (default False)

    Save ('True') or do not save ('False') the resulting plot.

  • plot_namestr, optional

    Filename to store the plot. Default is 'Ammonia_index_measurement.pdf'.

Returns:

  • Dictionary
    Dictionary with ammonia index parameters:
    • 'ammonia_index' : ammonia index

    • 'eammonia_index' : ammonia index uncertainty

    • 'ammonia_flux' : flux at the absorption

    • 'eammonia_flux' : flux uncertainty at the absorption

    • 'continuum_flux' : flux at the absorption continuum

    • 'econtinuum_flux' : flux uncertainty at the absorption continuum

    • 'ammonia_wl' : input ammonia_wl

    • 'continuum_wl' : input continuum_wl

    • 'ammonia_window' : input ammonia_window

    • 'continuum_window' : input continuum_window

    • 'wl' : input wl

    • 'flux' : input flux

    • 'eflux' : input eflux

  • Plot of the ammonia index measurement that will be stored if plot_save.

Author: Genaro Suárez

seda.spectral_indices.spectral_indices.methane_index(wl, flux, eflux, reference='SM22', methane_wl=None, methane_window=None, continuum_wl=None, continuum_window=None, plot=False, plot_title=None, plot_xrange=None, plot_yrange=None, plot_save=False, plot_name=False)[source]

Description:

Measure the strength of the mid-infrared methane absorption considering the defined methane index in Cushing et al. (2006) and modified in Suárez & Metchev (2022).

Parameters:

  • wlarray

    Spectrum wavelengths in microns.

  • fluxarray

    Spectrum fluxes in Jy.

  • efluxarray

    Spectrum flux errors in Jy.

  • reference{SM22, C06}, optional (default SM22)

    Reference to set default parameters to measure the methane index. SM22 (default) for Suárez & Metchev (2022) or C08 for Cushing et al (2006).

  • methane_wlfloat, optional (default 7.65 um)

    Wavelength reference of the feature.

  • methane_windowfloat, optional (default 0.6 um)

    Wavelength window around methane_wl used to calculate average fluxes.

  • continuum_wlfloat, optional (default 9.9 um)

    Wavelength reference of the feature continuum. Note: the default value is slightly smaller than the 10 um value in Suárez & Metchev (2022) to avoid including fluxes at the beginning of the ammonia feature.

  • continuum_windowfloat, optional (default 0.6 um)

    Wavelength window around continuum_wl used to calculate the average continuum flux.

  • plot{True, False}, optional (default False)

    Plot (True) or do not plot (False) the methane index measurement.

  • plot_titlestr, optional

    Plot title (default 'Methane Index Measurement'.

  • plot_xrangelist or array, optional

    Wavelength range (in microns) of the plot (default [5.2, 14] um).

  • plot_yrangelist or array, optional

    Flux range (in Jy) of the plot (default is the flux range in plot_xrange).

  • plot_save{True, False}, optional (default False)

    Save ('True') or do not save ('False') the resulting plot.

  • plot_namestr, optional

    Filename to store the plot. Default is 'Methane_index_measurement.pdf'.

Returns:

  • Dictionary
    Dictionary with methane index parameters:
    • 'methane_index' : methane index

    • 'emethane_index' : methane index uncertainty

    • 'methane_flux' : flux at the absorption

    • 'emethane_flux' : flux uncertainty at the absorption

    • 'continuum_flux' : flux at the absorption continuum

    • 'econtinuum_flux' : flux uncertainty at the absorption continuum

    • 'methane_wl' : input methane_wl

    • 'continuum_wl' : input continuum_wl

    • 'methane_window' : input methane_window

    • 'continuum_window' : input continuum_window

    • 'wl' : input wl

    • 'flux' : input flux

    • 'eflux' : input eflux

  • Plot of the methane index measurement that will be stored if plot_save.

Author: Genaro Suárez

seda.spectral_indices.spectral_indices.silicate_index(wl, flux, eflux, silicate_wl=None, silicate_window=None, continuum_wl1=None, continuum_window1=None, continuum_wl2=None, continuum_window2=None, continuum_fit=None, continuum_error=None, reference='SM23', plot=False, plot_title=None, plot_xrange=None, plot_yrange=None, plot_save=False, plot_name=False)[source]

Description:

Measure the strength of the mid-infrared silicate absorption feature considering the silicate index defined in Suárez & Metchev (2022,2023).

Parameters:

  • wlarray

    Spectrum wavelengths in microns.

  • fluxarray

    Spectrum fluxes in Jy.

  • efluxarray

    Spectrum flux errors in Jy.

  • silicate_wlfloat, optional (default 9.3 um)

    Wavelength reference to indicate the center of silicate absorption.

  • silicate_windowfloat, optional (default 0.6 um)

    Wavelength window around silicate_wl used to calculate the average flux at the absorption.

  • continuum_wl1float, optional (default 7.45 um)

    Wavelength reference to indicate the short-wavelength continuum of silicate absorption.

  • continuum_window1float, optional (default 0.5 um))

    Wavelength window around continuum_wl1 used to select data points to fit a curve to continuum regions.

  • continuum_wl2float, optional (default 13.5 um)

    Wavelength reference to indicate the long-wavelength continuum of silicate absorption.

  • continuum_window2float, optional (default 1.0 um)

    Wavelength window around continuum_wl2 used to select data points to fit a curve to continuum regions.

  • reference{SM23, SM22}, optional (default SM23)

    Reference to set default parameters to measure the silicate index. SM23 (default) for Suárez & Metchev (2023) and SM22 for Suárez & Metchev (2022).

  • continuum_errorstring, optional (default fit)
    Label indicating the approach used to estimate the continuum flux uncertainty. Available options are:
    • 'fit' (default) : from the error of the curve fit.

    • 'empirical' : from the scatter of the data points and the typical flux errors in the continuum regions.

  • continuum_fitstring, optional (default exponential)
    Label indicating the curve fit to the continuum regions.
    • 'line' : fit a line to continuum fluxes in both regions.

    • 'exponential' (default) : fit an exponential (or a line in log-log space) to continuum fluxes in both regions.

  • plot{True, False}, optional (default False)

    Plot (True) or do not plot (False) the silicate index measurement.

  • plot_titlestr, optional

    Plot title (default 'Silicate Index Measurement'.

  • plot_xrangelist or array, optional

    Wavelength range (in microns) of the plot (default [5.2, 14] um).

  • plot_yrangelist or array, optional

    Flux range (in Jy) of the plot (default is the flux range in plot_xrange).

  • plot_save{True, False}, optional (default False)

    Save ('True') or do not save ('False') the resulting plot.

  • plot_namestr, optional

    Filename to store the plot. Default is 'Silicate_index_measurement.pdf'.

Returns:

  • Dictionary
    Dictionary with silicate index parameters:
    • 'silicate_index' : silicate index

    • 'esilicate_index' : silicate index uncertainty

    • 'silicate_flux' : flux at the absorption feature

    • 'esilicate_flux' : flux error at the absorption feature

    • 'continuum_flux' : flux at the continuum of the absorption

    • 'econtinuum_flux' : flux uncertainty at the continuum of the absorption

    • 'slope' : slope of the fit to the continuum regions

    • 'eslope' : slope uncertainty

    • 'constant' : constant or intercept of the linear fit

    • 'econstant' : constant uncertainty

    • 'silicate_wl' : input silicate_wl

    • 'silicate_window' : input silicate_window

    • 'continuum_wl1' : input continuum_wl1

    • 'continuum_window1' : input continuum_window1

    • 'continuum_wl2' : input continuum_wl2

    • 'continuum_window2' : input continuum_window2

    • 'continuum_fit' : input continuum_fit

    • 'continuum_error' : input continuum_error

    • 'wl' : input wl

    • 'flux' : input flux

    • 'eflux' : input eflux

  • Plot of the silicate index measurement that will be stored if plot_save.

Author: Genaro Suárez

seda.spectral_indices.spectral_indices.sio_index(wl, flux, eflux, sio_wl=None, sio_window=None, continuum_wl1=None, continuum_window1=None, continuum_wl2=None, continuum_window2=None, continuum_fit=None, continuum_error=None, reference='B26', plot=False, plot_title=None, plot_xrange=None, plot_yrange=None, plot_save=False, plot_name=False)[source]

Description:

Measure the strength of the mid-infrared SiO (silicon monoxide) absorption feature considering the SiO index defined in Beiler et al. (2026).

Parameters:

  • wlarray

    Spectrum wavelengths in microns.

  • fluxarray

    Spectrum fluxes in Jy.

  • efluxarray

    Spectrum flux errors in Jy.

  • sio_wlfloat, optional (default 7.9 um)

    Wavelength reference to indicate the center of SiO absorption.

  • sio_windowfloat, optional (default 0.3 um)

    Wavelength window around sio_wl used to calculate the average flux at the absorption.

  • continuum_wl1float, optional (default 7.3 um)

    Wavelength reference to indicate the short-wavelength continuum of SiO absorption.

  • continuum_window1float, optional (default 0.3 um))

    Wavelength window around continuum_wl1 used to select data points to fit a curve to continuum regions.

  • continuum_wl2float, optional (default 9.7 um)

    Wavelength reference to indicate the long-wavelength continuum of SiO absorption.

  • continuum_window2float, optional (default 0.3 um)

    Wavelength window around continuum_wl2 used to select data points to fit a curve to continuum regions.

  • reference{B26}, optional (default B26)

    Reference to set default parameters to measure the SiO index.

  • continuum_errorstring, optional (default fit)
    Label indicating the approach used to estimate the continuum flux uncertainty. Available options are:
    • 'fit' (default) : from the error of the curve fit.

    • 'empirical' : from the scatter of the data points and the typical flux errors in the continuum regions.

  • continuum_fitstring, optional (default linear)
    Label indicating the curve fit to the continuum regions.
    • 'line' : fit a line to continuum fluxes in both regions.

    • 'exponential' (default) : fit an exponential (or a line in log-log space) to continuum fluxes in both regions.

  • plot{True, False}, optional (default False)

    Plot (True) or do not plot (False) the SiO index measurement.

  • plot_titlestr, optional

    Plot title (default 'Silicate Index Measurement'.

  • plot_xrangelist or array, optional

    Wavelength range (in microns) of the plot (default [5.2, 14] um).

  • plot_yrangelist or array, optional

    Flux range (in Jy) of the plot (default is the flux range in plot_xrange).

  • plot_save{True, False}, optional (default False)

    Save ('True') or do not save ('False') the resulting plot.

  • plot_namestr, optional

    Filename to store the plot. Default is 'Silicate_index_measurement.pdf'.

Returns:

  • Dictionary
    Dictionary with SiO index parameters:
    • 'sio_index' : SiO index

    • 'esio_index' : SiO index uncertainty

    • 'sio_flux' : flux at the absorption feature

    • 'esio_flux' : flux error at the absorption feature

    • 'continuum_flux' : flux at the continuum of the absorption

    • 'econtinuum_flux' : flux uncertainty at the continuum of the absorption

    • 'slope' : slope of the fit to the continuum regions

    • 'eslope' : slope uncertainty

    • 'constant' : constant or intercept of the linear fit

    • 'econstant' : constant uncertainty

    • 'sio_wl' : input sio_wl

    • 'sio_window' : input sio_window

    • 'continuum_wl1' : input continuum_wl1

    • 'continuum_window1' : input continuum_window1

    • 'continuum_wl2' : input continuum_wl2

    • 'continuum_window2' : input continuum_window2

    • 'continuum_fit' : input continuum_fit

    • 'continuum_error' : input continuum_error

    • 'wl' : input wl

    • 'flux' : input flux

    • 'eflux' : input eflux

  • Plot of the SiO index measurement that will be stored if plot_save.

Author: Genaro Suárez

Date: 2026-04-02

seda.spectral_indices.spectral_indices.user_index(wl, flux, eflux, feature_wl, feature_window, continuum_wl=None, continuum_window=None, continuum_wl1=None, continuum_window1=None, continuum_wl2=None, continuum_window2=None, index_name=None, continuum_fit=None, continuum_error='fit', plot=False, plot_title=None, plot_xrange=None, plot_yrange=None, plot_save=False, plot_name=False)[source]

Description:

Spectral index defined by the user as the ratio between the feature continuum and the feature flux.

Parameters:

  • wlarray

    Spectrum wavelengths in microns.

  • fluxarray

    Spectrum fluxes in any flux units.

  • efluxarray

    Spectrum flux errors in the same units as flux.

  • feature_wlfloat

    Wavelength reference to indicate the center of feature absorption.

  • feature_windowfloat

    Wavelength window around feature_wl used to calculate the average flux at the absorption.

  • continuum_wlfloat, optional (required if continuum_fit=None)

    Wavelength reference to indicate the continuum of feature absorption.

  • continuum_windowfloat, optional (required if continuum_fit=None)

    Wavelength window around continuum_wl used to calculate the average continuum flux.

  • continuum_wl1float, optional (required if continuum_fit!=None)

    Wavelength reference to indicate the short-wavelength continuum of the feature absorption.

  • continuum_window1float, optional (required if continuum_fit!=None)

    Wavelength window around continuum_wl1 used to select data points to fit a curve to continuum regions.

  • continuum_wl2float, optional (required if continuum_fit!=None)

    Wavelength reference to indicate the long-wavelength continuum of the feature absorption.

  • continuum_window2float, optional (required if continuum_fit!=None)

    Wavelength window around continuum_wl2 used to select data points to fit a curve to continuum regions.

  • index_namestr (optional)

    Name the user wants to give to the index to be included in the plot label and title (if not plot_title). If not provided, the string User-defined will be used.

  • continuum_errorstring, optional (required if continuum_fit!=None; default fit)
    Label indicating the approach used to estimate the continuum flux uncertainty. Available options are:
    • 'fit' (default): from the error of the curve fit.

    • 'empirical': from the scatter of the data points and the typical flux errors in the continuum regions.

  • continuum_fitstring, optional (required if continuum_fit!=None)
    Label indicating the curve fit to the continuum regions.
    • 'line': fit a line to continuum fluxes in both regions.

    • 'exponential': fit an exponential (or a line in log-log space) to continuum fluxes in both regions.

  • plot{True, False}, optional (default False)

    Plot (True) or do not plot (False) the feature index measurement.

  • plot_titlestr, optional

    Plot title (default '{index_name} Index Measurement'.

  • plot_xrangelist or array, optional

    Wavelength range (in same units as wl) of the plot (default is min and max values of wl).

  • plot_yrangelist or array, optional

    Flux range (in same units as flux) of the plot (default is the flux range in plot_xrange).

  • plot_save{True, False}, optional (default False)

    Save ('True') or do not save ('False') the resulting plot.

  • plot_namestr, optional

    Filename to store the plot. Default is '{index_name}_index_measurement.pdf'.

Returns:

  • Dictionary
    Dictionary with user-defined index parameters:
    • 'feature_index' : feature index

    • 'efeature_index' : feature index uncertainty

    • 'feature_flux' : flux at the absorption feature

    • 'efeature_flux' : flux error at the absorption feature

    • 'continuum_flux' : flux at the continuum of the absorption

    • 'econtinuum_flux' : flux uncertainty at the continuum of the absorption

    • 'slope' : (if continuum_fit!=None) slope of the fit to the continuum regions

    • 'eslope' : (if continuum_fit!=None) slope uncertainty

    • 'constant' : (if continuum_fit!=None) constant or intercept of the linear fit

    • 'econstant' : (if continuum_fit!=None) constant uncertainty

    • 'feature_wl' : input feature_wl

    • 'feature_window' : input feature_window

    • 'continuum_wl1' : input continuum_wl1

    • 'continuum_window1' : input continuum_window1

    • 'continuum_wl2' : input continuum_wl2

    • 'continuum_window2' : input continuum_window2

    • 'wl' : input wl

    • 'flux' : input flux

    • 'eflux' : input eflux

  • Plot of the user-defined index measurement that will be stored if plot_save.

Author: Genaro Suárez

seda.spectral_indices.spectral_indices.user_index_integral(wavelength, flux, num_range: Tuple[float, float], den_range: Tuple[float, float], *, mode: Literal['ratio', 'difference'] = 'ratio', normalize: bool = False, plot: bool = False, plot_save: bool | str = False) float[source]

Compute a near-infrared spectral index as an integrated flux ratio or difference, with optional normalization and plotting of numerator/denominator regions.

Parameters:
  • wavelength (array-like) – Wavelength array (typically in microns).

  • flux (array-like) – Flux array corresponding to wavelength. Assumed 1D, same length as wavelength.

  • num_range (tuple of float) – Wavelength limits (lambda_min, lambda_max) for the numerator bandpass.

  • den_range (tuple of float) – Wavelength limits (lambda_min, lambda_max) for the denominator bandpass.

  • mode ({"ratio", "difference"}, optional) –

    Definition of the index.

    • "ratio": index = int(F_num) / int(F_den)

    • "difference": index = int(F_den) - int(F_num)

  • normalize (bool, optional) – If True, flux is median-normalized (ignoring NaNs) before computing the index.

  • plot (bool, optional) – If True, plot the spectrum and the two bandpasses.

  • plot_save (bool or str, optional) – If True, saves to default filename "user_index.pdf". If str, saves to that specific path.

Returns:

Spectral index value.

Return type:

float

Notes

For ratio-type indices, a global flux normalization typically cancels out and does not change the numerical value of the index. However, for difference-type indices (e.g., J-H defined as int(F_den) - int(F_num)), normalization directly affects the absolute scale of the index and therefore the boundaries of variability or classification regions. Users should ensure that the same normalization convention is applied consistently to both the target spectrum and any reference/template spectra.

Author

Natalia Oliveros-Gomez

seda.spectral_indices.spectral_indices.water_index(wl, flux, eflux, reference='SM22', continuum_wl=None, continuum_window=None, water_wl1=None, water_window1=None, water_wl2=None, water_window2=None, plot=False, plot_title=None, plot_xrange=None, plot_yrange=None, plot_save=False, plot_name=False)[source]

Description:

Measure the strength of the mid-infrared water absorption considering the defined water index in Cushing et al. (2006) and modified in Suárez & Metchev (2022).

Parameters:

  • wlarray

    Spectrum wavelengths in microns.

  • fluxarray

    Spectrum fluxes in Jy.

  • efluxarray

    Spectrum flux errors in Jy.

  • reference{SM22, C06}, optional (default SM22)

    Reference to set default parameters to measure the water index. SM22 (default) for Suárez & Metchev (2022) or C08 for Cushing et al (2006).

  • water_wl1float, optional (default 5.80 um)

    Wavelength reference to measure the flux in the first absorption dip.

  • water_window1float, optional (default 0.3 um)

    Wavelength window around water_wl1 used to calculate the average flux.

  • water_wl2float, optional (default 6.75 um)

    Wavelength reference to measure the flux in the second absorption dip.

  • water_window2float, optional (default 0.3 um)

    Wavelength window around water_wl2 used to calculate the average flux.

  • continuum_wlfloat, optional (default 6.25 um)

    Wavelength reference to measure the flux in the feature pseudo-continuum.

  • continuum_windowfloat, optional (default 0.3 um)

    Wavelength window around continuum_wl used to calculate the average flux.

  • plot{True, False}, optional (default False)

    Plot (True) or do not plot (False) the water index measurement.

  • plot_titlestr, optional

    Plot title (default 'Water Index Measurement'.

  • plot_xrangelist or array, optional

    Wavelength range (in microns) of the plot (default [5.2, 14] um).

  • plot_yrangelist or array, optional

    Flux range (in Jy) of the plot (default is the flux range in plot_xrange).

  • plot_save{True, False}, optional (default False)

    Save ('True') or do not save ('False') the resulting plot.

  • plot_namestr, optional

    Filename to store the plot. Default is 'Water_index_measurement.pdf'.

Returns:

  • Dictionary
    Dictionary with water index parameters:
    • 'water_index' : water index

    • 'ewater_index' : water index uncertainty

    • 'water_flux1' : flux at the short-wavelength part of the absorption

    • 'ewater_flux1' : flux uncertainty at the short-wavelength part of the absorption

    • 'water_flux2' : flux at the long-wavelength part of the absorption

    • 'ewater_flux2' : flux uncertainty at the long-wavelength part of the absorption

    • 'continuum_flux' : flux at the absorption continuum

    • 'econtinuum_flux' : flux uncertainty at the absorption continuum

    • 'water_wl1' : input water_wl1

    • 'continuum_wl1' : input continuum_wl1

    • 'water_wl2' : input water_wl2

    • 'continuum_wl2' : input continuum_wl2

    • 'water_window' : input water_window

    • 'continuum_window' : input continuum_window

    • 'wl' : input wl

    • 'flux' : input flux

    • 'eflux' : input eflux

  • Plot of the water index measurement that will be stored if plot_save.

Author: Genaro Suárez

Synthetic Photometry

seda.synthetic_photometry.synthetic_photometry.calibrate_spectrum(wl, flux, flux_unit, mag, emag, filters, eflux=None)[source]

Description:

Calibrate a spectrum by scaling it to match observed photometry.

Computes synthetic photometry from the input spectrum, compares it to observed magnitudes, derives an average magnitude offset, and applies a corresponding scaling factor to the spectrum.

Parameters:

  • wlarray

    Wavelength array in microns.

  • fluxarray

    Flux values in flux_unit unit corresponding to wl.

  • efluxarray, optional

    Uncertainties on the flux in flux_unit unit. If None, uncertainties are ignored.

  • flux_unitstr

    Flux and flux error units: 'erg/s/cm2/A', 'Jy', or erg/s/cm2/um.

  • magarray

    Observed magnitudes in mag.

  • emagarray

    Uncertainties on observed magnitudes in mag.

  • filterslist, array, or str

    List of filters (following SVO filter IDs) used for photometry.

Returns:

Python dictionary with the following parameters:
  • 'wl’: wavelength in microns of calibrated spectrum.

  • 'flux’: flux in flux_unit of calibrated spectrum.

  • 'eflux’: flux uncertainties in flux_unit of calibrated spectrum.

  • 'syn_mag’: synthetic magnitudes in mag for filters from the calibrated spectrum.

  • 'esyn_mag’: synthetic magnitude errors in mag for filters from the calibrated spectrum.

  • 'syn_flux’: synthetic fluxes in flux_unit for filters from the calibrated spectrum.

  • 'esyn_flux’: synthetic flux errors in flux_unit for filters from the calibrated spectrum.

  • 'scaling’: scaling factor applied to the input spectrum to calibrate it.

  • 'flux_unit’: units of input spectrum fluxes and errors.

Example:

>>> # Flux-calibrate a near-infrared spectrum using 2MASS photometry.
>>> # Assume the spectrum wavelength, flux and flux errors are loaded in the variable wl, flux, and eflux,
>>> # and the units of fluxes are 'erg/s/cm2/um'.
>>> flux_unit='erg/s/cm2/um'
>>>
>>> # Example of 2MASS photometry
>>> filters = ['2MASS/2MASS.J', '2MASS/2MASS.H', '2MASS/2MASS.Ks']
>>> mag = [13.997, 13.284, 12.829]
>>> emag = [0.032, 0.036, 0.029]
>>>
>>>     # calibrate spectrum
>>> out = seda.synthetic_photometry.calibrate_spectrum(wl=wl, flux=flux, eflux=eflux,
                                                       flux_unit=flux_unit,
                                                       mag=mag, emag=emag, filters=filters)
>>>
>>> # visualize the results
>>> seda.plots.plot_calibrate_spectrum(out)

Author: Genaro Suárez

Date: 2026-05-04

seda.synthetic_photometry.synthetic_photometry.convert_flux(flux, wl, unit_in, unit_out, eflux=None)[source]

Description:

Convert fluxes from Jy to erg/s/cm2/A or vice versa.

Parameters:

  • fluxarray, list, or float

    Input fluxes in units specified by unit_in.

  • wlarray, float

    Wavelengths (in microns) associated to flux.

  • unit_instr

    Units of flux: 'Jy' or 'erg/s/cm2/A'.

  • unit_outstr

    Units of output fluxes: 'Jy' or 'erg/s/cm2/A'.

  • efluxarray, float, optional

    Flux uncertainties for flux in unit_in.

Returns:

Dictionary with converted fluxes:
  • 'flux_in' : input fluxes

  • 'flux_out' : output fluxes

  • 'wl_in' : input wavelengths

  • 'eflux_in' : (if eflux) input flux uncertainties

  • 'eflux_out' : (if eflux) output flux uncertainties

  • 'unit_in' : unit_in

  • 'unit_out' : unit_out

Example:

>>> # convert fluxes from Jy to erg/s/cm2/A
>>> import seda
>>> import numpy as np
>>>
>>> flux = np.array([0.005, 0.006]) # test fluxes in Jy
>>> wl = np.array([1.23, 2.16]) # test wavelengths in microns
>>> eflux = flux/10. # test flux errors in Jy
>>>
>>> seda.synthetic_photometry.convert_flux(flux=flux, wl=wl, eflux=eflux, unit_in='Jy', unit_out='erg/s/cm2/A')
    {'flux_in': array([0.005, 0.006]),
     'flux_out': array([9.90787422e-16, 3.85535568e-16]),
     'wl_in': array([1.23, 2.16]),
     'unit_in': 'Jy',
     'unit_out': 'erg/s/cm2/A',
     'eflux_in': array([0.0005, 0.0006]),
     'eflux_out': array([9.90787422e-17, 3.85535568e-17])}

Author: Genaro Suárez

seda.synthetic_photometry.synthetic_photometry.flux_to_mag(flux, filters, flux_unit='Jy', eflux=None, svo_data=None)[source]

Description:

Convert fluxes into magnitudes.

Parameters:

  • fluxarray, list, or float

    Input fluxes in units specified by flux_unit.

  • filtersarray, list, or str

    Filters (following SVO filter IDs) used to obtain flux. It must have the same size as flux.

  • flux_unitstr, optional (default 'Jy')

    Units of flux: 'Jy' or 'erg/s/cm2/A'.

  • efluxarray, float, optional

    Flux uncertainties for flux in unit_in.

  • svo_dataSVO table, optional

    Astropoy table from SVO.

Returns:

Dictionary with converted fluxes:
  • 'mag' : resulting magnitudes

  • 'emag' : (if eflux) uncertainty of resulting magnitudes

  • 'flux' : input flux

  • 'eflux' : (if eflux) input flux uncertainties

  • 'filters' : input filter IDs

  • 'zero_point(Jy)' : filters’ zero points in Jy

  • 'lambda_eff_SVO(um)' : effective wavelengths in microns from SVO

  • 'width_eff_SVO(um)' : effective width in microns from SVO

Example:

>>> # convert fluxes in Jy into magnitudes
>>> import seda
>>> import numpy as np
>>>
>>> flux = np.array([0.005, 0.006]) # test fluxes in Jy
>>> eflux = flux/10. # test flux errors in Jy
>>> filters=['2MASS/2MASS.J', '2MASS/2MASS.Ks'] # test filter IDs
>>>
>>> seda.synthetic_phtometry.flux_to_mag(flux=flux, eflux=eflux, filters=filters)
        {'flux': array([0.005, 0.006]),
         'mag': array([13.75879578, 12.61461085]),
         'filters': ['2MASS/2MASS.J', '2MASS/2MASS.Ks'],
         'zero_point(Jy)': array([1594. ,  666.8]),
         'flux_unit': 'Jy',
         'lambda_eff_SVO(um)': array([1.235, 2.159]),
         'width_eff_SVO(um)': array([0.1624319 , 0.26188695]),
         'eflux': array([0.0005, 0.0006]),
         'emag': array([0.10857362, 0.10857362])}

Author: Genaro Suárez

seda.synthetic_photometry.synthetic_photometry.mag_to_flux(mag, filters, flux_unit='Jy', emag=None, svo_data=None)[source]

Description:

Convert magnitudes into fluxes.

Parameters:

  • magarray, list, or float

    Input magnitudes in mag.

  • filtersarray, list, or str

    Filters (following SVO filter IDs) used to obtain mag. It must have the same size as mag.

  • flux_unitstr, optional (default 'Jy')

    Units to return flux: 'Jy' or 'erg/s/cm2/A'.

  • emagarray, float, optional

    Magnitude uncertainties for mag in mag.

  • svo_dataSVO table, optional

    Astropoy table from SVO.

Returns:

Dictionary with converted fluxes:
  • 'flux' : resulting fluxes

  • 'eflux' : (if emag) resulting flux uncertainties

  • 'mag' : input magnitudes

  • 'emag' : (if emag) uncertainty of input magnitudes

  • 'filters' : input filter IDs

  • 'zero_point(Jy)' : filters’ zero points in Jy

  • 'lambda_eff_SVO(um)' : effective wavelengths in microns from SVO

  • 'width_eff_SVO(um)' : effective width in microns from SVO

Example:

>>> # convert magnitudes into fluxes in Jy
>>> import seda
>>> import numpy as np
>>>
>>> mag = np.array([15.0, 15.5]) # test magnitudes in mag
>>> emag = mag/10. # test magnitude errors in mag
>>> filters=['2MASS/2MASS.J', '2MASS/2MASS.Ks'] # test filter IDs
>>>
>>> seda.synthetic_photometry.mag_to_flux(mag=mag, emag=emag, filters=filters)
    {'mag': array([15. , 15.5]),
     'flux': array([0.001594  , 0.00042072]),
     'filters': ['2MASS/2MASS.J', '2MASS/2MASS.Ks'],
     'zero_point(Jy)': array([1594. ,  666.8]),
     'flux_unit': 'Jy',
     'lambda_eff_SVO(um)': array([1.235, 2.159]),
     'width_eff_SVO(um)': array([0.1624319 , 0.26188695]),
     'emag': array([1.5 , 1.55]),
     'eflux': array([0.00220219, 0.00060062])}

Author: Genaro Suárez

seda.synthetic_photometry.synthetic_photometry.synthetic_photometry(wl, flux, filters, flux_unit, eflux=None, out_file=None)[source]

Description:

Compute synthetic photometry for any SVO filters from an input spectrum.

Parameters:

  • wlarray

    Wavelength in um.

  • fluxarray

    Fluxes in units specified by flux_unit.

  • filterslist, array, or str

    Filters (following SVO filter IDs) to derive synthetic photometry.

  • flux_unitstr

    Flux and flux error units: 'erg/s/cm2/A', 'Jy', or erg/s/cm2/um.

  • efluxarray (optional)

    Flux uncertainties in units specified by flux_unit.

  • out_filestr, optional

    File name to save the synthetic photometry (in erg/s/cm2/A) as prettytable. The file name can include a path e.g. my_path/syn_phot.dat If not provided, the synthetic photometry will not be saved.

Returns:

Python dictionary with the following parameters for each filter:
  • 'syn_flux(erg/s/cm2/A)' : synthetic fluxes in erg/s/cm2/A.

  • 'esyn_flux(erg/s/cm2/A)' : synthetic flux errors in erg/s/cm2/A (if input eflux is provided).

  • 'syn_flux(Jy)' : synthetic fluxes in Jy.

  • 'esyn_flux(Jy)' : synthetic flux errors in Jy (if input eflux is provided).

  • 'syn_mag' : synthetic magnitudes.

  • 'esyn_mag' : synthetic magnitude errors (if input eflux is provided).

  • 'filters' : filters used to derive synthetic photometry.

  • 'lambda_eff(um)' : filters’ effective wavelengths in microns computed using the input spectrum.

  • 'width_eff(um)' : filters’ effective width in micron computed using the input spectrum.

  • 'lambda_eff_SVO(um)' : filters’ effective wavelengths in microns from SVO.

  • 'width_eff(um)' : filters’ effective width in micron from SVO.

  • 'zero_point(Jy)' : filters’ zero points in Jy.

  • 'label' : label indicating if the filters are fully (‘complete’), partially (‘incomplete’), or no (‘none’) covered by the input spectrum or no recognized by SVO (‘unrecognizable’).

  • 'coverage_perc' : percentage of the filter transmission covered by the spectrum.

  • 'transmission' : dictionary with 2D arrays for the filter transmissions, where the first first entry is wavelength in microns and the second one is the transmission.

  • 'wl' : input spectrum wavelengths.

  • 'flux' : input spectrum fluxes.

  • 'eflux' : input spectrum flux uncertainties (if input eflux is provided)..

  • 'flux_unit' : flux units of the input spectrum.

Example:

>>> # obtain synthetic photometry and plot the results
>>> import seda
>>>
>>> # assume we have read a wavelengths (wl in um), fluxes (in erg/s/cm2/A),
>>> # and flux errors (eflux) for an input spectrum,
>>>     # and we would like synthetic photometry for several filters
>>> filters = (['2MASS/2MASS.J', 'Spitzer/IRAC.I1', 'WISE/WISE.W1']) # filters of interest
>>>
>>>     # run the code
>>> out = seda.synthetic_photometry.synthetic_photometry(wl=wl, flux=flux, eflux=eflux,
>>>                                                      flux_unit='erg/s/cm2/A', filters=filters)
>>>
>>> # visualize the derived synthetic fluxes
>>> seda.plots.plot_synthetic_photometry(out)

Author: Genaro Suárez

Utils

seda.utils.app_to_abs_flux(flux, distance, eflux=None, edistance=None, reverse=False)[source]

Description:

Convert apparent fluxes into absolute fluxes considering a distance.

Parameters:

  • fluxfloat array or float

    Fluxes (in any flux units).

  • distancefloat

    Target distance (in pc).

  • efluxfloat array or float, optional

    Flux uncertainties (in any flux units).

  • edistancefloat, optional

    Distance error (in pc).

  • reverse{True, False}, optional (default False)

    Label to indicate if apparent fluxes are converted into absolute fluxes (False) or vice versa (True).

Returns:

  • Dictionary with absolute fluxes and input parameters:
    • 'flux_abs' : absolute fluxes in the same units as the input fluxes.

    • 'eflux_abs' : (if eflux or edistance is provided) absolute flux uncertainties.

    • 'flux_app' : input apparent fluxes.

    • 'eflux_app' : (if provided) input apparent flux errors.

    • 'distance' : input distance.

    • 'edistance' : (if provided) input distance error.

Example:

>>> import seda
>>>
>>> # input parameters
>>> d = 5.00 # pc
>>> ed = 0.06 # pc
>>> flux = 2.10 # mJy
>>> eflux = 0.01 # mJy
>>>
>>> # convert fluxes
>>> seda.utils.app_to_abs_flux(flux=flux, distance=d, eflux=eflux, edistance=ed)
    {'flux_app': 2.1,
    'flux_abs': 0.525,
    'eflux_app': 0.01,
    'eflux_abs': 0.01284562182223967,
    'distance': 5.0,
    'edistance': 0.06}

Author: Genaro Suárez

Date: 2025-05

seda.utils.app_to_abs_mag(magnitude, distance, emagnitude=None, edistance=None)[source]

Description:

Convert apparent magnitudes into absolute fluxes considering a distance, assuming no extinction.

Parameters:

  • magnitudefloat array or float

    Magnitude (in any magnitude units).

  • distancefloat

    Target distance (in pc).

  • emagnitudefloat array or float, optional

    Magnitude uncertainties (in any magnitude units).

  • edistancefloat, optional

    Distance error (in pc).

Returns:

  • Dictionary with absolute mages and input parameters:
    • 'mag_abs' : absolute mages in the same units as the input mages.

    • 'emag_abs' : (if emag or edistance is provided) absolute mag uncertainties.

    • 'mag_app' : input apparent mages.

    • 'emag_app' : (if provided) input apparent mag errors.

    • 'distance' : input distance.

    • 'edistance' : (if provided) input distance error.

Example:

>>> import seda
>>> magnitude, emagnitude = 17.05, 0.03 # mag
>>> distance, edistance = 14.43, 0.79 # pc
>>>
>>> seda.utils.app_to_abs_mag(magnitude=magnitude, emagnitude=emagnitude,
>>>                     distance=distance, edistance=edistance)
    {'mag_app': 17.05,
     'mag_abs': 16.253668344532528,
     'emag_app': 0.03,
     'emag_abs': 0.12260857671946264,
     'distance': 14.43,
     'edistance': 0.79}

Author: Genaro Suárez

Date: 2025-04-28

seda.utils.best_bayesian_fit(output_bayes, grid=None, model_dir_ori=None, ori_res=False, save_spectrum=False)[source]

Description:

Generate model spectrum with the posterior parameters.

Parameters:

  • ‘output_bayes’dictionary or str

    Output dictionary with the results from the nested sampling by bayes. It can be either the name of the pickle file or simply the output dictionary.

  • griddictionary, optional

    Model grid ('wavelength' and 'flux') generated by seda.utils.read_grid for interpolations. If not provided (default), then a grid subset with model spectra around the median posteriors is read. If provided, the code will skip reading the grid, which will save some time.

  • ori_res{True, False}, optional (default False)

    Read (True) or do not read (False) model spectrum for the best fit with the original resolution.

  • model_dir_oristr, list, or array

    Path to the directory (str, list, or array) or directories (as a list or array) containing the model spectra with the original resolution. This parameter is needed if ori_res=True and seda.bayes_fit.bayes was run skipping the model spectra convolution (if skip_convolution=True`).

  • save_spectrum{True, False}, optional (default False)

    Save (True) or do not save (False) best model fit from the nested sampling.

Returns:

  • model_best_fit_bayesian_sampling.dat’ascii table

    Table with best model fit (if save_spectrum).

  • dictionary
    Dictionary with the best model fit from the nested sampling:
    • 'wl_spectra_fit' : (if fit_spectra) wavelength in um of the input spectra within fit_wl_range.

    • 'flux_spectra_fit' : (if fit_spectra) fluxes in erg/cm2/s/A of the input spectra within fit_wl_range.

    • 'eflux_spectra_fit' : (if fit_spectra) flux uncertainties in erg/cm2/s/A of the input spectra within fit_wl_range.

    • 'phot_fit' : (if fit_photometry) flux in erg/cm2/s/A of the input photometry within fit_wl_range.

    • 'ephot_fit' : (if fit_photometry) flux uncertainties in erg/cm2/s/A of the input photometry within fit_wl_range.

    • 'params_med' : median values for sampled parameters.

    • 'params_errors' : lower and upper parameter errors considering the confidence interval params_confidence_interval.

    • 'params_confidence_interval' : confidence interval for sampled parameters.

    • 'confidence_interval(%)' : central percentage considered to calculate the confidence interval.

    • 'wl_model' : wavelength in um of the best scaled model fit (convolved, and resampled when fit_spectra or synthetic fluxes when fit_spectra) within fit_wl_range.

    • 'flux_model' : fluxes in erg/cm2/s/A of the best scaled, convolved, and resampled model fit

    • 'wl_model_best' : (if ori_res is True) wavelength in um of the best scaled model fit with its original resolution

    • 'flux_model_best' : (if ori_res is True) fluxes in erg/cm2/s/A of the best scaled model fit with its original resolution

Author: Genaro Suárez

Date: 2024-09

seda.utils.best_chi2_fits(output_chi2, N_best_fits=1, model_dir_ori=None, ori_res=False)[source]

Description:

Read best-fitting model spectra from the chi-square minimization.

Parameters:

  • output_chi2dictionary or str

    Output dictionary with the results from the chi-square minimization by chi2. It can be either the name of the pickle file or simply the output dictionary.

  • N_best_fitsint, optional (default 1)

    Number of best model fits to be read.

  • ori_res{True, False}, optional (default False)

    Read (True) or do not read (False) model spectra with the original resolution.

  • model_dir_oristr, list, or array

    Path to the directory (str, list, or array) or directories (as a list or array) containing the model spectra with the original resolution. This parameter is needed if ori_res=True and seda.chi2_fit.chi2 was run skipping the model spectra convolution (if skip_convolution=True`).

Returns:

Dictionary with best model fits:
  • 'spectra_name_best' : model spectra names.

  • 'fit_spectra': label indicating whether spectra were fitted.

  • 'fit_photometry': label indicating whether photometry was fitted.

  • 'chi2_red_fit_best' : reduced chi-square.

  • 'chi2_red_wl_fit_best' : reduced chi-square as a function of wavelength.

  • 'wl_model_best' : (if ori_res) wavelength (in um) of original model spectra.

  • 'flux_model_best' : (if ori_res) fluxes (in erg/s/cm2/A) of original model spectra.

  • 'wl_array_model_conv_resam_best' : (if fit_spectra) wavelength (in um) of resampled, convolved model spectra in the input spectra ranges.

  • 'flux_array_model_conv_resam_best' : (if fit_spectra) fluxes (in erg/s/cm2/A) of resampled, convolved model spectra in the input spectra ranges.

  • 'wl_array_model_conv_resam_fit_best' : (if fit_spectra) wavelength (in um) of resampled, convolved model spectra within the fit range.

  • 'flux_array_model_conv_resam_fit_best' : (if fit_spectra) fluxes (in erg/s/cm2/A) of resampled, convolved model spectra within the fit range.

  • 'flux_residuals_spec_best' : (if fit_spectra) flux residuals in linear scale between model and input spectra.

  • 'logflux_residuals_spec_best' : (if fit_spectra) flux residuals in log scale between model and input spectra.

  • 'flux_syn_array_model_fit_best' : (if fit_photometry) synthetic photometry (in erg/s/cm2/A) for the filters within the fit range.

  • 'lambda_eff_array_model_fit_best' : (if fit_photometry) effective wavelength (in um) from model spectra for filters within the fit range.

  • 'width_eff_array_model_fit_best' : (if fit_photometry) effective width (in um) from model spectra for filters within the fit range.

  • 'flux_residuals_phot_best' : (if fit_photometry) flux residuals in linear scale between model and input spectra.

  • 'logflux_residuals_phot_best' : (if fit_photometry) flux residuals in log scale between model and input spectra.

  • 'params' : model free parameters

Author: Genaro Suárez

Date: 2024-10, 2025-09-07

seda.utils.convert_photometric_table(table, save_table=False, table_name=None)[source]

Description:

Convert a table with photometry in separate columns to a table with all magnitudes or fluxes in a column and all errors in another column.

Parameters:

  • tableastropy table

    Table with photometric measurements and their corresponding errors listed in separate columns. The magnitude or flux columns must be labeled with the corresponding SVO filter names. The table must include only photometry, structured such that each magnitude or flux column is immediately followed by its associated error column i.e. magnitude1, error1, magnitude2, error2, etc. Note: names of columns with photometric errors are irrelevant.

  • save_table{True, False}, optional (default False)

    Locally store (True) or do not store (False) the output dictionary as an ascii table using PrettyTable.

  • table_namestr, optional

    File name to save the output table (it can include a path e.g. my_path/output_table.dat). Default name is ‘photometry_prettytable.dat’.

Returns:

Dictionary with three keys: SVO filter names, magnitudes or fluxes, and corresponding errors.

Example:

>>> import seda
>>> from astropy.io import ascii
>>>
>>> # path to the seda package
>>> path_seda = os.path.dirname(os.path.dirname(seda.__file__))
>>> # read ascii table with photometry for 0415
>>> phot_file = path_seda+'/docs/notebooks/data/0415-0935_photometry.dat'
>>> photometry = ascii.read(phot_file)
>>>
>>> # keep columns with magnitudes of interest
>>> photometry = photometry['2MASS/2MASS.J', '2MASS/2MASS.eJ',
>>>                         '2MASS/2MASS.H', '2MASS/2MASS.eH',
>>>                         '2MASS/2MASS.Ks', '2MASS/2MASS.eKs']
>>>
>>> # convert table
>>> seda.utils.convert_photometric_table(photometry)
    {'filters': array(['2MASS/2MASS.J', '2MASS/2MASS.H', '2MASS/2MASS.Ks'], dtype='<U32'),
     'phot': array([15.695, 15.537, 15.429]),
     'ephot': array([0.058, 0.113, 0.201])}

Author: Genaro Suárez

Date: 2025-09-07

seda.utils.convolve_spectrum(wl, flux, res, eflux=None, lam_res=None, disp_wl_range=None, convolve_wl_range=None, out_file=None)[source]

Description:

Convolve a spectrum to a desired resolution at a given wavelength.

Parameters:

  • wlfloat array

    Wavelength (any length units) for the spectrum.

  • fluxfloat array

    Fluxes (any flux units) for the spectrum.

  • resfloat

    Spectral resolution (at lam_res) desired to smooth the input spectrum.

  • efluxfloat array, optional

    Flux uncertainties (any flux units) for the spectrum.

  • lam_resfloat, optional

    Wavelength of reference at which res is given. Default is the integer closest to the median wavelength of the spectrum.

  • disp_wl_rangefloat array, optional

    Minimum and maximum wavelengths (same units as wl) to compute the median wavelength dispersion of the input spectrum. Default values are the minimum and maximum wavelengths in wl.

  • convolve_wl_rangefloat array, optional

    Minimum and maximum wavelengths (same units as wl) to convolve the input spectrum. Default values are the minimum and maximum wavelengths in wl.

  • out_filestr, optional

    File name to save the convolved spectrum as netCDF with xarray (it produces lighter files compared to normal ASCII files). The file name can include a path e.g. my_path/convolved_spectrum.nc If not provided, the convolved spectrum will not be saved.

Returns:

  • Dictionary
    Dictionary with the convolved spectrum:
    • 'wl_conv' : wavelengths for the convolved spectrum (equal to input wl within convolve_wl_range).

    • 'flux_conv' : convolved fluxes.

    • 'eflux_conv' : convolved flux errors (if eflux is provided).

  • out_file file

    netCDF file with the convolved spectrum, if out_file is provided. Wavelengths and fluxes for the convolved spectrum have the same units as the input spectrum. Note: the wavelength data points are the same as in the input spectrum, so wavelength steps do not reflect the resolution of the convolved spectrum.

Example:

>>> import seda
>>> from astropy.io import ascii
>>>
>>> # read sample spectrum
>>> file = '../docs/notebooks/data/IRTF_SpeX_0415-0935.dat'
>>> spectrum = ascii.read(file)
>>> wl = spectrum['wl(um)'] # um
>>> flux = spectrum['flux(erg/s/cm2/A)'] # erg/s/cm2/A
>>> eflux = spectrum['eflux(erg/s/cm2/A)'] # erg/s/cm2/A
>>> # desired resolution
>>> res = 50 # resolution of 50
>>>
>>> out_convolve_spectrum = seda.utils.convolve_spectrum(wl=wl, flux=flux,
>>>                                                      eflux=eflux, res=res)

Author: Genaro Suárez

Date: 2020-03

seda.utils.fill_gap_spectrum(wl, flux, eflux, disp_threshold=None)[source]

Description:

Function to identify and fill a gap in a spectrum. It does a linear interpolation between the median flux before and after the gap and fill the gap with data points with the median wavelength step.

Parameters:

  • wlarray

    Wavelength (any units) of input spectrum.

  • fluxarray

    Fluxes (any units) of input spectrum.

  • efluxarray

    Flux uncertainties (any units) of input spectrum.

  • disp_thresholdfloat, optional

    Wavelength dispersion threshold used to identify gaps. Data points with a dispersion above this limit are classified as gaps. Default value is 50.

Returns:

Dictionary with:
  • 'gap_region': minimum and maximum wavelengths of the gap

  • 'wl_nogap': wavelengths after filling the gap

  • 'flux_nogap': fluxes after filling the gap

  • 'eflux_nogap': flux errors after filling the gap

Author: Genaro Suárez

Date: 2025-01-04

seda.utils.generate_model_spectrum(params, model, grid=None, model_dir=None, save_spectrum=False)[source]

Description:

Generate a synthetic spectrum for an arbitrary combination of free parameters within the coverage of the input atmospheric model grid.

The Python SciPy-based RegularGridInterpolator is used to perform multidimensional linear interpolation of the model spectra at each wavelength point.

The interpolated spectrum is constructed from the grid models enclosing the target point in parameter space. The result is a weighted linear combination of these models, with weights determined by the relative distances between the target parameters and the bounding grid nodes.

Parameters:

  • paramsdictionary

    Value for each free parameter in the models to generate a synthetic spectrum with the desired parameter values. E.g., params = {'Teff': 1010, 'logg': 4.2, 'Z': 0.1, 'fsed': 2.2} for a model grid with those free parameters.

  • modelstr

    Atmospheric models to generate the synthetic spectrum. See available models in seda.models.Models().available_models.

  • griddictionary, optional

    Model grid ('wavelength' and 'flux') generated by seda.utils.read_grid for interpolations. If not provided (default), then the grid is read (model and model_dir must be provided). If provided, the code will skip reading the grid, which will save some time (a few minutes).

  • model_dirstr or list, optional

    Path to the directory (str or list) or directories (as a list) containing the model spectra (e.g., model_dir = ['path_1', 'path_2']). Required if grid is not provided.

  • save_spectrum{True, False}, optional (default False)

    Save (True) or do not save (False) the generated spectrum as an ascii table. Default name is ‘model_``params``_.dat’.

Returns:

Dictionary with generated model spectrum:
  • 'wavelength': wavelengths in microns for the generated spectrum.

  • 'flux': fluxes in erg/s/cm2/A for the generated spectrum.

  • 'params': input parameters for the generated synthetic spectrum.

Example:

>>> import seda
>>>
>>> # models
>>> model = 'Sonora_Elf_Owl'
>>> model_dir = ['my_path/Sonora_Elf_Owl/spectra/output_700.0_800.0/',
>>>              'my_path/Sonora_Elf_Owl/spectra/output_850.0_950.0/']
>>>
>>> # parameters to generate a model spectrum
>>> params = {'Teff': 765, 'logg': 4.15, 'logKzz': 5.2, 'Z': 0.2, 'CtoO': 1.2}
>>>
>>> # generate model spectrum
>>> out = seda.utils.generate_model_spectrum(model=model, model_dir=model_dir,
>>>                                          params=params)

Author: Genaro Suárez

Date: 2025-03-14

seda.utils.merge_MRS(fits_files)[source]

Description:

Merge spectra from different MRS channels and grating settings

Parameters:

  • fits_filesarray, list

    File names (with full path) to the spectra to be merged. It is not necessary to include all four channels and three grating settings (short, medium, and long). The function works with any combination of channels and grating settings.

Returns:

Dictionary with the merged spectrum:
  • 'channel_grating': channel-grating setting label

  • 'channel_grating_range': wavelength range used for each channel-grating setting

  • 'wl_merge': wavelength value at which two consecutive overlapping spectra where merged

  • 'wl': wavelength in micron of the merged spectrum

  • 'flux_Jy': flux in Jy of the merged spectrum

  • 'eflux_Jy': flux uncertainties in Jy of the merged spectrum

  • 'flux_erg/s/cm2/A': flux in erg/s/cm2/A of the merged spectrum

  • 'eflux_erg/s/cm2/A': flux uncertainties in erg/s/cm2/A of the merged spectrum

Example:

>>> import seda
>>>
>>> # list of fits files to be merged
>>> fits_files = ['jw05474-o001_t001_miri_ch1-long_x1d.fits',
...               'jw05474-o001_t001_miri_ch1-medium_x1d.fits',
...               'jw05474-o001_t001_miri_ch1-short_x1d.fits',
...               'jw05474-o001_t001_miri_ch2-long_x1d.fits',
...               'jw05474-o001_t001_miri_ch2-medium_x1d.fits',
...               'jw05474-o001_t001_miri_ch2-short_x1d.fits',
...               'jw05474-o001_t001_miri_ch3-long_x1d.fits',
...               'jw05474-o001_t001_miri_ch3-medium_x1d.fits',
...               'jw05474-o001_t001_miri_ch3-short_x1d.fits']
>>> # merge files
>>> out_merge_MRS = seda.utils.merge_MRS(fits_files)

Author: Genaro Suárez

Date: 2025-10-13

seda.utils.normalize_flux(flx: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) ndarray[source]

Description:

Median-normalize a flux array while ignoring non-finite values.

The function divides the input flux by the median of the finite (non-NaN, non-infinite) values. This is commonly used to place spectra on a relative scale before computing spectral indices.

Parameters:

flxarray-like

Input flux array. Can contain NaNs or infinite values, which are ignored when computing the median.

returns:
  • normalized_flux (ndarray) – Flux array divided by the median of its finite values. If the median is zero, the original array is returned unchanged.

  • Raises

  • ——-

  • ValueError – If the input array contains no finite values.

  • Notes

  • ——

  • This is a simple normalization intended for index-based analysis.

  • It does not perform any continuum fitting or band-specific scaling.

  • Examples

  • ———

  • >>> import numpy as np

  • >>> flux = np.array([1.0, 2.0, 3.0, np.nan])

  • >>> normalize_flux(flux)

  • array([0.5, 1. , 1.5, nan])

seda.utils.np_trapz(y, x=None, dx=1.0, axis=-1)[source]

Version-safe trapezoidal integration for numpy 3.9-3.11+

seda.utils.parallax_to_distance(parallax, eparallax)[source]

Description:

Obtain distance as the inverse of the parallax.

Parameters:

  • parallaxfloat, array

    Parallax in mas.

  • eparallaxfloat, array

    Parallax uncertainty in mas.

Returns:

  • distancefloat, array

    Distance in pc.

  • edistancefloat, array

    Distance uncertainty in pc.

Example:

>>> import seda
>>> parallax = 175.2 # mas
>>> eparallax = 1.7 # mas
>>> # distance
>>> seda.utils.parallax_to_distance(parallax=parallax, eparallax=eparallax)
    (5.707762557077626, 0.055383540793561434)

Author: Genaro Suárez

Date: 2025-04-28

seda.utils.print_time(time)[source]

Description:

Print a time in suitable units.

Parameters:

  • time: float

    Time in seconds.

Returns:

Print time in seconds, minutes, or hours as appropriate.

Author: Genaro Suárez

seda.utils.read_SVO_params(filters, params)[source]

Description:

Read parameters of interest from SVO for a list of filters.

Parameters:

  • filterslist or array

    Filter names to retrieve parameters from SVO.

  • paramslist or array

    Parameter of interest following SVO names.

Returns:

Dictionary with the parameters params for the input filters.

Example:

>>> import seda
>>>
>>> filters = ['2MASS/2MASS.J', '2MASS/2MASS.H', '2MASS/2MASS.Ks']
>>> params = ['filterID', 'WavelengthEff', 'WidthEff']
>>> seda.utils.read_SVO_params(filters=filters, params=params)
    {'filterID': array(['2MASS/2MASS.J', '2MASS/2MASS.H', '2MASS/2MASS.Ks'], dtype=object),
     'WavelengthEff': array([12350., 16620., 21590.]),
     'WidthEff': array([1624.3190191 , 2509.40349871, 2618.86953322])}

Author: Genaro Suárez

Date: 2025-09-05

seda.utils.read_grid(model, model_dir, params_ranges=None, convolve=False, model_wl_range=None, fit_wl_range=None, res=None, lam_res=None, wl_resample=None, disp_wl_range=None, skip_convolution=False, filename_pattern=None, path_save_spectra_conv=None)[source]

Description:

Read a model grid of spectra constrained by input parameters.

Parameters:

  • modelstr

    Atmospheric models. See available models in seda.models.Models().available_models.

  • model_dirstr or list

    Path to the directory (str or list) or directories (as a list) containing the model spectra (e.g., model_dir = ['path_1', 'path_2']).

  • params_rangesdictionary, optional

    Minimum and maximum values for any model free parameters to select a model grid subset. E.g., params_ranges = {'Teff': [1000, 1200], 'logg': [4., 5.]} to consider spectra within those Teff and logg ranges. If a parameter range is not provided, the full range in model_dir is considered.

  • convolve: {True, False}, optional (default False)

    Convolve ('True') or do not convolve ('False') the model grid spectra to the indicated res at lam_res.

  • fit_wl_rangefloat array, optional

    Minimum and maximum wavelengths (in micron) to resample the model spectra to the fit range. E.g., fit_wl_range = np.array([fit_wl_min1, fit_wl_max1]). Default values are the minimum and the maximum wavelengths in wl_resample.

  • disp_wl_rangefloat array, optional

    Minimum and maximum wavelengths (in micron) to compute the median wavelength dispersion of model spectra to convolve them. Default values are the minimum and the maximum wavelengths in wl_resample.

  • model_wl_rangefloat array (optional)

    Minimum and maximum wavelength (in microns) to cut model spectra to keep only wavelengths of interest. Default values are the minimum and maximum wavelengths in wl_resample, if provided, with a padding to avoid issues with the resampling. Otherwise, model_wl_range=None, so model spectra will not be trimmed.

  • fit_phot_rangefloat array or list, optional

    Minimum and maximum wavelengths (in micron) where photometry will be compared to the models. E.g., fit_phot_range = np.array([fit_phot_min1, fit_phot_max1]). This parameter is used if fit_photometry but ignored if only fit_spectra. Default values are the minimum and the maximum of the filter effective wavelengths from SVO.

  • resfloat, optional (required if convolve).

    Spectral resolution (at lam_res) to smooth model spectra.

  • lam_resfloat, optional.

    Wavelength of reference for res. Default is the median wavelength of the spectrum.

  • wl_resamplefloat array or list, optional

    Wavelength data points to resample the grid

  • disp_wl_rangefloat array, optional

    Minimum and maximum wavelengths (in microns) to compute the median wavelength dispersion of model spectrum. Default values are the minimum and maximum wavelengths in model spectra.

  • skip_convolution{True, False}, optional (default False)

    Convolution of model spectra (the slowest process in the code) can (True) or cannot (False) be avoided. Once the code has be run and the convolved spectra were stored in path_save_spectra_conv, the convolved grid can be reused for other input data with the same resolution as the convolved spectra.

  • filename_patternstr, optional

    Pattern to select only files including it. Default is a common pattern in all spectra original filenames in model, as indicated by models.Models(model).filename_pattern.

  • path_save_spectra_conv: str, optional

    Directory path to store convolved model spectra. If not provided (default), the convolved spectra will not be saved. If the directory does not exist, it will be created. Otherwise, the spectra will be added to the existing folder. The convolved spectra will keep the same original names along with the res and lam_res parameters, e.g. ‘original_spectrum_name_R100at1um.nc’ for res=100 and lam_res=1. They will be saved as netCDF with xarray (it produces lighter files compared to normal ASCII files).

Returns:

Dictionary with the model grid either convolved and resampled (if requested) or synthetic photometry:
  • 'wavelength' : wavelengths in microns for the model spectra in the grid.

  • 'flux' : fluxes in erg/s/cm2/A for the model spectra in the grid.

  • 'params_unique' : dictionary with unique (non-repetitive) values for each model free parameter

  • 'N_model_spectra' : dictionary with unique (non-repetitive) values for each model free parameter

Example:

>>> import seda
>>>
>>> # models
>>> model = 'Sonora_Elf_Owl'
>>> model_dir = ['my_path/Sonora_Elf_Owl/spectra/output_700.0_800.0/',
>>>              'my_path/Sonora_Elf_Owl/spectra/output_850.0_950.0/']
>>>
>>> # set ranges for some (Teff and logg) free parameters to select only a grid subset
>>> params_ranges = {'Teff': [700, 900], 'logg': [4.0, 5.0]}
>>>
>>> # read the grid
>>> out_read_grid = seda.utils.read_grid(model=model, model_dir=model_dir,
>>>                                      params_ranges=params_ranges)

Author: Genaro Suárez

Date: 2023-02

seda.utils.read_grid_phot(model, model_dir, filters, params_ranges=None, fit_phot_range=None, skip_syn_phot=False, model_wl_range=None, path_save_syn_phot=None)[source]

Description:

Read a model grid of synthetic photometry constrained by input parameters.

Parameters:

  • modelstr

    Atmospheric models. See available models in seda.models.Models().available_models.

  • model_dirstr or list

    Path to the directory (str or list) or directories (as a list) containing the model spectra (e.g., model_dir = ['path_1', 'path_2']).

  • params_rangesdictionary, optional

    Minimum and maximum values for any model free parameters to select a model grid subset. E.g., params_ranges = {'Teff': [1000, 1200], 'logg': [4., 5.]} to consider spectra within those Teff and logg ranges. If a parameter range is not provided, the full range in model_dir is considered.

  • model_wl_rangefloat array (optional)

    Minimum and maximum wavelength (in microns) to cut model spectra to keep only wavelengths of interest. Default values are the minimum and maximum wavelengths in wl_resample, if provided, with a padding to avoid issues with the resampling. Otherwise, model_wl_range=None, so model spectra will not be trimmed.

  • fit_phot_rangefloat array or list, optional

    Minimum and maximum wavelengths (in micron) where photometry will be compared to the models. E.g., fit_phot_range = np.array([fit_phot_min1, fit_phot_max1]). This parameter is used if fit_photometry but ignored if only fit_spectra. Default values are the minimum and the maximum of the filter effective wavelengths from SVO.

  • filtersfloat array

    Filters to derive synthetic photometry following SVO filter IDs http://svo2.cab.inta-csic.es/theory/fps/

  • path_save_syn_phot: str, optional

    Directory path to store the synthetic fluxes (in erg/s/cm2/A). If not provided (default), the synthetic photometry will not be saved. If the directory does not exist, it will be created. Otherwise, the photometry will be added to the existing folder. The synthetic photometry for different filters derived from the same model spectrum will be saved in a single ASCII table, named after the model with the suffix “_syn_phot.dat”. If a synthetic photometry file for a given model spectrum already exists, it will be updated to include photometry for any new filters as needed.

  • skip_syn_phot{True, False}, optional (default False)

    Synthetic photometry calculation (the lowest process when fitting photometry) can (True) or cannot (False) be avoided. If ‘True’, model_dir should correspond to the directory with the synthetic photometry for filters in input_parameters.InputData.

Returns:

Dictionary with the model grid either convolved and resampled (if requested) or synthetic photometry:
  • 'wavelength' : wavelengths in microns for the model spectra in the grid.

  • 'flux' : fluxes in erg/s/cm2/A for synthetic photometry in the grid.

  • 'params_unique' : dictionary with unique (non-repetitive) values for each model free parameter

  • 'N_model_spectra' : dictionary with unique (non-repetitive) values for each model free parameter

Example:

>>> import seda
>>>
>>> # models
>>> model = 'Sonora_Elf_Owl'
>>> model_dir = ['my_path/Sonora_Elf_Owl/spectra/output_700.0_800.0/',
>>>              'my_path/Sonora_Elf_Owl/spectra/output_850.0_950.0/']
>>>
>>> # set ranges for some (Teff and logg) free parameters to select only a grid subset
>>> params_ranges = {'Teff': [700, 900], 'logg': [4.0, 5.0]}
>>>
>>> # read the grid
>>> out_read_grid = seda.utils.read_grid_phot(model=model, model_dir=model_dir,
>>>                                           params_ranges=params_ranges)

Author: Genaro Suárez

Date: 2025-11-22

seda.utils.read_prettytable(filename)[source]

Description:

Read ascii table created with prettytable.

Parameters:

  • filenamestr

    PrettyTable table.

Returns:

Astropy table with the information in the input file.

Example:

>>> import seda
>>>
>>> out = seda.utils.open_chi2_table('Sonora_Elf_Owl_chi2_minimization_multiple_spectra.dat')

Author: Rocio Kiman

Date: 2025-02-11

seda.utils.scale_synthetic_spectrum(wl, flux, distance, radius)[source]

Description:

Scale model spectrum when distance and radius are known.

Parameters:

  • wlfloat array

    Wavelength (any length units) for the spectrum.

  • fluxfloat array

    Fluxes (any flux units) for the spectrum.

  • radius: float

    Radius in Rjup.

  • distance: float

    Distance in pc.

Returns:

Scaled fluxes.

seda.utils.select_model_spectra(model, model_dir, params_ranges=None, filename_pattern=None, save_results=False, out_file=None)[source]

Description:

Select model spectra from the indicated models and meeting given parameters ranges.

Parameters:

  • modelstr

    Atmospheric models. See available models in seda.models.Models().available_models.

  • model_dirstr or list

    Path to the directory (str or list) or directories (as a list) containing the model spectra (e.g., model_dir = ['path_1', 'path_2']).

  • params_rangesdictionary, optional

    Minimum and maximum values for any model free parameters to select a model grid subset. E.g., params_ranges = {'Teff': [1000, 1200], 'logg': [4., 5.]} to consider spectra within those Teff and logg ranges. If a parameter range is not provided, the full range in model_dir is considered.

  • filename_patternstr, optional

    Pattern to select only files including it. Default is a common pattern in all spectra original filenames in model, as indicated by models.Models(model).filename_pattern.

  • save_results{True, False}, optional (default False)

    Save (True) or do not save (False) the output as a pickle file named ‘model_free_parameters.pickle’.

  • out_filestr, optional

    File name to save the results as a pickle file (it can include a path e.g. my_path/free_params.pickle). Default name is ‘model_free_parameters.pickle’ and is stored at the notebook location.

Returns:

Dictionary with the parameters:
  • spectra_name: selected model spectra names.

  • spectra_name_full: selected model spectra names with full path.

  • params: parameters for the selected model spectra, as given by the seda.models.separate_params output dictionary.

Example:

>>> import seda
>>>
>>> model = 'Sonora_Elf_Owl'
>>> model_dir = ['my_path/output_575.0_650.0/',
>>>              'my_path/output_700.0_800.0/'] # folders to seek model spectra
>>> # set ranges for some (Teff and logg) free parameters to select only a grid subset
>>> params_ranges = {'Teff': [700, 900], 'logg': [4.0, 5.0]}
>>> out = seda.utils.select_model_spectra(model=model, model_dir=model_dir,
>>>                                       params_ranges=params_ranges)

Author: Genaro Suárez

Date: 2020-05

seda.utils.spt_to_teff(spt, spt_type, ref=None)[source]

Description:

Convert spectral type into effective temperature using relationships in the literature.

Parameters:

  • sptfloat, str, array, or list

    Spectral types given as conventional letters or number, as indicated in spt_type. Convention between spectral type and float: M9=9, L0=10, …, T0=20, …

  • spt_typestr

    Label indicating whether the input spectral type is a string (‘str’) or a number (‘float’)

  • refstr, optional (default ‘F15’)

    Reference for the spectral type-temperature relationships. ‘F15’: Filippazzo et al. (2015), valid for M6-T9 (6-29) ‘K21’: Kirkpatrick et al. (2021), valid for M7-Y2 (7-32)

Returns:

  • teffarray

    Effective temperature (in K) corresponding to the input spectral types according to the ref reference.

Example:

>>> import seda
>>>
>>> # spectral type as a number
>>> spt = [15, 25] # for L5 and T5 types
>>> seda.utils.spt_to_teff(spt, spt_type='float') # Teff in K
    array([1581.053125, 1033.328125])
>>>
>>> # spectral type as a string
>>> spt = ['L5', 'T5']
>>> seda.utils.spt_to_teff(spt, spt_type='str') # Teff in K
    array([1581.053125, 1033.328125])

Author: Genaro Suárez

Date: 2023-02

seda.utils.teff_to_spt(teff, ref=None)[source]

Description:

Estimate the spectral type (returned as a string) from effective temperature, using numerical inversion of spt_to_teff() and the same spectral-type conventions.

Parameters:

  • tefffloat, array

    Effective temperatures (K)

  • refstr, optional (default ‘F15’)

    Reference for the spectral type-temperature relationships. ‘F15’: Filippazzo et al. (2015), valid for M6-T9 (6-29) ‘K21’: Kirkpatrick et al. (2021), valid for M7-Y2 (7-32)

Returns:

  • spt_strarray

    Estimated spectral type(s), formatted like ‘M6’, ‘L3.5’, ‘T8’, ‘Y1’, etc.

Example:

>>> import seda
>>>
>>> # effective temperature to spectral type
>>> teff = [2000, 1500, 1000] # K
>>> seda.utils.teff_to_spt(teff)
    array(['L1.7', 'L5.8', 'T5.4'], dtype='<U4')

Author: Genaro Suárez

Date: 2025-12-12

Variability

class seda.variability.VariabilityResult(spectral_type: str, scheme: str, is_candidate_variable: bool, n_regions_triggered: int, n_regions_total: int, threshold: int, indices: Dict[str, float], regions_triggered: List[str], normalize: bool | None = None)[source]
seda.variability.classify_variability(wavelength, flux, *, spectral_type: str, normalize: bool = True, scheme: str | None = None, plot_diagrams: bool = False, plot_index_windows: bool = False, plot_save: bool | str = False, show: bool = True) VariabilityResult[source]

Description:

Classify a brown dwarf as candidate variable or non-variable using NIR spectral index–index variability regions.

This is the main public interface for variability classification in SEDA. It computes the required spectral indices, evaluates the polygon-based variability criteria, and optionally produces diagnostic plots.

Parameters:

  • wavelengtharray-like

    Wavelength array (microns).

  • fluxarray-like

    Flux array corresponding to wavelength.

  • spectral_type{“L”, “T”}

    Spectral type scheme to use for the classification.

  • normalizebool, default True

    If True, the flux is median-normalized before computing indices.

  • schemestr or None, optional

    Name or reference of the variability scheme. If None, the default scheme for the selected spectral type is used.

  • plot_diagramsbool, default False

    If True, generate the index–index variability diagrams.

  • plot_index_windowsbool, default False

    If True, plot the spectrum with the numerator/denominator windows used to compute the NIR indices.

  • plot_savebool or str, default False

    If True, save plots to default filenames. If a string, use it as the base path or filename.

  • showbool, default True

    If True, display the plots using plt.show().

Returns:

  • resultVariabilityResult
    Structured classification result with the following attributes:
    • spectral_type : str Spectral type scheme used for the classification (“L” or “T”).

    • scheme : str Name or reference of the variability scheme (e.g., “Oliveros-Gomez+2022”, “Oliveros-Gomez+2024”).

    • is_candidate_variable : bool Final classification flag. True if the number of triggered index–index regions meets or exceeds the adopted threshold.

    • n_regions_triggered : int Number of variability regions in which the target falls.

    • n_regions_total : int Total number of regions evaluated for the selected spectral type.

    • threshold : int Minimum number of triggered regions required to be classified as a candidate variable.

    • indices : dict[str, float] Dictionary of computed NIR spectral indices. Keys correspond to the physical index names (e.g., “J”, “H”, “Jslope”, “Jcurve”, “H2OJ”, “CH4J”), and values are the numerical index values.

    • regions_triggered : list[str] List of region identifiers (or names) for which the target falls inside the corresponding variability polygon.

    • normalize : bool Whether a median flux normalization was applied to the input spectrum prior to computing the indices.

    • summary() : str Returns a human-readable, multi-line summary of the classification outcome. The result object also provides a convenience method:

Examples

>>> result = classify_variability(wave, flux, spectral_type="T", normalize=False)
>>> print(result.is_candidate_variable)
True
>>> print(result.n_regions_triggered, "/", result.n_regions_total)
11 / 12
>>> print(result.indices["Jslope"], result.indices["Jcurve"])
0.63 0.15
>>> print(result.summary())
Scheme: Oliveros-Gomez+2022
Spectral type: T
Normalize: False
Triggered regions: 11/12 (threshold >= 11)
Classification: candidate VARIABLE

Author:

Natalia Oliveros-Gomez