Core

Contents

Core#

Enumerations#

Enums used across the package for wavelength units, flux units, observation types, prior types, parameter kinds, and more.

class ForMoSA.core.enums.WavelengthUnit(*values)[source]#

Bases: Enum

Enumeration of wavelength units used in ForMoSA with accepted aliases

Notes

Authors: Allan Denis

ANGSTROM = Unit("Angstrom")#
NANOMETER = Unit("nm")#
MICROMETER = Unit("um")#
angstrom = Unit("Angstrom")#
Angstrom = Unit("Angstrom")#
AA = Unit("Angstrom")#
Nanometer = Unit("nm")#
nanometer = Unit("nm")#
nm = Unit("nm")#
Micrometer = Unit("um")#
micrometer = Unit("um")#
um = Unit("um")#
property unit: Unit#
class ForMoSA.core.enums.FluxUnit(*values)[source]#

Bases: Enum

Enumeration of flux units used in ForMoSA

Notes

Authors: Allan Denis

FLAM = Unit("erg / (Angstrom s cm2)")#
FNU = Unit("erg / (Hz s cm2)")#
JY = Unit("Jy")#
property unit: Unit#
class ForMoSA.core.enums.DataUnit(*values)[source]#

Bases: Enum

Enumeration of data units used in ForMoSA

Notes

Authors: Allan Denis

COUNTS = 'counts'#
ELECTRONS = 'electrons'#
ADU = 'adu'#
property unit: str#
class ForMoSA.core.enums.ObservationType(*values)[source]#

Bases: Enum

Enumeration of observation types used in ForMoSA with accepted aliases

Notes

Authors: Allan Denis

SPECTROSCOPIC = 'Spectroscopic'#
PHOTOMETRIC = 'Photometric'#
spectroscopic = 'Spectroscopic'#
SPECTRO = 'Spectroscopic'#
spectro = 'Spectroscopic'#
photometric = 'Photometric'#
PHOTO = 'Photometric'#
photo = 'Photometric'#
property obstype: str#
class ForMoSA.core.enums.ObservationKeys(canonical, aliases)[source]#

Bases: Enum

Enumeration of observation keys used in ForMoSA with accepted aliases

Examples

>>> WAVELENGTH = ObservationKeys.WAVELENGTH
>>> WAVELENGTH.canonical = "WAVELENGTH"
>>> WAVELENGTH.aliases = "WAVE", "WAV", "LAMBDA"

So the user can use “WAVELENGTH”, “WAVE”, “WAV” or “LAMBDA” to call the wavelength array of the observations

Notes

Authors: Allan Denis

WAVELENGTH = ('WAVELENGTH', ['WAVELENGTH', 'WAVE', 'WAV', 'LAMBDA'])#
FLUX = ('FLUX', ['FLUX', 'FLX'])#
ERROR = ('ERROR', ['ERROR', 'ERR', 'SIGMA'])#
FACILITY = ('FACILITY', ['FACILITY', 'FAC', 'Facility'])#
INSTRUMENT = ('INSTRUMENT', ['INSTRUMENT', 'INS'])#
FILTER_ID = ('FILTER_ID', ['FILTER_ID', 'FILTER', 'FILT', 'FILT_ID'])#
RESOLUTION = ('RESOLUTION', ['RESOLUTION', 'RES'])#
COVARIANCE = ('COVARIANCE', ['COVARIANCE', 'COV'])#
TRANSMISSION = ('TRANSMISSION', ['TRANSMISSION', 'TRANSM'])#
STAR_FLUX = ('STAR_FLUX', ['STAR_FLUX', 'STAR_FLX'])#
SYSTEMATICS = ('SYSTEMATICS', ['SYSTEMATICS', 'SYS'])#
WAVELENGTH_UNIT = ('WAVELENGTH_UNIT', ['WAVELENGTH_UNIT', 'UNIT', 'WAVE_UNIT'])#
FLUX_CONT = ('FLUX_CONT', ['FLUX_CONT'])#
STAR_FLUX_CONT = ('STAR_FLUX_CONT', ['STAR_FLUX_CONT'])#
WAVE_CONT = ('WAVE_CONT', ['WAVE_CONT'])#
RES_CONT = ('RES_CONT', ['RES_CONT'])#
classmethod required_common()[source]#
classmethod required_spectroscopic()[source]#
classmethod required_photometric()[source]#
classmethod validate_photometric(present)[source]#

Method to check that observation keys contains required photometric keys

Parameters:

present (set[str]) – set of canonical observation keys

Return type:

list[str]

Returns:

list[str] – List of required photometric keys absent

Notes

Authors: Allan Denis

classmethod validate_spectroscopic(present)[source]#

Method to check that observation keys contains required spectroscopic keys

Parameters:

present (set[str]) – set of canonical observation keys

Returns:

list[str] – List of required spectroscopic keys absent

Notes

Authors: Allan Denis

classmethod from_string(value)[source]#
Parameters:

value (str)

class ForMoSA.core.enums.PriorType(*values)[source]#

Bases: Enum

Enumeration of prior types used in ForMoSA

Notes

Authors: Allan Denis

UNIFORM = 'uniform'#
GAUSSIAN = 'gaussian'#
LOG_UNIFORM = 'log_uniform'#
CONSTANT = 'constant'#
property is_gaussian: bool#
property is_uniform: bool#
property is_log_uniform: bool#
property is_constant: bool#
property priortype: str#
class ForMoSA.core.enums.VsiniFunction(*values)[source]#

Bases: Enum

Enumeration of vsini calculation functions used in ForMoSA

Notes

Authors: Allan Denis

RotBroad = 'RotBroad'#
FastRotBroad = 'FastRotBroad'#
Accurate = 'Accurate'#
AccurateFast = 'AccurateFast'#
property function: str#
class ForMoSA.core.enums.ParameterKind(*values)[source]#

Bases: Enum

Enumeration of parameters names used in ForMoSA

Notes

Authors: Allan Denis

RADIUS = 'r'#
DISTANCE = 'd'#
AV = 'av'#
BB_T = 'bb_T'#
BB_R = 'bb_R'#
ALPHA = 'alpha'#
RV = 'rv'#
VSINI = 'vsini'#
LD = 'ld'#
GRID = 'grid'#
radius = 'r'#
R = 'r'#
r = 'r'#
distance = 'd'#
D = 'd'#
d = 'd'#
av = 'av'#
EXTINCTION = 'av'#
extinction = 'av'#
bb_T = 'bb_T'#
bb_R = 'bb_R'#
alpha = 'alpha'#
rv = 'rv'#
vsini = 'vsini'#
ld = 'ld'#
grid = 'grid'#
property kind: str#
class ForMoSA.core.enums.LogLikelihoodType(*values)[source]#

Bases: Enum

Enumeration of log-likelihood types used in ForMoSA

Notes

Authors: Allan Denis

CHI2 = 'chi2'#
CHI2_COVARIANCE = 'chi2_covariance'#
CHI2_NOISESCALING = 'chi2_noisescaling'#
CHI2_NOISESCALING_COVARIANCE = 'chi2_noisescaling_covariance'#
CCF_ZUCKER = 'CCF_Zucker'#
CCF_BROGI = 'CCF_Brogi'#
CCF_CUSTOM = 'CCF_custom'#
property loglike: str#
class ForMoSA.core.enums.NestedAlgorithm(*values)[source]#

Bases: Enum

Enumeration of nested sampling algorithms used in ForMoSA

Notes

Authors: Allan Denis

NESTLE = 'nestle'#
ULTRANEST = 'ultranest'#
PYMULTINEST = 'pymultinest'#
property algo: str#

Errors#

exception ForMoSA.core.errors.ForMoSAError(msg, logger=None)[source]#

Bases: Exception

Main ForMoSA error class.

Logging#

ForMoSA.core.loggings.setup_logging(level='INFO', logfile=None, name=None)[source]#

Setup the logging

Parameters:
  • level (str) – Level of the logger (‘INFO’, ‘DEBUG’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’)

  • logfile (str | PathLike) – Path of the log

  • name (str) – Name of the logger

Returns:

logger (logging.Logger) – Logger

Notes

Authors: Arthur Vigan and Allan Denis

Plot Configuration#

Dataclasses that control the visual style of every plot type produced by ForMoSA (corner, chains, radar, best-fit, etc.).

Inheritance diagram of ForMoSA.core.config.SpectralPlotConfig, ForMoSA.core.config.PhotometricPlotConfig
ForMoSA.core.config.set_filter_path(path)[source]#

Set the global path used to store photometry filters.

Parameters:

path (str | PathLike) – Path to the filters folder

Return type:

None

Notes

Authors: Allan Denis

ForMoSA.core.config.darken_color(color, factor=0.7)[source]#

Darken a matplotlib color.

Parameters:
  • color (str) – Any matplotlib-compatible color.

  • factor (float) – Multiplicative factor (<1 darker, >1 lighter)

Return type:

str

Returns:

str (hex color)

Notes

Authors: Allan Denis

class ForMoSA.core.config.MainPlotConfig(figsize=(10.0, 7.0), legend_ncol=1, legend_hc_ncol=1, legend_filt_ncol=1, legend_fontsize='small', minor_ticks=True, nb_minor_ticks=5)[source]#

Bases: object

Dataclass to handle main parameters for plotting.

Notes

Authors: Allan Denis

Parameters:
figsize: tuple[float, float] = (10.0, 7.0)#
legend_ncol: int = 1#
legend_hc_ncol: int = 1#
legend_filt_ncol: int = 1#
legend_fontsize: str = 'small'#
minor_ticks: bool = True#
nb_minor_ticks: int = 5#
class ForMoSA.core.config.ObsPlotConfig(cmap=<factory>, color='#7A1E22', edgecolor=None, norm=<factory>, marker='s', markersize=40, linewidth=1, errorbar_fmt='None', errorbar_alpha=1.0, errorbar_capsize=4.0, zorder_data=3, zorder_error=1, label=True)[source]#

Bases: object

Dataclass to handle configurations for plotting data.

Notes

Authors: Allan Denis

Parameters:
cmap: Colormap#
color: str = '#7A1E22'#
edgecolor: str = None#
norm: Normalize#
marker: str = 's'#
markersize: int = 40#
linewidth: float = 1#
errorbar_fmt: str = 'None'#
errorbar_alpha: float = 1.0#
errorbar_capsize: float = 4.0#
zorder_data: int = 3#
zorder_error: int = 1#
label: bool = True#
to_dict()[source]#

Return configuration options as a dictionary.

Notes

Authors: Allan Denis

Return type:

dict

set_plot_config(**kwargs)[source]#

Update global default plotting parameters for spectroscopic plots.

Parameters:

**kwargs (dict) – Keyword arguments to override attributes of the config

Return type:

None

Notes

Authors: Allan Denis

class ForMoSA.core.config.SpectralPlotConfig(cmap=<factory>, color='#7A1E22', edgecolor=None, norm=<factory>, marker='None', markersize=40, linewidth=1, errorbar_fmt='None', errorbar_alpha=1.0, errorbar_capsize=4.0, zorder_data=3, zorder_error=1, label=True)[source]#

Bases: ObsPlotConfig

Dataclass to handle configurations for plotting spectroscopic data.

Notes

Authors: Allan Denis

Parameters:
color: str = '#7A1E22'#
marker: str = 'None'#
class ForMoSA.core.config.PhotometricPlotConfig(cmap=<factory>, color='blue', edgecolor=None, norm=<factory>, marker='s', markersize=70, linewidth=2.0, errorbar_fmt='None', errorbar_alpha=1.0, errorbar_capsize=4.0, zorder_data=3, zorder_error=1, label=True, label_filter=False, label_data=True)[source]#

Bases: ObsPlotConfig

Dataclass to handle configurations for plotting photometric data.

Notes

Authors: Allan Denis

Parameters:
color: str = 'blue'#
markersize: int = 70#
linewidth: float = 2.0#
label_filter: bool = False#
label_data: bool = True#
class ForMoSA.core.config.CornerPlotConfig(figsize=(15.0, 15.0), color='#A12A1F', bins=80, smooth=1, smooth1d=None, plot_datapoints=False, plot_density=True, plot_contours=True, fill_contours=True, quantiles=(0.16, 0.5, 0.84), levels=<factory>, show_titles=True, title_fmt=' .2f', hist_kwargs=<factory>, contour_kwargs=<factory>, pcolor_kwargs=<factory>, title_kwargs=<factory>, label_kwargs=<factory>, max_n_ticks=4)[source]#

Bases: object

Dataclass to handle configurations for corner plots.

Notes

Authors: Allan Denis

Parameters:
figsize: tuple[float, float] = (15.0, 15.0)#
color: str = '#A12A1F'#
bins: int = 80#
smooth: float = 1#
smooth1d: float | None = None#
plot_datapoints: bool = False#
plot_density: bool = True#
plot_contours: bool = True#
fill_contours: bool = True#
quantiles: tuple = (0.16, 0.5, 0.84)#
levels: list#
show_titles: bool = True#
title_fmt: str = ' .2f'#
hist_kwargs: dict#
contour_kwargs: dict#
pcolor_kwargs: dict#
title_kwargs: dict#
label_kwargs: dict#
max_n_ticks: int = 4#
property to_dict: dict#

Return configuration options as a dictionary.

Notes

Authors: Allan Denis

set_corner_plot_config(**kwargs)[source]#

Update global default plotting parameters for corner plot.

Parameters:

**kwargs (dict) – Keyword arguments to override attributes of the config

Return type:

None

Notes

Authors: Allan Denis

class ForMoSA.core.config.ChainsPlotConfig(figsize=(18.0, 12.0), color_chains='violet', alpha_chains=0.8, color_plot_burn_in='#A12A1F', fontsize_burn_in=14, text_burn_in=(0.8, 0.8), color_text_burn_in='#A12A1F', linestyle_burn_in='--', show_weights=True, color_plot_weights='#1F1F1F', fontsize_weights=14, alpha_weights=0.4, text_weights=(0.8, 0.7), color_text_weights='#1F1F1F', plot_best_value=True, color_best_value='black', linestyle_best_value='-.')[source]#

Bases: object

Dataclass to handle configurations for chains plot.

Notes

Authors: Allan Denis

Parameters:
figsize: tuple[float, float] = (18.0, 12.0)#
color_chains: str = 'violet'#
alpha_chains: float = 0.8#
color_plot_burn_in: str = '#A12A1F'#
fontsize_burn_in: int = 14#
text_burn_in: tuple[float, float] = (0.8, 0.8)#
color_text_burn_in: str = '#A12A1F'#
linestyle_burn_in: str = '--'#
show_weights: bool = True#
color_plot_weights: str = '#1F1F1F'#
fontsize_weights: int = 14#
alpha_weights: float = 0.4#
text_weights: tuple[float, float] = (0.8, 0.7)#
color_text_weights: str = '#1F1F1F'#
plot_best_value: bool = True#
color_best_value: str = 'black'#
linestyle_best_value: str = '-.'#
property to_dict: dict#

Return configuration options as a dictionary.

Notes

Authors: Allan Denis

set_chains_plot_config(**kwargs)[source]#

Update global default plotting parameters for chains plot.

Parameters:

**kwargs (dict) – Keyword arguments to override attributes of the config

Return type:

None

Notes

Authors: Allan Denis

class ForMoSA.core.config.RadarPlotConfig(figsize=(6.0, 6.0), color_radar='#4A5FD9', color_uncertainty='#4A5FD9', linewidth=2.0, fontsize_names=11, fontsize_ticks=11, color_ticks='#24292E', show_ticks=False, alpha_fill=0.35, quantiles=(0.16, 0.84), size_quantiles=80, color_quantiles='#4A5FD9', lw_quantiles=2.0)[source]#

Bases: object

Dataclass to handle configurations for radar plot.

Notes

Authors: Allan Denis

Parameters:
figsize: tuple[float, float] = (6.0, 6.0)#
main_color = '#4A5FD9'#
fill_color = '#6B7FE8'#
uncertainty_color = '#A8B3F5'#
color_radar: str = '#4A5FD9'#
color_uncertainty: str = '#4A5FD9'#
linewidth: float = 2.0#
fontsize_names: int = 11#
fontsize_ticks: int = 11#
color_ticks: str = '#24292E'#
show_ticks: bool = False#
alpha_fill: float = 0.35#
quantiles: tuple[float, float] = (0.16, 0.84)#
size_quantiles: int = 80#
color_quantiles: str = '#4A5FD9'#
lw_quantiles: float = 2.0#
property to_dict: dict#

Return configuration options as a dictionary.

Notes

Authors: Allan Denis

set_radar_plot_config(**kwargs)[source]#

Update global default plotting parameters for radar plot.

Parameters:

**kwargs (dict) – Keyword arguments to override attributes of the config

Return type:

None

Notes

Authors: Allan Denis

class ForMoSA.core.config.BestFitPlotConfig(color_fit='black', color_residuals='#2C2C2C', linewidth=1.0, zorder=200)[source]#

Bases: object

Dataclass to handle configurations for best fit plot.

Notes

Authors: Allan Denis

Parameters:
  • color_fit (str)

  • color_residuals (str)

  • linewidth (float)

  • zorder (int)

color_fit: str = 'black'#
color_residuals: str = '#2C2C2C'#
linewidth: float = 1.0#
zorder: int = 200#
property to_dict: dict#

Return configuration options as a dictionary.

Notes

Authors: Allan Denis

set_best_fit_plot_config(**kwargs)[source]#

Update global default plotting parameters for best fit plot.

Parameters:

**kwargs (dict) – Keyword arguments to override attributes of the config

Return type:

None

Notes

Authors: Allan Denis

class ForMoSA.core.config.PlotsConfig(CornerPlot=<factory>, ChainsPlot=<factory>, RadarPlot=<factory>, BestFitPlot=<factory>)[source]#

Bases: object

Dataclass to handle configurations for plots.

Notes

Authors: Allan Denis

Parameters:
CornerPlot: CornerPlotConfig#
ChainsPlot: ChainsPlotConfig#
RadarPlot: RadarPlotConfig#
BestFitPlot: BestFitPlotConfig#
property to_dict: dict#