OverscanCorrectionTask¶
- class lsst.ip.isr.OverscanCorrectionTask(statControl=None, **kwargs)¶
Bases:
Task
Correction task for overscan.
This class contains a number of utilities that are easier to understand and use when they are not embedded in nested if/else loops.
- Parameters:
- statControl
lsst.afw.math.StatisticsControl
, optional Statistics control object.
- statControl
Methods Summary
broadcastFitToImage
(overscanValue, imageArray)Broadcast 0 or 1 dimension fit to appropriate shape.
collapseArray
(maskedArray[, fillMasked])Collapse overscan array (and mask) to a 1-D vector of values.
collapseArrayMedian
(maskedArray)Collapse overscan array (and mask) to a 1-D vector of using the correct integer median of row-values.
correctOverscan
(exposure, amp, imageBBox, ...)Trim the exposure, fit the overscan, subtract the fit, and calculate statistics.
debugView
(image, model[, amp, isTransposed])Debug display for the final overscan solution.
Empty (clear) the metadata for this Task and all sub-Tasks.
fillMaskedPixels
(overscanVector)Fill masked/NaN pixels in the overscan.
fitOverscan
(overscanImage[, isTransposed])Get metadata for all tasks.
Get the task name as a hierarchical name including parent task names.
getImageArray
(image)Extract the numpy array from the input image.
getName
()Get the name of the task.
Get a dictionary of all tasks as a shallow copy.
integerConvert
(image)Return an integer version of the input image.
makeField
(doc)Make a
lsst.pex.config.ConfigurableField
for this task.makeSubtask
(name, **keyArgs)Create a subtask as a new instance as the
name
attribute of this task.maskExtrapolated
(collapsed)Create mask if edges are extrapolated.
maskOutliers
(imageArray)Mask outliers in a row of overscan data from a robust sigma clipping procedure.
maskParallelOverscan
(exposure, detector)Mask the union of high values on all amplifiers in the parallel overscan.
measureConstantOverscan
(image)Measure a constant overscan value.
measureVectorOverscan
(image[, isTransposed])Calculate the 1-d vector overscan from the input overscan image.
run
(exposure, amp[, isTransposed])Measure and remove an overscan from an amplifier image.
splineEval
(indices, interp)Wrapper function to match spline evaluation API to polynomial fit API.
splineFit
(indices, collapsed, numBins)Wrapper function to match spline fit API to polynomial fit API.
timer
(name[, logLevel])Context manager to log performance data for an arbitrary block of code.
trimOverscan
(exposure, amp, bbox, ...[, ...])Trim overscan region to remove edges.
Methods Documentation
- broadcastFitToImage(overscanValue, imageArray, transpose=False)¶
Broadcast 0 or 1 dimension fit to appropriate shape.
- Parameters:
- overscanValue
numpy.ndarray
, (Nrows, ) or scalar Overscan fit to broadcast.
- imageArray
numpy.ndarray
, (Nrows, Ncols) Image array that we want to match.
- transpose
bool
, optional Switch order to broadcast along the other axis.
- overscanValue
- Returns:
- overscanModel
numpy.ndarray
, (Nrows, Ncols) or scalar Expanded overscan fit.
- overscanModel
- Raises:
- RuntimeError
Raised if no axis has the appropriate dimension.
- collapseArray(maskedArray, fillMasked=True)¶
Collapse overscan array (and mask) to a 1-D vector of values.
- Parameters:
- maskedArray
numpy.ma.masked_array
Masked array of input overscan data.
- fillMasked
bool
, optional If true, fill any pixels that are masked with a median of neighbors.
- maskedArray
- Returns:
- collapsed
numpy.ma.masked_array
Single dimensional overscan data, combined with the mean.
- collapsed
- collapseArrayMedian(maskedArray)¶
Collapse overscan array (and mask) to a 1-D vector of using the correct integer median of row-values.
- Parameters:
- maskedArray
numpy.ma.masked_array
Masked array of input overscan data.
- maskedArray
- Returns:
- collapsed
numpy.ma.masked_array
Single dimensional overscan data, combined with the afwMath median.
- collapsed
- correctOverscan(exposure, amp, imageBBox, overscanBBox, isTransposed=True)¶
Trim the exposure, fit the overscan, subtract the fit, and calculate statistics.
- Parameters:
- exposure
lsst.afw.image.Exposure
Exposure containing the data.
- amp
lsst.afw.cameraGeom.Amplifier
The amplifier that is to be corrected.
- imageBBox: `lsst.geom.Box2I`
Bounding box of the image data that will have the overscan subtracted. If parallel overscan will be performed, that area is added to the image bounding box during serial overscan correction.
- overscanBBox: `lsst.geom.Box2I`
Bounding box for the overscan data.
- isTransposed: `bool`
If true, then the data will be transposed before fitting the overscan.
- exposure
- Returns:
- results
lsst.pipe.base.Struct
ampOverscanModel
Overscan model broadcast to the full image size. (
lsst.afw.image.Exposure
)overscanOverscanModel
Overscan model broadcast to the full overscan image size. (
lsst.afw.image.Exposure
)overscanImage
Overscan image with the overscan fit subtracted. (
lsst.afw.image.Exposure
)overscanValue
Overscan model. (
float
ornp.array
)overscanMean
Mean value of the overscan fit. (
float
)overscanMedian
Median value of the overscan fit. (
float
)overscanSigma
Standard deviation of the overscan fit. (
float
)overscanMeanResidual
Mean value of the overscan region after overscan subtraction. (
float
)overscanMedianResidual
Median value of the overscan region after overscan subtraction. (
float
)overscanSigmaResidual
Standard deviation of the overscan region after overscan subtraction. (
float
)
- results
- debugView(image, model, amp=None, isTransposed=True)¶
Debug display for the final overscan solution.
- Parameters:
- image
lsst.afw.image.Image
Input image the overscan solution was determined from.
- model
numpy.ndarray
orfloat
Overscan model determined for the image.
- amp
lsst.afw.cameraGeom.Amplifier
, optional Amplifier to extract diagnostic information.
- isTransposed
bool
, optional Does the data need to be transposed before display?
- image
- fillMaskedPixels(overscanVector)¶
Fill masked/NaN pixels in the overscan.
- Parameters:
- overscanVector
np.array
ornp.ma.masked_array
Overscan vector to fill.
- overscanVector
- Returns:
- overscanVector
np.ma.masked_array
Filled vector.
- overscanVector
Notes
Each maskSlice is a section of overscan with contiguous masks. Ideally this adds 5 pixels from the left and right of that mask slice, and takes the median of those values to fill the slice. If this isn’t possible, the median of all non-masked values is used. The mask is removed for the pixels filled.
- fitOverscan(overscanImage, isTransposed=False)¶
- getFullMetadata() TaskMetadata ¶
Get metadata for all tasks.
- Returns:
- metadata
TaskMetadata
The keys are the full task name. Values are metadata for the top-level task and all subtasks, sub-subtasks, etc.
- metadata
Notes
The returned metadata includes timing information (if
@timer.timeMethod
is used) and any metadata set by the task. The name of each item consists of the full task name with.
replaced by:
, followed by.
and the name of the item, e.g.:topLevelTaskName:subtaskName:subsubtaskName.itemName
using
:
in the full task name disambiguates the rare situation that a task has a subtask and a metadata item with the same name.
- getFullName() str ¶
Get the task name as a hierarchical name including parent task names.
- Returns:
- fullName
str
The full name consists of the name of the parent task and each subtask separated by periods. For example:
The full name of top-level task “top” is simply “top”.
The full name of subtask “sub” of top-level task “top” is “top.sub”.
The full name of subtask “sub2” of subtask “sub” of top-level task “top” is “top.sub.sub2”.
- fullName
- getImageArray(image)¶
Extract the numpy array from the input image.
- Parameters:
- image
lsst.afw.image.Image
orlsst.afw.image.MaskedImage
Image data to pull array from.
- calcImage
numpy.ndarray
Image data array for numpy operating.
- image
- getTaskDict() Dict[str, ReferenceType[Task]] ¶
Get a dictionary of all tasks as a shallow copy.
- Returns:
- taskDict
dict
Dictionary containing full task name: task object for the top-level task and all subtasks, sub-subtasks, etc.
- taskDict
- static integerConvert(image)¶
Return an integer version of the input image.
- Parameters:
- image
numpy.ndarray
,lsst.afw.image.Image
orMaskedImage
Image to convert to integers.
- image
- Returns:
- outI
numpy.ndarray
,lsst.afw.image.Image
orMaskedImage
The integer converted image.
- outI
- Raises:
- RuntimeError
Raised if the input image could not be converted.
- classmethod makeField(doc: str) ConfigurableField ¶
Make a
lsst.pex.config.ConfigurableField
for this task.- Parameters:
- doc
str
Help text for the field.
- doc
- Returns:
- configurableField
lsst.pex.config.ConfigurableField
A
ConfigurableField
for this task.
- configurableField
Examples
Provides a convenient way to specify this task is a subtask of another task.
Here is an example of use:
class OtherTaskConfig(lsst.pex.config.Config): aSubtask = ATaskClass.makeField("brief description of task")
- makeSubtask(name: str, **keyArgs: Any) None ¶
Create a subtask as a new instance as the
name
attribute of this task.- Parameters:
- name
str
Brief name of the subtask.
- keyArgs
Extra keyword arguments used to construct the task. The following arguments are automatically provided and cannot be overridden:
“config”.
“parentTask”.
- name
Notes
The subtask must be defined by
Task.config.name
, an instance ofConfigurableField
orRegistryField
.
- static maskExtrapolated(collapsed)¶
Create mask if edges are extrapolated.
- Parameters:
- collapsed
numpy.ma.masked_array
Masked array to check the edges of.
- collapsed
- Returns:
- maskArray
numpy.ndarray
Boolean numpy array of pixels to mask.
- maskArray
- maskOutliers(imageArray)¶
Mask outliers in a row of overscan data from a robust sigma clipping procedure.
- Parameters:
- imageArray
numpy.ndarray
Image to filter along numpy axis=1.
- imageArray
- Returns:
- maskedArray
numpy.ma.masked_array
Masked image marking outliers.
- maskedArray
- maskParallelOverscan(exposure, detector)¶
Mask the union of high values on all amplifiers in the parallel overscan.
This operates on the image in-place.
- Parameters:
- exposure
lsst.afw.image.Exposure
An untrimmed raw exposure.
- detector
lsst.afw.cameraGeom.Detector
The detetor to use for amplifier geometry.
- exposure
- measureConstantOverscan(image)¶
Measure a constant overscan value.
- Parameters:
- image
lsst.afw.image.Image
orlsst.afw.image.MaskedImage
Image data to measure the overscan from.
- image
- Returns:
- results
lsst.pipe.base.Struct
Overscan result with entries: -
overscanValue
: Overscan value to subtract (float
) -isTransposed
: Orientation of the overscan (bool
)
- results
- measureVectorOverscan(image, isTransposed=False)¶
Calculate the 1-d vector overscan from the input overscan image.
- Parameters:
- image
lsst.afw.image.MaskedImage
Image containing the overscan data.
- isTransposed
bool
If true, the image has been transposed.
- image
- Returns:
- results
lsst.pipe.base.Struct
Overscan result with entries:
overscanValue
Overscan value to subtract (
float
)maskArray
List of rows that should be masked as
SUSPECT
when the overscan solution is applied. (list
[bool
])isTransposed
Indicates if the overscan data was transposed during calcuation, noting along which axis the overscan should be subtracted. (
bool
)
- results
- run(exposure, amp, isTransposed=False)¶
Measure and remove an overscan from an amplifier image.
- Parameters:
- exposure
lsst.afw.image.Exposure
Image data that will have the overscan corrections applied.
- amp
lsst.afw.cameraGeom.Amplifier
Amplifier to use for debugging purposes.
- isTransposed
bool
, optional Is the image transposed, such that serial and parallel overscan regions are reversed? Default is False.
- exposure
- Returns:
- overscanResults
lsst.pipe.base.Struct
Result struct with components:
imageFit
Value or fit subtracted from the amplifier image data (scalar or
lsst.afw.image.Image
).overscanFit
Value or fit subtracted from the serial overscan image data (scalar or
lsst.afw.image.Image
).overscanImage
Image of the serial overscan region with the serial overscan correction applied (
lsst.afw.image.Image
). This quantity is used to estimate the amplifier read noise empirically.parallelOverscanFit
Value or fit subtracted from the parallel overscan image data (scalar,
lsst.afw.image.Image
, or None).parallelOverscanImage
Image of the parallel overscan region with the parallel overscan correction applied (
lsst.afw.image.Image
or None).
- overscanResults
- Raises:
- RuntimeError
Raised if an invalid overscan type is set.
- static splineEval(indices, interp)¶
Wrapper function to match spline evaluation API to polynomial fit API.
- Parameters:
- indices
numpy.ndarray
Locations to evaluate the spline.
- interp
lsst.afw.math.interpolate
Interpolation object to use.
- indices
- Returns:
- values
numpy.ndarray
Evaluated spline values at each index.
- values
- splineFit(indices, collapsed, numBins)¶
Wrapper function to match spline fit API to polynomial fit API.
- Parameters:
- indices
numpy.ndarray
Locations to evaluate the spline.
- collapsed
numpy.ndarray
Collapsed overscan values corresponding to the spline evaluation points.
- numBins
int
Number of bins to use in constructing the spline.
- indices
- Returns:
- interp
lsst.afw.math.Interpolate
Interpolation object for later evaluation.
- interp
- timer(name: str, logLevel: int = 10) Iterator[None] ¶
Context manager to log performance data for an arbitrary block of code.
- Parameters:
See also
timer.logInfo
Examples
Creating a timer context:
with self.timer("someCodeToTime"): pass # code to time
- trimOverscan(exposure, amp, bbox, skipLeading, skipTrailing, transpose=False)¶
Trim overscan region to remove edges.
- Parameters:
- exposure
lsst.afw.image.Exposure
Exposure containing data.
- amp
lsst.afw.cameraGeom.Amplifier
Amplifier containing geometry information.
- bbox
lsst.geom.Box2I
Bounding box of the overscan region.
- skipLeading
int
Number of leading (towards data region) rows/columns to skip.
- skipTrailing
int
Number of trailing (away from data region) rows/columns to skip.
- transpose
bool
, optional Operate on the transposed array.
- exposure
- Returns:
- overscanArray
numpy.array
, (N, M) Data array to fit.
- overscanMask
numpy.array
, (N, M) Data mask.
- overscanArray