StepFocus

class sofia_redux.instruments.hawc.steps.stepfocus.StepFocus[source]

Bases: StepMOParent

Calculate an optimal focus value from short calibration scans.

This step fits and reports the best focus offset from a set of image with varying focus values.

Input for this step is a set calibrated scan maps. This step is typically run after sofia_redux.instruments.hawc.steps.StepStdPhotCal. The output from this step is identical to the input. It is not typically saved. As a side effect, this step produces several PNG images of focus plots, written to the same directory and basename as the input file.

Methods Summary

fitgaussian(data, nanpix, medianaverage)

Fit a Gaussian function to an image.

focusplot(focus, values, difftotfoc, label, ...)

Find and plot the best fit focus value.

gaussian(height, center_x, center_y, ...)

Return a Gaussian function with the given parameters.

moments(data)

Compute Gaussian parameters from moments.

run()

Run the data reduction algorithm.

setup()

Set parameters and metadata for the pipeline step.

Methods Documentation

fitgaussian(data, nanpix, medianaverage)[source]

Fit a Gaussian function to an image.

Parameters:
dataarray-like

The image to fit.

nanpixarray-like

A mask or index array indicating the positions of NaN pixels.

medianaveragebool

If not set, NaN pixels will be replaced with model values.

Returns:
height, x, y, width_x, width_ytuple of float

Parameters for a Gaussian fit to the data.

focusplot(focus, values, difftotfoc, label, lbl, sign, units='')[source]

Find and plot the best fit focus value.

The best focus value is at either the maximum or minimum of the values, as fit by a 2nd order polynomial. Plots showing the fit and best value are written to disk.

Parameters:
focuslist of float

Focus values (independent variable).

valueslist of float

Fit values (dependent variable).

difftotfocfloat

Mean difference from the total focus offset.

labelstr

Long label for the plot.

lblstr

Short label for the plot.

sign{-1, 1}

If -1, best fit is at a maximum. If 1, best fit is at a minimum.

unitsstr, optional

Units for the values.

gaussian(height, center_x, center_y, width_x, width_y, bgoffset)[source]

Return a Gaussian function with the given parameters.

Parameters:
heightfloat

Gaussian amplitude.

center_xfloat

Center x pixel.

center_yfloat

Center y pixel.

width_xfloat

Gaussian width, x-direction.

width_yfloat

Gaussian width, y-direction.

bgoffsetfloat

Background level.

Returns:
function

The Gaussian function. Arguments are x, y.

moments(data)[source]

Compute Gaussian parameters from moments.

Parameters:
dataarray-like

The image to fit.

Returns
——-
tuple of float

Elements are the Gaussian parameters for the 2D distribution: height, x, y, width_x, width_y, bgoffset.

run()[source]

Run the data reduction algorithm.

Because this step is multi-in, multi-out (MIMO), self.datain must be a list of DataFits objects. The output is also a list of DataFits objects, stored in self.dataout.

The process is:

  1. Read in each file, extract an image stamp, and fit a Gaussian to it.

  2. From the fit Gaussian parameters for all files, calculate the best focus value from: the minimum FWHM (x, y, and total), and the maximum Gaussian height.

setup()[source]

Set parameters and metadata for the pipeline step.

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

Parameters defined for this step are:

widowisgoodbool

Include widow pixels in the analysis if set.

medianaveragebool

If set, replace missing pixels with a local median value.

boxaverageint

Size of the box used in medianaverage.

autocropbool

If set, the image will be automatcally be cropped to center the target.

cropimagebool

If set, the image will be cropped, using ‘xyboxcent’ and ‘boxsizecrop’ parameters; ‘autocrop’ overrides this option if set.

xyboxcentlist

Central [x, y] pixel to crop around, if cropimage is set; ‘autocrop’ overrides this option if set.

boxsizecropint

Box size to crop to, if cropimage is set; ‘autocrop’ overrides this option if set.

primaryimgstr

Image extension name to use for the fit. If blank, the first image extension is used.