diff --git a/jwst/extract_1d/extract_1d_step.py b/jwst/extract_1d/extract_1d_step.py index a613bedf26..e26d3a53b8 100644 --- a/jwst/extract_1d/extract_1d_step.py +++ b/jwst/extract_1d/extract_1d_step.py @@ -88,8 +88,7 @@ class Extract1dStep(Step): ifu_rfcorr : bool Switch to select whether or not to apply a 1d residual fringe correction - for MIRI MRS IFU spectra. Default is False. - + for MIRI MRS IFU spectra. Default is True. ifu_set_srctype : str For MIRI MRS IFU data override srctype and set it to either POINT or EXTENDED. @@ -172,7 +171,7 @@ class Extract1dStep(Step): center_xy = float_list(min=2, max=2, default=None) # IFU extraction x/y center ifu_autocen = boolean(default=False) # Auto source centering for IFU point source data. bkg_sigma_clip = float(default=3.0) # background sigma clipping threshold for IFU - ifu_rfcorr = boolean(default=False) # Apply 1d residual fringe correction + ifu_rfcorr = boolean(default=True) # 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 ifu_covar_scale = float(default=1.0) # Scaling factor to apply to errors to account for IFU cube covariance diff --git a/jwst/extract_1d/ifu.py b/jwst/extract_1d/ifu.py index 3a68efd150..049b557d1e 100644 --- a/jwst/extract_1d/ifu.py +++ b/jwst/extract_1d/ifu.py @@ -71,7 +71,7 @@ def ifu_extract1d(input_model, ref_file, source_type, subtract_background, ifu_rfcorr : bool Switch to select whether or not to apply a 1d residual fringe correction - for MIRI MRS IFU spectra. Default is False. + for MIRI MRS IFU spectra. Default is True. ifu_rscale: float For MRS IFU data a value for changing the extraction radius. The value provided is the number of PSF @@ -106,7 +106,8 @@ def ifu_extract1d(input_model, ref_file, source_type, subtract_background, else: log.info(f"Source type = {source_type}") - output_model = datamodels.MultiSpecModel() + #output_model = datamodels.MultiSpecModel() + output_model = datamodels.MrsSpecModel() output_model.update(input_model, only="PRIMARY") slitname = input_model.meta.exposure.type @@ -183,21 +184,21 @@ def ifu_extract1d(input_model, ref_file, source_type, subtract_background, # Apply residual fringe to the flux array try: - temp_flux = rfutils.fit_residual_fringes_1d(temp_flux, wavelength, channel=channel, + temp_flux_rf = rfutils.fit_residual_fringes_1d(temp_flux, wavelength, channel=channel, dichroic_only=False, max_amp=None) except Exception: log.info("Flux residual fringe correction failed- skipping.") # Apply residual fringe to the surf_bright array try: - surf_bright = rfutils.fit_residual_fringes_1d(surf_bright, wavelength, channel=channel, + surf_bright_rf = rfutils.fit_residual_fringes_1d(surf_bright, wavelength, channel=channel, dichroic_only=False, max_amp=None) except Exception: log.info("Surf bright residual fringe correction failed- skipping.") # Apply residual fringe to the background array try: - background = rfutils.fit_residual_fringes_1d(background, wavelength, channel=channel, + background_rf = rfutils.fit_residual_fringes_1d(background, wavelength, channel=channel, dichroic_only=False, max_amp=None) except Exception: log.info("Background residual fringe correction failed- skipping.") @@ -208,17 +209,20 @@ def ifu_extract1d(input_model, ref_file, source_type, subtract_background, "the flux will not be correct.") pixel_solid_angle = 1. - # Convert flux from MJy / steradian to Jy. + # Convert flux from MJy / steradian to Jy flux = temp_flux * pixel_solid_angle * 1.e6 + flux_rf = temp_flux_rf * pixel_solid_angle * 1.e6 f_var_poisson *= (pixel_solid_angle ** 2 * 1.e12) # (MJy / sr)**2 --> Jy**2 f_var_rnoise *= (pixel_solid_angle ** 2 * 1.e12) # (MJy / sr)**2 --> Jy**2 f_var_flat *= (pixel_solid_angle ** 2 * 1.e12) # (MJy / sr)**2 --> Jy**2 # surf_bright and background were computed above del temp_flux + del temp_flux_rf error = np.sqrt(f_var_poisson + f_var_rnoise + f_var_flat) sb_error = np.sqrt(sb_var_poisson + sb_var_rnoise + sb_var_flat) berror = np.sqrt(b_var_poisson + b_var_rnoise + b_var_flat) - spec_dtype = datamodels.SpecModel().spec_table.dtype + spec_dtype = datamodels.MrsSpecModel().mrs_spec_table.dtype + # If we only used the Poisson variance array as a vehicle to pass through # non-differentiated errors, clear it again here so that only the total @@ -250,31 +254,38 @@ def ifu_extract1d(input_model, ref_file, source_type, subtract_background, list( zip(wavelength, flux, error, f_var_poisson, f_var_rnoise, f_var_flat, surf_bright, sb_error, sb_var_poisson, sb_var_rnoise, sb_var_flat, - dq, background, berror, b_var_poisson, b_var_rnoise, b_var_flat, npixels) + dq, background, berror, b_var_poisson, b_var_rnoise, b_var_flat, npixels, + flux_rf, surf_bright_rf, background_rf) ), dtype=spec_dtype ) - - spec = datamodels.SpecModel(spec_table=otab) + if ((input_model.meta.instrument.name == 'MIRI') & (extract_params['ifu_rfcorr'] is True)): + spec = datamodels.MrsSpecModel(mrs_spec_table=otab) + else: + spec = datamodels.SpecModel(spec_table=otab) spec.meta.wcs = spec_wcs.create_spectral_wcs(ra, dec, wavelength) - spec.spec_table.columns['wavelength'].unit = 'um' - spec.spec_table.columns['flux'].unit = "Jy" - spec.spec_table.columns['flux_error'].unit = "Jy" - spec.spec_table.columns['flux_var_poisson'].unit = "Jy^2" - spec.spec_table.columns['flux_var_rnoise'].unit = "Jy^2" - spec.spec_table.columns['flux_var_flat'].unit = "Jy^2" - spec.spec_table.columns['surf_bright'].unit = "MJy/sr" - spec.spec_table.columns['sb_error'].unit = "MJy/sr" - spec.spec_table.columns['sb_var_poisson'].unit = "(MJy/sr)^2" - spec.spec_table.columns['sb_var_rnoise'].unit = "(MJy/sr)^2" - spec.spec_table.columns['sb_var_flat'].unit = "(MJy/sr)^2" - spec.spec_table.columns['background'].unit = "MJy/sr" - spec.spec_table.columns['bkgd_error'].unit = "MJy/sr" - spec.spec_table.columns['bkgd_var_poisson'].unit = "(MJy/sr)^2" - spec.spec_table.columns['bkgd_var_rnoise'].unit = "(MJy/sr)^2" - spec.spec_table.columns['bkgd_var_flat'].unit = "(MJy/sr)^2" + spec.mrs_spec_table.columns['wavelength'].unit = 'um' + spec.mrs_spec_table.columns['flux'].unit = "Jy" + spec.mrs_spec_table.columns['flux_error'].unit = "Jy" + spec.mrs_spec_table.columns['flux_var_poisson'].unit = "Jy^2" + spec.mrs_spec_table.columns['flux_var_rnoise'].unit = "Jy^2" + spec.mrs_spec_table.columns['flux_var_flat'].unit = "Jy^2" + spec.mrs_spec_table.columns['surf_bright'].unit = "MJy/sr" + spec.mrs_spec_table.columns['sb_error'].unit = "MJy/sr" + spec.mrs_spec_table.columns['sb_var_poisson'].unit = "(MJy/sr)^2" + spec.mrs_spec_table.columns['sb_var_rnoise'].unit = "(MJy/sr)^2" + spec.mrs_spec_table.columns['sb_var_flat'].unit = "(MJy/sr)^2" + spec.mrs_spec_table.columns['background'].unit = "MJy/sr" + spec.mrs_spec_table.columns['bkgd_error'].unit = "MJy/sr" + spec.mrs_spec_table.columns['bkgd_var_poisson'].unit = "(MJy/sr)^2" + spec.mrs_spec_table.columns['bkgd_var_rnoise'].unit = "(MJy/sr)^2" + spec.mrs_spec_table.columns['bkgd_var_flat'].unit = "(MJy/sr)^2" + spec.mrs_spec_table.columns['rf_flux'].unit = "Jy" + spec.mrs_spec_table.columns['rf_surf_bright'].unit = "MJy/sr" + spec.mrs_spec_table.columns['rf_background'].unit = "MJy/sr" spec.slit_ra = ra spec.slit_dec = dec + if slitname is not None and slitname != "ANY": spec.name = slitname @@ -305,10 +316,14 @@ def ifu_extract1d(input_model, ref_file, source_type, subtract_background, radius = radius_match[i] apcorr.find_apcorr_func(i, radius) - apcorr.apply(spec.spec_table) - - output_model.spec.append(spec) + apcorr.apply(spec.mrs_spec_table) + #output_model.spec.append(spec) + output_model = spec + print(spec.mrs_spec_table['FLUX']) + print(spec.mrs_spec_table['RF_FLUX']) + print(spec.mrs_spec_table['RF_SURF_BRIGHT']) + print(spec.mrs_spec_table['RF_BACKGROUND']) # See output_model.spec[0].meta.wcs instead. output_model.meta.wcs = None