Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JP-3005: Pixel replacement for flagged pixels before spectral extraction #7398

Merged
merged 26 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e1b145f
init_commit
tapastro Dec 8, 2022
59844f8
checkpoint
tapastro Dec 9, 2022
c058537
initial implementation for imagemodel - lrs
tapastro Dec 15, 2022
8fd3fac
add suffix, clean up
tapastro Dec 19, 2022
4e6e240
fix flagging modification, other updates
tapastro Dec 21, 2022
9321c42
allow IFUImageModel
tapastro Jan 6, 2023
4ede81f
correct reported n_pix replaced, add TSO support for testing
tapastro Jan 12, 2023
cda6a03
remove relative imports that CI does not like
tapastro Jan 12, 2023
02438fd
one more relative import, and change source of loop range for CubeModels
tapastro Jan 12, 2023
61f9015
add step init to sidestep relative imports
tapastro Jan 12, 2023
52b5d47
move debug statement to proper place
tapastro Jan 13, 2023
2345a2e
allow BOTS SlitModel into CubeModel iteration codeblock
tapastro Jan 30, 2023
2abb6c0
trace-dependent normalization DEAD END
tapastro Feb 8, 2023
a100c8d
Run MRS traces one by one
tapastro Feb 8, 2023
03cfa16
typo in dq setting block
tapastro Feb 8, 2023
ff06bea
Prevent attempts to replace pixels with NON_SCIENCE flags
tapastro Feb 9, 2023
8f0f7cd
Use similar methods to MRS for NRS_IFU
tapastro Feb 9, 2023
d93af8f
changelog and final cleanup
tapastro Mar 15, 2023
5e348eb
clean up step code as well, set skip
tapastro Mar 15, 2023
31d1c26
use LOW_QE DQ bit as placeholder for testing
tapastro Mar 20, 2023
b317096
populate new dq bit, erase all knowledge of unreliable_reset
tapastro Mar 31, 2023
44bc5df
update step name in schema recording
tapastro Apr 4, 2023
11647ff
reverse it
tapastro Apr 5, 2023
53e30e9
update docs
tapastro Apr 6, 2023
e3fdd9c
respond to review comments
tapastro Apr 6, 2023
ec38675
add ref files
tapastro Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ pipeline
calling the ``resample_spec`` and ``extract_1d`` steps, to avoid issues with the
input data accidentally getting modified by those steps. [#7451]

pixel_replace
-------------

- Add ``pixel_replace`` step to ``Spec2Pipeline``, which uses a weighted interpolation
to estimate flux values for pixels flagged as ``DO_NOT_USE``. [#7398]

ramp_fitting
------------

Expand Down
4 changes: 3 additions & 1 deletion docs/jwst/pipeline/calwebb_spec2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ TSO exposures. The instrument mode abbreviations used in the table are as follow
+----------------------------------------------------------+-----+-----+-----+-----+-----+-----+------+------+--------+-----+
| :ref:`residual_fringe <residual_fringe_step>` \ :sup:`2` | | | | | | |c| | | | | |
+----------------------------------------------------------+-----+-----+-----+-----+-----+-----+------+------+--------+-----+
| :ref:`pixel_replace <pixel_replace_step>` \ :sup:`2` | |c| | |c| | | |c| | |c| | | | |c| | |c| | |
+----------------------------------------------------------+-----+-----+-----+-----+-----+-----+------+------+--------+-----+
| :ref:`resample_spec <resample_step>` | |c| | |c| | | |c| | | | | | | |
+----------------------------------------------------------+-----+-----+-----+-----+-----+-----+------+------+--------+-----+
| :ref:`cube_build <cube_build_step>` | | | |c| | | | |c| | | | | |
Expand All @@ -90,7 +92,7 @@ For NIRISS and NIRCam WFSS, as well as NIRCam TSO grism exposures, the order is
flat_field, extract_2d, and srctype (no wavecorr).
For all other modes the order is extract_2d, srctype, wavecorr, and flat_field.

:sup:`2`\ By default the :ref:`residual_fringe <residual_fringe_step>` is skipped in the ``calwebb_spec2`` pipeline.
:sup:`2`\ By default this step is skipped in the ``calwebb_spec2`` pipeline.

Notice that NIRSpec MOS is the only mode to receive master background subtraction
in the ``calwebb_spec2`` pipeline. All other spectral modes have master background
Expand Down
15 changes: 15 additions & 0 deletions docs/jwst/pixel_replace/arguments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Step Arguments
==============

The ``pixel_replace`` step has the following step-specific arguments:

``--algorithm`` (str, default='fit_profile')
This sets the method used to estimate flux values for bad pixels. Only one
option has been implemented so far, using a profile fit to adjacent column values.

``--n_adjacent_cols`` (int, default=3)
Number of adjacent columns (on either side of column containing a bad pixel) to use in
creation of the source profile, in cross-dispersion direction. The total number of
columns used in the profile will be twice this number; on array edges, the total number
of columns contributing to the source profile will be less than ``2 * n_adjacent_cols``.

14 changes: 14 additions & 0 deletions docs/jwst/pixel_replace/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _pixel_replace_step:

===============
Pixel Replacement
===============

.. toctree::
:maxdepth: 2

main.rst
arguments.rst
reference_files.rst

hbushouse marked this conversation as resolved.
Show resolved Hide resolved
.. automodapi:: jwst.pixel_replace.pixel_replace_step
34 changes: 34 additions & 0 deletions docs/jwst/pixel_replace/main.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Description
===========

:Classes: `jwst.pixel_replace.PixelReplaceStep`
:Alias: pixel_replace

During spectral extraction, pixels flagged as bad are ignored in the summation process.
If a bad pixel is part of the point-spread function (PSF) at a given wavelength, the
absence of the signal in the flagged pixel will lead to a divot at that wavelength in
the extracted spectrum.

To avoid this defect in the 1-D spectrum, this step estimates the flux values of pixels
flagged as ``DO_NOT_USE`` in 2-D extracted spectra, prior to rectification in the
``resample_spec`` step. ``pixel_replace`` inserts these estimates into the data array,
unsets the ``DO_NOT_USE`` flag and sets the ``FLUX_ESTIMATED`` flag for each pixel affected.

hbushouse marked this conversation as resolved.
Show resolved Hide resolved
Algorithms
==========

Currently, one algorithm has been tested to estimate the missing fluxes.

Adjacent Profile Approximation
------------------------------

First, the input 2-d spectral cutout is scanned across the dispersion axis to determine
which cross-dispersion vectors (column or row, depending on dispersion direction) contain
at least one flagged pixel. Next, for each affected vector, a median normalized profile is created.

First, the adjacent arrays (the number of which is set by the step argument
``n_adjacent_cols``) are individually normalized. Next, each pixel in the profile is set to
the median of the normalized values. This results in a median of normalized values filling the vector.

Finally, this profile is scaled to the vector containing a missing pixel, and the value is
estimated from the scaled profile.
4 changes: 4 additions & 0 deletions docs/jwst/pixel_replace/reference_files.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Reference File
==============

This step does not use any reference file.
4 changes: 2 additions & 2 deletions docs/jwst/references_general/references_general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ Bit Value Name Description
4 16 OUTLIER Flagged by outlier detection
5 32 PERSISTENCE High persistence
6 64 AD_FLOOR Below A/D floor
7 128 RESERVED
7 128 UNDERSAMP Undersampling correction
8 256 UNRELIABLE_ERROR Uncertainty exceeds quoted error
9 512 NON_SCIENCE Pixel not on science portion of detector
10 1024 DEAD Dead pixel
Expand All @@ -623,7 +623,7 @@ Bit Value Name Description
25 33554432 UNRELIABLE_FLAT Flat variance large
26 67108864 OPEN Open pixel (counts move to adjacent pixels)
27 134217728 ADJ_OPEN Adjacent to open pixel
28 268435456 UNRELIABLE_RESET Sensitive to reset anomaly
28 268435456 FLUX_ESTIMATED Pixel flux estimated due to missing/bad data
29 536870912 MSA_FAILED_OPEN Pixel sees light from failed-open shutter
30 1073741824 OTHER_BAD_PIXEL A catch-all flag
31 2147483648 REFERENCE_PIXEL Pixel is a reference pixel
Expand Down
1 change: 1 addition & 0 deletions jwst/lib/suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
'wavecorrstep',
'wfsscontamstep',
'undersamplingcorrectionstep',
'pixelreplacestep',
}


Expand Down
5 changes: 5 additions & 0 deletions jwst/pipeline/calwebb_spec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ..msaflagopen import msaflagopen_step
from ..pathloss import pathloss_step
from ..photom import photom_step
from ..pixel_replace import pixel_replace_step
from ..resample import resample_spec_step
from ..srctype import srctype_step
from ..straylight import straylight_step
Expand Down Expand Up @@ -78,6 +79,7 @@ class Spec2Pipeline(Pipeline):
'barshadow': barshadow_step.BarShadowStep,
'wfss_contam': wfss_contam_step.WfssContamStep,
'photom': photom_step.PhotomStep,
'pixel_replace': pixel_replace_step.PixelReplaceStep,
'resample_spec': resample_spec_step.ResampleSpecStep,
'cube_build': cube_build_step.CubeBuildStep,
'extract_1d': extract_1d_step.Extract1dStep
Expand Down Expand Up @@ -274,6 +276,9 @@ def process_exposure_product(
calibrated.meta.asn.table_name = op.basename(asn_file)
calibrated.meta.filename = self.make_output_path(suffix=suffix)

# Replace bad pixels before rectification
calibrated = self.pixel_replace(calibrated)

# Produce a resampled product, either via resample_spec for
# "regular" spectra or cube_build for IFU data. No resampled
# product is produced for time-series modes.
Expand Down
3 changes: 3 additions & 0 deletions jwst/pixel_replace/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .pixel_replace_step import PixelReplaceStep

__all__ = ["PixelReplaceStep"]
Loading