LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
Namespaces | Classes | Typedefs | Functions
lsst::ip::diffim Namespace Reference

Namespaces

 detail
 
 diaCatalogSourceSelector
 
 diaSourceAnalysis
 
 diffimTools
 
 dipoleFitTask
 
 dipoleMeasurement
 
 getTemplate
 
 imageDecorrelation
 
 imagePsfMatch
 
 kernelCandidateQa
 
 makeKernelBasisList
 
 makeRatingVector
 
 modelPsfMatch
 
 psfMatch
 
 snapPsfMatch
 
 utils
 
 version
 

Classes

class  MinimizeDipoleChi2
 Class to minimize PsfDipoleFlux; this is the object that Minuit minimizes. More...
 
class  DipoleCentroidControl
 
class  DipoleFluxControl
 
class  PsfDipoleFluxControl
 C++ control object for PSF dipole fluxes. More...
 
class  DipoleCentroidAlgorithm
 Intermediate base class for algorithms that compute a centroid. More...
 
class  DipoleFluxAlgorithm
 Intermediate base class for algorithms that compute a flux. More...
 
class  NaiveDipoleFlux
 
class  NaiveDipoleCentroid
 Intermediate base class for algorithms that compute a centroid. More...
 
class  PsfDipoleFlux
 Implementation of Psf dipole flux. More...
 
class  FindSetBits
 Class to accumulate Mask bits. More...
 
class  ImageStatistics
 Class to calculate difference image statistics. More...
 
class  KernelCandidate
 Class stored in SpatialCells for spatial Kernel fitting. More...
 
class  KernelCandidateDetection
 Search through images for Footprints with no masked pixels. More...
 
class  KernelSolution
 
class  StaticKernelSolution
 
class  MaskedKernelSolution
 
class  RegularizedKernelSolution
 
class  SpatialKernelSolution
 

Typedefs

typedef float PixelT
 
typedef float InputT
 

Functions

lsst::afw::math::KernelList makeDeltaFunctionBasisList (int width, int height)
 Generate a basis set of delta function Kernels. More...
 
lsst::afw::math::KernelList makeAlardLuptonBasisList (int halfWidth, int nGauss, std::vector< double > const &sigGauss, std::vector< int > const &degGauss)
 Generate an Alard-Lupton basis set of Kernels. More...
 
std::shared_ptr< Eigen::MatrixXd > makeRegularizationMatrix (lsst::pex::policy::Policy policy)
 Build a regularization matrix for Delta function kernels. More...
 
std::shared_ptr< Eigen::MatrixXd > makeCentralDifferenceMatrix (int width, int height, int stencil, float borderPenalty, bool fitForBackground)
 Generate regularization matrix for delta function kernels. More...
 
std::shared_ptr< Eigen::MatrixXd > makeForwardDifferenceMatrix (int width, int height, std::vector< int > const &orders, float borderPenalty, bool fitForBackground)
 Generate regularization matrix for delta function kernels. More...
 
lsst::afw::math::KernelList renormalizeKernelList (lsst::afw::math::KernelList const &kernelListIn)
 Rescale an input set of kernels. More...
 
std::shared_ptr< Eigen::MatrixXd > makeFiniteDifferenceRegularizationDeprecated (unsigned int width, unsigned int height, unsigned int order, unsigned int boundary_style, unsigned int difference_style, bool printB)
 Generate regularization matrix for delta function kernels. More...
 
int const NEGCENTXPAR (0)
 
int const NEGCENTYPAR (1)
 
int const NEGFLUXPAR (2)
 
int const POSCENTXPAR (3)
 
int const POSCENTYPAR (4)
 
int const POSFLUXPAR (5)
 
template<typename PixelT >
Eigen::MatrixXd imageToEigenMatrix (lsst::afw::image::Image< PixelT > const &img)
 Turns Image into a 2-D Eigen Matrix. More...
 
Eigen::MatrixXi maskToEigenMatrix (lsst::afw::image::Mask< lsst::afw::image::MaskPixel > const &mask)
 
template<typename PixelT , typename BackgroundT >
afwImage::MaskedImage< PixelTconvolveAndSubtract (lsst::afw::image::MaskedImage< PixelT > const &templateImage, lsst::afw::image::MaskedImage< PixelT > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, BackgroundT background, bool invert)
 Implement fundamental difference imaging step of convolution and subtraction : D = I - (K*T + bg) where * denotes convolution. More...
 
template<typename PixelT , typename BackgroundT >
afwImage::MaskedImage< PixelTconvolveAndSubtract (lsst::afw::image::Image< PixelT > const &templateImage, lsst::afw::image::MaskedImage< PixelT > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, BackgroundT background, bool invert)
 Implement fundamental difference imaging step of convolution and subtraction : D = I - (K.x.T + bg) More...
 
template Eigen::MatrixXd imageToEigenMatrix (lsst::afw::image::Image< double > const &)
 
template
lsst::afw::image::MaskedImage
< float > 
convolveAndSubtract (lsst::afw::image::Image< float > const &templateImage, lsst::afw::image::MaskedImage< float > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, double background, bool invert)
 
template afwImage::MaskedImage
< float > 
convolveAndSubtract (lsst::afw::image::Image< float > const &templateImage, lsst::afw::image::MaskedImage< float > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, lsst::afw::math::Function2< double > const &backgroundFunction, bool invert)
 
template
lsst::afw::image::MaskedImage
< float > 
convolveAndSubtract (lsst::afw::image::MaskedImage< float > const &templateImage, lsst::afw::image::MaskedImage< float > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, double background, bool invert)
 
template afwImage::MaskedImage
< float > 
convolveAndSubtract (lsst::afw::image::MaskedImage< float > const &templateImage, lsst::afw::image::MaskedImage< float > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, lsst::afw::math::Function2< double > const &backgroundFunction, bool invert)
 
template
lsst::afw::image::MaskedImage
< double > 
convolveAndSubtract (lsst::afw::image::Image< double > const &templateImage, lsst::afw::image::MaskedImage< double > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, double background, bool invert)
 
template afwImage::MaskedImage
< double > 
convolveAndSubtract (lsst::afw::image::Image< double > const &templateImage, lsst::afw::image::MaskedImage< double > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, lsst::afw::math::Function2< double > const &backgroundFunction, bool invert)
 
template
lsst::afw::image::MaskedImage
< double > 
convolveAndSubtract (lsst::afw::image::MaskedImage< double > const &templateImage, lsst::afw::image::MaskedImage< double > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, double background, bool invert)
 
template afwImage::MaskedImage
< double > 
convolveAndSubtract (lsst::afw::image::MaskedImage< double > const &templateImage, lsst::afw::image::MaskedImage< double > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, lsst::afw::math::Function2< double > const &backgroundFunction, bool invert)
 
template<typename PixelT , typename BackgroundT >
lsst::afw::image::MaskedImage
< PixelT
convolveAndSubtract (lsst::afw::image::MaskedImage< PixelT > const &templateImage, lsst::afw::image::MaskedImage< PixelT > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, BackgroundT background, bool invert=true)
 Execute fundamental task of convolving template and subtracting it from science image. More...
 
template<typename PixelT , typename BackgroundT >
lsst::afw::image::MaskedImage
< PixelT
convolveAndSubtract (lsst::afw::image::Image< PixelT > const &templateImage, lsst::afw::image::MaskedImage< PixelT > const &scienceMaskedImage, lsst::afw::math::Kernel const &convolutionKernel, BackgroundT background, bool invert=true)
 Execute fundamental task of convolving template and subtracting it from science image. More...
 
template<typename PixelT >
std::shared_ptr
< KernelCandidate< PixelT > > 
makeKernelCandidate (float const xCenter, float const yCenter, std::shared_ptr< afw::image::MaskedImage< PixelT > > const &templateMaskedImage, std::shared_ptr< afw::image::MaskedImage< PixelT > > const &scienceMaskedImage, pex::policy::Policy const &policy)
 Return a KernelCandidate pointer of the right sort. More...
 
template<typename PixelT >
std::shared_ptr
< KernelCandidate< PixelT > > 
makeKernelCandidate (std::shared_ptr< afw::table::SourceRecord > const &source, std::shared_ptr< afw::image::MaskedImage< PixelT > > const &templateMaskedImage, std::shared_ptr< afw::image::MaskedImage< PixelT > > const &scienceMaskedImage, pex::policy::Policy const &policy)
 Return a KernelCandidate pointer of the right sort. More...
 

Typedef Documentation

typedef float lsst::ip::diffim::InputT

Definition at line 1622 of file KernelSolution.cc.

typedef float lsst::ip::diffim::PixelT

Definition at line 448 of file KernelCandidate.cc.

Function Documentation

template<typename PixelT , typename BackgroundT >
lsst::afw::image::MaskedImage<PixelT> lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::MaskedImage< PixelT > const &  templateImage,
lsst::afw::image::MaskedImage< PixelT > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
BackgroundT  background,
bool  invert 
)

Execute fundamental task of convolving template and subtracting it from science image.

Note
This version accepts a MaskedImage for the template
Parameters
templateImageMaskedImage to apply convolutionKernel to
scienceMaskedImageMaskedImage from which convolved templateImage is subtracted
convolutionKernelKernel to apply to templateImage
backgroundBackground scalar or function to subtract after convolution
invertInvert the output difference image

Execute fundamental task of convolving template and subtracting it from science image.

Note
If you convolve the science image, D = (K*I + bg) - T, set invert=False
The template is taken to be an MaskedImage; this takes c 1.6 times as long as using an Image.
Instantiated such that background can be a double or Function2D
Returns
Difference image
Parameters
templateImageImage T to convolve with Kernel
scienceMaskedImageImage I to subtract T from
convolutionKernelPSF-matching Kernel used
backgroundDifferential background
invertInvert the output difference image

Definition at line 118 of file ImageSubtract.cc.

124  {
125 
126  boost::timer t;
127  t.restart();
128 
129  afwImage::MaskedImage<PixelT> convolvedMaskedImage(templateImage.getDimensions());
131  convolutionControl.setDoNormalize(false);
132  afwMath::convolve(convolvedMaskedImage, templateImage,
133  convolutionKernel, convolutionControl);
134 
135  /* Add in background */
136  *(convolvedMaskedImage.getImage()) += background;
137 
138  /* Do actual subtraction */
139  convolvedMaskedImage -= scienceMaskedImage;
140 
141  /* Invert */
142  if (invert) {
143  convolvedMaskedImage *= -1.0;
144  }
145 
146  double time = t.elapsed();
147  LOGL_DEBUG("TRACE4.ip.diffim.convolveAndSubtract",
148  "Total compute time to convolve and subtract : %.2f s", time);
149 
150  return convolvedMaskedImage;
151 }
Parameters to control convolution.
Definition: ConvolveImage.h:57
geom::Extent2I getDimensions() const
Definition: MaskedImage.h:910
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:78
void convolve(OutImageT &convolvedImage, InImageT const &inImage, KernelT const &kernel, ConvolutionControl const &convolutionControl=ConvolutionControl())
Convolve an Image or MaskedImage with a Kernel, setting pixels of an existing output image...
template<typename PixelT , typename BackgroundT >
lsst::afw::image::MaskedImage<PixelT> lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::Image< PixelT > const &  templateImage,
lsst::afw::image::MaskedImage< PixelT > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
BackgroundT  background,
bool  invert 
)

Execute fundamental task of convolving template and subtracting it from science image.

Note
This version accepts an Image for the template, and is thus faster during convolution
Parameters
templateImageImage to apply convolutionKernel to
scienceMaskedImageMaskedImage from which convolved templateImage is subtracted
convolutionKernelKernel to apply to templateImage
backgroundBackground scalar or function to subtract after convolution
invertInvert the output difference image

Execute fundamental task of convolving template and subtracting it from science image.

Note
The template is taken to be an Image, not a MaskedImage; it therefore has neither variance nor bad pixels
If you convolve the science image, D = (K*I + bg) - T, set invert=False
Instantiated such that background can be a double or Function2D
Returns
Difference image
Parameters
templateImageImage T to convolve with Kernel
scienceMaskedImageImage I to subtract T from
convolutionKernelPSF-matching Kernel used
backgroundDifferential background
invertInvert the output difference image

Definition at line 169 of file ImageSubtract.cc.

175  {
176 
177  boost::timer t;
178  t.restart();
179 
180  afwImage::MaskedImage<PixelT> convolvedMaskedImage(templateImage.getDimensions());
182  convolutionControl.setDoNormalize(false);
183  afwMath::convolve(*convolvedMaskedImage.getImage(), templateImage,
184  convolutionKernel, convolutionControl);
185 
186  /* Add in background */
187  *(convolvedMaskedImage.getImage()) += background;
188 
189  /* Do actual subtraction */
190  *convolvedMaskedImage.getImage() -= *scienceMaskedImage.getImage();
191 
192  /* Invert */
193  if (invert) {
194  *convolvedMaskedImage.getImage() *= -1.0;
195  }
196  convolvedMaskedImage.getMask()->assign(*scienceMaskedImage.getMask());
197  convolvedMaskedImage.getVariance()->assign(*scienceMaskedImage.getVariance());
198 
199  double time = t.elapsed();
200  LOGL_DEBUG("TRACE4.ip.diffim.convolveAndSubtract",
201  "Total compute time to convolve and subtract : %.2f s", time);
202 
203  return convolvedMaskedImage;
204 }
Parameters to control convolution.
Definition: ConvolveImage.h:57
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:875
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:896
geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:299
MaskPtr getMask(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s mask.
Definition: MaskedImage.h:885
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:78
void convolve(OutImageT &convolvedImage, InImageT const &inImage, KernelT const &kernel, ConvolutionControl const &convolutionControl=ConvolutionControl())
Convolve an Image or MaskedImage with a Kernel, setting pixels of an existing output image...
template<typename PixelT , typename BackgroundT >
afwImage::MaskedImage<PixelT> lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::MaskedImage< PixelT > const &  templateImage,
lsst::afw::image::MaskedImage< PixelT > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
BackgroundT  background,
bool  invert 
)

Implement fundamental difference imaging step of convolution and subtraction : D = I - (K*T + bg) where * denotes convolution.

Execute fundamental task of convolving template and subtracting it from science image.

Note
If you convolve the science image, D = (K*I + bg) - T, set invert=False
The template is taken to be an MaskedImage; this takes c 1.6 times as long as using an Image.
Instantiated such that background can be a double or Function2D
Returns
Difference image
Parameters
templateImageImage T to convolve with Kernel
scienceMaskedImageImage I to subtract T from
convolutionKernelPSF-matching Kernel used
backgroundDifferential background
invertInvert the output difference image

Definition at line 118 of file ImageSubtract.cc.

124  {
125 
126  boost::timer t;
127  t.restart();
128 
129  afwImage::MaskedImage<PixelT> convolvedMaskedImage(templateImage.getDimensions());
131  convolutionControl.setDoNormalize(false);
132  afwMath::convolve(convolvedMaskedImage, templateImage,
133  convolutionKernel, convolutionControl);
134 
135  /* Add in background */
136  *(convolvedMaskedImage.getImage()) += background;
137 
138  /* Do actual subtraction */
139  convolvedMaskedImage -= scienceMaskedImage;
140 
141  /* Invert */
142  if (invert) {
143  convolvedMaskedImage *= -1.0;
144  }
145 
146  double time = t.elapsed();
147  LOGL_DEBUG("TRACE4.ip.diffim.convolveAndSubtract",
148  "Total compute time to convolve and subtract : %.2f s", time);
149 
150  return convolvedMaskedImage;
151 }
Parameters to control convolution.
Definition: ConvolveImage.h:57
geom::Extent2I getDimensions() const
Definition: MaskedImage.h:910
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:78
void convolve(OutImageT &convolvedImage, InImageT const &inImage, KernelT const &kernel, ConvolutionControl const &convolutionControl=ConvolutionControl())
Convolve an Image or MaskedImage with a Kernel, setting pixels of an existing output image...
template<typename PixelT , typename BackgroundT >
afwImage::MaskedImage<PixelT> lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::Image< PixelT > const &  templateImage,
lsst::afw::image::MaskedImage< PixelT > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
BackgroundT  background,
bool  invert 
)

Implement fundamental difference imaging step of convolution and subtraction : D = I - (K.x.T + bg)

Execute fundamental task of convolving template and subtracting it from science image.

Note
The template is taken to be an Image, not a MaskedImage; it therefore has neither variance nor bad pixels
If you convolve the science image, D = (K*I + bg) - T, set invert=False
Instantiated such that background can be a double or Function2D
Returns
Difference image
Parameters
templateImageImage T to convolve with Kernel
scienceMaskedImageImage I to subtract T from
convolutionKernelPSF-matching Kernel used
backgroundDifferential background
invertInvert the output difference image

Definition at line 169 of file ImageSubtract.cc.

175  {
176 
177  boost::timer t;
178  t.restart();
179 
180  afwImage::MaskedImage<PixelT> convolvedMaskedImage(templateImage.getDimensions());
182  convolutionControl.setDoNormalize(false);
183  afwMath::convolve(*convolvedMaskedImage.getImage(), templateImage,
184  convolutionKernel, convolutionControl);
185 
186  /* Add in background */
187  *(convolvedMaskedImage.getImage()) += background;
188 
189  /* Do actual subtraction */
190  *convolvedMaskedImage.getImage() -= *scienceMaskedImage.getImage();
191 
192  /* Invert */
193  if (invert) {
194  *convolvedMaskedImage.getImage() *= -1.0;
195  }
196  convolvedMaskedImage.getMask()->assign(*scienceMaskedImage.getMask());
197  convolvedMaskedImage.getVariance()->assign(*scienceMaskedImage.getVariance());
198 
199  double time = t.elapsed();
200  LOGL_DEBUG("TRACE4.ip.diffim.convolveAndSubtract",
201  "Total compute time to convolve and subtract : %.2f s", time);
202 
203  return convolvedMaskedImage;
204 }
Parameters to control convolution.
Definition: ConvolveImage.h:57
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:875
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:896
geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: Image.h:299
MaskPtr getMask(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s mask.
Definition: MaskedImage.h:885
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:78
void convolve(OutImageT &convolvedImage, InImageT const &inImage, KernelT const &kernel, ConvolutionControl const &convolutionControl=ConvolutionControl())
Convolve an Image or MaskedImage with a Kernel, setting pixels of an existing output image...
template lsst::afw::image::MaskedImage< float > lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::Image< float > const &  templateImage,
lsst::afw::image::MaskedImage< float > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
double  background,
bool  invert 
)
template afwImage::MaskedImage< float > lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::Image< float > const &  templateImage,
lsst::afw::image::MaskedImage< float > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
lsst::afw::math::Function2< double > const &  backgroundFunction,
bool  invert 
)
template lsst::afw::image::MaskedImage< float > lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::MaskedImage< float > const &  templateImage,
lsst::afw::image::MaskedImage< float > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
double  background,
bool  invert 
)
template afwImage::MaskedImage< float > lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::MaskedImage< float > const &  templateImage,
lsst::afw::image::MaskedImage< float > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
lsst::afw::math::Function2< double > const &  backgroundFunction,
bool  invert 
)
template lsst::afw::image::MaskedImage< double > lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::Image< double > const &  templateImage,
lsst::afw::image::MaskedImage< double > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
double  background,
bool  invert 
)
template afwImage::MaskedImage< double > lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::Image< double > const &  templateImage,
lsst::afw::image::MaskedImage< double > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
lsst::afw::math::Function2< double > const &  backgroundFunction,
bool  invert 
)
template lsst::afw::image::MaskedImage< double > lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::MaskedImage< double > const &  templateImage,
lsst::afw::image::MaskedImage< double > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
double  background,
bool  invert 
)
template afwImage::MaskedImage< double > lsst::ip::diffim::convolveAndSubtract ( lsst::afw::image::MaskedImage< double > const &  templateImage,
lsst::afw::image::MaskedImage< double > const &  scienceMaskedImage,
lsst::afw::math::Kernel const &  convolutionKernel,
lsst::afw::math::Function2< double > const &  backgroundFunction,
bool  invert 
)
template<typename PixelT >
Eigen::MatrixXd lsst::ip::diffim::imageToEigenMatrix ( lsst::afw::image::Image< PixelT > const &  img)

Turns Image into a 2-D Eigen Matrix.

Turns a 2-d Image into a 2-d Eigen Matrix.

Parameters
imgImage whose pixel values are read into an Eigen::MatrixXd

Definition at line 65 of file ImageSubtract.cc.

67  {
68  unsigned int rows = img.getHeight();
69  unsigned int cols = img.getWidth();
70  Eigen::MatrixXd M = Eigen::MatrixXd::Zero(rows, cols);
71  for (int y = 0; y != img.getHeight(); ++y) {
72  int x = 0;
73  for (typename afwImage::Image<PixelT>::x_iterator ptr = img.row_begin(y);
74  ptr != img.row_end(y); ++ptr, ++x) {
75  // M is addressed row, col. Need to invert y-axis.
76  // WARNING : CHECK UNIT TESTS BEFORE YOU COMMIT THIS (-y-1) INVERSION
77  M(rows-y-1,x) = *ptr;
78  }
79  }
80  return M;
81 }
int y
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: Image.h:325
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:240
double x
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y&#39;th row.
Definition: Image.h:320
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:238
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:416
template Eigen::MatrixXd lsst::ip::diffim::imageToEigenMatrix ( lsst::afw::image::Image< double > const &  )
lsst::afw::math::KernelList lsst::ip::diffim::makeAlardLuptonBasisList ( int  halfWidth,
int  nGauss,
std::vector< double > const &  sigGauss,
std::vector< int > const &  degGauss 
)

Generate an Alard-Lupton basis set of Kernels.

Build a set of Alard/Lupton basis kernels.

Note
Should consider implementing as SeparableKernels for additional speed, but this will make the normalization a bit more complicated
Returns
Vector of Alard-Lupton Kernels.
Note
Should consider implementing as SeparableKernels for additional speed, but this will make the normalization a bit more complicated
Parameters
halfWidthsize is 2*N + 1
nGaussnumber of gaussians
sigGaussWidths of the Gaussian Kernels
degGaussLocal spatial variation of bases
Parameters
halfWidthsize is 2*N + 1
nGaussnumber of gaussians
sigGausswidth of the gaussians
degGausslocal spatial variation of gaussians

Definition at line 78 of file BasisLists.cc.

83  {
84  typedef afwMath::Kernel::Pixel Pixel;
85  typedef afwImage::Image<Pixel> Image;
86 
87  if (halfWidth < 1) {
88  throw LSST_EXCEPT(pexExcept::Exception, "halfWidth must be positive");
89  }
90  if (nGauss != static_cast<int>(sigGauss.size())) {
91  throw LSST_EXCEPT(pexExcept::Exception, "sigGauss does not have enough entries");
92  }
93  if (nGauss != static_cast<int>(degGauss.size())) {
94  throw LSST_EXCEPT(pexExcept::Exception, "degGauss does not have enough entries");
95  }
96  int fullWidth = 2 * halfWidth + 1;
97  Image image(afwGeom::Extent2I(fullWidth, fullWidth));
98 
99  afwMath::KernelList kernelBasisList;
100  for (int i = 0; i < nGauss; i++) {
101  /*
102  sigma = FWHM / ( 2 * sqrt(2 * ln(2)) )
103  */
104  double sig = sigGauss[i];
105  int deg = degGauss[i];
106 
107  LOGL_DEBUG("TRACE1.ip.diffim.BasisLists.makeAlardLuptonBasisList",
108  "Gaussian %d : sigma %.2f degree %d", i, sig, deg);
109 
110  afwMath::GaussianFunction2<Pixel> gaussian(sig, sig);
111  afwMath::AnalyticKernel kernel(fullWidth, fullWidth, gaussian);
112  afwMath::PolynomialFunction2<Pixel> polynomial(deg);
113 
114  for (int j = 0, n = 0; j <= deg; j++) {
115  for (int k = 0; k <= (deg - j); k++, n++) {
116  /* for 0th order term, skip polynomial */
117  (void)kernel.computeImage(image, true);
118  if (n == 0) {
119  std::shared_ptr<afwMath::Kernel>
120  kernelPtr(new afwMath::FixedKernel(image));
121  kernelBasisList.push_back(kernelPtr);
122  continue;
123  }
124 
125  /* gaussian to be modified by this term in the polynomial */
126  polynomial.setParameter(n, 1.);
127  (void)kernel.computeImage(image, true);
128  for (int y = 0, v = -halfWidth; y < image.getHeight(); y++, v++) {
129  int u = -halfWidth;
130  for (Image::xy_locator ptr = image.xy_at(0, y),
131  end = image.xy_at(image.getWidth(), y);
132  ptr != end; ++ptr.x(), u++) {
133  /* Evaluate from -1 to 1 */
134  *ptr = *ptr * polynomial(u/static_cast<double>(halfWidth),
135  v/static_cast<double>(halfWidth));
136  }
137  }
138  std::shared_ptr<afwMath::Kernel>
139  kernelPtr(new afwMath::FixedKernel(image));
140  kernelBasisList.push_back(kernelPtr);
141  polynomial.setParameter(n, 0.);
142  }
143  }
144  }
145  return renormalizeKernelList(kernelBasisList);
146  }
int y
lsst::afw::math::KernelList renormalizeKernelList(lsst::afw::math::KernelList const &kernelListIn)
Rescale an input set of kernels.
Definition: BasisLists.cc:419
2-dimensional polynomial function with cross terms
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
metadata import lsst afw display as afwDisplay n
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
A kernel described by a function.
Definition: Kernel.h:625
A kernel created from an Image.
Definition: Kernel.h:548
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:539
std::shared_ptr< Eigen::MatrixXd > lsst::ip::diffim::makeCentralDifferenceMatrix ( int  width,
int  height,
int  stencil,
float  borderPenalty,
bool  fitForBackground 
)

Generate regularization matrix for delta function kernels.

Build a central difference Laplacian regularization matrix for Delta function kernels.

Parameters
widthWidth of basis set you want to regularize
heightHeight of basis set you want to regularize
stencilWhich type of Laplacian approximation to use
borderPenaltyAmount of penalty (if any) to apply to border pixels; > 0
fitForBackgroundFit for differential background?

Definition at line 211 of file BasisLists.cc.

217  {
218 
219  /* 5- or 9-point stencil to approximate the Laplacian; i.e. this is a second
220  * order central finite difference.
221  *
222  * 5-point approximation ignores off-diagonal elements, and is
223  *
224  * f(x-1,y) + f(x+1,y) + f(x,y-1) + f(x,y+1) - 4 f(x,y)
225  *
226  * 0 1 0
227  * 1 -4 1
228  * 0 1 0
229  *
230  *
231  * 9-point approximation includes diagonals and is
232  *
233  * 1 4 1
234  * 4 -20 4 / 6
235  * 1 4 1
236  *
237  */
238 
239  if (borderPenalty < 0)
240  throw LSST_EXCEPT(pexExcept::Exception, "Only border penalty of >= 0 allowed");
241 
242  std::vector<std::vector<float> >
243  coeffs(3, std::vector<float>(3,0));
244 
245  if (stencil == 5) {
246  /* http://www.physics.arizona.edu/~restrepo/475B/Notes/source/node51.html
247  *
248  * This is equivalent to a second order central difference summed along
249  * the x-axis, and then summed along the y-axis.
250  *
251  * http://www.holoborodko.com/pavel/?page_id=239
252  *
253  */
254  coeffs[0][1] = 1.;
255  coeffs[1][0] = 1.;
256  coeffs[1][1] = -4.;
257  coeffs[1][2] = 1.;
258  coeffs[2][1] = 1.;
259  }
260  else if (stencil == 9) {
261  /* http://www.physics.arizona.edu/~restrepo/475B/Notes/source/node52.html */
262  coeffs[0][0] = 1. / 6.;
263  coeffs[0][1] = 4. / 6.;
264  coeffs[0][2] = 1. / 6.;
265  coeffs[1][0] = 4. / 6.;
266  coeffs[1][1] = -20. / 6.;
267  coeffs[1][2] = 4. / 6.;
268  coeffs[2][0] = 1. / 6.;
269  coeffs[2][1] = 4. / 6.;
270  coeffs[2][2] = 1. / 6.;
271  }
272  else {
273  throw LSST_EXCEPT(pexExcept::Exception, "Only 5- or 9-point Laplacian stencils allowed");
274  }
275 
276  int nBgTerms = fitForBackground ? 1 : 0;
277  Eigen::MatrixXd bMat = Eigen::MatrixXd::Zero(width * height + nBgTerms, width * height + nBgTerms);
278 
279  for (int i = 0; i < width*height; i++) {
280  int const x0 = i % width; // the x coord in the kernel image
281  int const y0 = i / width; // the y coord in the kernel image
282  int const distX = width - x0 - 1; // distance from edge of image
283  int const distY = height - y0 - 1; // distance from edge of image
284 
285  if ( (x0 > 0) && (y0 > 0) && (distX > 0) && (distY > 0) ) {
286  for (int dx = -1; dx < 2; dx += 1) {
287  for (int dy = -1; dy < 2; dy += 1) {
288  bMat(i, i + dx + dy * width) += coeffs[dx+1][dy+1];
289  }
290  }
291  }
292  else {
293  bMat(i, i) = borderPenalty;
294  }
295  }
296 
297  if (fitForBackground) {
298  /* Last row / col should have no regularization since its the background term */
299  if (bMat.col(width*height).sum() != 0.) {
300  throw LSST_EXCEPT(pexExcept::Exception, "Error 1 in regularization matrix");
301  }
302  if (bMat.row(width*height).sum() != 0.) {
303  throw LSST_EXCEPT(pexExcept::Exception, "Error 2 in regularization matrix");
304  }
305  }
306 
307  std::shared_ptr<Eigen::MatrixXd> bMatPtr (new Eigen::MatrixXd(bMat));
308  return bMatPtr;
309  }
int const x0
Definition: saturated.cc:45
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
int const y0
Definition: saturated.cc:45
lsst::afw::math::KernelList lsst::ip::diffim::makeDeltaFunctionBasisList ( int  width,
int  height 
)

Generate a basis set of delta function Kernels.

Build a set of Delta Function basis kernels.

Generates a vector of Kernels sized nCols * nRows, where each Kernel has a unique pixel set to value 1.0 with the other pixels valued 0.0. This is the "delta function" basis set.

Returns
Vector of orthonormal delta function Kernels.
Exceptions
lsst::pex::exceptions::DomainErrorif nRows or nCols not positive
Note
Total number of basis functions is width*height
Parameters
widthWidth of basis set (cols)
heightHeight of basis set (rows)
Parameters
widthnumber of columns in the set
heightnumber of rows in the set

Definition at line 47 of file BasisLists.cc.

50  {
51  if ((width < 1) || (height < 1)) {
52  throw LSST_EXCEPT(pexExcept::Exception, "nRows and nCols must be positive");
53  }
54  const int signedWidth = static_cast<int>(width);
55  const int signedHeight = static_cast<int>(height);
56  afwMath::KernelList kernelBasisList;
57  for (int row = 0; row < signedHeight; ++row) {
58  for (int col = 0; col < signedWidth; ++col) {
59  std::shared_ptr<afwMath::Kernel>
61  kernelBasisList.push_back(kernelPtr);
62  }
63  }
64  return kernelBasisList;
65  }
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
int row
Definition: CR.cc:158
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:741
int col
Definition: CR.cc:157
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:539
std::shared_ptr<Eigen::MatrixXd> lsst::ip::diffim::makeFiniteDifferenceRegularizationDeprecated ( unsigned int  width,
unsigned int  height,
unsigned int  order,
unsigned int  boundary_style,
unsigned int  difference_style,
bool  printB 
)

Generate regularization matrix for delta function kernels.

Definition at line 515 of file BasisLists.cc.

522  {
523 
524  if (order > 2) throw LSST_EXCEPT(pexExcept::Exception, "Only orders 0..2 allowed");
525 
526  if (boundary_style > 2) {
527  throw LSST_EXCEPT(pexExcept::Exception, "Boundary styles 0..2 defined");
528  }
529  if (difference_style > 1) {
530  throw LSST_EXCEPT(pexExcept::Exception, "Only forward(0), and central(1) difference types defined");
531  }
532 
533  /* what works, and what doesn't */
534  // == good job ==
535  // - order 0, wrapped, forward
536  // - order 1, wrapped or tapered, central or forward
537  // - order 2, wrapped or tapered, forward
538  // == bad job (usually diagongal stripes) ==
539  // - all others
540 
541 
542  /*
543  Instead of Taylor expanding the forward difference approximation of
544  derivatives (N.R. section 18.5) lets just hard code in the expansion of
545  the 1st through 3rd derivatives, which will try and enforce smoothness of
546  0 through 2nd derivatives.
547 
548  A property of the basic "finite difference regularization" is that their
549  rows (column multipliers) sum to 0.
550 
551  Another consideration is to use *multiple* finite difference operators as
552  a constraint.
553 
554  */
555 
556 
557  // ===========================================================================
558  // Get the coeffs for the finite differencing
559  // note: The coeffs are stored 2D although they are essentially 1D entities.
560  // The 2d design was chosen to allow cross-terms to be included,
561  // though they are not yet implemented.
562  //
563  std::vector<std::vector<std::vector<float> > >
564  coeffs(3, std::vector<std::vector<float> >(5, std::vector<float>(5,0)));
565  unsigned int x_cen = 0, y_cen = 0; // center of reqested order coeffs
566  unsigned int x_cen1 = 0, y_cen1 = 0; // center of order 1 coeffs
567  unsigned int x_cen2 = 0, y_cen2 = 0; // center of order 2 coeffs
568  unsigned int x_size = 0, y_size = 0;
569 
570  // forward difference coefficients
571  if (difference_style == 0) {
572 
573  y_cen = x_cen = 0;
574  x_cen1 = y_cen1 = 0;
575  x_cen2 = y_cen2 = 0;
576 
577  x_size = y_size = order + 2;
578 
579  // default forward difference suggested in NR chap 18
580  // 0th order
581  coeffs[0][0][0] = -2;
582  coeffs[0][0][1] = 1;
583  coeffs[0][1][0] = 1;
584  coeffs[0][1][1] = 0;
585 
586  // 1st 2
587  coeffs[1][0][0] = -2;
588  coeffs[1][0][1] = 2;
589  coeffs[1][0][2] = -1;
590  coeffs[1][1][0] = 2;
591  coeffs[1][1][1] = 0;
592  coeffs[1][1][2] = 0;
593  coeffs[1][2][0] = -1;
594  coeffs[1][2][1] = 0;
595  coeffs[1][2][2] = 0;
596 
597  // 2nd 2
598  coeffs[2][0][0] = -2;
599  coeffs[2][0][1] = 3;
600  coeffs[2][0][2] = -3;
601  coeffs[2][0][3] = 1;
602  coeffs[2][1][0] = 3;
603  coeffs[2][1][1] = 0;
604  coeffs[2][1][2] = 0;
605  coeffs[2][1][3] = 0;
606  coeffs[2][2][0] = -3;
607  coeffs[2][2][1] = 0;
608  coeffs[2][2][2] = 0;
609  coeffs[2][2][3] = 0;
610  coeffs[2][3][0] = 1;
611  coeffs[2][3][1] = 0;
612  coeffs[2][3][2] = 0;
613  coeffs[2][3][3] = 0;
614  }
615 
616  // central difference coefficients
617  if (difference_style == 1) {
618 
619  // this is asymmetric and produces diagonal banding in the kernel
620  // from: http://www.holoborodko.com/pavel/?page_id=239
621  if (order == 0) {
622  y_cen = x_cen = 1;
623  x_size = y_size = 3;
624  }
625  coeffs[0][0][0] = 0;
626  coeffs[0][0][1] = -1;
627  coeffs[0][0][2] = 0;
628 
629  coeffs[0][1][0] = -1;
630  coeffs[0][1][1] = 0;
631  coeffs[0][1][2] = 1;
632 
633  coeffs[0][2][0] = 0;
634  coeffs[0][2][1] = 1;
635  coeffs[0][2][2] = 0;
636 
637 
638  // this works well and is largely the same as order=1 forward-diff.
639  // from: http://www.holoborodko.com/pavel/?page_id=239
640  if (order == 1) {
641  y_cen = x_cen = 1;
642  x_size = y_size = 3;
643  }
644  y_cen1 = x_cen1 = 1;
645  coeffs[1][0][0] = 0;
646  coeffs[1][0][1] = 1;
647  coeffs[1][0][2] = 0;
648 
649  coeffs[1][1][0] = 1;
650  coeffs[1][1][1] = -4;
651  coeffs[1][1][2] = 1;
652 
653  coeffs[1][2][0] = 0;
654  coeffs[1][2][1] = 1;
655  coeffs[1][2][2] = 0;
656 
657 
658  // asymmetric and produces diagonal banding in the kernel
659  // from http://www.holoborodko.com/pavel/?page_id=239
660  if (order == 2) {
661  y_cen = x_cen = 2;
662  x_size = y_size = 5;
663  }
664  y_cen2 = x_cen2 = 2;
665  coeffs[2][0][0] = 0;
666  coeffs[2][0][1] = 0;
667  coeffs[2][0][2] = -1;
668  coeffs[2][0][3] = 0;
669  coeffs[2][0][4] = 0;
670 
671  coeffs[2][1][0] = 0;
672  coeffs[2][1][1] = 0;
673  coeffs[2][1][2] = 2;
674  coeffs[2][1][3] = 0;
675  coeffs[2][1][4] = 0;
676 
677  coeffs[2][2][0] = -1;
678  coeffs[2][2][1] = 2;
679  coeffs[2][2][2] = 0;
680  coeffs[2][2][3] = -2;
681  coeffs[2][2][4] = 1;
682 
683  coeffs[2][3][0] = 0;
684  coeffs[2][3][1] = 0;
685  coeffs[2][3][2] = -2;
686  coeffs[2][3][3] = 0;
687  coeffs[2][3][4] = 0;
688 
689  coeffs[2][4][0] = 0;
690  coeffs[2][4][1] = 0;
691  coeffs[2][4][2] = 1;
692  coeffs[2][4][3] = 0;
693  coeffs[2][4][4] = 0;
694  }
695 
696 
697  /* Note we have to add 1 extra (empty) term here because of the differential
698  * background fitting */
699  Eigen::MatrixXd bMat = Eigen::MatrixXd::Zero(width*height+1, width*height+1);
700 
701  /* Forward difference approximation */
702  for (unsigned int i = 0; i < width*height; i++) {
703 
704  unsigned int const x0 = i % width; // the x coord in the kernel image
705  unsigned int const y0 = i / width; // the y coord in the kernel image
706 
707  unsigned int x_edge_distance = (x0 > (width - x0 - 1)) ? width - x0 - 1 : x0;
708  unsigned int y_edge_distance = (y0 > (height - y0 - 1)) ? height - y0 - 1 : y0;
709  unsigned int edge_distance = (x_edge_distance < y_edge_distance) ? x_edge_distance :
710  y_edge_distance;
711 
712  for (unsigned int dx = 0; dx < x_size; dx++) {
713  for (unsigned int dy = 0; dy < y_size; dy++) {
714 
715  // determine where to put this coeff
716 
717  // handle the boundary condition
718  // note: adding width and height in the sum prevents negatives
719  unsigned int x = 0;
720  unsigned int y = 0;
721  double this_coeff = 0;
722 
723  // no-wrapping at edges
724  if (boundary_style == 0) {
725  x = x0 + dx - x_cen;
726  y = y0 + dy - y_cen;
727  if (y > height - 1 || x > width - 1) {
728  continue;
729  }
730  this_coeff = coeffs[order][dx][dy];
731 
732  // wrapping at edges
733  } else if (boundary_style == 1) {
734  x = (width + x0 + dx - x_cen) % width;
735  y = (height + y0 + dy - y_cen) % height;
736  this_coeff = coeffs[order][dx][dy];
737 
738  // order tapering to the edge (just clone wrapping for now)
739  // - use the lowest order possible
740  } else if (boundary_style == 2) {
741 
742  // edge rows and columns ... set to constant
743  if (edge_distance == 0) {
744  x = x0;
745  y = y0;
746  this_coeff = 1;
747  }
748  // in one from edge, use 1st order
749  else if (edge_distance == 1 && order > 0) {
750  x = (width + x0 + dx - x_cen1) % width;
751  y = (height + y0 + dy - y_cen1) % height;
752  if ((dx < 3) && (dy < 3)) { this_coeff = coeffs[1][dx][dy]; }
753  }
754  // in two from edge, use 2st order if order > 1
755  else if (edge_distance == 2 && order > 1){
756  x = (width + x0 + dx - x_cen2) % width;
757  y = (height + y0 + dy - y_cen2) % height;
758  if ((dx < 5) && (dy < 5)) { this_coeff = coeffs[2][dx][dy]; }
759  }
760  // if we're somewhere in the middle
761  else if (edge_distance > order) {
762  x = (width + x0 + dx - x_cen) % width;
763  y = (height + y0 + dy - y_cen) % height;
764  this_coeff = coeffs[order][dx][dy];
765  }
766 
767  }
768 
769  bMat(i, y*width + x) = this_coeff;
770 
771  }
772 
773  }
774 
775  }
776 
777  if (printB) {
778  std::cout << bMat << std::endl;
779  }
780 
781  std::shared_ptr<Eigen::MatrixXd> hMat (new Eigen::MatrixXd(bMat.transpose() * bMat));
782  return hMat;
783  }
int y
int const x0
Definition: saturated.cc:45
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
double x
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
int const y0
Definition: saturated.cc:45
std::shared_ptr< Eigen::MatrixXd > lsst::ip::diffim::makeForwardDifferenceMatrix ( int  width,
int  height,
std::vector< int > const &  orders,
float  borderPenalty,
bool  fitForBackground 
)

Generate regularization matrix for delta function kernels.

Build a forward difference regularization matrix for Delta function kernels.

Parameters
widthWidth of basis set you want to regularize
heightHeight of basis set you want to regularize
ordersWhich derivatives to penalize (1,2,3)
borderPenaltyAmount of penalty (if any) to apply to border pixels; > 0
fitForBackgroundFit for differential background?

Definition at line 315 of file BasisLists.cc.

321  {
322 
323  /*
324  Instead of Taylor expanding the forward difference approximation of
325  derivatives (N.R. section 18.5) lets just hard code in the expansion of
326  the 1st through 3rd derivatives, which will try and enforce smoothness of
327  0 through 2nd derivatives.
328 
329  A property of the basic "finite difference regularization" is that their
330  rows (column multipliers) sum to 0.
331 
332  We taper the order of the constraint as you get close to the boundary.
333  The actual perimeter values are left unconstrained but we might want to
334  consider giving these the same penalties as the other border pixels,
335  which is +1 (since the value gets squared).
336 
337  */
338 
339  if (borderPenalty < 0)
340  throw LSST_EXCEPT(pexExcept::Exception, "Only border penalty of >= 0 allowed");
341 
342  std::vector<std::vector<float> >
343  coeffs(4, std::vector<float>(4,0));
344 
345  // penalize border? this is along the diagonal and gets squared, so sign does not matter
346  coeffs[0][0] = borderPenalty;
347 
348  // penalize zeroth derivative
349  coeffs[1][0] = -1.;
350  coeffs[1][1] = +1.;
351 
352  // penalize first derivative
353  coeffs[2][0] = -1.;
354  coeffs[2][1] = +2.;
355  coeffs[2][2] = -1.;
356 
357  // penalize second derivative
358  coeffs[3][0] = -1.;
359  coeffs[3][1] = +3.;
360  coeffs[3][2] = -3.;
361  coeffs[3][3] = +1.;
362 
363  int nBgTerms = fitForBackground ? 1 : 0;
364  Eigen::MatrixXd bTot = Eigen::MatrixXd::Zero(width * height + nBgTerms, width * height + nBgTerms);
365 
366  std::vector<int>::const_iterator order;
367  for (order = orders.begin(); order != orders.end(); order++) {
368  if ((*order < 1) || (*order > 3))
369  throw LSST_EXCEPT(pexExcept::Exception, "Only orders 1..3 allowed");
370 
371  Eigen::MatrixXd bMatX = Eigen::MatrixXd::Zero(width * height + nBgTerms,
372  width * height + nBgTerms);
373  Eigen::MatrixXd bMatY = Eigen::MatrixXd::Zero(width * height + nBgTerms,
374  width * height + nBgTerms);
375 
376  for (int i = 0; i < width*height; i++) {
377  int const x0 = i % width; // the x coord in the kernel image
378  int const y0 = i / width; // the y coord in the kernel image
379 
380  int distX = width - x0 - 1; // distance from edge of image
381  int orderToUseX = std::min(distX, *order);
382  for (int j = 0; j < orderToUseX+1; j++) {
383  bMatX(i, i + j) = coeffs[orderToUseX][j];
384  }
385 
386  int distY = height - y0 - 1; // distance from edge of image
387  int orderToUseY = std::min(distY, *order);
388  for (int j = 0; j < orderToUseY+1; j++) {
389  bMatY(i, i + j * width) = coeffs[orderToUseY][j];
390  }
391  }
392  bTot += bMatX;
393  bTot += bMatY;
394  }
395 
396  if (fitForBackground) {
397  /* Last row / col should have no regularization since its the background term */
398  if (bTot.col(width*height).sum() != 0.) {
399  throw LSST_EXCEPT(pexExcept::Exception, "Error in regularization matrix");
400  }
401  if (bTot.row(width*height).sum() != 0.) {
402  throw LSST_EXCEPT(pexExcept::Exception, "Error in regularization matrix");
403  }
404  }
405 
406  std::shared_ptr<Eigen::MatrixXd> bMatPtr (new Eigen::MatrixXd(bTot));
407  return bMatPtr;
408  }
int const x0
Definition: saturated.cc:45
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
int const y0
Definition: saturated.cc:45
template<typename PixelT >
std::shared_ptr<KernelCandidate<PixelT> > lsst::ip::diffim::makeKernelCandidate ( float const  xCenter,
float const  yCenter,
std::shared_ptr< afw::image::MaskedImage< PixelT > > const &  templateMaskedImage,
std::shared_ptr< afw::image::MaskedImage< PixelT > > const &  scienceMaskedImage,
pex::policy::Policy const &  policy 
)

Return a KernelCandidate pointer of the right sort.

Parameters
xCenterX-center of candidate
yCenterY-center of candidate
templateMaskedImageTemplate subimage
scienceMaskedImageScience image subimage
policyPolicy file for creation of rating

Definition at line 219 of file KernelCandidate.h.

223  {
224 
225  return typename KernelCandidate<PixelT>::Ptr(new KernelCandidate<PixelT>(xCenter, yCenter,
226  templateMaskedImage,
227  scienceMaskedImage,
228  policy));
229  }
template<typename PixelT >
std::shared_ptr<KernelCandidate<PixelT> > lsst::ip::diffim::makeKernelCandidate ( std::shared_ptr< afw::table::SourceRecord > const &  source,
std::shared_ptr< afw::image::MaskedImage< PixelT > > const &  templateMaskedImage,
std::shared_ptr< afw::image::MaskedImage< PixelT > > const &  scienceMaskedImage,
pex::policy::Policy const &  policy 
)

Return a KernelCandidate pointer of the right sort.

Parameters
sourceafw::table::SourceRecord used to construct the KernelCandidate
templateMaskedImageTemplate subimage
scienceMaskedImageScience image subimage
policyPolicy file for creation of rating

Definition at line 244 of file KernelCandidate.h.

247  {
248 
249  return typename KernelCandidate<PixelT>::Ptr(new KernelCandidate<PixelT>(source,
250  templateMaskedImage,
251  scienceMaskedImage,
252  policy));
253  }
std::shared_ptr< Eigen::MatrixXd > lsst::ip::diffim::makeRegularizationMatrix ( lsst::pex::policy::Policy  policy)

Build a regularization matrix for Delta function kernels.

Parameters
policyPolicy file dictating which type of matrix to make
Note
Calls either makeForwardDifferenceMatrix or makeCentralDifferenceMatrix based on the policy file.

Definition at line 150 of file BasisLists.cc.

152  {
153 
154  /* NOTES
155  *
156  * The 3-point first derivative central difference (Laplacian) yields
157  * diagonal stripes and should not be used.
158 
159  coeffs[0][1] = -1. / 2.;
160  coeffs[1][0] = -1. / 2.;
161  coeffs[1][2] = 1. / 2.;
162  coeffs[2][1] = 1. / 2.;
163 
164  * The 5-point second derivative central difference (Laplacian) looks great.
165  * For smaller lambdas you need a higher border penalty. In general, if you
166  * decrease the regularization strength you should increase the border
167  * penalty to avoid noise in the border pixels. This has been used to value
168  * 10 and things still look OK.
169 
170  * The 9-point second derivative central difference (Laplacian with off
171  * diagonal terms) also looks great. Seems to have slightly higher-valued
172  * border pixels so make boundary larger if using this. E.g. 1.5.
173 
174  * The forward finite difference, first derivative term works good
175  *
176  * The forward finite difference, second derivative term is slightly banded
177  * in LLC
178  *
179  * The forward finite difference, third derivative term is highly banded in
180  * LLC and should not be used.
181  *
182  */
183 
184  std::string regularizationType = policy.getString("regularizationType");
185  int width = policy.getInt("kernelSize");
186  int height = policy.getInt("kernelSize");
187  float borderPenalty = policy.getDouble("regularizationBorderPenalty");
188  bool fitForBackground = policy.getBool("fitForBackground");
189 
190  std::shared_ptr<Eigen::MatrixXd> bMat;
191  if (regularizationType == "centralDifference") {
192  int stencil = policy.getInt("centralRegularizationStencil");
193  bMat = makeCentralDifferenceMatrix(width, height, stencil, borderPenalty, fitForBackground);
194  }
195  else if (regularizationType == "forwardDifference") {
196  std::vector<int> orders = policy.getIntArray("forwardRegularizationOrders");
197  bMat = makeForwardDifferenceMatrix(width, height, orders, borderPenalty, fitForBackground);
198  }
199  else {
200  throw LSST_EXCEPT(pexExcept::Exception, "regularizationType not recognized");
201  }
202 
203  std::shared_ptr<Eigen::MatrixXd> hMat (new Eigen::MatrixXd((*bMat).transpose() * (*bMat)));
204  return hMat;
205  }
int getInt(const std::string &name) const
return an integer value associated with the given name.
Definition: Policy.h:603
bool getBool(const std::string &name) const
return a boolean value associated with the given name.
Definition: Policy.h:589
const std::string getString(const std::string &name) const
return a string value associated with the given name .
Definition: Policy.h:631
std::shared_ptr< Eigen::MatrixXd > makeForwardDifferenceMatrix(int width, int height, std::vector< int > const &orders, float borderPenalty, bool fitForBackground)
Generate regularization matrix for delta function kernels.
Definition: BasisLists.cc:315
std::shared_ptr< Eigen::MatrixXd > makeCentralDifferenceMatrix(int width, int height, int stencil, float borderPenalty, bool fitForBackground)
Generate regularization matrix for delta function kernels.
Definition: BasisLists.cc:211
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
double getDouble(const std::string &name) const
return a double value associated with the given name.
Definition: Policy.h:617
IntArray getIntArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:1035
Eigen::MatrixXi lsst::ip::diffim::maskToEigenMatrix ( lsst::afw::image::Mask< lsst::afw::image::MaskPixel > const &  mask)

Definition at line 83 of file ImageSubtract.cc.

85  {
86  unsigned int rows = mask.getHeight();
87  unsigned int cols = mask.getWidth();
88  Eigen::MatrixXi M = Eigen::MatrixXi::Zero(rows, cols);
89  for (int y = 0; y != mask.getHeight(); ++y) {
90  int x = 0;
92  ptr != mask.row_end(y); ++ptr, ++x) {
93  // M is addressed row, col. Need to invert y-axis.
94  // WARNING : CHECK UNIT TESTS BEFORE YOU COMMIT THIS (-y-1) INVERSION
95  M(rows-y-1,x) = *ptr;
96  }
97  }
98  return M;
99 }
int y
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:92
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: Image.h:325
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:240
double x
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y&#39;th row.
Definition: Image.h:320
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:238
int const lsst::ip::diffim::NEGCENTXPAR ( )
int const lsst::ip::diffim::NEGCENTYPAR ( )
int const lsst::ip::diffim::NEGFLUXPAR ( )
int const lsst::ip::diffim::POSCENTXPAR ( )
int const lsst::ip::diffim::POSCENTYPAR ( )
int const lsst::ip::diffim::POSFLUXPAR ( )
lsst::afw::math::KernelList lsst::ip::diffim::renormalizeKernelList ( lsst::afw::math::KernelList const &  kernelListIn)

Rescale an input set of kernels.

Renormalize a list of basis kernels.

Returns
Vector of renormalized kernels
Note
Renormalization means make Ksum_0 = 1.0, Ksum_i = 0.0, K_i.dot.K_i = 1.0
Output list of shared pointers to FixedKernels
Parameters
kernelListIninput list of basis kernels
Note
Images are checked for their current kernel sum. If it is larger than std::numeric_limits<double>::epsilon(), the kernel is first divided by the kernel sum, giving it a kSum of 1.0, and then the first (normalized) component is subtracted from it, giving it a kSum of 0.0.
Parameters
kernelListInInput list to be renormalized

Definition at line 419 of file BasisLists.cc.

421  {
422  typedef afwMath::Kernel::Pixel Pixel;
423  typedef afwImage::Image<Pixel> Image;
424  double kSum;
425 
426  /*
427 
428  We want all the bases except for the first to sum to 0.0. This allows
429  us to achieve kernel flux conservation (Ksum) across the image since all
430  the power will be in the first term, which will not vary spatially.
431 
432  K(x,y) = Ksum * B_0 + Sum_i : a(x,y) * B_i
433 
434  To do this, normalize all Kernels to sum = 1. and subtract B_0 from all
435  subsequent kenrels.
436 
437  To get an idea of the relative contribution of each of these basis
438  functions later on down the line, lets also normalize them such that
439 
440  Sum(B_i) == 0.0 *and*
441  B_i * B_i == 1.0
442 
443  For completeness
444 
445  Sum(B_0) == 1.0
446  B_0 * B_0 != 1.0
447 
448  */
449  afwMath::KernelList kernelListOut;
450  if (kernelListIn.size() == 0) {
451  return kernelListOut;
452  }
453 
454  Image image0(kernelListIn[0]->getDimensions());
455  for (unsigned int i = 0; i < kernelListIn.size(); i++) {
456  if (i == 0) {
457  /* Make sure that it is normalized to kSum 1. */
458  (void)kernelListIn[i]->computeImage(image0, true);
459  std::shared_ptr<afwMath::Kernel>
460  kernelPtr(new afwMath::FixedKernel(image0));
461  kernelListOut.push_back(kernelPtr);
462 
463  continue;
464  }
465 
466  /* Don't normalize here */
467  Image image(kernelListIn[i]->getDimensions());
468  (void)kernelListIn[i]->computeImage(image, false);
469  /* image.writeFits(str(boost::format("in_k%d.fits") % i)); */
470 
471  /* Check the kernel sum; if its close to zero don't do anything */
472  kSum = 0.;
473  for (int y = 0; y < image.getHeight(); y++) {
474  for (Image::xy_locator ptr = image.xy_at(0, y), end = image.xy_at(image.getWidth(), y);
475  ptr != end; ++ptr.x()) {
476  kSum += *ptr;
477  }
478  }
479 
480  /* std::numeric_limits<float>::epsilon() ~ e-7
481  std::numeric_limits<double>::epsilon() ~ e-16
482 
483  If we end up with 2e-16 kernel sum, this still blows up the kernel values.
484  Even though the kernels are double, use the float limits instead
485  */
486  if (fabs(kSum) > std::numeric_limits<float>::epsilon()) {
487  image /= kSum;
488  image -= image0;
489  }
490 
491  /* Finally, rescale such that the inner product is 1 */
492  kSum = 0.;
493  for (int y = 0; y < image.getHeight(); y++) {
494  for (Image::xy_locator ptr = image.xy_at(0, y), end = image.xy_at(image.getWidth(), y);
495  ptr != end; ++ptr.x()) {
496  kSum += *ptr * *ptr;
497  }
498  }
499  image /= std::sqrt(kSum);
500  /* image.writeFits(str(boost::format("out_k%d.fits") % i)); */
501 
502  std::shared_ptr<afwMath::Kernel>
503  kernelPtr(new afwMath::FixedKernel(image));
504  kernelListOut.push_back(kernelPtr);
505  }
506  return kernelListOut;
507  }
int y
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
A kernel created from an Image.
Definition: Kernel.h:548
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:539