Skip to content

Loader

Parse FRECKLL input file.

ace_equil_chemistry_loader(*, species, temperature, pressure, therm_file=None, elements=('H', 'He', 'C', 'N', 'O'), abundances=(12, 10.93, 8.39, 7.86, 8.73), **kwargs)

Loads and runs the ACE chemistry model.

Source code in src/freckll/io/loader.py
def ace_equil_chemistry_loader(
    *,
    species: list[SpeciesFormula],
    temperature: u.Quantity,
    pressure: u.Quantity,
    therm_file: t.Optional[pathlib.Path] = None,
    elements: t.Sequence[str] = ("H", "He", "C", "N", "O"),
    abundances: t.Sequence[float] = (
        12,
        10.93,
        8.39,
        7.86,
        8.73,
    ),
    **kwargs: t.Any,
) -> npt.NDArray[np.floating]:
    """Loads and runs the ACE chemistry model."""
    from ..ace import equil_chemistry_ace

    return equil_chemistry_ace(
        composition=species,
        therm_file=therm_file,
        elements=elements,
        abundances=abundances,
        temperature=temperature,
        pressure=pressure,
    )

default_full_network_loader()

Load the default full network.

Source code in src/freckll/io/loader.py
def default_full_network_loader() -> VenotChemicalNetwork:
    """Load the default full network."""
    import importlib.resources
    import pathlib

    full_network_path = importlib.resources.files("freckll.data") / "Venot2020_Taurex"
    full_network_path = full_network_path.resolve()
    full_network_path = pathlib.Path(full_network_path)

    return VenotChemicalNetwork(
        full_network_path,
    )

default_network_loader(network)

Load the default network.

Parameters:

Name Type Description Default
network Networks

The network to load. Can be "venot-methanol-2020" or "venot-methanol-2020-reduced".

required

Returns:

Type Description
VenotChemicalNetwork

The loaded network.

Source code in src/freckll/io/loader.py
def default_network_loader(network: Networks) -> VenotChemicalNetwork:
    """Load the default network.

    Args:
        network: The network to load. Can be "venot-methanol-2020" or "venot-methanol-2020-reduced".

    Returns:
        The loaded network.

    """
    if network == "venot-methanol-2020":
        return default_full_network_loader()
    elif network == "venot-methanol-2020-reduced":
        return default_reduced_network_loader()
    else:
        _log.error(f"Unknown network '{network}'")
        raise ValueError

default_photonetwork_loader(species_list)

Load the default photo network.

Source code in src/freckll/io/loader.py
def default_photonetwork_loader(species_list: list[SpeciesFormula]) -> VenotPhotoChemistry:
    """Load the default photo network."""
    import importlib.resources

    photo_file = importlib.resources.files("freckll.data") / "Venot2020_Taurex" / "photodissociations.dat"
    photo_file = photo_file.resolve()
    section_path = importlib.resources.files("freckll.data") / "Sections"

    section_path = section_path.resolve()

    return VenotPhotoChemistry(
        species_list,
        photodissociation_file=photo_file,
        cross_section_path=section_path,
    )

default_reduced_network_loader()

Load the default reduced network.

Source code in src/freckll/io/loader.py
def default_reduced_network_loader() -> VenotChemicalNetwork:
    """Load the default reduced network."""
    import importlib.resources
    import pathlib

    reduced_network_path = importlib.resources.files("freckll.data") / "Venot2020_reduced_TAUREX"
    reduced_network_path = reduced_network_path.resolve()
    reduced_network_path = pathlib.Path(reduced_network_path)

    return VenotChemicalNetwork(
        reduced_network_path,
    )

default_stellar_spectra_loader(star)

Load the default stellar spectra.

Parameters:

Name Type Description Default
star Stars

The star to load. Can be "55cnc", "adleo", "gj436", "gj3470", "hd128167", "hd189733", "hd209458", "sun", "wasp12", "wasp39", "wasp43".

required

Returns:

Type Description
StarSpectra

The loaded stellar spectra.

Source code in src/freckll/io/loader.py
def default_stellar_spectra_loader(
    star: Stars,
) -> StarSpectra:
    """Load the default stellar spectra.

    Args:
        star: The star to load. Can be "55cnc", "adleo", "gj436", "gj3470", "hd128167", "hd189733", "hd209458", "sun", "wasp12", "wasp39", "wasp43".

    Returns:
        The loaded stellar spectra.
    """

    import importlib.resources
    import pathlib

    if star not in t.get_args(Stars):
        _log.error(f"Unknown star '{star}'")
        raise ValueError

    star_path = importlib.resources.files("freckll.data") / "Stars" / f"stellarflux_{star}.dat"
    star_path = star_path.resolve()
    star_path = pathlib.Path(star_path)

    with open(star_path) as f:
        wav, flux = np.loadtxt(
            f,
            unpack=True,
        )

    return StarSpectra(
        wav << u.nm,
        flux << u.photon / u.cm**2 / u.s / u.nm,
        reference_distance=1.0 * u.AU,
    )

generic_csv_loader(filename, columns, column_units, skiprows=0, delimiter=None, comments=None)

Load a csv file

Parameters:

Name Type Description Default
filename PathLike

Path to the csv file.

required
columns list[int]

List of columns to load. 0 being first

required
column_units list[Unit | None]

List of units for each column.

required
skiprows Optional[int]

Number of rows to skip at the beginning of the file.

0
delimiter Optional[str]

Delimiter used in the file.

None
comments Optional[str]

Comment character in the file.

None

Returns: Tuple of quantities for each column.

Source code in src/freckll/io/loader.py
def generic_csv_loader(
    filename: PathLike,
    columns: list[int],
    column_units: list[u.Unit | None],
    skiprows: t.Optional[int] = 0,
    delimiter: t.Optional[str] = None,
    comments: t.Optional[str] = None,
) -> tuple[u.Quantity | npt.NDArray[np.floating], ...]:
    """Load a csv file

    Args:
        filename: Path to the csv file.
        columns: List of columns to load. 0 being first
        column_units: List of units for each column.
        skiprows: Number of rows to skip at the beginning of the file.
        delimiter: Delimiter used in the file.
        comments: Comment character in the file.
    Returns:
        Tuple of quantities for each column.

    """
    filename = pathlib.Path(filename)
    if not filename.exists():
        _log.error(f"File {filename} does not exist.")
        raise FileNotFoundError

    if not filename.is_file():
        _log.error(f"File {filename} is not a file.")
        raise FileNotFoundError

    columns = [int(c) for c in columns]

    with open(filename) as f:
        res = np.loadtxt(
            f,
            skiprows=int(skiprows),
            delimiter=delimiter,
            usecols=columns,
            comments=comments,
            unpack=True,
        )

    # Convert to quantities
    quantities = []
    for data, quantity in zip(res, column_units):
        if quantity is None:
            quantities.append(data)
        else:
            quantities.append(data * quantity)
    return tuple(quantities)

kzz_profile_loader(*, filename, kzz_column, pressure_column, kzz_unit, pressure_unit, skiprows=0, delimiter=None, comments=None, start='bottom')

Load a kzz profile from a csv file.

Parameters:

Name Type Description Default
filename PathLike

Path to the csv file.

required
kzz_column int

Column index for kzz. 0 being first

required
pressure_column int

Column index for pressure. 0 being first

required
kzz_unit Unit

Unit for kzz.

required
skiprows Optional[int]

Number of rows to skip at the beginning of the file.

0
delimiter Optional[str]

Delimiter used in the file.

None
comments Optional[str]

Comment character in the file.

None

Returns: Tuple of kzz and pressure quantities.

Source code in src/freckll/io/loader.py
def kzz_profile_loader(
    *,
    filename: PathLike,
    kzz_column: int,
    pressure_column: int,
    kzz_unit: u.Unit,
    pressure_unit: u.Unit,
    skiprows: t.Optional[int] = 0,
    delimiter: t.Optional[str] = None,
    comments: t.Optional[str] = None,
    start: t.Literal["top", "bottom"] = "bottom",
) -> tuple[u.Quantity, u.Quantity]:
    """Load a kzz profile from a csv file.

    Args:
        filename: Path to the csv file.
        kzz_column: Column index for kzz. 0 being first
        pressure_column: Column index for pressure. 0 being first
        kzz_unit: Unit for kzz.
        skiprows: Number of rows to skip at the beginning of the file.
        delimiter: Delimiter used in the file.
        comments: Comment character in the file.
    Returns:
        Tuple of kzz and pressure quantities.


    """
    pressure, kzz = generic_csv_loader(
        filename,
        [pressure_column, kzz_column],
        [pressure_unit, kzz_unit],
        skiprows=skiprows,
        delimiter=delimiter,
        comments=comments,
    )

    # Reverse the profile if it starts at the top
    if start == "top":
        pressure = pressure[::-1]
        kzz = kzz[::-1]
    return pressure, kzz

star_spectra_loader(*, filename, flux_column, spectral_column, flux_unit, spectral_unit, reference_distance, skiprows=0, delimiter=None, comments=None)

Load a kzz profile from a csv file.

Parameters:

Name Type Description Default
filename PathLike

Path to the csv file.

required
flux_column int

Column index for flux. 0 being first

required
spectral_column int

Column index for spectral. 0 being first

required
flux_unit Unit

Unit for flux.

required
spectral_unit Unit

Unit for spectral.

required
reference_distance Quantity

Reference distance for the flux.

required
skiprows Optional[int]

Number of rows to skip at the beginning of the file.

0
delimiter Optional[str]

Delimiter used in the file.

None
comments Optional[str]

Comment character in the file.

None

Returns: Tuple of kzz and pressure quantities.

Source code in src/freckll/io/loader.py
def star_spectra_loader(
    *,
    filename: PathLike,
    flux_column: int,
    spectral_column: int,
    flux_unit: u.Unit,
    spectral_unit: u.Unit,
    reference_distance: u.Quantity,
    skiprows: t.Optional[int] = 0,
    delimiter: t.Optional[str] = None,
    comments: t.Optional[str] = None,
) -> StarSpectra:
    """Load a kzz profile from a csv file.

    Args:
        filename: Path to the csv file.
        flux_column: Column index for flux. 0 being first
        spectral_column: Column index for spectral. 0 being first
        flux_unit: Unit for flux.
        spectral_unit: Unit for spectral.
        reference_distance: Reference distance for the flux.
        skiprows: Number of rows to skip at the beginning of the file.
        delimiter: Delimiter used in the file.
        comments: Comment character in the file.
    Returns:
        Tuple of kzz and pressure quantities.


    """
    wav, flux = generic_csv_loader(
        filename,
        [spectral_column, flux_column],
        [spectral_unit, flux_unit],
        skiprows=skiprows,
        delimiter=delimiter,
        comments=comments,
    )

    return StarSpectra(
        wav,
        flux,
        reference_distance=reference_distance,
    )

tp_profile_loader(*, filename, temperature_column, pressure_column, temperature_unit, pressure_unit, skiprows=0, delimiter=None, comments=None, start='bottom')

Load a temperature-pressure profile from a csv file.

Parameters:

Name Type Description Default
filename PathLike

Path to the csv file.

required
temperature_column int

Column index for temperature. 0 being first

required
pressure_column int

Column index for pressure. 0 being first

required
temperature_unit Unit

Unit for temperature.

required
skiprows Optional[int]

Number of rows to skip at the beginning of the file.

0
delimiter Optional[str]

Delimiter used in the file.

None
comments Optional[str]

Comment character in the file.

None
start Literal['top', 'bottom']

Whether the profile starts at the top or bottom of the atmosphere.

'bottom'

Returns: Tuple of temperature and pressure quantities.

Source code in src/freckll/io/loader.py
def tp_profile_loader(
    *,
    filename: PathLike,
    temperature_column: int,
    pressure_column: int,
    temperature_unit: u.Unit,
    pressure_unit: u.Unit,
    skiprows: t.Optional[int] = 0,
    delimiter: t.Optional[str] = None,
    comments: t.Optional[str] = None,
    start: t.Literal["top", "bottom"] = "bottom",
) -> tuple[u.Quantity, u.Quantity]:
    """Load a temperature-pressure profile from a csv file.

    Args:
        filename: Path to the csv file.
        temperature_column: Column index for temperature. 0 being first
        pressure_column: Column index for pressure. 0 being first
        temperature_unit: Unit for temperature.
        skiprows: Number of rows to skip at the beginning of the file.
        delimiter: Delimiter used in the file.
        comments: Comment character in the file.
        start: Whether the profile starts at the top or bottom of the atmosphere.
    Returns:
        Tuple of temperature and pressure quantities.
    """
    pressure, temperature = generic_csv_loader(
        filename,
        [pressure_column, temperature_column],
        [pressure_unit, temperature_unit],
        skiprows=skiprows,
        delimiter=delimiter,
        comments=comments,
    )

    # Reverse the profile if it starts at the top
    if start == "top":
        pressure = pressure[::-1]
        temperature = temperature[::-1]

    return pressure, temperature