apply_emicorr

jwst.emicorr.emicorr.apply_emicorr(input_model, emicorr_model, save_onthefly_reffile=None, algorithm='sequential', nints_to_phase=None, nbins=None, scale_reference=True, onthefly_corr_freq=None, use_n_cycles=3, fit_ints_separately=False)[source]

Apply an EMI correction to MIRI ramps.

The sequential algorithm corrects data for EMI by the following procedure (repeat iteratively for each discrete EMI frequency desired):

  1. Make very crude slope image and fixed pattern superbias for each integration, ignoring everything (nonlin, saturation, badpix, etc).

  2. Subtract scaled slope image and bias from each frame of each integration.

  3. Calculate phase of every pixel in the image at the desired EMI frequency (e.g., 390 Hz) relative to the first pixel in the image.

  4. Make a binned, phased amplitude (PA) wave from the cleaned data.

  5. Either:

    • measure the phase shift between the binned PA wave and the input reference wave. Use look-up table to get the aligned reference wave value for each pixel (the noise array corresponding to the input image); or

    • use the binned PA wave instead of the reference wave to “self-correct”.

  6. Subtract the noise array from the input image and return the cleaned result.

  7. (Repeat for next frequency using cleaned output as input.)

The joint algorithm proceeds similarly, except that the linear ramps and the EMI noise are fit simultaneously. It works by choosing pixels with modest scatter among the reads, and then finding the amplitude and phase of a supplied reference waveform that, when subtracted, makes these pixels’ ramps as straight as possible. The straightness of the ramps is measured by chi squared after fitting lines to each one. As for the sequential algorithm, the EMI signal at each frequency is fit and removed iteratively, for each desired frequency.

For either algorithm, removing the highest amplitude EMI first will probably give best results.

Parameters:
input_modelRampModel

Input science data model to be EMI-corrected. Updated in place.

emicorr_modelEmiModel or None

Data model containing EMI correction.

save_onthefly_reffilestr or None, optional

Full path and root name to save an on-the-fly reference file to.

algorithm{‘sequential’, ‘joint’}, optional

Algorithm for fitting EMI noise in ramps. If ‘sequential’, ramps are fit and then EMI noise is fit to the residuals. If ‘joint’, ramps and noise are fit simultaneously. The ‘sequential’ algorithm can be used without a reference waveform, generating a new reference file on-the-fly, but it requires 10 or more groups for a reliable fit. The ‘joint’ algorithm requires a reference waveform but can successfully fit EMI in ramps with 3 or more groups.

nints_to_phaseint or None, optional

Number of integrations to phase, when algorithm is ‘sequential’.

nbinsint or None, optional

Number of bins to use in one phased wave, when algorithm is ‘sequential’.

scale_referencebool, optional

If True and algorithm is ‘sequential’, the reference wavelength will be scaled to the data’s phase amplitude.

onthefly_corr_freqlist of float or None, optional

Frequency values to use to create a correction on-the-fly. If provided, any input emicorr_model is ignored and the algorithm is set to ‘sequential’.

use_n_cyclesint, optional

Only use N cycles to calculate the phase to reduce code running time, when algorithm is ‘sequential’.

fit_ints_separatelybool, optional

If True, fit each integration separately, when algorithm is ‘joint’.

Returns:
output_modelRampModel

Input science data model, corrected for EMI.