desihub / desispec

DESI spectral pipeline
BSD 3-Clause "New" or "Revised" License
33 stars 24 forks source link

Only select cte if have 120s flat in proc_night #2254

Closed akremin closed 1 month ago

akremin commented 1 month ago

This fixes a bug introduced by me in PR #2221 that is causing crashes in determine_calibrations_to_proc() when no valid flats are available on a night.

The fix is simple, we now check that there is at least one valid 120s flat before trying to add the cte flats. Given that we need a 120s flat to do the cte correction, this is a reasonable thing to do.

The traceback was the following:

Traceback (most recent call last):
  File "/global/common/software/desi/perlmutter/desiconda/20240425-2.2.0/code/desispec/0.63.0/bin/desi_proc_night", line 137, in <module>
    proc_night(**args.__dict__)
  File "/global/common/software/desi/perlmutter/desiconda/20240425-2.2.0/code/desispec/0.63.0/lib/python3.10/site-packages/desispec/scripts/proc_night.py", line 429, in proc_night
    cal_etable = determine_calibrations_to_proc(etable,
  File "/global/common/software/desi/perlmutter/desiconda/20240425-2.2.0/code/desispec/0.63.0/lib/python3.10/site-packages/desispec/workflow/calibration_selection.py", line 92, in determine_calibrations_to_proc
    lastflattime = np.max(best_arcflat_set['MJD-OBS'][best_arcflat_set['OBSTYPE']=='flat'])
  File "<__array_function__ internals>", line 180, in amax
  File "/global/common/software/desi/perlmutter/desiconda/20240425-2.2.0/conda/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 2791, in amax
    return _wrapreduction(a, np.maximum, 'max', axis, None, out,
  File "/global/common/software/desi/perlmutter/desiconda/20240425-2.2.0/conda/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 84, in _wrapreduction
    return reduction(axis=axis, out=out, **passkwargs)
  File "/global/common/software/desi/perlmutter/desiconda/20240425-2.2.0/conda/lib/python3.10/site-packages/numpy/core/_methods.py", line 40, in _amax
    return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity
akremin commented 1 month ago

I also fixed a typo in the initialization of z_submit_types in desi_proc_night that has never been an issue because it only occurs when it is run as a python function rather than as a bash script via argparse.

sbailey commented 1 month ago

Looks good; thanks for including unit test.