Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Nov 20, 2023
1 parent 0bd8f63 commit 2fa277c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions py/desispec/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ def __init__(self, bands=[], wave={}, flux={}, ivar={}, mask=None,
if resolution_data[b].shape[2] != wave[b].shape[0]:
raise RuntimeError("resolution array wavelength dimension for band {} does not match grid".format(b))
if extra is not None:
for ex in extra[b].items():
if ex[1].shape != flux[b].shape:
raise RuntimeError("extra arrays must have the same shape as the flux array")
try:
for ex in extra[b].items():
if ex[1].shape != flux[b].shape:
raise RuntimeError("extra arrays must have the same shape as the flux array")
except (KeyError, AttributeError):
pass

if fibermap is not None and extra_catalog is not None:
if len(fibermap) != len(extra_catalog):
Expand Down Expand Up @@ -204,7 +207,6 @@ def __init__(self, bands=[], wave={}, flux={}, ivar={}, mask=None,
for ex in extra[b].items():
self.extra[b][ex[0]] = np.copy(ex[1].astype(self._ftype))


@property
def bands(self):
"""
Expand Down
7 changes: 5 additions & 2 deletions py/desispec/test/test_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def test_read_targetids(self):

# read subset in different order than original file, with repeats and missing targetids
spec.fibermap['TARGETID'] = (np.arange(self.nspec) // 2) * 2 # [0, 0, 2, 2, 4, 4] for nspec=6
spec.fibermap['TARGETID'][-1] = 5
write_spectra(self.fileio, spec)
targetids = [2,10,4,4,4,0,0]
comp_subset = read_spectra(self.fileio, targetids=targetids)
Expand All @@ -234,8 +235,10 @@ def test_read_targetids(self):
# targetid 4 appears 3x because it was requested 3 times
# targetid 0 appears 4x because it was in the input file twice and requested twice
# and targetid 0 is at the end of comp_subset, not the beginning like the file
# targetid 5 was not requested.
# targetid 10 doesn't appear because it wasn't in the input file, ok
self.assertTrue(np.all(comp_subset.fibermap['TARGETID'] == np.array([2,2,4,4,4,0,0,0,0])))
self.assertListEqual(comp_subset.fibermap['TARGETID'].tolist(),
[2, 2, 4, 4, 4, 0, 0, 0, 0])

# make sure coadded spectra with FIBERMAP vs. EXP_FIBERMAP works
tid = 555666
Expand Down Expand Up @@ -466,7 +469,7 @@ def test_slice(self):
for band in self.bands:
self.assertEqual(sp2.flux[band].shape[0], 2)

sp2 = sp1[[True,False,True,False,True]]
sp2 = sp1[[True, False, True, False, True, False]]
for band in self.bands:
self.assertEqual(sp2.flux[band].shape[0], 3)

Expand Down

0 comments on commit 2fa277c

Please sign in to comment.