StepDemodulate

class sofia_redux.instruments.hawc.steps.stepdemodulate.StepDemodulate[source]

Bases: StepParent

Demodulate chops for chopped and nodded data.

This step subtracts low chops from high chops by weighting all chopped data with a sine wave, then summing. A phase correction is computed from the real and imaginary parts of the chop offset and is applied after the demodulation. Incomplete first and last chops are excluded. Data exceeding defined tolerances, and data for which the HWP was moving, are flagged for later removal in the Chop Mask column. Variances on the flux are also computed during demodulation, and propagated throughout all pipeline steps.

The input data expected is a DataFits containing one table with columns for R Array, T array, Chop Offset (arcsec), Nod Offset (arcsec), HWP Angle (degrees), Azimuth (degrees), Elevation (degrees), Azimuth Error (arcsec), Elevation Error (arcsec), and Array VPA (degrees). In addition, the Primary HDU header must contain the following keywords: NHWP, SMPLFREQ, CHPFREQ, NODDING, NODPATT.

This input is typically produced by the sofia_redux.instruments.hawc.steps.StepPrepare pipeline step, from raw HAWC data.

This step outputs one table containing the demodulated data. The columns are the same as for input data, with some additional columns. Each row in the table corresponds to the value for that demodulated chop cycle.

The additional columns are:

  • Samples: number of raw samples that make up a chop cycle

  • R array VAR: variance on the demodulated data for the R array

  • T array VAR: variance on the demodulated data for the T array

  • R array Imag: imaginary part of the demodulated data for the R array

  • T array Imag: imaginary part the demodulated data for the T array

  • R array Imag VAR: variance on the imaginary part of the demodulated data for the R array

  • T array Imag VAR: variance on the imaginary part of the demodulated data for the T array

  • Nod Index : integer-valued (0, 1, 2 for L, R, L)

  • HWP Index : integer-valued (0, 1, 2, 3)

  • Chop Mask : integer-valued, with bits for each flag type

The flag bits for the Chop Mask column are:

  • bit 0: incomplete chop

  • bit 1: check on azelstate

  • bit 2: HWP moving

  • bit 3: check on nodstate

  • bit 4: spare

  • bit 5: spare

  • bit 6: LOS rewind

  • bit 7: tracking errors too high

  • bit 8: CentroidExpMsec below threshold

  • bit 9: extra samples before and after tracking tolerance violation

The EXPTIME keyword in the primary header is updated to account only for the on-source time, rejecting samples that were excluded by the algorithm (when the HWP or telescope are moving). If chopping on-chip (header keyword CHPONFPA = True), then EXPTIME is multiplied by 2.

The Configuration HDU present in raw data will be propagated to the demodulated file, but will not be carried along in subsequent steps.

Depending on results from tracking tolerance, the keyword “TRCKSTAT” will be added to the header with one of the following values: ‘NONE - TrackErrAoi3 and 4 not found’, ‘GOOD - less than 1/3 of samples removed’, ‘BAD - more than 1/3 of samples removed’, or ‘NONE - tracking tolerance is deactivated’.

Methods Summary

avgdemodsin(choptag, phasetag, chopsamp, ...)

Average data with sine-wave demodulation.

make_chop_phase_tags(chopstate, chopsamp, ...)

Create the choptag and phasetag arrays from chopstate.

makedemod(nchop)

Construct arrays to hold demodulated data.

read_beam()

Read the beam size for the observed filter.

readdata()

Read raw data into memory.

run()

Run the data reduction algorithm.

setup()

Set parameters and metadata for the pipeline step.

Methods Documentation

avgdemodsin(choptag, phasetag, chopsamp, nchop, data_sigma)[source]

Average data with sine-wave demodulation.

Demodulated data is stored in self.pdemod.

Parameters:
choptagarray-like

Array values specifying which chop each sample belongs to.

phasetagarray-like

Array of values specifying sample number in current nod and hwp angle.

chopsamparray-like

Number of samples per chop cycle.

nchopint

Number of chops.

data_sigmafloat

Value for sigma-clipping of detector data, used in determining variance values for the demodulated flux.

make_chop_phase_tags(chopstate, chopsamp, hwpstate, nodstate)[source]

Create the choptag and phasetag arrays from chopstate.

This function is intended for sine-wave demodulation and the outputs are to be used by avgdemodsin.

Parameters:
chopstate: array-like

Array of -1, 0, +1 derived from chop signal.

chopsamp: int

Number of samples per chop.

hwpstate: array-like

Array of 0 (HWP moving), 1 (HWP stable) from HWP Angle.

nodstate: array-like

Array of -1, 0, +1 derived from Nod Offset signal.

Returns:
nchops: int

Number of chops.

choptag: array-like

Array of chop tags which number the chops.

phasetag: array-like

Array of integer phase, numbering samples within a chop.

makedemod(nchop)[source]

Construct arrays to hold demodulated data.

Arrays are stored in self.pdemod, a dictionary with keys as specified by self.column_names.

Parameters:
nchopint

Number of chop cycles.

read_beam()[source]

Read the beam size for the observed filter.

Returns:
beamfloat

The beam size.

wavebandstr

The filter band name.

readdata()[source]

Read raw data into memory.

Data is stored in the self.praw dictionary, with keys set by self.column_names.

run()[source]

Run the data reduction algorithm.

This step is run as a single-in single-out (SISO) step: self.datain should be a DataFits object, and output will also be a single DataFits, stored in self.dataout.

The process is:

  1. Read data and tag chop, nod, and HWP state for all samples.

  2. Convolve data with a box filter.

  3. Flag data for bad tracking states.

  4. Weight the chop data with a sine wave and average to demodulate the chops. Compute the variance across samples at the same time.

  5. Apply a phase correction to every pixel to correct for readout delays.

  6. Compute the magnitude of the demodulated signal (from real, imaginary, or absolute value).

  7. Store demodulated data in a new DataFits.

setup()[source]

Set parameters and metadata for the pipeline step.

Output files have PRODTYPE = ‘demodulate’, and are named with the step abbreviation ‘DMD’.

Parameters defined for this step are:

chop_tolfloat

Chop tolerance in arcsec. Used in determining high/low state.

nod_tolfloat

Nod tolerance in arcsec. Used in determining high/low state.

hwp_tolfloat

HWP tolerance in degrees. Used in determining angle and moving state.

az_tolfloat

Azimuth error tolerance in arcsec.

el_tolfloat

Elevation error tolerance in arcsec.

track_tolfloat or str

Tracking error tolerance in arcsec, as recorded by AOI 3 or AOI 4. Set negative to turn off flagging for tracking errors. Set to the string ‘beam’ to use a default beam-size value appropriate to the observed filter band. Set to ‘centroidexp’ to use the the CentroidExpMsec column to flag bad data instead of TrackErrAoi3 and TrackErrAoi4.

track_extralist of float

Extra samples removed (in seconds) before and after samples flagged by track_tol. Set to [0, 0] to disable.

chopphasebool

If not set, chop phases are not corrected.

checkhwpbool

If set, the NHWP keyword is not corrected from the number of angles actually found in the data, and a warning is issued. If not set, NHWP is corrected to the actual number of HWP angles.

phasefilestr or float

If a string, this should be set to a path to a file containing phase corrections for each pixel. If a float, then the value assigned is applied as the phase correction to every pixel. The value should be the phase delay in seconds.

phaseoffsetfloat

Phase offset to apply in addition to the per-pixel offsets assigned by the phasefile. This is specified in degrees, and may be determined from the plots produced by the StepDmdPlot pipeline step for CALMODE = INT_CAL files. Not applied if the phasefile parameter is not a file.

l0method{‘RE’, ‘IM’, ‘ABS’}

Method to normalize data: real component only, imaginary component only, or absolute value.

boxfilterfloat

Time constant for a box filter to convolve with the data before demodulation. Set to -1 to use 1/CHPFREQ. Set to 0 to disable.

chopavgbool

If set, R and T arrays before demodulation will be averaged over the chop period and stored in ‘R array AVG’ and ‘T array AVG’ columns in the output table.

tracksampcutfloat

If the fraction of all samples removed due to tracking is larger than this number, then tracking status (TRCKSTAT) is set to BAD.

data_sigmafloat

Value for sigma-clipping of detector data, used in determining variance values for the demodulated flux.