From b16e2b78bd601290b633ca74aeaf7383a2c169a5 Mon Sep 17 00:00:00 2001 From: Jane Morrison Date: Wed, 20 Sep 2023 17:41:03 -0700 Subject: [PATCH] JP-3355 added parameter to extract 1d to override srctype and use point source extraction (#7883) --- CHANGES.rst | 8 ++++++- docs/jwst/extract_1d/arguments.rst | 13 +++++++++++ jwst/extract_1d/extract.py | 31 +++++++++++++++++++++++++- jwst/extract_1d/extract_1d_step.py | 35 ++++++++++++++++++++++++++++++ jwst/extract_1d/ifu.py | 22 +++++++++++++++---- 5 files changed, 103 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 57cb81c587..b4555b7196 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) =================== @@ -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 ---------- diff --git a/docs/jwst/extract_1d/arguments.rst b/docs/jwst/extract_1d/arguments.rst index 9022b8d16e..ca74b0e813 100644 --- a/docs/jwst/extract_1d/arguments.rst +++ b/docs/jwst/extract_1d/arguments.rst @@ -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``. diff --git a/jwst/extract_1d/extract.py b/jwst/extract_1d/extract.py index bb9b056d44..1ee5d34722 100644 --- a/jwst/extract_1d/extract.py +++ b/jwst/extract_1d/extract.py @@ -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. @@ -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 @@ -2655,6 +2667,8 @@ def run_extract1d( center_xy, ifu_autocen, ifu_rfcorr, + ifu_set_srctype, + ifu_rscale, was_source_model, ) @@ -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. @@ -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 @@ -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: diff --git a/jwst/extract_1d/extract_1d_step.py b/jwst/extract_1d/extract_1d_step.py index 22f9b0e980..5cd5f8f836 100644 --- a/jwst/extract_1d/extract_1d_step.py +++ b/jwst/extract_1d/extract_1d_step.py @@ -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 @@ -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. @@ -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): @@ -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 @@ -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 @@ -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, ) @@ -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, ) diff --git a/jwst/extract_1d/ifu.py b/jwst/extract_1d/ifu.py index 93093cc07c..ccf90a9ea4 100644 --- a/jwst/extract_1d/ifu.py +++ b/jwst/extract_1d/ifu.py @@ -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 @@ -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 @@ -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]) @@ -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 @@ -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,