508 "Error: variance less than 0.0");
512 "Error: variance equals 0.0, cannot inverse variance weight");
535 int growPix = (*kiter)->getCtr().getX();
539 for (
typename afwDet::FootprintSet::FootprintList::iterator
540 ptr = maskedFpSetGrown.getFootprints()->begin(),
541 end = maskedFpSetGrown.getFootprints()->end();
545 afwDet::setMaskFromFootprint(finalMask,
552 for (
auto const & foot : *(maskedFpSetGrown.getFootprints())) {
556 finalMask.writeFits(
"finalmask.fits");
559 ndarray::Array<int, 1, 1> maskArray =
560 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
561 fullFp->getSpans()->flatten(maskArray, finalMask.getArray(), templateImage.
getXY0());
562 auto maskEigen = ndarray::asEigenMatrix(maskArray);
564 ndarray::Array<InputT, 1, 1> arrayTemplate =
565 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
566 fullFp->getSpans()->flatten(arrayTemplate, templateImage.
getArray(), templateImage.
getXY0());
567 auto eigenTemplate0 = ndarray::asEigenMatrix(arrayTemplate);
569 ndarray::Array<InputT, 1, 1> arrayScience =
570 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
571 fullFp->getSpans()->flatten(arrayScience, scienceImage.
getArray(), scienceImage.
getXY0());
572 auto eigenScience0 = ndarray::asEigenMatrix(arrayScience);
574 ndarray::Array<afwImage::VariancePixel, 1, 1> arrayVariance =
575 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
576 fullFp->getSpans()->flatten(arrayVariance, varianceEstimate.
getArray(), varianceEstimate.
getXY0());
577 auto eigenVariance0 = ndarray::asEigenMatrix(arrayVariance);
580 for (
int i = 0; i < maskEigen.size(); i++) {
581 if (maskEigen(i) == 0.0)
585 Eigen::VectorXd eigenTemplate(nGood);
586 Eigen::VectorXd eigenScience(nGood);
587 Eigen::VectorXd eigenVariance(nGood);
589 for (
int i = 0; i < maskEigen.size(); i++) {
590 if (maskEigen(i) == 0.0) {
591 eigenTemplate(nUsed) = eigenTemplate0(i);
592 eigenScience(nUsed) = eigenScience0(i);
593 eigenVariance(nUsed) = eigenVariance0(i);
602 unsigned int const nKernelParameters = basisList.size();
604 unsigned int const nParameters = nKernelParameters + nBackgroundParameters;
616 for (kiter = basisList.begin(); kiter != basisList.end(); ++kiter, ++eiter) {
619 ndarray::Array<InputT, 1, 1> arrayC =
620 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
621 fullFp->getSpans()->flatten(arrayC, cimage.getArray(), cimage.getXY0());
622 auto eigenC0 = ndarray::asEigenMatrix(arrayC);
624 Eigen::VectorXd eigenC(nGood);
626 for (
int i = 0; i < maskEigen.size(); i++) {
627 if (maskEigen(i) == 0.0) {
628 eigenC(nUsed) = eigenC0(i);
635 double time = t.elapsed();
636 LOGL_DEBUG(
"TRACE3.ip.diffim.StaticKernelSolution.buildWithMask",
637 "Total compute time to do basis convolutions : %.2f s", time);
641 Eigen::MatrixXd cMat(eigenTemplate.size(), nParameters);
644 for (
unsigned int kidxj = 0; eiterj != eiterE; eiterj++, kidxj++) {
645 cMat.block(0, kidxj, eigenTemplate.size(), 1) =
646 Eigen::MatrixXd(*eiterj).block(0, 0, eigenTemplate.size(), 1);
650 cMat.col(nParameters-1).fill(1.);
653 this->
_ivVec = eigenVariance.array().inverse().matrix();
654 this->
_iVec = eigenScience;
Eigen::MatrixXd _cMat
K_i x R.
Eigen::VectorXd _bVec
Derived least squares B vector.
Use (pixels & (given mask))
A Threshold is used to pass a threshold value to detection algorithms.
Provides consistent interface for LSST exceptions.
Eigen::VectorXd _iVec
Vectorized I.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Eigen::VectorXd _ivVec
Inverse variance.
A class to evaluate image statistics.
bool _fitForBackground
Background terms included in fit.
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
Represent a 2-dimensional array of bitmask pixels.
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
A kernel that is a linear combination of fixed basis kernels.
T dynamic_pointer_cast(T... args)
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR'd together.
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...
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
Eigen::MatrixXd _mMat
Derived least squares M matrix.
lsst::geom::Point2I getXY0() const
Return the image's origin.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
std::shared_ptr< lsst::afw::math::Kernel > _kernel
Derived single-object convolution kernel.
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), std::string const &mode="w") const
Write a mask to a regular FITS file.
lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
A class to represent a 2-dimensional array of pixels.