static void wcslib_radec_bounds(const anwcs_t* genwcs, const anwcslib_t* wcs, int stepsize, double* pramin, double* pramax, double* pdecmin, double* pdecmax) { struct radecbounds b; anwcs_get_radec_center_and_radius(genwcs, &(b.rac), &(b.decc), NULL); b.ramin = b.ramax = b.rac; b.decmin = b.decmax = b.decc; anwcs_walk_image_boundary(genwcs, stepsize, radec_bounds_callback, &b); // Check for poles... // north pole if (anwcs_radec_is_inside_image(genwcs, 0, 90)) { b.ramin = 0; b.ramax = 360; b.decmax = 90; } if (anwcs_radec_is_inside_image(genwcs, 0, -90)) { b.ramin = 0; b.ramax = 360; b.decmin = -90; } if (pramin) *pramin = b.ramin; if (pramax) *pramax = b.ramax; if (pdecmin) *pdecmin = b.decmin; if (pdecmax) *pdecmax = b.decmax; }
int coadd_add_image(coadd_t* ca, const number* img, const number* weightimg, number weight, const anwcs_t* wcs) { int W, H; int i, j; int xlo,xhi,ylo,yhi; check_bounds_t cb; W = anwcs_imagew(wcs); H = anwcs_imageh(wcs); // if check_bounds: cb.xlo = W; cb.xhi = 0; cb.ylo = H; cb.yhi = 0; cb.wcs = ca->wcs; anwcs_walk_image_boundary(wcs, 50, check_bounds, &cb); xlo = MAX(0, floor(cb.xlo)); xhi = MIN(ca->W, ceil(cb.xhi)+1); ylo = MAX(0, floor(cb.ylo)); yhi = MIN(ca->H, ceil(cb.yhi)+1); logmsg("Image projects to output image region: [%i,%i), [%i,%i)\n", xlo, xhi, ylo, yhi); for (i=ylo; i<yhi; i++) { for (j=xlo; j<xhi; j++) { double ra, dec; double px, py; double wt; double val; // +1 for FITS if (anwcs_pixelxy2radec(ca->wcs, j+1, i+1, &ra, &dec)) { ERROR("Failed to project pixel (%i,%i) through output WCS\n", j, i); continue; } if (anwcs_radec2pixelxy(wcs, ra, dec, &px, &py)) { ERROR("Failed to project pixel (%i,%i) through input WCS\n", j, i); continue; } // -1 for FITS px -= 1; py -= 1; if (px < 0 || px >= W) continue; if (py < 0 || py >= H) continue; val = ca->resample_func(px, py, img, weightimg, W, H, &wt, ca->resample_token); ca->img[i*ca->W + j] += val * weight; ca->weight[i*ca->W + j] += wt * weight; } logverb("Row %i of %i\n", i+1, ca->H); } return 0; }