lfkit.utils.io module#

I/O utilities for packaged Poggianti (1997) correction tables.

This module provides helpers to: - locate Poggianti (1997) CSV files shipped as package data - load VizieR-style CSV tables into NumPy structured arrays - list available bands and SED columns - extract validated (z, y) series for a given (band, sed)

The functions here are intentionally limited to file/resource access and table parsing.

lfkit.utils.io.available_from_table(tab)[source]#

Return available band labels and SED columns in a Poggianti-style table.

Parameters:

tab (ndarray) – Structured array loaded from a Poggianti VizieR CSV.

Returns:

  • bands are unique values from the Filt column (sorted)

  • seds are SED column names excluding metadata columns

Return type:

A tuple (bands, seds) where

Raises:

ValueError – If required columns are missing.

lfkit.utils.io.available_pairs(tab, *, min_points=5)[source]#

List usable (band -> SEDs) pairs in a Poggianti-style table.

Parameters:
  • tab (ndarray) – Structured array for a single correction table (k-corr or e-corr).

  • min_points (int) – Minimum number of samples required per extracted series.

Returns:

Mapping from band label to a list of SED labels that have usable data.

Return type:

dict[str, list[str]]

lfkit.utils.io.extract_series(tab, *, band, sed, min_points=5)[source]#

Extract a validated (z, y) correction curve for a band and SED.

Parameters:
  • tab (ndarray) – Structured array for a single correction table (k-corr or e-corr).

  • band (str) – Band label to select from the Filt column.

  • sed (str) – SED column name to extract.

  • min_points (int) – Minimum number of points required after cleaning.

Returns:

A tuple (z, y) where z is strictly increasing and y is the corresponding correction values.

Raises:

ValueError – If the band/SED is not present, has no finite values, or does not contain enough usable samples.

Return type:

tuple[ndarray, ndarray]

lfkit.utils.io.load_kcorr_package(path)[source]#

Load a saved .npz package created by save_kcorr_package.

Parameters:

path (str | Path)

Return type:

dict[str, Any]

lfkit.utils.io.load_vizier_csv(path)[source]#

Load a VizieR CSV file into a NumPy structured array.

Parameters:

path (str | Path) – Path to a CSV file written with column headers.

Returns:

A NumPy structured array with named columns.

Raises:

ValueError – If the CSV cannot be read as a headered table.

Return type:

ndarray

lfkit.utils.io.resolve_packaged_csv(name, *, pkg='lfkit.data.poggianti1997')[source]#

Resolve a packaged CSV resource to a concrete filesystem path.

Parameters:
  • name (str) – Filename within the package data directory (e.g. kcorr.csv).

  • pkg (str) – Package path containing the data resources.

Returns:

A concrete filesystem path to the resource.

Return type:

Path

Notes

When running from a wheel, resources may not exist as real files. importlib.resources.as_file provides a temporary path-like view.

lfkit.utils.io.save_kcorr_package(pkg, path)[source]#

Save the generated package to .npz (portable, fast).

Parameters:
  • pkg (dict[str, Any])

  • path (str | Path)

Return type:

None