Observations

Contents

Observations#

Observation Base#

Abstract base class shared by all observation types.

Inheritance diagram of ForMoSA.observation.observation_spectroscopy.SpectralObservation, ForMoSA.observation.observation_photometry.PhotometryObservation
class ForMoSA.observation.observation_base.Observation(wave, flux, err, native_unit, facility, instrument, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER, plot_config=ObsPlotConfig(cmap=<matplotlib.colors.LinearSegmentedColormap object>, color='#7A1E22', edgecolor='#551518', norm=<matplotlib.colors.Normalize object>, 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: ABC

Base class for any observation (photometric or spectroscopic).

Parameters:
  • wave (ndarray) – Wavelength array

  • flux (ndarray) – Flux array

  • err (ndarray) – Error array

  • native_unit (WavelengthUnit) – Native unit of the wavelength array

  • facility (str) – Facility name

  • instrument (str) – Instrument name

  • logger (Logger | None) – Logger

  • log_level (str) – Level of the logging

  • display_unit (WavelengthUnit) – Display unit of the wavelength array

  • plot_config (ObsPlotConfig) – Plot configuration for the observation

Notes

Authors: Allan Denis

abstract property ObsType: <property object at 0x7d7380ea7150>#

Observation type.

abstract property to_dict: dict[str, ndarray]#

Dictionary representation of the observations.

abstract property name: str#

Observation name.

abstract property wavelength_range: tuple[float, float]#

Wavelength range.

abstract property res: ndarray[float]#

Resolution.

abstract property hc_mode: bool#

Whether observation is in high-contrast mode.

abstractmethod plot_data(fig=None, ax=None, ax_filt=None, draw_legend=True)[source]#

Plot the observation.

Parameters:
  • fig (Figure | None) – Figure (used to overplot on an existing figure)

  • ax (Axes | None) – Ax (used to overplot on an existing ax)

  • ax_filt (Axes | None) – Ax used to overplot the transmission filter on an existing ax

  • draw_legend (bool) – Whether to draw the legend. Set to False when called from a parent function (e.g. plot_all) that manages the legend itself.

Return type:

tuple[Figure, Axes, Axes]

Notes

Authors: Allan Denis

property is_spectroscopic: bool#

Whether observation is spectroscopic.

property is_photometric: bool#

Whether observation is photometric.

property native_unit: Unit#

Native unit of the wavelength array.

property unit: PrefixUnit#

Display unit of the wavelength array.

property wave: ndarray#

Wavelength array.

property central_wavelength: float#

Central wavelength.

property flux: ndarray[float]#

Flux array.

property err: ndarray[float]#

Error array.

property facility: ndarray[str]#

Facility (e.g. ‘JWST’, ‘Keck’, ‘Paranal’).

property instrument: ndarray[str]#

Instrument (e.g. ‘NIRCam’, ‘NIRC2’, ‘SPHERE’).

property n_points: int#

Number of points.

property logger: Logger#

Logger.

property path: Path#

Path of the observation (if any).

property plot_config: ObsPlotConfig#

Configuration plotting.

classmethod from_dict(data, logger=None, log_level='INFO', **kwargs)[source]#

Generate Observation from dictionary of data.

Parameters:
  • data (dict) – Dictionary of data

  • logger (Logger | None) – Logger

  • log_level (str) – Level of the Logger

  • **kwargs (Additional arguments)

Return type:

Observation

Returns:

Obervation – An instance of class Observation

Examples

>>> obs = Observation.from_dict(data, logger, log_level)

Notes

Authors: Allan Denis

classmethod from_file(path, logger=None, log_level='INFO', **kwargs)[source]#

Generate Observation from a fits file.

Parameters:
  • path (str | PathLike) – Path to the observation

  • logger (Logger | None) – Logger

  • log_level (str) – Level of the Logger

  • **kwargs (Additional keyword arguments)

Return type:

Observation

Returns:

“Observation” – Instance of class Observation

Examples

>>> obs = Observation._from_file(path, logger, log_level)

Notes

Authors: Allan Denis

classmethod from_attributes(logger=None, log_level='INFO', **kwargs)[source]#

Generation Observation from attributes.

Parameters:
  • **kwargs (Keyword attributes)

  • logger (Logger | None)

  • log_level (str)

Return type:

Observation

Returns:

“Observation” – Instance of class Observation

Examples

>>> obs = Observation._from_attributes(**attributes, logger, log_level)

Notes

Authors: Allan Denis

save_observation(store_path, file_format='npz')[source]#

Save observation to disk as .npz files.

Parameters:
  • store_path (str | PathLike) – Path where to store the observation file

  • file_format (str) – Format of the file to save (‘npz’ or ‘fits’)

Return type:

None

Notes

Authors: Allan Denis

Observation Loader#

Factory that creates Observation instances from FITS files, dictionaries, or raw attributes.

class ForMoSA.observation.observation_loader.ObservationLoader[source]#

Bases: object

Class responsible for observation loading from various inputs format

Notes

Authors: Allan Denis

Spectral Observation#

class ForMoSA.observation.observation_spectroscopy.SpectralObservation(wave, flux, err, res, facility, instrument, native_unit, cov=None, transm=None, star_flux=None, system=None, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER)[source]#

Bases: Observation

Spectral observation class.

Parameters:
  • wave (ndarray) – Wavelength array

  • flux (ndarray) – Flux array

  • err (ndarray) – Error array

  • res (ndarray) – Spectral resolution array

  • facility (str) – Facility name

  • instrument (str) – Instrument name

  • native_unit (WavelengthUnit) – Native unit of the wavelength

  • cov (ndarray | None) – Covariance matrix

  • transm (ndarray | None) – Transmission array (Atmo+inst)

  • star_flux (ndarray | None) – Star flux array

  • system (ndarray | None) – Systematics array

  • logger (Logger | None) – Logger

  • log_level (str) – Level of the logger

  • display_unit (WavelengthUnit) – Unit of the wavelength to display

Notes

Authors: Allan Denis

property ObsType: ObservationType#

Observation type.

property res: ndarray[float]#

Resolution.

property cov: ndarray[float] | None#

Covariance.

property inv_cov: ndarray[float] | None#

Inverse of covariance.

property transm: ndarray[float] | None#

Transmission.

property star_flux: ndarray[float] | None#

Stellar flux.

property system: ndarray[float] | None#

Systematics.

property flux_cont: ndarray[float] | None#

Continuum of the flux.

property star_flux_cont: ndarray[float] | None#

Continuum of the star flux.

property wave_cont: str | None#

Wavelengths used for the continuum.

property res_cont: float | None#

Resolution used for the continuum.

property hc_mode: bool#

Whether the observation is in high-contrast mode.

property max_resolution: float#

Maximum resolution.

property min_resolution: float#

Minimum resolution.

property to_dict: dict[str, ndarray]#

Dictionary representation of spectroscopic data.

property name: str#

Observation name.

property wavelength_range: tuple[float, float]#

Wavelength range of the observation.

property instrument_idxs: ndarray#

Indexes of occurence of new instruments.

property nb_instruments: int#

Number of instruments.

plot_data(fig=None, ax=None, ax_filt=None, draw_legend=True)[source]#

Plot spectroscopic data.

Parameters:
  • fig (Figure | None) – Figure (used to overplot on an existing figure)

  • ax (Axes | None) – Ax (used to overplot on an existing ax)

  • ax_filt (Axes | None) – Ax used to overplot the transmission filter on an existing ax

  • draw_legend (bool) – Whether to draw the legend. Set to False when called from a parent function (e.g. plot_all) that manages the legend itself.

Return type:

tuple[Figure, Axes, Axes]

Returns:

  • fig (matplotlib.figure.Figure) – Updated figure

  • ax (matplotlib.axes._axes.Axes) – Updated ax

  • ax_filt (matplotlib.axes._axes.Axes) – Non updated ax_filt

Notes

Authors: Allan Denis

Photometry Observation#

class ForMoSA.observation.observation_photometry.PhotometryObservation(wave, flux, err, instrument, facility, filter_id, native_unit, logger=None, log_level='INFO', display_unit=WavelengthUnit.MICROMETER)[source]#

Bases: Observation

Photometric observation class.

Parameters:

Notes

Authors: Allan Denis

property ObsType: ObservationType#

Observation type.

property res: ndarray[float]#

Resolution.

property hc_mode: bool#

Whether observation is in high-contrast mode.

property to_dict: dict[str, ndarray]#

Dictionary representation of photometric observations.

property Filter: ndarray[PhotometryFilter]#

Photometric filters.

property filter_id: ndarray[str]#

Filter ID.

property name: str#

Observation name.

property wavelength_range: tuple#

Wavelength range of the observation.

property filter_idxs: ndarray#

Indexes of occurence of new filters.

property nb_filters: int#

Number of filters.

plot_data(fig=None, ax=None, ax_filt=None, draw_legend=True)[source]#

Plot photometric data.

Parameters:
  • figure (matplotlib.figure.Figure) – Figure (used to overplot on an existing figure)

  • ax (Axes | None) – Ax (used to overplot on an existing ax)

  • ax_filt (Axes | None) – Ax used to overplot the transmission filter on an existing ax

  • fig (Figure | None)

  • draw_legend (bool)

Return type:

tuple[Figure, Axes, Axes]

Returns:

  • fig (matplotlib.figure.Figure) – Updated figure

  • ax (matplotlib.axes._axes.Axes) – Updated ax

  • ax_filt (matplotlib.axes._axes.Axes) – Updated ax_filt

Notes

Authors: Allan Denis

Observation Set#

Container that groups multiple observations together.

class ForMoSA.observation.observation_set.ObservationSet(logger=None, log_level='INFO')[source]#

Bases: object

Container for a set of Observation objects.

Parameters:
  • logger (Logger | None) – Logger

  • log_level (str) – Level of the logging

Notes

Authors: Allan Denis

property is_empty: bool#

Whether ObservationSet is empty.

property logger: Logger#

Logger.

property observation_names: list[str]#

List of observation names.

property observations: list[Observation]#

List of observations.

property n_observations: int#

Number of observations.

property has_spectroscopy: bool#

Whether the observation set has spectroscopy.

property has_photometry: bool#

Whether the observation set has photometry.

property has_high_contrast: bool#

Whether the observation set has high-contrast observations.

property spectral_observations: list[SpectralObservation]#

List of spectroscopic observations.

property photometry_observations: list[PhotometryObservation]#

List of photometric observations.

property high_contrast_observations: list[Observation]#

List of high-contrast observation.

property max_resolution: float | None#

Maximum resolution (None if no spectroscopic observation).

property min_resolution: float | None#

Minimum resolution (None if no spectroscopic observation).

property wavelength_range: tuple[float, float]#

Global wavelength range.

property to_dict: dict#

Dictionary representation of the set of observations.

property mcolors_normalize: Normalize#

Color normalization (for plotting).

classmethod from_npz(path, logger=None, log_level='INFO')[source]#

Create an instance of ObservationSet from a path containing observation fits files.

Parameters:
  • path (str | PathLike) – Path containing all the observations

  • logger (Logger | None) – Logger

  • log_level (str) – Level of the Logger

Return type:

ObservationSet

Returns:

“ObservationSet” – An instance of ObservationSet

Notes

Authors: Allan Denis

classmethod from_fits(path, logger=None, log_level='INFO')[source]#

Create an instance of ObservationSet from a path containing observation fits files.

Parameters:
Return type:

ObservationSet

Returns:

“ObservationSet” – An instance of ObservationSet

Notes

Authors: Allan Denis

classmethod from_dict(data, logger=None, log_level='INFO')[source]#

Reconstruct an ObservationSet from a dictionary of ObservationSet.

Parameters:
  • data (dict) – Dictionary containing ObservationSet parameters

  • logger (Logger | None) – Logger

  • log_level (str) – Level of the logging

Return type:

ObservationSet

Returns:

‘ParameterSet’ – An instance of class ParameterSet

Notes

Authors: Allan Denis

classmethod from_json(path, logger=None, log_level='INFO')[source]#

Reconstruct an ObservationSet from a json file.

Parameters:
  • path (str | PathLike) – Path to the json file

  • logger (Logger | None) – Logger

  • log_level (str) – Level of the logging

Return type:

ObservationSet

Returns:

‘ParameterSet’ – An instance of class ParameterSet

Notes

Authors: Allan Denis

classmethod from_list(obs_list, logger=None, log_level='INFO')[source]#

Reconstruct an ObservationSet from a list of observations.

Parameters:
Return type:

ObservationSet

Returns:

‘ParameterSet’ – An instance of class ParameterSet

Notes

Authors: Allan Denis

add_observation(*args, **kwargs)[source]#

Add an observation to the set based on the type of data provided.

Parameters:
  • args

    • If a Observation object is provided, directly add the observation

    • If a .fits file is provided, provide a single argument path (str | Path)

    • If a dictionary of data is provided, provide a single argument data (dict)

    • If attributes are provided, provide the necessary arguments to create the observation (Spectral or Photometric)

  • kwargs (Additional attributes for the observations if necessary.)

  • Example

  • self.add_observation(path="path/to/file.fits") (-)

  • self.add_observation(data={"wavelength" (-)

  • self.add_observation(name="spectral_obs" (-)

  • wavelength=...

  • flux=...

  • ...)

Notes

Authors: Allan Denis

save_all(path, to_json=False)[source]#

Save all observations to disk as .npz files.

Parameters:
  • path (str | PathLike) – Directory where to save the observations

  • prefix (str) – Prefix for the saved files

  • to_json (bool) – Whether to save all observations in a json file

Return type:

None

Notes

Authors: Allan Denis

adapt_all(target_resolution, wave_cont=None, res_cont=None)[source]#

Adapt all observations to the target resolution.

Parameters:
  • target_resolution (list[ndarray])

  • wave_cont (list[str] | None) – List of wavelengths used for the continuum

  • res_cont (list[float] | None) – List os resolutions used for the continuum

Return type:

None

Notes

Authors: Simon Petrus, Matthieu Ravet and Allan Denis

to_json(path)[source]#

Save the set of observations to a given path as a json file.

Parameters:

path (str | PathLike) – Path to save the set of parameters

Return type:

None

Notes

Authors: Allan Denis

plot_all(fig=None, ax=None, ax_hc=None, ax_filt=None)[source]#

Plot all the observations and photometric filters.

Parameters:
  • fig (Figure | None) – Figure (used to overplot on an existing figure)

  • ax (Axes | None) – Ax (used to overplot non-high-contrast observations)

  • ax_hc (Axes | None) – Ax used to overplot high-contrast observations. When None and ax is provided, HC observations fall back to ax (e.g. inside plot_fit).

  • ax_filt (Axes | None) – Ax used to overplot the transmission filter

Return type:

tuple[Figure, Axes, Axes | None]

Returns:

  • fig (matplotlib.figure.Figure) – New Figure object

  • ax (matplotlib.axes._axes.Axes) – New Ax object

  • ax_filt (matplotlib.axes._axes.Axes) – New ax object for photometric filters

Notes

Authors: Allan Denis