506 {
507
511 "Error: variance less than 0.0");
512 }
515 "Error: variance equals 0.0, cannot inverse variance weight");
516 }
517
518
521
523 std::dynamic_pointer_cast<afwMath::LinearCombinationKernel>(this->
_kernel)->getKernelList();
525
526
532
533
536
537
538 int growPix = (*kiter)->getCtr().getX();
540
541#if 0
542 for (typename afwDet::FootprintSet::FootprintList::iterator
543 ptr = maskedFpSetGrown.getFootprints()->begin(),
544 end = maskedFpSetGrown.getFootprints()->end();
547
548 afwDet::setMaskFromFootprint(finalMask,
551 }
552#endif
553
555 for (auto const & foot : *(maskedFpSetGrown.getFootprints())) {
557 }
559 finalMask.writeFits("finalmask.fits");
560
561
562 ndarray::Array<int, 1, 1> maskArray =
563 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
564 fullFp->getSpans()->flatten(maskArray, finalMask.getArray(), templateImage.
getXY0());
565 auto maskEigen = ndarray::asEigenMatrix(maskArray);
566
567 ndarray::Array<InputT, 1, 1> arrayTemplate =
568 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
569 fullFp->getSpans()->flatten(arrayTemplate, templateImage.
getArray(), templateImage.
getXY0());
570 auto eigenTemplate0 = ndarray::asEigenMatrix(arrayTemplate);
571
572 ndarray::Array<InputT, 1, 1> arrayScience =
573 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
574 fullFp->getSpans()->flatten(arrayScience, scienceImage.
getArray(), scienceImage.
getXY0());
575 auto eigenScience0 = ndarray::asEigenMatrix(arrayScience);
576
577 ndarray::Array<afwImage::VariancePixel, 1, 1> arrayVariance =
578 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
579 fullFp->getSpans()->flatten(arrayVariance, varianceEstimate.
getArray(), varianceEstimate.
getXY0());
580 auto eigenVariance0 = ndarray::asEigenMatrix(arrayVariance);
581
582 int nGood = 0;
583 for (int i = 0; i < maskEigen.size(); i++) {
584 if (maskEigen(i) == 0.0)
585 nGood += 1;
586 }
587
588 Eigen::VectorXd eigenTemplate(nGood);
589 Eigen::VectorXd eigenScience(nGood);
590 Eigen::VectorXd eigenVariance(nGood);
591 int nUsed = 0;
592 for (int i = 0; i < maskEigen.size(); i++) {
593 if (maskEigen(i) == 0.0) {
594 eigenTemplate(nUsed) = eigenTemplate0(i);
595 eigenScience(nUsed) = eigenScience0(i);
596 eigenVariance(nUsed) = eigenVariance0(i);
597 nUsed += 1;
598 }
599 }
600
601
602 boost::timer::cpu_timer t;
603
604 unsigned int const nKernelParameters = basisList.
size();
606 unsigned int const nParameters = nKernelParameters + nBackgroundParameters;
607
608
610
611
613
614
615 typename std::vector<Eigen::VectorXd>::iterator eiter = convolvedEigenList.begin();
616
617
620 for (kiter = basisList.
begin(); kiter != basisList.
end(); ++kiter, ++eiter) {
622
623 ndarray::Array<InputT, 1, 1> arrayC =
624 ndarray::allocate(ndarray::makeVector(fullFp->getArea()));
625 fullFp->getSpans()->flatten(arrayC, cimage.getArray(), cimage.getXY0());
626 auto eigenC0 = ndarray::asEigenMatrix(arrayC);
627
628 Eigen::VectorXd eigenC(nGood);
629 int nUsed = 0;
630 for (int i = 0; i < maskEigen.size(); i++) {
631 if (maskEigen(i) == 0.0) {
632 eigenC(nUsed) = eigenC0(i);
633 nUsed += 1;
634 }
635 }
636
637 *eiter = eigenC;
638 }
639 t.stop();
640 double time = 1e-9 * t.elapsed().wall;
641 LOGL_DEBUG(
"TRACE3.ip.diffim.StaticKernelSolution.buildWithMask",
642 "Total compute time to do basis convolutions : %.2f s", time);
643
644
645 Eigen::MatrixXd cMat(eigenTemplate.size(), nParameters);
646 typename std::vector<Eigen::VectorXd>::iterator eiterj = convolvedEigenList.begin();
647 typename std::vector<Eigen::VectorXd>::iterator eiterE = convolvedEigenList.end();
648 for (unsigned int kidxj = 0; eiterj != eiterE; eiterj++, kidxj++) {
649 cMat.block(0, kidxj, eigenTemplate.size(), 1) =
650 Eigen::MatrixXd(*eiterj).block(0, 0, eigenTemplate.size(), 1);
651 }
652
654 cMat.col(nParameters-1).fill(1.);
655
657 this->
_ivVec = eigenVariance.array().inverse().matrix();
658 this->
_iVec = eigenScience;
659
660
663 }
A Threshold is used to pass a threshold value to detection algorithms.
lsst::geom::Point2I getXY0() const
Return the image's origin.
void writeFits(std::string const &fileName, daf::base::PropertySet const *metadata=nullptr, std::string const &mode="w") const
Write a mask to a regular FITS file.