lsst.meas.algorithms g1581cd22ba+880e5d07f7
Loading...
Searching...
No Matches
lsst.meas.algorithms.maskStreaks.LineProfile Class Reference

Public Member Functions

 __init__ (self, data, weights, line=None, detectionMask=None)
 
 getLineXY (self, line)
 
 setLineMask (self, line, maxStreakWidth, nSigmaMask, logger=None, detectionMask=None)
 
 makeProfile (self, line, fitFlux=True)
 
 fit (self, dChi2Tol=0.1, maxIter=100, log=None)
 

Public Attributes

 data = data
 
 weights = weights
 
tuple mask = (weights != 0)
 
bool modelFailure = False
 
tuple lineMask = self.mask & m
 

Protected Member Functions

 _makeMaskedProfile (self, line, fitFlux=True)
 
 _lineChi2 (self, line, grad=True)
 
 _rejectOutliers (self, line)
 

Protected Attributes

 _ymax
 
 _xmax = data.shape
 
 _dtype = data.dtype
 
tuple _rhoMax = ((0.5 * self._ymax)**2 + (0.5 * self._xmax)**2)**0.5
 
 _xmesh
 
 _ymesh = np.meshgrid(xrange, yrange)
 
 _initLine = line
 
 _maskData = self.data[self.lineMask]
 
 _maskWeights = self.weights[self.lineMask]
 
 _mxmesh = self._xmesh[self.lineMask]
 
 _mymesh = self._ymesh[self.lineMask]
 

Detailed Description

Construct and/or fit a model for a linear streak.

This assumes a simple model for a streak, in which the streak
follows a straight line in pixels space, with a Moffat-shaped profile. The
model is fit to data using a Newton-Raphson style minimization algorithm.
The initial guess for the line parameters is assumed to be fairly accurate,
so only a narrow band of pixels around the initial line estimate is used in
fitting the model, which provides a significant speed-up over using all the
data. The class can also be used just to construct a model for the data with
a line following the given coordinates.

Parameters
----------
data : `np.ndarray`
    2d array of data.
weights : `np.ndarray`
    2d array of weights.
line : `Line`, optional
    Guess for position of line. Data far from line guess is masked out.
    Defaults to None, in which case only data with `weights` = 0 is masked
    out.
detectionMask : `np.ndarray`, optional
        2-d boolean array where detected pixels are True.

Definition at line 112 of file maskStreaks.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.meas.algorithms.maskStreaks.LineProfile.__init__ ( self,
data,
weights,
line = None,
detectionMask = None )

Definition at line 138 of file maskStreaks.py.

Member Function Documentation

◆ _lineChi2()

lsst.meas.algorithms.maskStreaks.LineProfile._lineChi2 ( self,
line,
grad = True )
protected
Construct the chi2 between the data and the model.

Parameters
----------
line : `Line`
    `Line` parameters for which to build model and calculate chi2.
grad : `bool`, optional
    Whether or not to return the gradient and hessian.

Returns
-------
reducedChi : `float`
    Reduced chi2 of the model.
reducedDChi : `np.ndarray`
    Derivative of the chi2 with respect to rho, theta, invSigma.
reducedHessianChi : `np.ndarray`
    Hessian of the chi2 with respect to rho, theta, invSigma.

Definition at line 346 of file maskStreaks.py.

◆ _makeMaskedProfile()

lsst.meas.algorithms.maskStreaks.LineProfile._makeMaskedProfile ( self,
line,
fitFlux = True )
protected
Construct the line model in the masked region and calculate its
derivatives.

Parameters
----------
line : `Line`
    Parameters of line profile for which to make profile in the masked
    region.
fitFlux : `bool`
    Fit the amplitude of the line profile to the data.

Returns
-------
model : `np.ndarray`
    Model in the masked region.
dModel : `np.ndarray`
    Derivative of the model in the masked region.

Definition at line 268 of file maskStreaks.py.

◆ _rejectOutliers()

lsst.meas.algorithms.maskStreaks.LineProfile._rejectOutliers ( self,
line )
protected
Reject outlier pixels.

This calculates the chi2/dof in bins of pixels perpendicular to the
streak direction and removes outliers. This is done so that the profile
fitter ignores regions like the area around bright stars.

Parameters
----------
line : `Line`
    `Line` parameters for which to build model and calculate chi2.

Returns
-------
nOutliers : `int`
    Number of outlier pixels.

Definition at line 381 of file maskStreaks.py.

◆ fit()

lsst.meas.algorithms.maskStreaks.LineProfile.fit ( self,
dChi2Tol = 0.1,
maxIter = 100,
log = None )
Perform Newton-Raphson minimization to find line parameters.

This method takes advantage of having known derivative and Hessian of
the multivariate function to quickly and efficiently find the minimum.
This is more efficient than the scipy implementation of the Newton-
Raphson method, which doesn't take advantage of the Hessian matrix. The
method here also performs a line search in the direction of the steepest
derivative at each iteration, which reduces the number of iterations
needed.

Parameters
----------
dChi2Tol : `float`, optional
    Change in Chi2 tolerated for fit convergence.
maxIter : `int`, optional
    Maximum number of fit iterations allowed. The fit should converge in
    ~10 iterations, depending on the value of dChi2Tol, but this
    maximum provides a backup.
log : `lsst.utils.logging.LsstLogAdapter`, optional
    Logger to use for reporting more details for fitting failures.

Returns
-------
outline : `Line`
    Coordinates, inverse width, and chi2 of fit line.
fitFailure : `bool`
    Boolean where `False` corresponds to a successful  fit.

Definition at line 439 of file maskStreaks.py.

◆ getLineXY()

lsst.meas.algorithms.maskStreaks.LineProfile.getLineXY ( self,
line )
Return the pixel coordinates of the ends of the line.

Parameters
----------
line : `Line`
    Line for which to find the endpoints.

Returns
-------
boxIntersections : `np.ndarray`
    (x, y) coordinates of the start and endpoints of the line.

Definition at line 153 of file maskStreaks.py.

◆ makeProfile()

lsst.meas.algorithms.maskStreaks.LineProfile.makeProfile ( self,
line,
fitFlux = True )
Construct the line profile model.

Parameters
----------
line : `Line`
    Parameters of the line profile to model.
fitFlux : `bool`, optional
    Fit the amplitude of the line profile to the data.

Returns
-------
finalModel : `np.ndarray`
    Model for line profile.

Definition at line 326 of file maskStreaks.py.

◆ setLineMask()

lsst.meas.algorithms.maskStreaks.LineProfile.setLineMask ( self,
line,
maxStreakWidth,
nSigmaMask,
logger = None,
detectionMask = None )
Set mask around the image region near the line.

Parameters
----------
line : `Line`
    Parameters of line in the image.
maxStreakWidth : `float`
    Maximum width in pixels of streak mask.
nSigmaMask : `float`
    Factor by which to multiply the line's width to get the mask width.
logger : `lsst.utils.logging.LsstLogAdapter`, optional
    Logger to use for reporting when maxStreakWidth is reached.
detectionMask : `np.ndarray`, optional
    2-d boolean array where detected pixels are True.

Definition at line 197 of file maskStreaks.py.

Member Data Documentation

◆ _dtype

lsst.meas.algorithms.maskStreaks.LineProfile._dtype = data.dtype
protected

Definition at line 142 of file maskStreaks.py.

◆ _initLine

lsst.meas.algorithms.maskStreaks.LineProfile._initLine = line
protected

Definition at line 149 of file maskStreaks.py.

◆ _maskData

lsst.meas.algorithms.maskStreaks.LineProfile._maskData = self.data[self.lineMask]
protected

Definition at line 263 of file maskStreaks.py.

◆ _maskWeights

lsst.meas.algorithms.maskStreaks.LineProfile._maskWeights = self.weights[self.lineMask]
protected

Definition at line 264 of file maskStreaks.py.

◆ _mxmesh

lsst.meas.algorithms.maskStreaks.LineProfile._mxmesh = self._xmesh[self.lineMask]
protected

Definition at line 265 of file maskStreaks.py.

◆ _mymesh

lsst.meas.algorithms.maskStreaks.LineProfile._mymesh = self._ymesh[self.lineMask]
protected

Definition at line 266 of file maskStreaks.py.

◆ _rhoMax

lsst.meas.algorithms.maskStreaks.LineProfile._rhoMax = ((0.5 * self._ymax)**2 + (0.5 * self._xmax)**2)**0.5
protected

Definition at line 145 of file maskStreaks.py.

◆ _xmax

lsst.meas.algorithms.maskStreaks.LineProfile._xmax = data.shape
protected

Definition at line 141 of file maskStreaks.py.

◆ _xmesh

lsst.meas.algorithms.maskStreaks.LineProfile._xmesh
protected

Definition at line 146 of file maskStreaks.py.

◆ _ymax

lsst.meas.algorithms.maskStreaks.LineProfile._ymax
protected

Definition at line 141 of file maskStreaks.py.

◆ _ymesh

lsst.meas.algorithms.maskStreaks.LineProfile._ymesh = np.meshgrid(xrange, yrange)
protected

Definition at line 146 of file maskStreaks.py.

◆ data

lsst.meas.algorithms.maskStreaks.LineProfile.data = data

Definition at line 139 of file maskStreaks.py.

◆ lineMask

tuple lsst.meas.algorithms.maskStreaks.LineProfile.lineMask = self.mask & m

Definition at line 225 of file maskStreaks.py.

◆ mask

tuple lsst.meas.algorithms.maskStreaks.LineProfile.mask = (weights != 0)

Definition at line 147 of file maskStreaks.py.

◆ modelFailure

bool lsst.meas.algorithms.maskStreaks.LineProfile.modelFailure = False

Definition at line 150 of file maskStreaks.py.

◆ weights

lsst.meas.algorithms.maskStreaks.LineProfile.weights = weights

Definition at line 140 of file maskStreaks.py.


The documentation for this class was generated from the following file: