tardis.io.model.csvy package

Submodules

Module contents

Read and write CSVY model files.

class tardis.io.model.csvy.CSVYData(model_config: ~tardis.io.configuration.config_reader.Configuration, velocity: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.float64]], density: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy.float64]] | None, mass_fractions: ~pandas.DataFrame = <factory>, isotope_mass_fractions: ~pandas.DataFrame = <factory>, raw_csv_data: ~pandas.DataFrame | None = None)[source]

Bases: object

Data structure for CSVY model data.

Parameters:
model_configConfiguration

Validated configuration object from the CSVY file.

velocitynumpy.ndarray

Velocity array for the model shells.

densitynumpy.ndarray or None

Density array for the model shells.

mass_fractionspandas.DataFrame, optional

Mass fractions DataFrame with atomic_number as index.

isotope_mass_fractionspandas.DataFrame, optional

Isotope mass fractions DataFrame with MultiIndex of atomic and mass number.

raw_csv_datapandas.DataFrame or None, optional

Raw CSV data from the CSVY file.

density: ndarray[tuple[Any, ...], dtype[float64]] | None
isotope_mass_fractions: DataFrame
mass_fractions: DataFrame
model_config: Configuration
raw_csv_data: DataFrame | None = None
velocity: ndarray[tuple[Any, ...], dtype[float64]]
tardis.io.model.csvy.load_csv_from_csvy(fpath: str | Path) → DataFrame | None[source]

Load only the CSV data from a CSVY file.

Parameters:
fnamestr or pathlib.Path

Path to csvy file.

Returns:
datapandas.DataFrame or None

CSV data from csvy file, or None if no CSV data is present.

tardis.io.model.csvy.load_csvy(fname: str | Path) → CSVYData[source]

Load CSVY file and return a CSVYData dataclass object.

This function extracts velocity, density, and mass fractions from the CSVY file and constructs a CSVYData object. Velocity and density can be defined either in the YAML metadata or in the CSV data section.

Parameters:
fnamestr or pathlib.Path

Path to csvy file.

Returns:
CSVYData

Dataclass containing YAML metadata, velocity, density, and mass fractions.

tardis.io.model.csvy.load_yaml_from_csvy(fpath: str | Path) → dict[source]

Load only the YAML metadata from a CSVY file.

Parameters:
fnamestr or pathlib.Path

Path to csvy file.

Returns:
dict

YAML metadata dictionary from the csvy file.

Raises:
AssertionError

If the first line is not the YAML delimiter ‘—‘.

ValueError

If the closing YAML delimiter ‘—’ is not found.

tardis.io.model.csvy.parse_csv_mass_fractions(csvy_data: DataFrame) → tuple[Index, DataFrame, DataFrame][source]

Parse the CSV data part of a CSVY model file and extract mass fractions.

This function filters out columns that are not mass fractions and separates elemental and isotopic mass fractions. Element symbols are case-insensitive (e.g. “si” or “Si”).

Parameters:
csvy_datapandas.DataFrame

CSV data from CSVY file containing mass fraction columns.

Returns:
indexpandas.Index

Index of atomic numbers for elemental mass fractions.

mass_fractionspandas.DataFrame

DataFrame of elemental mass fractions with atomic_number as index.

isotope_mass_fractionspandas.DataFrame

DataFrame of isotopic mass fractions with MultiIndex of (atomic_number, mass_number).

tardis.io.model.csvy.write_csvy(path: str | Path, density_t_0: Quantity, isotope_t_0: Quantity, velocity: Quantity, density: Quantity, abundance: DataFrame, elements: list[str], overwrite: bool = False) → Path[source]

Write a CSVY model file.

Parameters:
pathstr or pathlib.Path

Output path. The .csvy suffix is added or replaced.

density_t_0astropy.units.Quantity

Initial time for the density model.

isotope_t_0astropy.units.Quantity

Initial time for isotope decay.

velocityastropy.units.Quantity

Shell boundary velocities.

densityastropy.units.Quantity

Shell densities.

abundancepandas.DataFrame

Abundance values indexed by shell and species.

elementslist of str

Species names corresponding to the abundance columns.

overwritebool, optional

Whether to overwrite an existing file. Defaults to False.

Returns:
pathlib.Path

The path of the written CSVY file.

Raises:
FileExistsError

If the output exists and overwrite is False.