46 namespace afwDetection = lsst::afw::detection;
47 namespace afwGeom = lsst::afw::geom;
49 namespace afwMath = lsst::afw::math;
53 namespace algorithms {
86 template<
typename ImageT>
88 computeFirstMoment(ImageT
const&
image,
89 float const xCen,
float const yCen
94 for (
int iY = 0; iY != image->getHeight(); ++iY) {
97 end = image->row_end(iY); ptr != end; ++ptr, ++iX) {
98 double const x = iX - xCen;
99 double const y = iY - yCen;
100 double const r = std::sqrt( x*x + y*y );
101 double const m = (*ptr)*r;
107 std::string errmsg(
"");
109 errmsg =
"sum(I*r) is negative. ";
112 errmsg +=
"sum(I) is <= 0.";
115 throw LSST_EXCEPT(lsst::pex::exceptions::DomainError, errmsg);
126 template<
typename ImageT>
128 computeSecondMoment(ImageT
const& image,
129 float const xCen,
float const yCen
134 for (
int iY = 0; iY != image->getHeight(); ++iY) {
137 end = image->row_end(iY); ptr != end; ++ptr, ++iX) {
138 double const x = iX - xCen;
139 double const y = iY - yCen;
140 double const r2 = x*x + y*
y;
141 double const m = (*ptr)*r2;
147 std::string errmsg(
"");
149 errmsg =
"sum(I*r*r) is negative. ";
152 errmsg +=
"sum(I) is <= 0.";
155 throw LSST_EXCEPT(lsst::pex::exceptions::DomainError, errmsg);
165 template<
typename ImageT>
166 std::pair<bool, double>
167 calcmom(ImageT
const& image,
168 float const xCen,
float const yCen,
173 if (fabs(w11) > 1e6) {
174 return std::make_pair(
false, std::numeric_limits<double>::quiet_NaN());
177 double sum = 0, sumrr = 0.0;
179 for (
int i = 0; i < image.getHeight(); ++i) {
180 float const y = i - yCen;
181 float const y2 = y*
y;
183 typename ImageT::x_iterator ptr = image.row_begin(i);
184 for (
int j = 0; j < image.getWidth(); ++j, ++ptr) {
185 float const x = j - xCen;
186 float const x2 = x*
x;
187 float const expon = (x2 + y2)*w11;
190 float const weight = exp(-0.5*expon);
191 float const tmod = *ptr;
192 float const ymod = tmod*weight;
194 sumrr += (x2 + y2)*ymod;
199 if (sum <= 0 || sumrr < 0) {
200 return std::make_pair(
false, std::numeric_limits<double>::quiet_NaN());
203 return std::make_pair(
true, 0.5*sumrr/sum);
214 template<
typename ImageT>
216 computeSecondMomentAdaptive(ImageT
const& image,
217 float const xCen,
float const yCen
220 int const MAXIT = 100;
221 float const TOL = 0.0001;
223 float sigma11_ow_old = 1e6;
225 bool unweighted =
false;
228 std::pair<bool, double> moments = calcmom(*image, xCen, yCen, w11);
230 if (not moments.first) {
237 float const sigma11_ow = moments.second;
239 if (iter > 0 && fabs(sigma11_ow/sigma11_ow_old - 1.0) < TOL) {
243 sigma11_ow_old = sigma11_ow;
263 w11 = 1/sigma11_ow - w11;
275 if (iter == MAXIT || unweighted) {
277 std::pair<bool, double> moments = calcmom(*image, xCen, yCen, w11);
280 sigma11W = moments.second;
316 source->setFootprint(foot);
317 ms.
apply(*source, *exposure, center);
320 float const xCen = centroid.getX() -
_psfImage->getX0();
321 float const yCen = centroid.getY() -
_psfImage->getY0();
325 return ::sqrt(0.5*computeSecondMomentAdaptive(
_psfImage, xCen, yCen));
329 return ::sqrt(0.5*computeSecondMoment(
_psfImage, xCen, yCen));
336 for (
int iY = 0; iY !=
_psfImage->getHeight(); ++iY) {
339 end =
_psfImage->row_end(iY); ptr != end;
341 double const x = iX - xCen;
342 double const y = iY - yCen;
343 double const r = std::sqrt( x*x + y*y );
344 double const m = (*ptr)*r;
345 norm += (*ptr)*(*ptr);
349 return sqrt(sum/norm);
364 for (
int iY = 0; iY !=
_psfImage->getHeight(); ++iY) {
368 sumsqr += (*ptr)*(*ptr);
371 return sum*sum/sumsqr;
Calculate width as sqrt(n_eff/(4 pi))
Defines the fields and offsets for a table.
Field< MeasTag >::Value MeasValue
the value type used for the measurement
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.
Support for PCA analysis of 2-D images.
A class to contain the data, WCS, and other information needed to describe an image of the sky...
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.
C++ control object for Gaussian centroid.
MeasureSourcesBuilder & addAlgorithm(AlgorithmControl const &algorithmControl)
Add an algorithm defined by a control object.
table::Key< table::Array< Kernel::Pixel > > image
Calculate width using <r^2>
double const PI
The ratio of a circle's circumference to diameter.
boost::shared_ptr< lsst::afw::image::Image< double > > _psfImage
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) )
MeasureSources build(afw::table::Schema &schema, boost::shared_ptr< daf::base::PropertyList > const &metadata=boost::shared_ptr< daf::base::PropertyList >()) const
Build a MeasureSources object.
Calculate width using <r>
void apply(afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure, afw::geom::Point2D const ¢er, bool refineCenter=true) const
Apply the registered algorithms to the given source.
boost::shared_ptr< lsst::afw::image::Image< double > > _psfImage
static Schema makeMinimalSchema()
Return a minimal schema for Source tables and records.
Table class that contains measurements made on a single exposure.
#define LSST_EXCEPT(type,...)
static boost::shared_ptr< SourceTable > make(Schema const &schema, boost::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
Weight <r^2> by I^2 to avoid negative fluxes.
A class used as a handle to a particular field in a table.
Calculate width using adaptive Gaussian weights.
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 >())
Record class that contains measurements made on a single exposure.
x_iterator row_begin(int y) const
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.
Point< double, 2 > PointD