Skip to content

Commit 6cce887

Browse files
committed
Fix attribute error in log message
1 parent 35feafe commit 6cce887

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

changes/9848.combine_1d.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed a log message that caused a crashing error in the ``master_background_mos`` step,
2+
when attempting to combine one or more background spectra with no valid values.

jwst/combine_1d/combine1d.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,17 @@ def _read_input_spectra(input_model, exptime_key, input_spectra):
735735
spectra = input_model.spec
736736
for in_spec in spectra:
737737
if not np.any(np.isfinite(in_spec.spec_table.field("flux"))):
738-
log.warning(
739-
f"Input spectrum {in_spec.source_id} order {in_spec.spectral_order} "
740-
f"from group_id {in_spec.meta.group_id} has no valid flux values; skipping."
741-
)
738+
if in_spec.meta.hasattr("group_id"):
739+
msg = (
740+
f"Input spectrum {in_spec.source_id} order {in_spec.spectral_order} "
741+
f"from group_id {in_spec.meta.group_id} has no valid flux values; skipping."
742+
)
743+
else:
744+
msg = (
745+
f"Input spectrum {in_spec.source_id} order {in_spec.spectral_order} "
746+
"has no valid flux values; skipping."
747+
)
748+
log.warning(msg)
742749
continue
743750
spectral_order = in_spec.spectral_order
744751
if spectral_order not in input_spectra:

jwst/combine_1d/tests/test_combine1d.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,28 @@ def test_allnan_skip(wfss_multiexposure, monkeypatch):
265265
watcher2.assert_seen()
266266

267267

268+
def test_allnan_skip_non_wfss(caplog, three_spectra):
269+
"""Test that all-nan spectra are skipped."""
270+
# Set all flux values to NaN
271+
for spec in three_spectra.spec:
272+
spec.spec_table["FLUX"][:] = np.nan
273+
274+
result = Combine1dStep.call(three_spectra)
275+
assert result.meta.cal_step.combine_1d == "SKIPPED"
276+
277+
# message when a single spectrum has no valid flux values
278+
msg1 = "Input spectrum 0 order 1 has no valid flux values; skipping."
279+
assert msg1 in caplog.text
280+
281+
# message when no valid input spectra are found for the source
282+
msg2 = "No valid input spectra found for source. Skipping."
283+
assert msg2 in caplog.text
284+
285+
# message when no valid input spectra at all are found
286+
msg3 = "No valid input spectra found in WFSSMultiSpecModel"
287+
assert msg2 in caplog.text
288+
289+
268290
def test_output_is_not_input(two_spectra):
269291
"""Test that input is not modified."""
270292
result = Combine1dStep.call(two_spectra)

0 commit comments

Comments
 (0)