40 namespace algorithms {
83 _cov->TMV_colsize() == rhs.
_cov->TMV_colsize() &&
84 _cov->TMV_rowsize() == rhs.
_cov->TMV_rowsize()) {
97 std::complex<double>
getPQ(
int p,
int q)
101 if (p < q)
return std::conj(
getPQ(q,p));
108 int k = (p+q)*(p+q+1)/2 + 2*q;
109 return std::complex<double>(v(k),v(k+1));
132 std::complex<double> z(x,y);
142 boost::shared_ptr<ShapeletCovariance>
_cov;
201 #if 0 // crashes g++ 4.3.5
221 J(0,0) = localTransform.
getMatrix()(0,0) * 3600.;
222 J(0,1) = localTransform.
getMatrix()(0,1) * 3600.;
223 J(1,0) = localTransform.
getMatrix()(1,0) * 3600.;
224 J(1,1) = localTransform.
getMatrix()(1,1) * 3600.;
230 static void getPixList(
231 shapelet::PixelList& pix,
238 using shapelet::Pixel;
239 using shapelet::PixelList;
243 Shapelet::Exposure::MaskedImageT::Image::ConstPtr imagePtr = maskedImage.
getImage();
244 Shapelet::Exposure::MaskedImageT::Mask::ConstPtr maskPtr = maskedImage.getMask();
245 Shapelet::Exposure::MaskedImageT::Variance::ConstPtr variancePtr = maskedImage.getVariance();
247 PointD pos(source.getX(),source.getY());
248 Eigen::Matrix2d J =
getJacobian(*(exposure.getWcs()), pos);
250 double det = std::abs(J.determinant());
251 double pixScale = sqrt(det);
252 xdbg<<
"pixscale = "<<pixScale<<std::endl;
256 double xAp = aperture / det *
257 sqrt(J(0,0)*J(0,0) + J(0,1)*J(0,1));
258 double yAp = aperture / det *
259 sqrt(J(1,0)*J(1,0) + J(1,1)*J(1,1));
260 xdbg<<
"aperture = "<<aperture<<std::endl;
261 xdbg<<
"xap = "<<xAp<<
", yap = "<<yAp<<std::endl;
263 double xCen = cen.getX();
264 double yCen = cen.getY();
265 xdbg<<
"cen = "<<xCen<<
" "<<yCen<<std::endl;
268 int i1 = int(
floor(xCen-xAp));
269 int i2 = int(
ceil(xCen+xAp));
270 int j1 = int(
floor(yCen-yAp));
271 int j2 = int(
ceil(yCen+yAp));
272 xdbg<<
"i1,i2,j1,j2 = "<<i1<<
','<<i2<<
','<<j1<<
','<<j2<<std::endl;
280 int xMin = exposure.getX0();
281 int yMin = exposure.getY0();
282 int xMax = xMin + exposure.getWidth();
283 int yMax = yMin + exposure.getHeight();
284 xdbg<<
"xMin, yMin = "<<xMin<<
" "<<yMin<<std::endl;
285 if (i1 < xMin) { i1 = xMin; }
286 if (i2 > xMax) { i2 = xMax; }
287 if (j1 < yMin) { j1 = yMin; }
288 if (j2 > yMax) { j2 = yMax; }
289 xdbg<<
"i1,i2,j1,j2 => "<<i1<<
','<<i2<<
','<<j1<<
','<<j2<<std::endl;
296 xdbg<<
"nx = "<<i2-i1+1<<std::endl;
297 xdbg<<
"ny = "<<j2-j1+1<<std::endl;
300 std::vector<std::vector<bool> > shouldUsePix(
301 i2-i1+1,std::vector<bool>(j2-j1+1,
false));
304 const double apsq = aperture*aperture;
306 double chipX = i1-xCen;
307 for(
int i=i1;i<=i2;++i,chipX+=1.) {
308 double chipY = j1-yCen;
309 double u = J(0,0)*chipX+J(0,1)*chipY;
310 double v = J(1,0)*chipX+J(1,1)*chipY;
311 for(
int j=j1;j<=j2;++j,u+=J(0,1),v+=J(1,1)) {
313 double rsq = u*u + v*v;
314 if ( ((*maskPtr)(i,j) & ~okmask) &&
316 shouldUsePix[i-i1][j-j1] =
true;
322 xdbg<<
"npix = "<<nPix<<std::endl;
325 xdbg<<
"pixlist size = "<<nPix<<
" = "<<nPix*
sizeof(Pixel)<<
" bytes = "
326 <<nPix*
sizeof(Pixel)/1024.<<
" KB\n";
333 for(
int i=i1;i<=i2;++i,chipX+=1.) {
334 double chipY = j1-yCen;
335 double u = J(0,0)*chipX+J(0,1)*chipY;
336 double v = J(1,0)*chipX+J(1,1)*chipY;
337 for(
int j=j1;j<=j2;++j,u+=J(0,1),v+=J(1,1)) {
338 if (shouldUsePix[i-i1][j-j1]) {
339 double flux = (*imagePtr)(i,j)-sky;
340 double variance = (*variancePtr)(i,j);
341 if (variance > 0.0) {
342 double inverseSigma = sqrt(1.0/variance);
343 Assert(k <
int(pix.size()));
344 pix[k++] = Pixel(u,v,flux,inverseSigma);
349 Assert(k <=
int(pix.size()));
353 Assert(k ==
int(pix.size()));
355 xdbg<<
"npix => "<<nPix<<std::endl;
360 bool isCentroidFixed,
bool isSigmaFixed,
double aperture,
367 std::vector<PixelList> pix(1);
369 getPixList(pix[0], source, pos, aperture, exposure, okmask);
374 if (isCentroidFixed) ell.fixCen();
380 ell.peakCentroid(pix[0],aperture/3.);
381 ell.crudeMeasure(pix[0],sigma);
383 if (isSigmaFixed) ell.fixMu();
386 if (!isCentroidFixed || !isSigmaFixed) {
387 if (!ell.measure(pix,order,order+4,order,sigma,flag,1.e-4)) {
390 if (flag)
return false;
392 double mu = ell.getMu();
394 dbg<<
"sigma = "<<sigma<<std::endl;
401 if (ell.measureShapelet(pix,*
pImpl,order,order+4,order,cov)) {
Eigen::VectorXcd CDVector
boost::uint16_t MaskPixel
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's image.
An include file to include the header files for lsst::afw::geom.
const ShapeletVector & getValues() const
get the values as a vector.
~Shapelet()
Destructor needs to delete pImpl.
ShapeletImpl(const BVec &rhs)
void setSigma(double sigma)
set a new value of sigma
geom::AffineTransform linearizePixelToSky(coord::Coord const &coord, geom::AngleUnit skyUnit=geom::degrees) const
Return the local linear approximation to Wcs::pixelToSky at a point given in sky coordinates.
BVec & operator=(const AssignableToBVec &rhs)
A class to contain the data, WCS, and other information needed to describe an image of the sky...
double evaluateAt(const PointD &pos)
Evaluate f(x,y)
Defines the Shapelet class.
Shapelet::ShapeletCovariance ShapeletCovariance
void operator=(const ShapeletImpl &rhs)
bool measureFromImage(const Source &source, const PointD &pos, bool isCentroidFixed, bool isSigmaFixed, double aperture, const Exposure &exposure, const MaskPixel okmask=0)
measure shapelet decomposition of an image
lsst::afw::geom::PointD PointD
Implementation of the WCS standard for a any projection.
double getSigma() const
get the scale size of the shapelet
int getOrder() const
get the order of the shapelet
const shapelet::BVec & viewAsBVec() const
View the shapelet as a BVec.
Extent< int, N > ceil(Extent< double, N > const &input)
Shapelet & operator=(const Shapelet &rhs)
op= does a deep copy
ShapeletImpl(int order, double sigma)
Eigen::MatrixXd ShapeletCovariance
afw::table::Key< double > sigma
boost::shared_ptr< ShapeletCovariance > _cov
void makePsi(DMatrix &psi, CDVectorView z, int order, const DVector *coeff=0)
std::complex< double > getPQ(int p, int q)
lsst::afw::table::SourceRecord Source
ShapeletImpl(const ShapeletImpl &rhs)
bool hasCovariance() const
does the shapelet have a covariance matrix stored?
boost::shared_ptr< const ShapeletCovariance > getCovariance() const
get the covariance matrix
Eigen::Matrix2d getJacobian(const lsst::afw::image::Wcs &wcs, const lsst::afw::geom::PointD &pos)
a helper function to deal with the fact that Wcs doesn't directly return a Jacobian.
void setSigma(double sigma)
std::complex< double > getPQ(int p, int q)
Get a complex b_pq value.
lsst::afw::image::Exposure< PixelT > Exposure
double evaluateAt(double x, double y)
const DVector & getValues() const
Shapelet::ShapeletVector ShapeletVector
Extent< int, N > floor(Extent< double, N > const &input)
MaskedImage< ImageT, MaskT, VarianceT > MaskedImageT
ShapeletImpl(int order, double sigma, const ShapeletVector &vector)
Point< double, 2 > PointD
Eigen::VectorXd ShapeletVector
Record class that contains measurements made on a single exposure.
Implementation of the Class MaskedImage.
ShapeletImpl(int order, double sigma, const ShapeletVector &vector, const ShapeletCovariance &cov)
int size() const
the size of the shapelet vector
boost::shared_ptr< ShapeletCovariance > & getCovariance()
Shapelet(int order, double sigma)
Basic constructor requires order and sigma.