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-3753: Refactor extract1d #8961

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
56227e4
Start extract1d refactor
melanieclarke Oct 31, 2024
69dc8fd
Add test for custom extraction with polynomial limits
melanieclarke Nov 5, 2024
37d0986
Fix log message f-string
melanieclarke Nov 5, 2024
913d364
Deduplicate extraction interface
melanieclarke Nov 5, 2024
9db15fc
Remove image reference type
melanieclarke Nov 6, 2024
5b9466a
Separate IFU from slit extraction
melanieclarke Nov 6, 2024
4b8a4f6
Remove NIRISS SOSS references from slit extraction code
melanieclarke Nov 6, 2024
a088795
Remove unnecessary middleman function; condense input type checking
melanieclarke Nov 6, 2024
b24c183
Add helper functions for special extraction modes
melanieclarke Nov 7, 2024
6324216
Clean up messages
melanieclarke Nov 7, 2024
ed4890e
First version incorporating new extraction engine
melanieclarke Nov 8, 2024
377c62a
Fix extraction limit defaults and partial pixel weights
melanieclarke Nov 11, 2024
615ca32
Npixels is sum of weights instead of sum of pixels with non-zero weight
melanieclarke Nov 11, 2024
d314aff
Move profile and wavelength calculations out of integration loop
melanieclarke Nov 11, 2024
c29fd7f
Tidying up
melanieclarke Nov 11, 2024
2f36bd0
Update unit tests for new extract1d
melanieclarke Nov 12, 2024
1b72081
Add left/right limit handling, fix partial pixel weights
melanieclarke Nov 12, 2024
2cf239d
Make polynomial coefficient definition backward compatible
melanieclarke Nov 12, 2024
6b08645
Clean up aperture definition, fix edge cases
melanieclarke Nov 12, 2024
69bf433
Coverage tests for step interface
melanieclarke Nov 13, 2024
31a62eb
Move aperture correction setup outside integration loop
melanieclarke Nov 13, 2024
5d23eea
Return separate values from locn_from_wcs function
melanieclarke Nov 14, 2024
60df66c
Rename 'boxcar' extraction to 'box'
melanieclarke Nov 14, 2024
7994a45
Set up for future optimal extraction
melanieclarke Nov 14, 2024
cba690b
Tidy up code organization, add docstrings
melanieclarke Nov 14, 2024
e8998e8
Code style fixes
melanieclarke Nov 14, 2024
df50982
Make sure background values are finite: they default to 0, not NaN
melanieclarke Nov 15, 2024
316a07e
More general check for unresampled nirspec data
melanieclarke Nov 18, 2024
6c61932
More robust file saving for containers
melanieclarke Nov 19, 2024
a5c574e
Add option to save spatial profile
melanieclarke Nov 19, 2024
e51b836
Add check for negative values in profile
melanieclarke Nov 20, 2024
7d2abec
Add option to save scene model
melanieclarke Nov 20, 2024
794eb9e
Fix scene model default
melanieclarke Nov 21, 2024
9653a69
Minor fixes for optimal extraction support
melanieclarke Nov 21, 2024
3fc022d
Add check for missing variances
melanieclarke Nov 21, 2024
be0c3d5
Adding unit tests for extraction
melanieclarke Nov 21, 2024
535ecd5
Add temporary fix for background fit test
melanieclarke Nov 21, 2024
2ecd4fd
Coverage tests for extract1d
melanieclarke Nov 21, 2024
6b7b64d
Better npixels estimate for optimal extraction; fix background fit test
melanieclarke Nov 22, 2024
d380ddd
More unit tests for extract_1d coverage
melanieclarke Nov 22, 2024
067458d
Fix npixels for non-uniform weights
melanieclarke Nov 25, 2024
07b3ec4
More coverage tests
melanieclarke Nov 25, 2024
1ba4dd8
More unit tests for extract
melanieclarke Nov 25, 2024
69ecbbc
Tests for extract_one_slit
melanieclarke Nov 26, 2024
ee2b263
Add change log fragment
melanieclarke Nov 26, 2024
284ece4
Make some parameters for create_extraction keywords instead of args
melanieclarke Nov 26, 2024
3d0621e
Test coverage for create_extraction and run_extract1d
melanieclarke Nov 26, 2024
f94612c
Reformat change note
melanieclarke Nov 27, 2024
20d2c0b
Update docs for extract1d
melanieclarke Nov 27, 2024
422b0f9
Add more API docs for extraction tools
melanieclarke Nov 27, 2024
bb7b338
Make change notes fit on one line
melanieclarke Nov 27, 2024
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
1 change: 1 addition & 0 deletions changes/8961.extract_1d.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor the core extraction algorithm and aperture definition modules for slit and slitless extractions, for greater efficiency and maintainability. Extraction reference files in FITS format are no longer supported. Current behavior for extractions proceeding from extract1d reference files in JSON format is preserved, with minor improvements: DQ arrays are populated and error propagation is improved for some aperture types.
140 changes: 75 additions & 65 deletions docs/jwst/extract_1d/arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@ Step Arguments

The ``extract_1d`` step has the following step-specific arguments.

General Step Arguments
----------------------
The following arguments apply to all modes unless otherwise specified.

``--subtract_background``
This is a boolean flag to specify whether the background should be
subtracted. If None, the value in the :ref:`EXTRACT1D <extract1d_reffile>`
reference file (if any) will be used. If not None, this parameter overrides
the value in the reference file. Has no effect for NIRISS SOSS data.

``--apply_apcorr``
Switch to select whether or not to apply an APERTURE correction during the
Extract1dStep processing. Default is ``True``. Has no effect for NIRISS SOSS data.

Step Arguments for Slit and Slitless Spectroscopic Data
-------------------------------------------------------

``--use_source_posn``
This is a boolean flag to specify whether the target and background extraction
region locations specified in the :ref:`EXTRACT1D <extract1d_reffile>` reference
file should be shifted to account for the expected position of the source. If None (the default),
the step will make the decision of whether to use the source position based
on the observing mode and the source type. The source position will only be
used for point sources and for modes where the source could be located
off-center due to nodding or dithering. If turned on, the position
of the source is used in conjunction with the World Coordinate System (WCS) to
compute the x/y source location. For NIRSpec modes, the source position
is determined from the ``source_xpos/source_ypos`` metadata. For MIRI LRS fixed slit,
the dither offset is applied to the sky pointing location to determine source position.
If this parameter is specified in the
:ref:`EXTRACT1D <extract1d_reffile>` reference file, the reference file value will
override any automatic settings based on exposure and source type. As always, a value
given by the user as an argument to the step overrides all settings in the reference
file or within the step code.

``--smoothing_length``
If ``smoothing_length`` is greater than 1 (and is an odd integer), the
image data used to perform background extraction will be smoothed in the
Expand All @@ -20,7 +55,7 @@ The ``extract_1d`` step has the following step-specific arguments.
``--bkg_fit``
The type of fit to perform to the background data in each image column
(or row, if the dispersion is vertical). There are four allowed values:
"poly", "mean", and "median", and None (the default value). If left as None,
"poly", "mean", "median", and None (the default value). If left as None,
the step will search the reference file for a value - if none is found,
``bkg_fit`` will be set to "poly". If set to "poly", the background
values for each pixel within all background regions in a given column (or
Expand All @@ -45,59 +80,28 @@ The ``extract_1d`` step has the following step-specific arguments.
0 for that particular column (or row). If "bkg_fit" is not "poly", this
parameter will be ignored.

``--bkg_sigma_clip``
The background values will be sigma-clipped to remove outlier values from
the determination of the background. The default value is a 3.0 sigma clip.

``--log_increment``
Most log messages are suppressed while looping over integrations, i.e. when
the input is a CubeModel or a 3-D SlitModel. Messages will be logged while
processing the first integration, but since they would be the same for
every integration, most messages will only be written once. However, since
there can be hundreds or thousands of integrations, which can take a long
time to process, it would be useful to log a message every now and then to
let the user know that the step is still running.

``log_increment`` is an integer, with default value 50. If it is greater
than 0, an INFO message will be printed every ``log_increment``
integrations, e.g. "... 150 integrations done".
For multi-integration extractions, if this parameter is set to a value greater
than zero, an INFO-level log message will be printed every `log_increment` integrations,
to report on progress. Default value is 50.

``--subtract_background``
This is a boolean flag to specify whether the background should be
subtracted. If None, the value in the :ref:`EXTRACT1D <extract1d_reffile>`
reference file (if any) will be used. If not None, this parameter overrides
the value in the reference file.
``--save_profile``
If True, the spatial profile representing the extraction aperture
is saved to disk with suffix "profile".

``--use_source_posn``
This is a boolean flag to specify whether the target and background extraction
region locations specified in the :ref:`EXTRACT1D <extract1d_reffile>` reference
file should be shifted
to account for the expected position of the source. If None (the default),
the step will make the decision of whether to use the source position based
on the observing mode and the source type. The source position will only be
used for point sources and for modes where the source could be located
off-center due to things like nodding or dithering. If turned on, the position
of the source is used in conjunction with the World Coordinate System (WCS) to
compute the x/y source location. For NIRSpec non-IFU modes, the source position
is determined from the ``source_xpos/source_ypos`` parameters. For MIRI LRS fixed slit,
the dither offset is applied to the sky pointing location to determine source position.
All other modes use ``targ_ra/targ_dec``. If this parameter is specified in the
:ref:`EXTRACT1D <extract1d_reffile>` reference file, the reference file value will
override any automatic settings based on exposure and source type. As always, a value
given by the user as an argument to the step overrides all settings in the reference
file or within the step code.
``--save_scene_model``
If True, a model of the 2D flux as defined by the extraction aperture
is saved to disk with suffix "scene_model".

Step Arguments for IFU Data
---------------------------

``--center_xy``
A list of two integer values giving the desired x/y location for the center
of the circular extraction aperture used for extracting spectra from 3-D
IFU cubes. Ignored for non-IFU modes and non-point sources. Must be given in
x,y order and in units of pixels along the x,y axes of the 3-D IFU cube, e.g.
``--center_xy="27,28"``. If given, the values override any position derived
from the use of the ``use_source_posn`` argument. Default is None.

``--apply_apcorr``
Switch to select whether or not to apply an APERTURE correction during the
Extract1dStep processing. Default is ``True``
IFU cubes. Must be given in x,y order and in units of pixels along the x,y
axes of the 3-D IFU cube, e.g. ``--center_xy="27,28"``.
Default is None.

``--ifu_autocen``
Switch to select whether or not to enable auto-centroiding of the extraction
Expand All @@ -106,6 +110,10 @@ The ``extract_1d`` step has the following step-specific arguments.
becomes extremely low) and using DAOStarFinder to locate the brightest
source in the field. Default is ``False``.

``--bkg_sigma_clip``
The background values will be sigma-clipped to remove outlier values from
the determination of the background. The default value is a 3.0 sigma clip.

``--ifu_rfcorr``
Switch to select whether or not to run 1d residual fringe correction on the
extracted 1d spectrum (MIRI MRS only). Default is ``False``.
Expand All @@ -128,65 +136,67 @@ The ``extract_1d`` step has the following step-specific arguments.
for covariance between adjacent spaxels in the IFU data cube. The default value is
1.0 (i.e., no correction) unless set by a user or a parameter reference file. This
parameter only affects MIRI and NIRSpec IFU spectroscopy.


Step Arguments for NIRISS SOSS Data
-----------------------------------

``--soss_atoca``
This is a NIRISS-SOSS algorithm-specific parameter; if True, use the ATOCA
algorithm to treat order contamination. Default is ``True``.
If True, use the ATOCA algorithm to treat order contamination. Default is ``True``.

``--soss_threshold``
This is a NIRISS-SOSS algorithm-specific parameter; this sets the threshold
Sets the threshold
value for a pixel to be included when modelling the spectral trace. The default
value is 0.01.

``--soss_n_os``
This is a NIRISS-SOSS algorithm-specific parameter; this is an integer that sets
An integer that sets
the oversampling factor of the underlying wavelength grid used when modeling the
trace. The default value is 2.

``--soss_estimate``
This is a NIRISS-SOSS algorithm-specific parameter; filename or SpecModel of the
estimate of the target flux. The estimate must be a SpecModel with wavelength and
flux values.

``--soss_wave_grid_in``
This is a NIRISS-SOSS algorithm-specific parameter; filename or SossWaveGridModel
Filename or SossWaveGridModel
containing the wavelength grid used by ATOCA to model each valid pixel of the
detector. If not given, the grid is determined based on an estimate of the flux
(soss_estimate), the relative tolerance (soss_rtol) required on each pixel model
and the maximum grid size (soss_max_grid_size).

``--soss_wave_grid_out``
This is a NIRISS-SOSS algorithm-specific parameter; filename to hold the wavelength
Filename to hold the wavelength
grid calculated by ATOCA, stored in a SossWaveGridModel.

``--soss_estimate``
Filename or SpecModel of the
estimate of the target flux. The estimate must be a SpecModel with wavelength and
flux values.

``--soss_rtol``
This is a NIRISS-SOSS algorithm-specific parameter; the relative tolerance needed on a
The relative tolerance needed on a
pixel model. It is used to determine the sampling of the soss_wave_grid when not
directly given. Default value is 1.e-4.

``--soss_max_grid_size``
This is a NIRISS-SOSS algorithm-specific parameter; the maximum grid size allowed. It is
The maximum grid size allowed. It is
used when soss_wave_grid is not provided to make sure the computation time or the memory
used stays reasonable. Default value is 20000.

``--soss_tikfac``
This is a NIRISS-SOSS algorithm-specific parameter; this is the regularization
This is the regularization
factor used in the SOSS extraction. If not specified, ATOCA will calculate a
best-fit value for the Tikhonov factor.

``--soss_width``
This is a NIRISS-SOSS algorithm-specific parameter; this specifies the aperture
This specifies the aperture
width used to extract the 1D spectrum from the decontaminated trace. The default
value is 40.0 pixels.

``--soss_bad_pix``
This is a NIRISS-SOSS algorithm-specific parameter; this parameter sets the method
This parameter sets the method
used to handle bad pixels. There are currently two options: "model" will replace
the bad pixel values with a modeled value, while "masking" will omit those pixels
from the spectrum. The default value is "model".

``--soss_modelname``
This is a NIRISS-SOSS algorithm-specific parameter; if set, this will provide
If set, this will provide
the optional ATOCA model output of traces and pixel weights, with the filename
set by this parameter. By default this is set to None and this output is
not provided.
Loading
Loading