Repository: spacetelescope/jwst

Issue:
IndexError: index 0 is out of bounds for axis 0 with size 0 for  jw01209-o001_20230722t185001_spec2_00001
_Issue [JP-3325](https://jira.stsci.edu/browse/JP-3325) was created on JIRA by [Michael Ridgaway](https://jira.stsci.edu/secure/ViewProfile.jspa?name=ridgaway):_

Dataset  [jw01209-o001_20230722t185001_spec2_00001](https://pljwdmsweb.stsci.edu/owlgui/logs/directory_view?directory_path=/ifs/archive/ops/jwst/info/owl/logs/owlmgr_jw01209-o001_20230722t185001_spec2_00001_1690106085.994623&fileset_name=jw01209-o001_20230722t185001_spec2_00001&dag_name=LEVEL_2B) failed at Level 2B in the DMS pipeline with the following error:

----------------------------------------------------------------------
ERROR RUNNING STEP 'Spec2Pipeline':
Traceback (most recent call last): File "/dms/local/jwst/pipelin
e/pkgs/miniconda3/envs/jwstdp-1.10.1.20230413-py3.9/lib/python3.9/
site-packages/jwst/pipeline/calwebb_spec2.py", line 120, in
process result = self.process_exposure_product( File "/dms/l
ocal/jwst/pipeline/pkgs/miniconda3/envs/jwstdp-1.10.1.20230413-py3
.9/lib/python3.9/site-packages/jwst/pipeline/calwebb_spec2.py",
line 320, in process_exposure_product x1d =
self.extract_1d(x1d) File "/dms/local/jwst/pipeline/pkgs/minicon
da3/envs/jwstdp-1.10.1.20230413-py3.9/lib/python3.9/site-
packages/stpipe/step.py", line 454, in run step_result =
self.process(*args) File "/dms/local/jwst/pipeline/pkgs/minicond
a3/envs/jwstdp-1.10.1.20230413-py3.9/lib/python3.9/site-
packages/jwst/extract_1d/extract_1d_step.py", line 400, in process
result, ref_outputs, atoca_outputs = soss_extract.run_extract1d(
File "/dms/local/jwst/pipeline/pkgs/miniconda3/envs/jwstdp-1.10.1.
20230413-py3.9/lib/python3.9/site-
packages/jwst/extract_1d/soss_extract/soss_extract.py", line 1183,
in run_extract1d result = model_image(scidata_bkg, scierr,
scimask, refmask, ref_files, box_weights, subarray, **kwargs)
File "/dms/local/jwst/pipeline/pkgs/miniconda3/envs/jwstdp-1.10.1.
20230413-py3.9/lib/python3.9/site-
packages/jwst/extract_1d/soss_extract/soss_extract.py", line 540,
in model_image ref_file_args = get_ref_file_args(ref_files,
transform) File "/dms/local/jwst/pipeline/pkgs/miniconda3/envs/j
wstdp-1.10.1.20230413-py3.9/lib/python3.9/site-
packages/jwst/extract_1d/soss_extract/soss_extract.py", line 51,
in get_ref_file_args wavemap_o1, flag_o1 =
mask_bad_dispersion_direction(wavemap_o1) File "/dms/local/jwst/
pipeline/pkgs/miniconda3/envs/jwstdp-1.10.1.20230413-py3.9/lib/pyt
hon3.9/site-packages/jwst/extract_1d/soss_extract/atoca_utils.py",
line 315, in mask_bad_dispersion_direction is_good_direction =
check_dispersion_direction(wave_map, dispersion_axis, dwv_sign)
File "/dms/local/jwst/pipeline/pkgs/miniconda3/envs/jwstdp-1.10.1.
20230413-py3.9/lib/python3.9/site-
packages/jwst/extract_1d/soss_extract/atoca_utils.py", line 274,
in check_dispersion_direction wave_left, wave_right =
get_wv_map_bounds(wave_map, dispersion_axis=dispersion_axis)
File "/dms/local/jwst/pipeline/pkgs/miniconda3/envs/jwstdp-1.10.1.
20230413-py3.9/lib/python3.9/site-
packages/jwst/extract_1d/soss_extract/atoca_utils.py", line 241,
in get_wv_map_bounds wv_col_top[0] = wv_col_valid[0] -
delta_wave[0] / 2 IndexError: index 0 is out of bounds for axis 0
with size 0
----------------------------------------------------------------------


This appears to be a similar error to one recently closed for NIS_SOSS detailed in <https://jira.stsci.edu/browse/JP-2982.>

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/spacetelescope/jwst/pull/8225?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`2c6df23`)](https://app.codecov.io/gh/spacetelescope/jwst/commit/2c6df239d7fdb5ef66059e3326b384153f4cd729?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope) 75.18% compared to head [(`dd17499`)](https://app.codecov.io/gh/spacetelescope/jwst/pull/8225?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope) 75.22%.
> Report is 1 commits behind head on master.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #8225      +/-   ##
==========================================
+ Coverage   75.18%   75.22%   +0.04%     
==========================================
  Files         470      470              
  Lines       38542    38554      +12     
==========================================
+ Hits        28976    29003      +27     
+ Misses       9566     9551      -15     
```

| [Flag](https://app.codecov.io/gh/spacetelescope/jwst/pull/8225/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope) | Coverage Δ | | *Carryforward flag |
|---|---|---|---|
| [nightly](https://app.codecov.io/gh/spacetelescope/jwst/pull/8225/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope) | `77.38% <ø> (+0.01%)` | :arrow_up: | Carriedforward from [2c6df23](https://app.codecov.io/gh/spacetelescope/jwst/commit/2c6df239d7fdb5ef66059e3326b384153f4cd729?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope) |

*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope) to find out more.


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/spacetelescope/jwst/pull/8225?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=spacetelescope).


Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index b01fcdd21..f79479d06 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -39,6 +39,9 @@ extract_1d
 
 - Fixed a bug in the calling of optional MIRI MRS 1d residual fringe
   correction that could cause defringing to fail in some cases. [#8180]
+
+- Added a hook to bypass the ``extract_1d`` step for NIRISS SOSS data in 
+  the FULL subarray with warning. [#8225]
   
 outlier_detection
 -----------------
@@ -59,6 +62,10 @@ photom
   the pipeline put the (variable, calculated per pixel) dispersion back in.  Assumes that
   the dispersion needs to be in Angstroms/pixel to match the required factor of ~10. [#8207]
 
+- Added a hook to bypass the ``photom`` step when the ``extract_1d`` step 
+  was bypassed and came before the ``photom`` step, e.g. for NIRISS SOSS
+  data in the FULL subarray. [#8225]
+
 refpix
 ------
 
diff --git a/docs/jwst/references_general/drizpars_reffile.inc b/docs/jwst/references_general/drizpars_reffile.inc
index bbe3c8e77..faeb08009 100644
--- a/docs/jwst/references_general/drizpars_reffile.inc
+++ b/docs/jwst/references_general/drizpars_reffile.inc
@@ -46,6 +46,6 @@ filter       integer  The filter used to obtain the images
 pixfrac      float    The pixel "shrinkage" fraction
 kernel       string   The kernel function used to distribute flux
 fillval      float    Value assigned to pixels with no input flux
-wht_type     sting    The input image weighting type
+wht_type     string   The input image weighting type
 stepsize     integer  Output WCS grid interpolation step size
 ===========  =======  ===========================================
diff --git a/jwst/extract_1d/extract_1d_step.py b/jwst/extract_1d/extract_1d_step.py
index 36a06c9ae..44c8f71ca 100644
--- a/jwst/extract_1d/extract_1d_step.py
+++ b/jwst/extract_1d/extract_1d_step.py
@@ -412,19 +412,16 @@ class Extract1dStep(Step):
                     self.log.info('Exposure is in the SUBSTRIP256 subarray.')
                     self.log.info('Traces 1 and 2 will be modelled and decontaminated before extraction.')
                     subarray = 'SUBSTRIP256'
-                elif input_model.meta.subarray.name == 'FULL':
-                    self.log.info('Exposure is in the FULL subarray.')
-                    self.log.info('Traces 1 and 2 will be modelled and decontaminated before extraction.')
-                    subarray = 'FULL'
                 elif input_model.meta.subarray.name == 'SUBSTRIP96':
                     self.log.info('Exposure is in the SUBSTRIP96 subarray.')
                     self.log.info('Traces of orders 1 and 2 will be modelled but only order 1'
                                   ' will be decontaminated before extraction.')
                     subarray = 'SUBSTRIP96'
                 else:
-                    self.log.error('The SOSS extraction is implemented for the SUBSTRIP256,'
-                                   ' SUBSTRIP96 and FULL subarray only.')
-                    self.log.error('extract_1d will be skipped.')
+                    self.log.error('The SOSS extraction is implemented for the SUBSTRIP256'
+                                   'and SUBSTRIP96 subarrays only. Subarray is currently '
+                                   f'{input_model.meta.subarray.name}.')
+                    self.log.error('Extract1dStep will be skipped.')
                     input_model.meta.cal_step.extract_1d = 'SKIPPED'
                     return input_model
 
diff --git a/jwst/photom/photom.py b/jwst/photom/photom.py
index 6e60a43d5..78dbbed13 100644
--- a/jwst/photom/photom.py
+++ b/jwst/photom/photom.py
@@ -33,6 +33,14 @@ class MatchFitsTableRowError(Exception):
         super().__init__(message)
 
 
+class DataModelTypeError(Exception):
+
+    def __init__(self, message):
+        if message is None:
+            message = "Unexpected DataModel type."
+        super().__init__(message)
+
+
 def find_row(fits_table, match_fields):
     """
     Find a row in a FITS table matching fields.
@@ -413,6 +421,9 @@ class DataSet():
                     continue
                 self.photom_io(ftab.phot_table[row])
 
+        elif isinstance(self.input, datamodels.CubeModel):
+            raise DataModelTypeError(f"Unexpected input data model type for NIRISS: {self.input.__class__.__name__}")
+
         elif self.exptype in ['NIS_SOSS']:
             for spec in self.input.spec:
                 self.specnum += 1
@@ -481,13 +492,13 @@ class DataSet():
                 photom_corr = miri_imager.time_corr_photom(ftab.timecoeff[row], mid_time)
 
                 data = np.array(
-                    [(self.filter, self.subarray, ftab.phot_table[row]['photmjsr']+photom_corr, ftab.phot_table[row]['uncertainty'])],
+                    [(self.filter, self.subarray, ftab.phot_table[row]['photmjsr'] + photom_corr, ftab.phot_table[row]['uncertainty'])],
                     dtype=[
                         ("filter", "O"),
                         ("subarray", "O"),
                         ("photmjsr", "<f4"),
                         ("uncertainty", "<f4")
-                        ],
+                    ],
                 )
                 fftab = datamodels.MirImgPhotomModel(phot_table=data)
                 self.photom_io(fftab.phot_table[0])
@@ -539,12 +550,12 @@ class DataSet():
                 log.info("Skipping MRS MIRI time correction. Extensions not found in the reference file.")
                 self.mrs_time_correction = False
 
-            #if np.any(ftab.timecoeff_ch1['binwave']) and self.mrs_time_correction:
+            # if np.any(ftab.timecoeff_ch1['binwave']) and self.mrs_time_correction:
             if self.mrs_time_correction:
                 log.info("Applying MRS IFU time dependent correction.")
                 mid_time = self.input.meta.exposure.mid_time
                 correction = miri_mrs.time_correction(self.input, self.detector,
-                                                     ftab, mid_time)
+                                                      ftab, mid_time)
                 self.input.data /= correction
                 self.input.err /= correction
             else:
diff --git a/jwst/photom/photom_step.py b/jwst/photom/photom_step.py
index 9bc857a69..c2070194a 100644
--- a/jwst/photom/photom_step.py
+++ b/jwst/photom/photom_step.py
@@ -64,13 +64,21 @@ class PhotomStep(Step):
             result.meta.cal_step.photom = 'SKIPPED'
             return result
 
-        # Do the correction
-        phot = photom.DataSet(input_model, self.inverse, self.source_type,
-                              self.mrs_time_correction, correction_pars)
-        result = phot.apply_photom(phot_filename, area_filename)
-        result.meta.cal_step.photom = 'COMPLETE'
-
-        self.correction_pars = phot.correction_pars
-        self.correction_pars['refs'] = {'photom': phot_filename, 'area': area_filename}
-
+        try:
+            # Do the correction
+            phot = photom.DataSet(input_model, self.inverse, self.source_type,
+                                  self.mrs_time_correction, correction_pars)
+            result = phot.apply_photom(phot_filename, area_filename)
+            result.meta.cal_step.photom = 'COMPLETE'
+            self.correction_pars = phot.correction_pars
+            self.correction_pars['refs'] = {'photom': phot_filename, 'area': area_filename}
+
+        except photom.DataModelTypeError:
+            # should trip e.g. for NIRISS SOSS data in FULL subarray
+            self.log.error(f'Unexpected data model type {model_type} for '
+                           f'{input_model.meta.instrument.name.upper()}. '
+                           'Photom will be skipped.')
+            result = input_model.copy()
+            result.meta.cal_step.photom = 'SKIPPED'
+            return result
         return result


Test patch:
diff --git a/jwst/extract_1d/tests/test_expected_skips.py b/jwst/extract_1d/tests/test_expected_skips.py
new file mode 100644
index 000000000..86910c037
--- /dev/null
+++ b/jwst/extract_1d/tests/test_expected_skips.py
@@ -0,0 +1,31 @@
+import stdatamodels.jwst.datamodels as dm
+from jwst.extract_1d import Extract1dStep
+from jwst.photom import PhotomStep
+import pytest
+import numpy as np
+
+
+@pytest.fixture(scope='module')
+def mock_niriss_full():
+    model = dm.CubeModel((3, 3, 3))
+    model.meta.instrument.name = 'NIRISS'
+    model.meta.instrument.detector = 'NIS'
+    model.meta.observation.date = '2023-07-22'
+    model.meta.observation.time = '06:24:45.569'
+    model.meta.instrument.name = 'NIRISS'
+    model.meta.instrument.detector = 'NIS'
+    model.meta.instrument.filter = 'CLEAR'
+    model.meta.exposure.type = 'NIS_SOSS'
+    model.meta.subarray.name = 'FULL'
+    model.data = np.arange(27).reshape((3, 3, 3))
+    return model
+
+
+def test_expected_skip_niriss_soss_full(mock_niriss_full):
+
+    with mock_niriss_full as model:
+        result = Extract1dStep().process(model)
+        result2 = PhotomStep().process(result)
+        assert result2.meta.cal_step.photom == 'SKIPPED'
+        assert result2.meta.cal_step.extract_1d == 'SKIPPED'
+        assert np.all(result2.data == model.data)
diff --git a/jwst/photom/tests/test_photom.py b/jwst/photom/tests/test_photom.py
index fa987f5ce..43c7d5e60 100644
--- a/jwst/photom/tests/test_photom.py
+++ b/jwst/photom/tests/test_photom.py
@@ -341,7 +341,7 @@ def create_input(instrument, detector, exptype,
             input_model.var_flat = np.ones(shape, dtype=np.float32)
             input_model.meta.subarray.name = 'SUB256'       # matches 'GENERIC'
             input_model.meta.target.source_type = 'POINT'
-            input_model.meta.exposure.mid_time = 60000.0 # Added for new PHOTOM step
+            input_model.meta.exposure.mid_time = 60000.0  # Added for new PHOTOM step
             input_model.meta.photometry.pixelarea_arcsecsq = 0.0025
             input_model.meta.photometry.pixelarea_steradians = 0.0025 * A2_TO_SR
     elif instrument == 'FGS':
@@ -803,7 +803,7 @@ def create_photom_miri_image(min_wl=16.5, max_wl=19.5,
                       ('tau', '<f4'),
                       ('t0', '<f4')])
     reftabc = np.array(list(zip(timecoeff_amp, timecoeff_tau, timecoeff_t0)),
-                      dtype=dtypec)
+                       dtype=dtypec)
     ftab = datamodels.MirImgPhotomModel(phot_table=reftab, timecoeff=reftabc)
 
     return ftab
@@ -1342,6 +1342,21 @@ def test_niriss_image():
     assert np.allclose(ratio, compare, rtol=1.e-7)
 
 
+def test_expected_failure_niriss_cubemodel():
+    """
+    Test that passing a CubeModel to calc_niriss raises an exception
+    This occurs when extract_1d step is skipped, e.g. for NIRISS SOSS data
+    in FULL subarray.
+    """
+
+    input_model = create_input('NIRISS', 'NIS', 'NIS_SOSS',
+                               filter='CLEAR', pupil='GR700XD')
+    ds = photom.DataSet(input_model)
+    ds.input = datamodels.CubeModel()
+    with pytest.raises(photom.DataModelTypeError):
+        ds.calc_niriss(None)
+
+
 def test_miri_mrs():
     """Test calc_miri, MRS data"""
 
@@ -1431,7 +1446,7 @@ def test_miri_image():
     shape = input.shape
     ix = shape[1] // 2
     iy = shape[0] // 2
-    compare = photmjsr + amplitude * np.exp(-(60000 - t0)/tau) # Added for new PHOTOM step
+    compare = photmjsr + amplitude * np.exp(-(60000 - t0) / tau)  # Added for new PHOTOM step
     # Compare the values at the center pixel.
     ratio = output[iy, ix] / input[iy, ix]
     assert np.allclose(ratio, compare, rtol=1.e-7)