31 namespace algorithms {
36 const Image<double>& im, PixelList& pix,
37 const Position cen,
double sky,
double noise,
double gain,
38 const Image<double>* weightImage,
const Transformation& trans,
39 double aperture,
double xOffset,
double yOffset,
long& flag)
41 xdbg<<
"Start GetPixList\n";
43 xdbg<<
"Using weight image for pixel noise.\n";
45 xdbg<<
"noise = "<<noise<<std::endl;
46 xdbg<<
"gain = "<<gain<<std::endl;
50 trans.getDistortion(cen,D);
54 xdbg<<
"D = "<<D<<std::endl;
55 double det = std::abs(D.TMV_det());
56 double pixScale = sqrt(det);
57 xdbg<<
"pixscale = "<<pixScale<<std::endl;
61 double xAp = aperture * sqrt(D(1,0)*D(1,0) + D(1,1)*D(1,1))/det;
62 double yAp = aperture * sqrt(D(0,0)*D(0,0) + D(0,1)*D(0,1))/det;
63 xdbg<<
"aperture = "<<aperture<<std::endl;
64 xdbg<<
"xap = "<<xAp<<
", yap = "<<yAp<<std::endl;
66 int xMin = im.getXMin();
67 int yMin = im.getYMin();
69 double xCen = cen.getX();
70 double yCen = cen.getY();
71 xdbg<<
"cen = "<<xCen<<
" "<<yCen<<std::endl;
72 xdbg<<
"xmin, ymin = "<<xMin<<
" "<<yMin<<std::endl;
82 int i1 = int(
floor(xCen-xAp-xMin));
83 int i2 = int(
ceil(xCen+xAp-xMin));
84 int j1 = int(
floor(yCen-yAp-yMin));
85 int j2 = int(
ceil(yCen+yAp-yMin));
86 xdbg<<
"i1,i2,j1,j2 = "<<i1<<
','<<i2<<
','<<j1<<
','<<j2<<std::endl;
88 if (i1 < 0) { i1 = 0; flag |= EDGE; }
89 if (i2 >
int(im.getMaxI())) { i2 = im.getMaxI(); flag |= EDGE; }
90 if (j1 < 0) { j1 = 0; flag |= EDGE; }
91 if (j2 >
int(im.getMaxJ())) { j2 = im.getMaxJ(); flag |= EDGE; }
92 xdbg<<
"i1,i2,j1,j2 => "<<i1<<
','<<i2<<
','<<j1<<
','<<j2<<std::endl;
94 double apsq = aperture*aperture;
101 xdbg<<
"nx = "<<i2-i1+1<<std::endl;
102 xdbg<<
"ny = "<<j2-j1+1<<std::endl;
105 std::vector<std::vector<bool> > shouldUsePix(
106 i2-i1+1,std::vector<bool>(j2-j1+1,
false));
109 double chipX = xMin+i1-xCen;
111 for(
int i=i1;i<=i2;++i,chipX+=1.) {
112 double chipY = yMin+j1-yCen;
113 double u = D(0,0)*chipX+D(0,1)*chipY;
114 double v = D(1,0)*chipX+D(1,1)*chipY;
115 for(
int j=j1;j<=j2;++j,u+=D(0,1),v+=D(1,1)) {
116 double rsq = u*u+v*v;
118 shouldUsePix[i-i1][j-j1] =
true;
120 if (im(i,j) > peak) peak = im(i,j);
125 xdbg<<
"npix = "<<nPix<<std::endl;
128 xdbg<<
"pixlist size = "<<nPix<<
" = "<<nPix*
sizeof(Pixel)<<
129 " bytes = "<<nPix*
sizeof(Pixel)/1024.<<
" KB\n";
132 chipX = xMin+i1-xCen;
133 xdbg<<
"Bright pixels are:\n";
135 for(
int i=i1;i<=i2;++i,chipX+=1.) {
136 double chipY = yMin+j1-yCen;
137 double u = D(0,0)*chipX+D(0,1)*chipY;
138 double v = D(1,0)*chipX+D(1,1)*chipY;
139 for(
int j=j1;j<=j2;++j,u+=D(0,1),v+=D(1,1)) {
140 if (shouldUsePix[i-i1][j-j1]) {
141 double flux = im(i,j)-sky;
142 double inverseVariance;
144 inverseVariance = (*weightImage)(i,j);
147 if (gain != 0.) var += im(i,j)/gain;
148 inverseVariance = 1./var;
150 if (inverseVariance > 0.0) {
151 double inverseSigma = sqrt(inverseVariance);
152 Assert(k <
int(pix.size()));
153 Pixel p(u,v,flux,inverseSigma);
155 if (flux > peak / 10.) {
156 xdbg<<p.getPos()<<
" "<<p.getFlux()<<std::endl;
162 Assert(k <=
int(pix.size()));
165 Assert(k ==
int(pix.size()));
167 xdbg<<
"npix => "<<nPix<<std::endl;
168 if (nPix < 10) flag |= LT10PIX;
172 const Image<double>& bkg,
173 const Position cen,
const Transformation& trans,
double aperture,
174 double xOffset,
double yOffset,
long& flag)
181 xdbg<<
"Start GetLocalSky\n";
184 trans.getDistortion(cen,D);
186 double det = std::abs(D.TMV_det());
187 double pixScale = sqrt(det);
188 xdbg<<
"pixscale = "<<pixScale<<std::endl;
192 double xAp = aperture / det *
193 sqrt(D(0,0)*D(0,0) + D(0,1)*D(0,1));
194 double yAp = aperture / det *
195 sqrt(D(1,0)*D(1,0) + D(1,1)*D(1,1));
196 xdbg<<
"aperture = "<<aperture<<std::endl;
197 xdbg<<
"xap = "<<xAp<<
", yap = "<<yAp<<std::endl;
199 int xMin = bkg.getXMin();
200 int yMin = bkg.getYMin();
202 double xCen = cen.getX();
203 double yCen = cen.getY();
204 xdbg<<
"cen = "<<xCen<<
" "<<yCen<<std::endl;
205 xdbg<<
"xmin, ymin = "<<xMin<<
" "<<yMin<<std::endl;
209 int i1 = int(
floor(xCen-xAp-xMin));
210 int i2 = int(
ceil(xCen+xAp-xMin));
211 int j1 = int(
floor(yCen-yAp-yMin));
212 int j2 = int(
ceil(yCen+yAp-yMin));
213 xdbg<<
"i1,i2,j1,j2 = "<<i1<<
','<<i2<<
','<<j1<<
','<<j2<<std::endl;
214 if (i1 < 0) { i1 = 0; }
215 if (i2 >
int(bkg.getMaxI())) { i2 = bkg.getMaxI(); }
216 if (j1 < 0) { j1 = 0; }
217 if (j2 >
int(bkg.getMaxJ())) { j2 = bkg.getMaxJ(); }
218 xdbg<<
"i1,i2,j1,j2 => "<<i1<<
','<<i2<<
','<<j1<<
','<<j2<<std::endl;
220 double apsq = aperture*aperture;
222 xdbg<<
"nx = "<<i2-i1+1<<std::endl;
223 xdbg<<
"ny = "<<j2-j1+1<<std::endl;
230 double chipX = xMin+i1-xCen;
231 for(
int i=i1;i<=i2;++i,chipX+=1.) {
232 double chipY = yMin+j1-yCen;
233 double u = D(0,0)*chipX+D(0,1)*chipY;
234 double v = D(1,0)*chipX+D(1,1)*chipY;
235 for(
int j=j1;j<=j2;++j,u+=D(0,1),v+=D(1,1)) {
237 double rsq = u*u + v*v;
245 xdbg<<
"nPix = "<<nPix<<std::endl;
246 if (nPix == 0) { flag |= BKG_NOPIX;
return 0.; }
249 xdbg<<
"meansky = "<<meanSky<<std::endl;
256 std::complex<double> cen_offset, std::complex<double> shear,
257 double aperture,
long& flag)
260 const int nTot = allPix.
size();
261 xdbg<<
"Start GetSubPixList\n";
262 xdbg<<
"allPix has "<<nTot<<
" objects\n";
263 xdbg<<
"new aperture = "<<aperture<<std::endl;
264 xdbg<<
"cen_offset = "<<cen_offset<<std::endl;
265 xdbg<<
"shear = "<<shear<<std::endl;
267 double normg =
norm(shear);
268 double g1 =
real(shear);
269 double g2 = imag(shear);
270 double apsq = aperture*aperture;
277 std::vector<bool> shouldUsePix(nTot,
false);
281 for(
int i=0;i<nTot;++i) {
282 std::complex<double> z = allPix[i].getPos() - cen_offset;
289 double rsq = (1.+normg)*(usq+vsq) - 2.*g1*(usq-vsq) - 4.*g2*u*v;
293 shouldUsePix[i] =
true;
295 if (allPix[i].getFlux() > peak) peak = allPix[i].getFlux();
299 xdbg<<
"npix = "<<nPix<<std::endl;
302 xdbg<<
"pixlist size = "<<nPix<<
" = "<<nPix*
sizeof(
Pixel)<<
303 " bytes = "<<nPix*
sizeof(
Pixel)/1024.<<
" KB\n";
306 xdbg<<
"Bright pixels are:\n";
307 for(
int i=0;i<nTot;++i)
if(shouldUsePix[i]) {
311 if (p.
getFlux() > peak / 10.) {
317 if (nPix < 10) flag |= LT10PIX;
std::complex< double > getPos() const
void setPos(const std::complex< double > &pos)
Extent< int, N > ceil(Extent< double, N > const &input)
void getSubPixList(PixelList &pix, const PixelList &allPix, std::complex< double > cen_offset, std::complex< double > shear, double aperture, long &flag)
Extent< int, N > floor(Extent< double, N > const &input)
Eigen::Matrix< double, 2, 2 > DSmallMatrix22