Main Utilities
Global functions:
- class ForMoSA.global_file.GlobFile(config_file_path)[source]
Class that import all the parameters from the config file and make them GLOBAL FORMOSA VARIABLES.
Authors: Paulina Palma-Bifani, Matthieu Ravet and Allan Denis
- ForMoSA.global_file.get_config_value(config, section, key, default, cast=None)[source]
Helper function to get a config value with a fallback default.
- Parameters:
config (obj) – config object
section (str) – config section name
key (str) – config key name
default – default value if key is missing
cast – a function to cast the value (e.g., int, list, eval, etc.)
- Returns:
The value (possibly cast), and stores it back into self.config if it was missing.
Author: Matthieu Ravet
Utilities:
- ForMoSA.utils.decoupe(second)[source]
Re-arranged a number of seconds in the hours-minutes-seconds format.
- Parameters:
second (float) – number of second
- Returns:
hours - float : minutes - float : seconds
- Return type:
float
Author: Simon Petrus
- ForMoSA.utils.find_nearest(array, value)[source]
Return the indice of the closest values from a desire value in an array.
- Parameters:
array (array) – Array to explore
value (float) – Desire value
- Returns:
Indice of the closest values from the desire value
- Return type:
idx (int)
Author: Simon Petrus
- ForMoSA.utils.format_grid(grid, attr, free_comp, weights)[source]
Format PCA or NMF outputs into a single xarray
- Parameters:
grid (-) – Original grid
attr (-) – Original grid attributs
free_comp (-) – Number of free components in the new grid (= PCA component used during PCA + 1 (nfs))
weights (-) – PCA or NMF weights grid
- Returns:
Xarray of the PCA or NMF weights grid
- Return type:
ds_weights (xarray)
Author: Matthieu Ravet
- ForMoSA.utils.yesno(text)[source]
Function to interact with the terminal and decide for different options when running ForMoSA (Loop to repeat question if answer is different to ‘y’ or ‘n).
- Parameters:
text (str) – (y/n) answer in the terminall in interactive mode
- Returns:
answer y or n
- Return type:
asw (str)
Author: Simon Petrus
Spectra utilities:
- ForMoSA.utils_spec.bb_cpd_fct(wav_mod_spectro, wav_obs_photo, flx_mod_spectro, flx_mod_photo, distance, bb_t_picked, bb_r_picked)[source]
Function to add the effect of a cpd (circum planetary disc) to the models.
- Parameters:
wav_mod_spectro (array) – Wavelength grid of the model (spectroscopy)
wav_obs_photo (array) – Wavelength of the data/model (photometry)
flx_mod_spectro (array) – Flux of the interpolated synthetic spectrum (spectroscopy)
flx_mod_photo (array) – Flux of the interpolated synthetic spectrum (photometry)
distance (array) – Distance from the observation in pc units
bb_temp (float) – Temperature value randomly picked by the nested sampling in K units
bb_rad (float) – Radius randomly picked by the nested sampling in units of planetary radius
- Returns:
New flux of the interpolated synthetic spectrum (spectroscopy) - flx_mod_photo_bb (array): New flux of the interpolated synthetic spectrum (photometry)
- Return type:
flx_mod_spectro_bb (array)
Author: Paulina Palma-Bifani
- ForMoSA.utils_spec.calc_flx_scale(obs_dict, flx_mod_spectro, flx_mod_photo, r_picked, d_picked, alpha=1, mode='physical', use_cov=False)[source]
Calculation of the flux scaling factor (from the radius and distance or analytically).
- Parameters:
obs_dict (dict) – Dictionay containing all the observationnal entries (photometry, spectroscopy and/or optional)
flx_mod_spectro (array) – Flux of the interpolated synthetic spectrum (spectroscopy)
flx_mod_photo (array) – Flux of the interpolated synthetic spectrum (photometry)
r_picked (float) – Radius randomly picked by the nested sampling (in RJup)
d_picked (float) – Distance randomly picked by the nested sampling (in pc)
alpha (float) – Manual scaling factor (set to 1 by default) such that ck = alpha * (r/d)²
mode (str) – = ‘physical’ if the scaling needs to be calulated with r and d = ‘analytic’ if the scaling needs to be calculated analytically by the formula from Cushing et al. (2008)
use_cov (bool) – True or False if you want to use or not the full covariance matrix (formula from De Regt et al. (2025))
- Returns:
Flux scaling factor of the spectroscopy - scale_photo (float): Flus scaling factor of the photometry
- Return type:
scale_spectro (float)
Author: Simon Petrus
- ForMoSA.utils_spec.continuum_estimate(wav_input, flx_input, res_input, wav_cont_bounds, res_cont)[source]
Decrease the resolution of a spectrum (data or model). The function calculates the FWHM as a function of the wavelengths of the custom spectral resolution (estimated for the continuum). It then calculates a sigma to decrease the resolution of the spectrum to this custom FWHM for each wavelength using a gaussian filter and resample it on the wavelength grid of the data.
- Parameters:
wav_input (array) – Wavelength grid of the spectrum for which you want to estimate the continuum
flx_input (array) – Flux of the spectrum for which you want to estimate the continuum
res_input (array) – Spectral resolution of the spectrum for which you want to estimate the continuum
wav_cont_bounds (array) – Wavelength bounds where you want to estimate the continuum
res_cont (int) – Approximate resolution of the continuum
- Returns:
Estimated continuum of the spectrum re-sampled on the data wavelength grid
- Return type:
continuum (array)
Author: Simon Petrus, Matthieu Ravet
- ForMoSA.utils_spec.convolve_and_sample(wv_channels, sigmas_wvs, model_wvs, model_fluxes, num_sigma=3, force_int=True)[source]
Simulate the observations of a model. Convolves the model with a variable Gaussian LSF, sampled at each desired spectral channel.
- Parameters:
wv_channels (list(floats)) – the wavelengths values desired
sigmas_wvs (list(floats)) – the LSF gaussian standard deviation of each wv_channels [IN UNITS OF model_wvs]
model_wvs (array) – the wavelengths of the model
model_fluxes (array) – the fluxes of the model
num_sigma (float) – number of +/- sigmas to evaluate the LSF to.
force_int (bolean) – False by default. If True, will force interpolation onto wv_channels when the kernel is singular
- Returns:
the fluxes in each of the wavelength channels
- Return type:
output_model (array)
Author: Jason Wang
- ForMoSA.utils_spec.doppler_fct(wav_mod_spectro, flx_mod_spectro, rv_picked)[source]
Application of a Doppler shifting to the interpolated synthetic spectrum using the function pyasl.dopplerShift. The side effects of the Doppler shifting are taking into account by using a model interpolated on a larger wavelength grid as the wavelength grid of the data. After the Doppler shifting, the model is then cut to the wavelength of the data.
- Parameters:
wav_mod_spectro (array) – Wavelength grid of the model
flx_mod_spectro (array) – Flux of the interpolated synthetic spectrum
rv_picked (float) – Radial velocity randomly picked by the nested sampling (in km.s-1)
- Returns:
Wavelength grid after Doppler shifting - flx_post_doppler (array): New flux of the interpolated synthetic spectrum
- Return type:
wav_post_doppler (array)
Author: Simon Petrus, Allan Denis and Matthieu Ravet
- ForMoSA.utils_spec.reddening_fct(wav_mod_spectro, wav_obs_photo, flx_mod_spectro, flx_mod_photo, av_picked)[source]
Application of a sythetic interstellar extinction to the interpolated synthetic spectrum using the function extinction.fm07.
- Parameters:
wav_mod_spectro (array) – Wavelength grid of the model (spectroscopy)
wav_obs_photo (array) – Wavelength of the data/model (photometry)
flx_mod_spectro (array) – Flux of the interpolated synthetic spectrum (spectroscopy)
flx_mod_photo (array) – Flux of the interpolated synthetic spectrum (photometry)
av_picked (float) – Extinction randomly picked by the nested sampling (in mag)
- Returns:
New flux of the interpolated synthetic spectrum (spectroscopy) - flx_mod_photo_rd (array): New flux of the interpolated synthetic spectrum (photometry)
- Return type:
flx_mod_spectro_rd (array)
Author: Simon Petrus
- ForMoSA.utils_spec.resolution_decreasing(wav_input, flx_input, res_input, wav_output, res_output)[source]
Decrease the resolution of a spectrum. The function calculates the FWHM as a function of the wavelengths for the input and output fluxes and estimates the highest one for each wavelength (the lowest spectral resolution). It then calculates a sigma to decrease the resolution of the spectrum to this lowest FWHM for each wavelength and resample it on the wavelength grid of the data using the function ‘convolve_and_sample’.
- Parameters:
wav_input (array) – Wavelength grid of the input
flx_input (array) – Flux of the input
res_input (array) – Spectral resolution of the input as a function of wav_output
wav_output (array) – Wavelength grid of the output
res_output (array) – Spectral resolution of the output as a function of the wavelength grid of the input
- Returns:
Flux of the spectrum with a decreased spectral resolution, re-sampled on the data wavelength grid
- Return type:
flx_output (array)
Author: Simon Petrus
- ForMoSA.utils_spec.vsini_fct(wav_mod_spectro, flx_mod_spectro, res_mod_obs_spectro, ld_picked, vsini_picked, vsini_type)[source]
Application of a rotational velocity (line broadening) to the interpolated synthetic spectrum
- Parameters:
wav_mod_spectro (array) – Wavelength grid of the model
flx_mod_spectro (array) – Flux of tge interpolated synthetic spectrum (spectroscopy)
res_mod_obs_spectro (array) – Resolution of the model as a function of the wavelength grid of the data
ld_picked (float) – Limb darkening randomly picked by the nested sampling
vsini_picked (float) – v.sin(i) randomly picked by the nested samplin (in km.s-1)
vsini_type (str) – Vsin(i) function to use
- Returns:
New flux of the broadened synthetic spectrum (spectroscopy) - res_mod_obs_broad (array): New resolution of the broadened synthetic spectrum (photometry)
- Return type:
flx_mod_spectro_broad (array)
Author: Allan Denis
- ForMoSA.utils_spec.vsini_fct_accurate(wav_mod_spectro, flx_mod_spectro, ld_picked, vsini_picked, nr=50, ntheta=100, dif=0.0)[source]
A routine to quickly rotationally broaden a spectrum in linear time. Adapted from Carvalho & Johns-Krull 2023 https://ui.adsabs.harvard.edu/abs/2023RNAAS…7…91C/abstract
- Parameters:
wav_mod_spectro (array) – Wavelength grid of the model
flx_mod_spectro (array) – Flux of the interpolated synthetic spectrum
ld_picked (float) – Limd darkening randomly picked by the nested sampling
vsini_picked (float) – v.sin(i) randomly picked by the nested sampling (in km.s-1)
nr (int) – (default = 10) The number of radial bins on the projected disk
ntheta (int) – (default = 100) The number of azimuthal bins in the largest radial annulus note: the number of bins at each r is int(r*ntheta) where r < 1
dif (float) – (default = 0) The differential rotation coefficient, applied according to the law Omeg(th)/Omeg(eq) = (1 - dif/2 - (dif/2) cos(2 th)). Dif = .675 nicely reproduces the law proposed by Smith, 1994, A&A, Vol. 287, p. 523-534, to unify WTTS and CTTS. Dif = .23 is similar to observed solar differential rotation. Note: the th in the above expression is the stellar co-latitude, not the same as the integration variable used below. This is a disk integration routine.
- Returns:
New flux of the interpolated synthetic spectrum
- Return type:
flx_mod_spectro_broad (array)
Author: Allan Denis
- ForMoSA.utils_spec.vsini_fct_accurate_fast_rot_broad(wav_mod_spectro, flx_mod_spectro, ld_picked, vsini_picked)[source]
Application of a rotation velocity (line broadening) to the interpolated synthetic spectrum using the Carvalho & Johns-Krull (2023) approach
- Parameters:
wav_mod_spectro (array) – Wavelength grid of the model
flx_mod_spectro (array) – Flux of the interpolated synthetic spectrum
ld_picked (float) – Limd darkening randomly picked by the nested sampling
vsini_picked (float) – v.sin(i) randomly picked by the nested sampling (in km.s-1)
- Returns:
New flux of the interpolated synthetic spectrum
- Return type:
flx_mod_spectro_broad (array)
Author: Simon Petrus, Arthur Vigan and Allan Denis
- ForMoSA.utils_spec.vsini_fct_fast_rot_broad(wav_mod_spectro, flx_mod_spectro, ld_picked, vsini_picked)[source]
Application of a rotation velocity (line broadening) to the interpolated synthetic spectrum using the function extinction.fm07.
- Parameters:
wav_mod_spectro (array) – Wavelength grid of the model
flx_mod_spectro (array) – Flux of the interpolated synthetic spectrum
ld_picked (float) – Limd darkening randomly picked by the nested sampling
vsini_picked (float) – v.sin(i) randomly picked by the nested sampling (in km.s-1)
- Returns:
New flux of the interpolated synthetic spectrum
- Return type:
flx_mod_spectro_broad (array)
Author: Simon Petrus
- ForMoSA.utils_spec.vsini_fct_rot_broad(wav_mod_spectro, flx_mod_spectro, ld_picked, vsini_picked)[source]
Application of a rotation velocity (line broadening) to the interpolated synthetic spectrum using the function extinction.fm07.
- Parameters:
wav_mod_spectro (array) – Wavelength grid of the model
flx_mod_spectro (array) – Flux of the interpolated synthetic spectrum
ld_picked (float) – Limd darkening randomly picked by the nested sampling
vsini_picked (float) – v.sin(i) randomly picked by the nested sampling (in km.s-1)
- Returns:
New flux of the interpolated synthetic spectrum
- Return type:
flx_mod_spectro_broad (array)
Author: Simon Petrus