From 35f1be13e31cfa23593158d0e2838f3abc2fe7a3 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Sat, 10 Oct 2026 11:23:38 -0600 Subject: [PATCH] List the ions of the database `utu.spectrum.ions()` is given `utu.spectrum.ions(hdf5_dbase_root=...)` opened each ion from the given database but listed the ions from fiasco's default one, so an ion only the given database has was never returned. The ions are now listed from the database in `hdf5_dbase_root` when it is given. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TN11CvLpJ9mX44K3MaCyB1 --- utu/spectrum/_lines.py | 7 ++++++- utu/spectrum/_tests/test_lines.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/utu/spectrum/_lines.py b/utu/spectrum/_lines.py index d8271ef..abad7a3 100644 --- a/utu/spectrum/_lines.py +++ b/utu/spectrum/_lines.py @@ -41,6 +41,8 @@ def ions( worth including. kwargs Additional arguments passed to :class:`fiasco.Ion`. + If ``hdf5_dbase_root`` is among them, the ions are listed from that + database too. Notes ----- @@ -116,7 +118,10 @@ def _catalog( """ result = {} - for name in fiasco.list_ions(): + # the ions of the database they are read from, not of the default one + database = kwargs.get("hdf5_dbase_root") + + for name in fiasco.list_ions(hdf5_dbase_root=database): try: ion = fiasco.Ion(name, 1 * u.MK, **kwargs) diff --git a/utu/spectrum/_tests/test_lines.py b/utu/spectrum/_tests/test_lines.py index fb46178..0eab0de 100644 --- a/utu/spectrum/_tests/test_lines.py +++ b/utu/spectrum/_tests/test_lines.py @@ -1,3 +1,5 @@ +import pathlib + import astropy.units as u import fiasco import named_arrays as na @@ -83,6 +85,22 @@ def test_ions(ions_window: list[str], ions_all: list[str]): assert len(ions_window) < len(ions_all) +def test_ions_database(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path): + """The ions are listed from the database they are read from.""" + found = [] + + def list_ions(hdf5_dbase_root: object = None, sort: bool = True) -> list[str]: + """Record the database the ions are listed from, which has none.""" + found.append(hdf5_dbase_root) + return [] + + monkeypatch.setattr(fiasco, "list_ions", list_ions) + database = tmp_path / "chianti.h5" + + assert utu.spectrum.ions(hdf5_dbase_root=database) == [] + assert found == [database] + + @needs_database def test_contribution_function(proton_electron_ratio: u.Quantity): ion = fiasco.Ion("O 5", temperature.ndarray)