510 "Error: variance less than 0.0");
514 "Error: variance equals 0.0, cannot inverse variance weight");
537 int growPix = (*kiter)->getCtr().getX();
541 for (
typename afwDet::FootprintSet::FootprintList::iterator
542 ptr = maskedFpSetGrown.getFootprints()->begin(),
543 end = maskedFpSetGrown.getFootprints()->end();
547 afwDet::setMaskFromFootprint(finalMask,
554 for (
auto const & foot : *(maskedFpSetGrown.getFootprints())) {
558 finalMask.writeFits(
"finalmask.fits");
561 ndarray::Array<int, 1, 1> maskArray =
562 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
563 fullFp->getSpans()->flatten(maskArray, finalMask.getArray(), templateImage.
getXY0());
564 auto maskEigen = ndarray::asEigenMatrix(maskArray);
566 ndarray::Array<InputT, 1, 1> arrayTemplate =
567 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
568 fullFp->getSpans()->flatten(arrayTemplate, templateImage.
getArray(), templateImage.
getXY0());
569 auto eigenTemplate0 = ndarray::asEigenMatrix(arrayTemplate);
571 ndarray::Array<InputT, 1, 1> arrayScience =
572 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
573 fullFp->getSpans()->flatten(arrayScience, scienceImage.
getArray(), scienceImage.
getXY0());
574 auto eigenScience0 = ndarray::asEigenMatrix(arrayScience);
576 ndarray::Array<afwImage::VariancePixel, 1, 1> arrayVariance =
577 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
578 fullFp->getSpans()->flatten(arrayVariance, varianceEstimate.
getArray(), varianceEstimate.
getXY0());
579 auto eigenVariance0 = ndarray::asEigenMatrix(arrayVariance);
582 for (
int i = 0; i < maskEigen.size(); i++) {
583 if (maskEigen(i) == 0.0)
587 Eigen::VectorXd eigenTemplate(nGood);
588 Eigen::VectorXd eigenScience(nGood);
589 Eigen::VectorXd eigenVariance(nGood);
591 for (
int i = 0; i < maskEigen.size(); i++) {
592 if (maskEigen(i) == 0.0) {
593 eigenTemplate(nUsed) = eigenTemplate0(i);
594 eigenScience(nUsed) = eigenScience0(i);
595 eigenVariance(nUsed) = eigenVariance0(i);
604 unsigned int const nKernelParameters = basisList.size();
606 unsigned int const nParameters = nKernelParameters + nBackgroundParameters;
618 for (kiter = basisList.begin(); kiter != basisList.end(); ++kiter, ++eiter) {
621 ndarray::Array<InputT, 1, 1> arrayC =
622 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
623 fullFp->getSpans()->flatten(arrayC, cimage.getArray(), cimage.getXY0());
624 auto eigenC0 = ndarray::asEigenMatrix(arrayC);
626 Eigen::VectorXd eigenC(nGood);
628 for (
int i = 0; i < maskEigen.size(); i++) {
629 if (maskEigen(i) == 0.0) {
630 eigenC(nUsed) = eigenC0(i);
637 double time = t.elapsed();
638 LOGL_DEBUG(
"TRACE3.ip.diffim.StaticKernelSolution.buildWithMask",
639 "Total compute time to do basis convolutions : %.2f s", time);
643 Eigen::MatrixXd cMat(eigenTemplate.size(), nParameters);
646 for (
unsigned int kidxj = 0; eiterj != eiterE; eiterj++, kidxj++) {
647 cMat.block(0, kidxj, eigenTemplate.size(), 1) =
648 Eigen::MatrixXd(*eiterj).block(0, 0, eigenTemplate.size(), 1);
652 cMat.col(nParameters-1).fill(1.);
655 this->
_ivVec = eigenVariance.array().inverse().matrix();
656 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.