47 namespace afwDetection = lsst::afw::detection;
48 namespace afwGeom = lsst::afw::geom;
50 namespace afwMath = lsst::afw::math;
54 namespace algorithms {
87 template<
typename ImageT>
89 computeFirstMoment(ImageT
const&
image,
90 float const xCen,
float const yCen
95 for (
int iY = 0; iY != image->getHeight(); ++iY) {
98 end = image->row_end(iY); ptr != end; ++ptr, ++iX) {
99 double const x = iX - xCen;
100 double const y = iY - yCen;
101 double const r = std::sqrt( x*x + y*y );
102 double const m = (*ptr)*r;
108 std::string errmsg(
"");
110 errmsg =
"sum(I*r) is negative. ";
113 errmsg +=
"sum(I) is <= 0.";
116 throw LSST_EXCEPT(lsst::pex::exceptions::DomainError, errmsg);
127 template<
typename ImageT>
129 computeSecondMoment(ImageT
const& image,
130 float const xCen,
float const yCen
135 for (
int iY = 0; iY != image->getHeight(); ++iY) {
138 end = image->row_end(iY); ptr != end; ++ptr, ++iX) {
139 double const x = iX - xCen;
140 double const y = iY - yCen;
141 double const r2 = x*x + y*
y;
142 double const m = (*ptr)*r2;
148 std::string errmsg(
"");
150 errmsg =
"sum(I*r*r) is negative. ";
153 errmsg +=
"sum(I) is <= 0.";
156 throw LSST_EXCEPT(lsst::pex::exceptions::DomainError, errmsg);
166 template<
typename ImageT>
167 std::pair<bool, double>
168 calcmom(ImageT
const& image,
169 float const xCen,
float const yCen,
174 if (fabs(w11) > 1e6) {
175 return std::make_pair(
false, std::numeric_limits<double>::quiet_NaN());
178 double sum = 0, sumrr = 0.0;
180 for (
int i = 0; i < image.getHeight(); ++i) {
181 float const y = i - yCen;
182 float const y2 = y*
y;
184 typename ImageT::x_iterator ptr = image.row_begin(i);
185 for (
int j = 0; j < image.getWidth(); ++j, ++ptr) {
186 float const x = j - xCen;
187 float const x2 = x*
x;
188 float const expon = (x2 + y2)*w11;
191 float const weight = exp(-0.5*expon);
192 float const tmod = *ptr;
193 float const ymod = tmod*
weight;
195 sumrr += (x2 + y2)*ymod;
200 if (sum <= 0 || sumrr < 0) {
201 return std::make_pair(
false, std::numeric_limits<double>::quiet_NaN());
204 return std::make_pair(
true, 0.5*sumrr/sum);
215 template<
typename ImageT>
217 computeSecondMomentAdaptive(ImageT
const& image,
218 float const xCen,
float const yCen
221 int const MAXIT = 100;
222 float const TOL = 0.0001;
224 float sigma11_ow_old = 1e6;
226 bool unweighted =
false;
229 std::pair<bool, double> moments = calcmom(*image, xCen, yCen, w11);
231 if (not moments.first) {
238 float const sigma11_ow = moments.second;
240 if (iter > 0 && fabs(sigma11_ow/sigma11_ow_old - 1.0) < TOL) {
244 sigma11_ow_old = sigma11_ow;
264 w11 = 1/sigma11_ow - w11;
276 if (iter == MAXIT || unweighted) {
278 std::pair<bool, double> moments = calcmom(*image, xCen, yCen, w11);
281 sigma11W = moments.second;
311 double x(center.getX());
312 double y(center.getY());
314 double const xCen = fittedCenter.getX();
315 double const yCen = fittedCenter.getY();
318 return ::sqrt(0.5*computeSecondMomentAdaptive(
_psfImage, xCen, yCen));
322 return ::sqrt(0.5*computeSecondMoment(
_psfImage, xCen, yCen));
329 for (
int iY = 0; iY !=
_psfImage->getHeight(); ++iY) {
332 end =
_psfImage->row_end(iY); ptr != end;
334 double const x = iX - xCen;
335 double const y = iY - yCen;
336 double const r = std::sqrt( x*x + y*y );
337 double const m = (*ptr)*r;
338 norm += (*ptr)*(*ptr);
342 return sqrt(sum/norm);
357 for (
int iY = 0; iY !=
_psfImage->getHeight(); ++iY) {
361 sumsqr += (*ptr)*(*ptr);
364 return sum*sum/sumsqr;
Calculate width as sqrt(n_eff/(4 pi))
A coordinate class intended to represent absolute positions.
PsfAttributes(boost::shared_ptr< lsst::afw::detection::Psf const > psf, int const iX, int const iY)
Constructor for PsfAttributes.
x_iterator row_begin(int y) const
tbl::Key< double > weight
A class to contain the data, WCS, and other information needed to describe an image of the sky...
static afw::geom::Point2D fitCentroid(afw::image::Image< PixelT > const &im, double x0, double y0)
x0, y0 is an initial guess for position, column
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
table::Key< table::Array< Kernel::Pixel > > image
Calculate width using <r^2>
boost::shared_ptr< lsst::afw::image::Image< double > > _psfImage
boost::shared_ptr< lsst::afw::image::Image< double > > _psfImage
Support for PCA analysis of 2-D images.
A class to manipulate images, masks, and variance as a single object.
double computeEffectiveArea() const
Compute the effective area of the psf ( sum(I)^2/sum(I^2) )
Calculate width using <r>
#define LSST_EXCEPT(type,...)
Weight <r^2> by I^2 to avoid negative fluxes.
Calculate width using adaptive Gaussian weights.
boost::shared_ptr< Image > computeImage(geom::Point2D position=makeNullPoint(), image::Color color=image::Color(), ImageOwnerEnum owner=COPY) const
Return an Image of the PSF, in a form that can be compared directly with star images.
Class to ensure constraints for spatial modeling.
Exposure< ImagePixelT, MaskPixelT, VariancePixelT >::Ptr makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, boost::shared_ptr< Wcs const > wcs=boost::shared_ptr< Wcs const >())
Point< double, 2 > PointD
double const PI
The ratio of a circle's circumference to diameter.
A polymorphic base class for representing an image's Point Spread Function.
double computeGaussianWidth(Method how=ADAPTIVE_MOMENT) const
Compute the 'sigma' value for an equivalent gaussian psf.
A class to represent a 2-dimensional array of pixels.