Model Grids#
Model Grid#
Core grid class that wraps an xarray.Dataset and exposes wavelength,
resolution, parameter coordinates, and interpolation helpers.
- class ForMoSA.grid.model_grid.ModelGrid(dataset, model_path=None, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER)[source]#
Bases:
objectRepresentation of a model grid with metadata. Handles loading from file and exposing basic properties.
- Parameters:
Notes
Authors: Allan Denis
- property grid_as_dataarray: DataArray#
Grid as xr.DataArray (more tailored to manipulations).
- property native_unit: PrefixUnit#
Native unit of the wavelength.
- property unit: PrefixUnit#
Unit of the wavelength to display.
- property grid: Dataset#
Grid as xr.Dataset.
- property lims_params_grid#
Limits of grid parameters.
- property effective_resolution: ndarray#
Effective resolution beeing the minimum between Nyquist sampling and resolution.
Grid Loader#
Responsible for loading and validating NetCDF grid files.
SubGrid Base#
Abstract base class for spectroscopic and photometric subgrids.

- class ForMoSA.grid.subgrid_base.SubGrid(grid, parent_grid, logger=None, log_level='INFO', name='Unknown', display_unit=WavelengthUnit.MICROMETER)[source]#
-
Base class for any subgrid (spectroscopic or photometric). Inherits from the ModelGrid class.
- Parameters:
Notes
Authors: Allan Denis
- abstract property GridType: <property object at 0x7d7380ea7150>#
Grid type (spectroscopic or photometric).
- abstract property relevant_parameter_kinds: list[ParameterKind]#
List of relevant parameter kinds the subgrid applies to.
- property unit: PrefixUnit#
Unit of the wavelength to display.
- classmethod from_dataset(ds, parent_grid, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER)[source]#
Generate SubGrid from dataset.
- Parameters:
ds (
Dataset) – Dataset containing the parameters of the subgridparent_grid (
ModelGrid) – Parent model gridlog_level (
str) – Level of the Loggerdisplay_unit (WavelengthUnit)
- Return type:
- Returns:
‘SubGrid’ – An instance of class SubGrid
Notes
Authors: Allan Denis
- classmethod from_file(path, parent_grid, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER)[source]#
Generate SubGrid from file.
- Parameters:
- Return type:
- Returns:
‘SubGrid’ – An instance of class SubGrid
Notes
Authors: Allan Denis
- adapt_grid(backend='loky', n_jobs=-1)[source]#
Adapt the entire grid to the observation.
- Parameters:
- Return type:
Notes
Authors: Arthur Vigan and Allan Denis
- evaluate_at_gridpoints(grid_params, interp_method='linear')[source]#
Evaluate model given a list of parameters and their associated values.
- Parameters:
params (Dict[Parameter, float]) – Dictionary of grid parameters and their associated values
interp_method (
str) – Interpolation methodgrid_params (ObservedParameters)
- Return type:
- Returns:
observed_model (ObservedModel) – Instance of class ObservedModel
Notes
Authors: Allan Denis
SubGrid Set#
Container for a collection of adapted subgrids.
- class ForMoSA.grid.subgrid_set.SubGridSet(parent_grid, logger=None, log_level='INFO')[source]#
Bases:
objectContainer for a set of subgrids (spectroscopic or photometric).
Can be initialized empty or directly from an ObservationSet.
- Parameters:
Notes
Authors: Allan Denis
- property spectroscopic_subgrids: list[SubGridSpectroscopy]#
List of spectroscopic subgrids.
- property photometric_subgrids: list[SubGridPhotometry]#
List of photometric subgrids.
- classmethod from_path(path, parent_grid, logger=None, log_level='INFO')[source]#
Generate an instance of SubGridSet from the folder containing all the subgrids.
- Parameters:
- Return type:
- Returns:
“SubGridSet” – Instance of SubGridSet
Notes
Authors: Allan Denis
- add_subgrid(*args, **kwargs)[source]#
Add a subgrid to the set based on the type of data provided.
- Parameters:
args –
If a SubGrid object is provided, directly add it
If a .nc file is provided, provide a single argument (str | Path)
If an xr.Dataset is provided, provide a single argument
- Return type:
Notes
Authors: Allan Denis
Spectroscopic SubGrid#
- class ForMoSA.grid.subgrid_spectroscopy.SubGridSpectroscopy(grid, parent_grid=None, remove_continuum=False, wave_cont=None, res_cont=None, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER, name='Unknown')[source]#
Bases:
SubGridSpectral subgrid class, which implements adaptation to a specific wavelength and resolution.
- Parameters:
grid (
Dataset) – Gridremove_continuum (
bool) – Whether to remove the continuumwave_cont (
str|None) – Wavelengths for continuum removal (‘window1 / window2 / windw3 / …’ where window{i} = ‘wave{i}, wave{i+1}’)log_level (
str) – Level of the loggername (
str) – Name of the subgriddisplay_unit (WavelengthUnit)
Notes
Authors: Allan Denis
- property GridType: ObservationType#
Observation type.
- property relevant_parameter_kinds: list[ParameterKind]#
List of relevant parameter kinds the observation applies to.
- classmethod from_parent(parent_grid, target_wavelength, target_resolution, remove_continuum=False, wave_cont=None, res_cont=None, name='unknown', logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER, backend='loky', n_jobs=-1)[source]#
Build spectroscopic subgrid from the parent grid, target_wavelength and target resolution to reach.
- Parameters:
parent_grid (
ModelGrid) – Instance of ModelGridtarget_wavelength (
ndarray) – Target wavelength to reach for the subgridtarget_resolution (
ndarray) – Target resolution to reach for the subgridremove_continuum (
bool) – Whether to remove the continuumwave_cont (
ndarray|None) – Wavelengths used for the continuumname (
str) – Name of the subgridlog_level (
str) – Level of the Loggerdisplay_unit (
WavelengthUnit) – Unit to display for the wavelengthbackend (str)
n_jobs (int)
- Return type:
- Returns:
SubGridSPectroscopy – Instance of SubGridSpectroscopy
Examples
>>> subgrid = SubGridSpectroscopy.from_parent(parent_grid, target_wavelength, target_resolution, remove_continuum, wave_cont, res_cont, name, logger, log_level, display_unit)
Notes
Authors: Allan Denis
- classmethod from_grid(ds, parent_grid, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER)[source]#
Retrieve spectorscopic subgrid from grid.
- Parameters:
dx (xr.Dataset) – Grid data
parent_grid (
ModelGrid) – Instance of ModelGridlog_level (
str) – Level of the Loggerdisplay_unit (
WavelengthUnit) – Unit to display for the wavelengthds (Dataset)
- Return type:
- Returns:
SubGridSpectroscopy – Instance of SubGridSpectroscopy
Examples
>>> subgrid = SubGridSpectroscopy.from_grid(grid, parent_grid, logger, log_level, display_unit)
Notes
Authors: Allan Denis
Photometric SubGrid#
- class ForMoSA.grid.subgrid_photometry.SubGridPhotometry(grid, parent_grid, Filter, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER, name='Unknown')[source]#
Bases:
SubGridPhotometric subgrid class, which implements adaptation to a specific filter.
- Parameters:
grid (
Dataset) – Dataset containing the subgridparent_grid (
ModelGrid) – Parent model gridFilter (
ndarray[PhotometryFilter]) – Instance of :class:~PhotometryFilter corresponding to the photometric filterlog_level (
str) – Level of the loggerdisplay_unit (
WavelengthUnit) – Unit of the wavelength to displayname (
str) – Name of the subgrid
Notes
Authors: Allan Denis
- property GridType: ObservationType#
Observation type.
- property Filter: ndarray[PhotometryFilter]#
Filter.
- property relevant_parameter_kinds: list[ParameterKind]#
List of relevant parameter kinds the subgrid applies to.
- classmethod from_parent(parent_grid, Filter, name='unknown', logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER, backend='loky', n_jobs=-1)[source]#
Build Photometric subgrid from the parent grid, target_wavelength.
- Parameters:
parent_grid (
ModelGrid) – Instance of ModelGridFilter (
ndarray[PhotometryFilter]) – Arrays containing instances of class PhotometryFilter corresponding to the photometric filtername (
str) – Name of the subgridlog_level (
str) – Level of the Loggerdisplay_unit (
WavelengthUnit) – Unit to display for the wavelengthbackend (str)
n_jobs (int)
- Return type:
- Returns:
SubGridPhotometryy – Instance of SubGridPhotometry
Examples
>>> subgrid = SubGridPhotometry.from_parent(parent_grid, Filter, name, logger, log_level, display_unit)
Notes
Authors: Allan Denis
- classmethod from_grid(ds, parent_grid, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER)[source]#
Retrieve photometric subgrid from grid.
- Parameters:
dx (xr.Dataset) – Grid data
parent_grid (
ModelGrid) – Instance of ModelGridlog_level (
str) – Level of the Loggerdisplay_unit (
WavelengthUnit) – Unit to display for the wavelengthds (Dataset)
- Return type:
- Returns:
SubGridPhotometry – Instance of SubGridPhotometry
Examples
>>> subgrid = SubGridPhotometry.from_grid(ds, parent_grid, logger, log_level, display_unit)
Notes
Authors: Allan Denis
- adapt(backend='loky', n_jobs=-1)[source]#
Adapt the native grid to the target wavelength and resolution.
Notes
Authors: Allan Denis
- integrate_filter_curve(model_to_adapt, print_logger=False)[source]#
Method to integrate the filter curve on a spectrum
- Parameters:
model_to_adapt (
DataArray) – Model to integrateprint_logger (bool)
- Return type:
- Returns:
xr.DataArray – Integrated value under the filter curve
Notes
Authors: Allan Denis