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)