Ref. Pixel Correction

Summary

NRC_refs(data, header[, DMS, altcol, do_all])

Reference pixel correction object

reffix_hxrg(cube[, nchans, in_place, fixcol])

Reference pixel correction function

reffix_amps(cube[, nchans, in_place, …])

Correct amplifier offsets

ref_filter(cube[, nchans, in_place, …])

Optimal Smoothing

calc_avg_amps(refs_all, data_shape[, …])

Calculate amplifier averages

calc_avg_cols([refs_left, refs_right, avg_type])

Calculate average of column references

calc_col_smooth(refvals, data_shape[, …])

Perform optimal smoothing of side ref pix

smooth_fft(data, delt[, first_deriv, …])

Optimal smoothing algorithm

Class Documentation

class pynrc.reduce.ref_pixels.NRC_refs(data, header, DMS=False, altcol=True, do_all=False, **kwargs)[source]

Bases: object

Reference pixel correction object

Object class for reference pixel correction of NIRCam data (single integration). Specify the data cube, header, and whether or not the header is in DMS format.

General usage of functions:

  1. Create instance: ref = NRC_refs(data, header)

  2. Determine reference offset values: ref.calc_avg_amps(). Stored at ref.refs_amps_avg.

  3. Fix amplifier offsets: ref.correct_amp_refs(). Removes offsets that are stored at ref.refs_amps_avg.

  4. Determine average of column references tracking 1/f noise: ref.calc_avg_cols(). Reference values offset for a mean value of 0. Averages are stored at ref.refs_side_avg.

  5. Optimal smoothing of side reference values: ref.calc_col_smooth(). Stores smoothed version at ref.refs_side_smth.

  6. Remove approximation of 1/f noise: ref.correct_col_refs().

Parameters
  • data (ndarray) – Input datacube. Can be two or three dimensions (nz,ny,nx).

  • header (obj) – NIRCam Header associated with data.

  • DMS (bool) – Is the header in DMS format?

  • altcol (bool) – Calculate separate reference values for even/odd columns? Default=True.

  • do_all (bool) – Perform the default pixel correction procedures.

Attributes Summary

multiaccum

A multiaccum object

multiaccum_times

Exposure timings in dictionary

refs_bot

Return raw bottom reference values

refs_top

Return raw top reference values

refs_right

Return raw right reference values

refs_left

Return raw left reference values

Methods Summary

calc_avg_amps([top_ref, bot_ref])

Calculate amplifier averages

calc_avg_cols([left_ref, right_ref, avg_type])

Calculate average of column references

calc_col_smooth([perint, edge_wrap, savgol])

Optimal smoothing of side reference pixels

correct_amp_refs([supermean])

Correct amplifier offsets

correct_col_refs()

Remove 1/f noise from data

Methods Documentation

calc_avg_amps(top_ref=True, bot_ref=True)[source]

Calculate amplifier averages

Save the average reference value for each amplifier in each frame. Each array has a size of (namp, ngroup). Average values are saved at self.refs_amps_avg.

Parameters
  • top_ref (bool) – Include top reference rows when correcting channel offsets.

  • bot_ref (bool) – Include bottom reference rows when correcting channel offsets.

calc_avg_cols(left_ref=True, right_ref=True, avg_type='frame')[source]

Calculate average of column references

Create a copy of the left and right reference pixels, removing the average value of the reference pixels on an int, frame, or pixel basis. Do this after correcting the amplifier offsets with correct_amp_refs(). Averages are stored in self.refs_side_avg.

Parameters
  • left_ref (bool) – Include left reference cols when correcting 1/f noise.

  • right_ref (bool) – Include right reference cols when correcting 1/f noise.

  • avg_type (str) – Type of ref col averaging to perform. Allowed values are ‘pixel’, ‘frame’, or ‘int’.

calc_col_smooth(perint=False, edge_wrap=False, savgol=False, **kwargs)[source]

Optimal smoothing of side reference pixels

Geneated smoothed version of column reference values. Uses calc_avg_cols() to determine approx 1/f noise in data and store in self.refs_side_smth.

Parameters
  • perint (bool) – Smooth side reference pixel per int, otherwise per frame.

  • edge_wrap (bool) – Add a partial frames to the beginning and end of each averaged time series pixels in order to get rid of edge effects.

correct_amp_refs(supermean=False)[source]

Correct amplifier offsets

Use values in self.refs_amps_avg to correct amplifier offsets.

Parameters

supermean (bool) – Add back the overall mean of the reference pixels.

correct_col_refs()[source]

Remove 1/f noise from data

Correct 1/f noise using the approximation stored in self.refs_side_smth.


Functions Documentation

pynrc.reduce.ref_pixels.reffix_hxrg(cube, nchans=4, in_place=True, fixcol=False, **kwargs)[source]

Reference pixel correction function

This function performs a reference pixel correction on HAWAII-[1,2,4]RG detector data read out using N outputs. Top and bottom reference pixels are used first to remove channel offsets.

Parameters
  • cube (ndarray) – Input datacube. Can be two or three dimensions (nz,ny,nx).

  • in_place (bool) – Perform calculations in place. Input array is overwritten.

  • nchans (int) – Number of output amplifier channels in the detector. Default=4.

  • fixcol (bool) – Perform reference column corrections?

Keyword Arguments
  • altcol (bool) – Calculate separate reference values for even/odd columns.

  • supermean (bool) – Add back the overall mean of the reference pixels.

  • top_ref (bool) – Include top reference rows when correcting channel offsets.

  • bot_ref (bool) – Include bottom reference rows when correcting channel offsets.

  • ntop (int) – Specify the number of top reference rows.

  • nbot (int) – Specify the number of bottom reference rows.

  • left_ref (bool) – Include left reference cols when correcting 1/f noise.

  • right_ref (bool) – Include right reference cols when correcting 1/f noise.

  • nleft (int) – Specify the number of left reference columns.

  • nright (int) – Specify the number of right reference columns.

  • perint (bool) – Smooth side reference pixel per integration, otherwise do frame-by-frame.

  • avg_type (str) –

    Type of side column averaging to perform to determine ref pixel drift. Allowed values are ‘pixel’, ‘frame’, or ‘int’:

    • ’int’ : Subtract the avg value of all side ref pixels in ramp.

    • ’frame’ : For each frame, get avg of side ref pixels and subtract framewise.

    • ’pixel’ : For each ref pixel, subtract its avg value from all frames.

  • savgol (bool) – Using Savitsky-Golay filter method rather than FFT.

  • winsize (int) – Size of the window filter.

  • order (int) – Order of the polynomial used to fit the samples.

pynrc.reduce.ref_pixels.reffix_amps(cube, nchans=4, in_place=True, altcol=True, supermean=False, top_ref=True, bot_ref=True, ntop=4, nbot=4, **kwargs)[source]

Correct amplifier offsets

Matches all amplifier outputs of the detector to a common level.

This routine subtracts the average of the top and bottom reference rows for each amplifier and frame individually.

By default, reference pixel corrections are performed in place since it’s faster and consumes less memory.

Parameters
  • cube (ndarray) – Input datacube. Can be two or three dimensions (nz,ny,nx).

  • nchans (int) – Number of output amplifier channels in the detector. Default=4.

  • altcol (bool) – Calculate separate reference values for even/odd columns.

  • supermean (bool) – Add back the overall mean of the reference pixels.

  • in_place (bool) – Perform calculations in place. Input array is overwritten.

  • top_ref (bool) – Include top reference rows when correcting channel offsets.

  • bot_ref (bool) – Include bottom reference rows when correcting channel offsets.

  • ntop (int) – Specify the number of top reference rows.

  • nbot (int) – Specify the number of bottom reference rows.

pynrc.reduce.ref_pixels.ref_filter(cube, nchans=4, in_place=True, avg_type='frame', perint=False, edge_wrap=False, left_ref=True, right_ref=True, nleft=4, nright=4, **kwargs)[source]

Optimal Smoothing

Performs an optimal filtering of the vertical reference pixel to reduce 1/f noise (horizontal stripes).

Adapted from M. Robberto IDL code: http://www.stsci.edu/~robberto/Main/Software/IDL4pipeline/

Parameters
  • cube (ndarray) – Input datacube. Can be two or three dimensions (nz,ny,nx).

  • nchans (int) – Number of output amplifier channels in the detector. Default=4.

  • in_place (bool) – Perform calculations in place. Input array is overwritten.

  • perint (bool) – Smooth side reference pixel per integration, otherwise do frame-by-frame.

  • avg_type (str) – Type of ref col averaging to perform. Allowed values are ‘pixel’, ‘frame’, or ‘int’.

  • left_ref (bool) – Include left reference cols when correcting 1/f noise.

  • right_ref (bool) – Include right reference cols when correcting 1/f noise.

  • nleft (int) – Specify the number of left reference columns.

  • nright (int) – Specify the number of right reference columns.

Keyword Arguments
  • savgol (bool) – Using Savitsky-Golay filter method rather than FFT.

  • winsize (int) – Size of the window filter.

  • order (int) – Order of the polynomial used to fit the samples.

pynrc.reduce.ref_pixels.calc_avg_amps(refs_all, data_shape, nchans=4, altcol=True)[source]

Calculate amplifier averages

Save the average reference value for each amplifier in each frame. Assume by default that alternating columns are offset from each other, so we save two arrays: self.refs_amps_avg1 and self.refs_amps_avg2. Each array has a size of (namp, ngroup).

Parameters
  • refs_all (ndarray) – The top and/or bottom references pixels order in a shape (nz, nref_rows, nx)

  • data_shape (tuple) – Shape of the data array: (nz, ny, nx).

  • nchans (int) – Number of amplifier output channels.

  • altcol (bool) – Calculate separate reference values for even/odd columns? Default=True.

pynrc.reduce.ref_pixels.calc_avg_cols(refs_left=None, refs_right=None, avg_type='frame')[source]

Calculate average of column references

Determine the average values for the column references, which is subsequently used to estimate the 1/f noise contribution.

Parameters
  • refs_left (ndarray) – Left reference columns.

  • refs_right (ndarray) – Right reference columns.

  • avg_type (str) – Type of ref column averaging to perform to determine ref pixel variation. Allowed values are ‘pixel’, ‘frame’, or ‘int’. ‘pixel’ : For each ref pixel, subtract its avg value from all frames. ‘frame’ : For each frame, get avg ref pixel values and subtract framewise. ‘int’ : Calculate avg of all ref pixels within the ramp and subtract.

pynrc.reduce.ref_pixels.calc_col_smooth(refvals, data_shape, perint=False, edge_wrap=False, delt=0.000524, savgol=False, winsize=31, order=3, **kwargs)[source]

Perform optimal smoothing of side ref pix

Geneated smoothed version of column reference values. Smooths values from calc_avg_cols() via FFT.

Parameters
  • refvals (ndarray) – Averaged column reference pixels

  • data_shape (tuple) – Shape of original data (nz,ny,nx)

Keyword Arguments
  • perint (bool) – Smooth side reference pixel per int, otherwise per frame.

  • edge_wrap (bool) – Add a partial frames to the beginning and end of each averaged time series pixels in order to get rid of edge effects.

  • delt (float) – Time between reference pixel samples.

  • savgol (bool) – Using Savitsky-Golay filter method rather than FFT.

  • winsize (int) – Size of the window filter.

  • order (int) – Order of the polynomial used to fit the samples.

pynrc.reduce.ref_pixels.smooth_fft(data, delt, first_deriv=False, second_deriv=False)[source]

Optimal smoothing algorithm

Smoothing algorithm to perform optimal filtering of the vertical reference pixel to reduce 1/f noise (horizontal stripes), based on the Kosarev & Pantos algorithm. This assumes that the data to be filtered/smoothed has been sampled evenly.

If first_deriv is set, then returns two results if second_deriv is set, then returns three results.

Adapted from M. Robberto IDL code: http://www.stsci.edu/~robberto/Main/Software/IDL4pipeline/

Parameters
  • data (ndarray) – Signal to be filtered.

  • delt (float) – Delta time between samples.

  • first_deriv (bool) – Return the first derivative.

  • second_deriv (bool) – Return the second derivative (along with first).