Skip to content

Commit

Permalink
JP-3355 added parameter to extract 1d to override srctype and use poi…
Browse files Browse the repository at this point in the history
…nt source extraction (#7883)
  • Loading branch information
jemorrison authored Sep 21, 2023
1 parent 2144710 commit b16e2b7
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
1.12.1 (unreleased)
===================

-
extract_1d
----------

- For MIRS MRS IFU data allow the user to set the src_type and allow
the user to scale the extraction radius between 0.5 to 3.0 FWHM [#7883]


1.12.0 (2023-09-18)
===================
Expand Down Expand Up @@ -112,6 +117,7 @@ extract_1d
- Use ``source_{x/y}pos`` metadata to center extraction region for NIRSpec
(non-IFU) data; use dithered pointing info for MIRI LRS fixed slit data. [#7796]


extract_2d
----------

Expand Down
13 changes: 13 additions & 0 deletions docs/jwst/extract_1d/arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ The ``extract_1d`` step has the following step-specific arguments.
Switch to select whether or not to run 1d residual fringe correction on the
extracted 1d spectrum (MIRI MRS only). Default is ``False``.

``--ifu_set_srctype``
A string that can be used to override the extraction method for the source_type
given by the SRCTYPE keyword. The allowed values are POINT and EXTENDED. The SRCTYPE keyword is
not changed, instead the extraction method used is based on this parameter setting. This is
only allowed for MIRI MRS IFU data.

``--ifu_rscale``
A float designating the number of PSF FWHMs to use for the extraction radius. This
is a MIRI MRS only paramenter. Values accepted are between 0.5 to 3.0. The default extraction
size is set to 2 * FWHM. Values below 2 will result in a smaller
radius, a value of 2 results in no change to radius and a value above 2 results in a larger
extraction radius.

``--soss_atoca``
This is a NIRISS-SOSS algorithm-specific parameter; if True, use the ATOCA
algorithm to treat order contamination. Default is ``True``.
Expand Down
31 changes: 30 additions & 1 deletion jwst/extract_1d/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,8 @@ def run_extract1d(
center_xy: Union[float, None],
ifu_autocen: Union[bool, None],
ifu_rfcorr: Union[bool, None],
ifu_set_srctype: str,
ifu_rscale: float,
was_source_model: bool = False,
) -> DataModel:
"""Extract 1-D spectra.
Expand Down Expand Up @@ -2607,6 +2609,16 @@ def run_extract1d(
Switch to select whether or not to apply a 1d residual fringe correction
for MIRI MRS IFU spectra. Default is False.
ifu_set_srctype : str
For MIRI MRS IFU data override srctype and set it to either POINT or EXTENDED.
ifu_rscale: float
For MRS IFU data a value for changing the extraction radius. The value provided is the number of PSF
FWHMs to use for the extraction radius. Values accepted are between 0.5 to 3.0. The
default extraction size is set to 2 * FWHM. Values below 2 will result in a smaller
radius, a value of 2 results in no change to the radius and a value above 2 results in a larger
extraction radius.
was_source_model : bool
True if and only if `input_model` is actually one SlitModel
obtained by iterating over a SourceModelContainer. The default
Expand Down Expand Up @@ -2655,6 +2667,8 @@ def run_extract1d(
center_xy,
ifu_autocen,
ifu_rfcorr,
ifu_set_srctype,
ifu_rscale,
was_source_model,
)

Expand Down Expand Up @@ -2717,6 +2731,8 @@ def do_extract1d(
center_xy: Union[int, None] = None,
ifu_autocen: Union[bool, None] = None,
ifu_rfcorr: Union[bool, None] = None,
ifu_set_srctype: str = None,
ifu_rscale: float = None,
was_source_model: bool = False
) -> DataModel:
"""Extract 1-D spectra.
Expand Down Expand Up @@ -2787,6 +2803,16 @@ def do_extract1d(
Switch to select whether or not to apply a 1d residual fringe correction
for MIRI MRS IFU spectra. Default is False.
ifu_set_srctype : str
For MIRI MRS IFU data override srctype and set it to either POINT or EXTENDED.
ifu_rscale: float
For MRS IFU data a value for changing the extraction radius. The value provided is the number of PSF
FWHMs to use for the extraction radius. Values accepted are between 0.5 to 3.0. The
default extraction size is set to 2 * FWHM. Values below 2 will result in a smaller
radius, a value of 2 results in no change to the radius and a value above 2 results in a larger
extraction radius.
was_source_model : bool
True if and only if `input_model` is actually one SlitModel
obtained by iterating over a SourceModelContainer. The default
Expand Down Expand Up @@ -2994,9 +3020,12 @@ def do_extract1d(
if source_type is None:
source_type = "UNKNOWN"

if ifu_set_srctype is not None and input_model.meta.exposure.type == 'MIR_MRS':
source_type = ifu_set_srctype
log.info(f"Overriding source type and setting it to = {ifu_set_srctype}")
output_model = ifu.ifu_extract1d(
input_model, extract_ref_dict, source_type, subtract_background,
bkg_sigma_clip, apcorr_ref_model, center_xy, ifu_autocen, ifu_rfcorr
bkg_sigma_clip, apcorr_ref_model, center_xy, ifu_autocen, ifu_rfcorr, ifu_rscale
)

else:
Expand Down
35 changes: 35 additions & 0 deletions jwst/extract_1d/extract_1d_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ class Extract1dStep(Step):
Switch to select whether or not to apply a 1d residual fringe correction
for MIRI MRS IFU spectra. Default is False.
ifu_set_srctype : str
For MIRI MRS IFU data override srctype and set it to either POINT or EXTENDED.
ifu_rscale : float
For MRS IFU data a value for changing the extraction radius. The value provided is
the number of PSF FWHMs to use for the extraction radius. Values accepted are between
0.5 to 3.0. The default extraction size is set to 2 * FWHM. Values below 2 will result
in a smaller radius, a value of 2 results in no change to the radius and a value above
2 results in a larger extraction radius.
soss_atoca : bool, default=False
Switch to toggle extraction of SOSS data with the ATOCA algorithm.
WARNING: ATOCA results not fully validated, and require the photom step
Expand Down Expand Up @@ -149,6 +159,8 @@ class Extract1dStep(Step):
apply_apcorr = boolean(default=True) # apply aperture corrections?
ifu_autocen = boolean(default=False) # Auto source centering for IFU point source data.
ifu_rfcorr = boolean(default=False) # Apply 1d residual fringe correction
ifu_set_srctype = option("POINT", "EXTENDED", None, default=None) # user-supplied source type
ifu_rscale = float(default=None, min=0.5, max=3) # Radius in terms of PSF FWHM to scale extraction radii
soss_atoca = boolean(default=True) # use ATOCA algorithm
soss_threshold = float(default=1e-2) # TODO: threshold could be removed from inputs. Its use is too specific now.
soss_n_os = integer(default=2) # minimum oversampling factor of the underlying wavelength grid used when modeling trace.
Expand Down Expand Up @@ -217,6 +229,21 @@ def process(self, input):
input_model.meta.cal_step.extract_1d = 'SKIPPED'
return input_model

if self.ifu_rfcorr:
if input_model.meta.exposure.type != "MIR_MRS":
self.log.warning("The option to apply a residual refringe correction is"
f" not supported for {input_model.meta.exposure.type} data.")

if self.ifu_rscale is not None:
if input_model.meta.exposure.type != "MIR_MRS":
self.log.warning("The option to change the extraction radius is"
f" not supported for {input_model.meta.exposure.type} data.")

if self.ifu_set_srctype is not None:
if input_model.meta.exposure.type != "MIR_MRS":
self.log.warning("The option to change the source type is"
f" not supported for {input_model.meta.exposure.type} data.")

# ______________________________________________________________________
# Do the extraction for ModelContainer - this might only be WFSS data
if isinstance(input_model, ModelContainer):
Expand Down Expand Up @@ -260,6 +287,8 @@ def process(self, input):
self.center_xy,
self.ifu_autocen,
self.ifu_rfcorr,
self.ifu_set_srctype,
self.ifu_rscale,
was_source_model=was_source_model
)
# Set the step flag to complete
Expand Down Expand Up @@ -296,6 +325,8 @@ def process(self, input):
self.center_xy,
self.ifu_autocen,
self.ifu_rfcorr,
self.ifu_set_srctype,
self.ifu_rscale,
was_source_model=was_source_model,
)
# Set the step flag to complete in each MultiSpecModel
Expand Down Expand Up @@ -335,6 +366,8 @@ def process(self, input):
self.center_xy,
self.ifu_autocen,
self.ifu_rfcorr,
self.ifu_set_srctype,
self.ifu_rscale,
was_source_model=was_source_model,
)

Expand Down Expand Up @@ -476,6 +509,8 @@ def process(self, input):
self.center_xy,
self.ifu_autocen,
self.ifu_rfcorr,
self.ifu_set_srctype,
self.ifu_rscale,
was_source_model=False,
)

Expand Down
22 changes: 18 additions & 4 deletions jwst/extract_1d/ifu.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

def ifu_extract1d(input_model, ref_dict, source_type, subtract_background,
bkg_sigma_clip, apcorr_ref_model=None, center_xy=None,
ifu_autocen=False, ifu_rfcorr=False):
ifu_autocen=False, ifu_rfcorr=False, ifu_rscale=None):
"""Extract a 1-D spectrum from an IFU cube.
Parameters
Expand Down Expand Up @@ -77,6 +77,13 @@ def ifu_extract1d(input_model, ref_dict, source_type, subtract_background,
Switch to select whether or not to apply a 1d residual fringe correction
for MIRI MRS IFU spectra. Default is False.
ifu_rscale: float
For MRS IFU data a value for changing the extraction radius. The value provided is the number of PSF
FWHMs to use for the extraction radius. Values accepted are between 0.5 to 3.0. The
default extraction size is set to 2 * FWHM. Values below 2 will resuls in a smaller
radius, a value of 2 results in no change to radius and a value above 2 results in a larger
extraction radius.
Returns
-------
output_model : MultiSpecModel
Expand Down Expand Up @@ -108,14 +115,17 @@ def ifu_extract1d(input_model, ref_dict, source_type, subtract_background,

extract_params = get_extract_parameters(ref_dict, bkg_sigma_clip, slitname)

# Add info about IFU auto-centroiding and residual fringe correction to extract_params for use later
# Add info about IFU auto-centroiding, residual fringe correction and extraction radius scale
# to extract_params for use later
extract_params['ifu_autocen'] = ifu_autocen
extract_params['ifu_rfcorr'] = ifu_rfcorr
extract_params['ifu_rscale'] = ifu_rscale

# If the user supplied extraction center coords,
# load them into extract_params for use later.
extract_params['x_center'] = None
extract_params['y_center'] = None

if center_xy is not None:
if len(center_xy) == 2:
extract_params['x_center'] = float(center_xy[0])
Expand Down Expand Up @@ -515,6 +525,10 @@ def extract_ifu(input_model, source_type, extract_params):
outer_bkg = extract_params['outer_bkg'].flatten()
radius = extract_params['radius'].flatten()

if ((input_model.meta.instrument.name == 'MIRI') & (extract_params['ifu_rscale'] is not None)):
radius = radius * extract_params['ifu_rscale']/2.0
log.info("Scaling radius by factor = %g", extract_params['ifu_rscale'] / 2.0)

frad = interp1d(wave_extract, radius, bounds_error=False, fill_value="extrapolate")
radius_match = frad(wavelength)
# radius_match is in arc seconds - need to convert to pixels
Expand Down Expand Up @@ -741,14 +755,14 @@ def extract_ifu(input_model, source_type, extract_params):
# Determine which MRS channel the spectrum is from
thischannel = input_model.meta.instrument.channel
# Valid single-channel values
validch=['1','2','3','4']
validch = ['1', '2', '3', '4']
# Embed all calls to residual fringe code in a try/except loop as the default behavior
# if problems are encountered should be to not apply this optional step
try:
# If a valid single channel, specify it in call to residual fringe code
if (thischannel in validch):
temp_flux = rfutils.fit_residual_fringes_1d(temp_flux, wavelength, channel=thischannel,
dichroic_only=False, max_amp=None)
dichroic_only=False, max_amp=None)
# Otherwise leave channel blank
else:
temp_flux = rfutils.fit_residual_fringes_1d(temp_flux, wavelength,
Expand Down

0 comments on commit b16e2b7

Please sign in to comment.