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

Expand on trace #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion changes/9022.extract_1d.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Added on option to calculate a source trace from WCS and expected source positions for NIRSpec BOTS/MOS/FS data and perform a box extraction around that trace. This option is turned on by default for the BOTS mode.
Expanded the ``use_source_posn`` option to calculate a source trace from WCS and expected source positions for unresampled NIRSpec and MIRI LRS fixed slit data.
Added the step parameter ``position_offset`` to allow an additional aperture offset in pixels.
16 changes: 4 additions & 12 deletions docs/jwst/extract_1d/arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,13 @@ Step Arguments for Slit and Slitless Spectroscopic Data
file should be shifted to account for the expected position of the source. If None (the default),
the step will decide whether to use the source position based
on the observing mode and the source type. By default, source position corrections
are attempted only for NIRSpec MOS and NIRSpec and MIRI LRS fixed-slit point sources.
are attempted only for point sources in NIRSpec MOS/FS/BOTS and MIRI LRS fixed-slit exposures.
Set to False to ignore position estimates for all modes; set to True to additionally attempt
source position correction for NIRSpec BOTS data or extended sources.
source position correction for extended sources.

``--use_trace``
Specify whether to calculate a 2D trace and extract the pixels around that trace
within the ``extract_width`` defined in the :ref:`EXTRACT1D <extract1d_reffile>`.
If None (the default), the step will decide whether to use the source position based
on the observing mode. Currently this option is only available for NIRSpec BOTS, MOS,
and fixed-slit modes, where the trace will be calculated from the expected positions
of the sources. This option is used by default for the NIRSpec BOTS mode.

``--trace_offset``
``--position_offset``
Specify a number of pixels (fractional pixels are allowed) to offset the
calculated trace if ``use_trace`` is set to True. The default is 0.
extraction aperture from the nominal position. The default is 0.

``--smoothing_length``
If ``smoothing_length`` is greater than 1 (and is an odd integer), the
Expand Down
342 changes: 181 additions & 161 deletions jwst/extract_1d/extract.py

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions jwst/extract_1d/extract_1d_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ class Extract1dStep(Step):
apply_apcorr = boolean(default=True) # apply aperture corrections?

use_source_posn = boolean(default=None) # use source coords to center extractions?
use_trace = boolean(default=None) # use source trace for extraction
trace_offset = float(default=0) # number of pixels to shift source trace in the cross-dispersion direction
position_offset = float(default=0) # number of pixels to shift source trace in the cross-dispersion direction
smoothing_length = integer(default=None) # background smoothing size
bkg_fit = option("poly", "mean", "median", None, default=None) # background fitting type
bkg_order = integer(default=None, min=0) # order of background polynomial fit
Expand Down Expand Up @@ -424,8 +423,7 @@ def process(self, input):
self.log_increment,
self.subtract_background,
self.use_source_posn,
self.use_trace,
self.trace_offset,
self.position_offset,
self.save_profile,
self.save_scene_model,
)
Expand Down
36 changes: 29 additions & 7 deletions jwst/extract_1d/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,24 @@ def simple_wcs_function(x, y):
# Add a bounding box
simple_wcs_function.bounding_box = wcs_bbox_from_shape(shape)

# Add a few expected attributes, so they can be monkeypatched as needed
simple_wcs_function.get_transform = None
simple_wcs_function.backward_transform = None
# Define a simple transform
def get_transform(*args, **kwargs):
def return_results(*args, **kwargs):
if len(args) == 2:
zeros = np.zeros(args[0].shape)
wave, _ = np.meshgrid(args[0], args[1])
return zeros, zeros, wave
if len(args) == 3:
try:
nx = len(args[0])
except TypeError:
nx = 1
pix = np.arange(nx)
trace = np.ones(nx)
return pix, trace
return return_results

simple_wcs_function.get_transform = get_transform
simple_wcs_function.available_frames = []

return simple_wcs_function
Expand Down Expand Up @@ -68,10 +83,17 @@ def simple_wcs_function(x, y):
# Add a bounding box
simple_wcs_function.bounding_box = wcs_bbox_from_shape(shape)

# Add a few expected attributes, so they can be monkeypatched as needed
simple_wcs_function.get_transform = None
simple_wcs_function.backward_transform = None
simple_wcs_function.available_frames = []
# Mock a simple backward transform
def backward_transform(*args, **kwargs):
try:
nx = len(args[0])
except TypeError:
nx = 1
pix = np.arange(nx)
trace = np.ones(nx)
return trace, pix

simple_wcs_function.backward_transform = backward_transform

return simple_wcs_function

Expand Down
Loading
Loading