From 934cfe5fe72ce449c00f5496e7bedf6273e5000b Mon Sep 17 00:00:00 2001 From: John Moustakas Date: Mon, 9 Oct 2023 04:31:37 -0700 Subject: [PATCH] fix #2125 --- py/desispec/io/spectra.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/py/desispec/io/spectra.py b/py/desispec/io/spectra.py index a6b6443f7..de7c230d7 100644 --- a/py/desispec/io/spectra.py +++ b/py/desispec/io/spectra.py @@ -252,15 +252,22 @@ def read_spectra( if targetids is not None and rows is not None: raise ValueError('Set rows or targetids but not both') + exp_rows = None if targetids is not None: targetids = np.atleast_1d(targetids) file_targetids = hdus["FIBERMAP"].read(columns="TARGETID") + exp_targetids = hdus["EXP_FIBERMAP"].read(columns="TARGETID") rows = np.where(np.isin(file_targetids, targetids))[0] + exp_rows = np.where(np.isin(exp_targetids, targetids))[0] if len(rows) == 0: return Spectra() elif rows is not None: rows = np.asarray(rows) - + # figure out exp_rows + file_targetids = hdus["FIBERMAP"].read(rows=rows, columns="TARGETID") + exp_targetids = hdus["EXP_FIBERMAP"].read(columns="TARGETID") + exp_rows = np.where(np.isin(exp_targetids, file_targetids))[0] + if skip_hdus is None: skip_hdus = set() #- empty set, include everything @@ -306,7 +313,7 @@ def read_spectra( elif name == "EXP_FIBERMAP" and name not in skip_hdus: expfmap = encode_table( Table( - hdus[h].read(rows=rows, columns=select_columns["EXP_FIBERMAP"]), + hdus[h].read(rows=exp_rows, columns=select_columns["EXP_FIBERMAP"]), copy=True, ).as_array() )