1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/*** File saoimage/wcslib/dsspos.c
*** October 21, 1999
*** By Doug Mink, dmink@cfa.harvard.edu
*** Harvard-Smithsonian Center for Astrophysics
* Module: dsspos.c (Plate solution WCS conversion)
* Purpose: Compute WCS from Digital Sky Survey plate fit
* Subroutine: dsspos() converts from pixel location to RA,Dec
* Subroutine: dsspix() converts from RA,Dec to pixel location
These functions are based on the astrmcal.c portion of GETIMAGE by
J. Doggett and the documentation distributed with the Digital Sky Survey.
*/
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "vimoswcs.h"
int
dsspos (xpix, ypix, vimoswcs, xpos, ypos)
/* Routine to determine accurate position for pixel coordinates */
/* returns 0 if successful otherwise 1 = angle too large for projection; */
/* based on amdpos() from getimage */
/* Input: */
double xpix; /* x pixel number (RA or long without rotation) */
double ypix; /* y pixel number (dec or lat without rotation) */
struct WorldCoor *vimoswcs; /* WCS parameter structure */
/* Output: */
double *xpos; /* Right ascension or longitude in degrees */
double *ypos; /* Declination or latitude in degrees */
{
double x, y, xmm, ymm, xmm2, ymm2, xmm3, ymm3, x2y2;
double xi, xir, eta, etar, raoff, ra, dec;
double cond2r = 1.745329252e-2;
double cons2r = 206264.8062470964;
double twopi = 6.28318530717959;
double ctan, ccos;
/* Ignore magnitude and color terms
double mag = 0.0;
double color = 0.0; */
/* Convert from image pixels to plate pixels */
x = xpix + vimoswcs->x_pixel_offset - 1.0 + 0.5;
y = ypix + vimoswcs->y_pixel_offset - 1.0 + 0.5;
/* Convert from pixels to millimeters */
xmm = (vimoswcs->ppo_coeff[2] - x * vimoswcs->x_pixel_size) / 1000.0;
ymm = (y * vimoswcs->y_pixel_size - vimoswcs->ppo_coeff[5]) / 1000.0;
xmm2 = xmm * xmm;
ymm2 = ymm * ymm;
xmm3 = xmm * xmm2;
ymm3 = ymm * ymm2;
x2y2 = xmm2 + ymm2;
/* Compute coordinates from x,y and plate model */
xi = vimoswcs->x_coeff[ 0]*xmm + vimoswcs->x_coeff[ 1]*ymm +
vimoswcs->x_coeff[ 2] + vimoswcs->x_coeff[ 3]*xmm2 +
vimoswcs->x_coeff[ 4]*xmm*ymm + vimoswcs->x_coeff[ 5]*ymm2 +
vimoswcs->x_coeff[ 6]*(x2y2) + vimoswcs->x_coeff[ 7]*xmm3 +
vimoswcs->x_coeff[ 8]*xmm2*ymm + vimoswcs->x_coeff[ 9]*xmm*ymm2 +
vimoswcs->x_coeff[10]*ymm3 + vimoswcs->x_coeff[11]*xmm*(x2y2) +
vimoswcs->x_coeff[12]*xmm*x2y2*x2y2;
/* Ignore magnitude and color terms
+ vimoswcs->x_coeff[13]*mag + vimoswcs->x_coeff[14]*mag*mag +
vimoswcs->x_coeff[15]*mag*mag*mag + vimoswcs->x_coeff[16]*mag*xmm +
vimoswcs->x_coeff[17]*mag*x2y2 + vimoswcs->x_coeff[18]*mag*xmm*x2y2 +
vimoswcs->x_coeff[19]*color; */
eta = vimoswcs->y_coeff[ 0]*ymm + vimoswcs->y_coeff[ 1]*xmm +
vimoswcs->y_coeff[ 2] + vimoswcs->y_coeff[ 3]*ymm2 +
vimoswcs->y_coeff[ 4]*xmm*ymm + vimoswcs->y_coeff[ 5]*xmm2 +
vimoswcs->y_coeff[ 6]*(x2y2) + vimoswcs->y_coeff[ 7]*ymm3 +
vimoswcs->y_coeff[ 8]*ymm2*xmm + vimoswcs->y_coeff[ 9]*ymm*xmm2 +
vimoswcs->y_coeff[10]*xmm3 + vimoswcs->y_coeff[11]*ymm*(x2y2) +
vimoswcs->y_coeff[12]*ymm*x2y2*x2y2;
/* Ignore magnitude and color terms
+ vimoswcs->y_coeff[13]*mag + vimoswcs->y_coeff[14]*mag*mag +
vimoswcs->y_coeff[15]*mag*mag*mag + vimoswcs->y_coeff[16]*mag*ymm +
vimoswcs->y_coeff[17]*mag*x2y2) + vimoswcs->y_coeff[18]*mag*ymm*x2y2 +
vimoswcs->y_coeff[19]*color; */
/* Convert to radians */
xir = xi / cons2r;
etar = eta / cons2r;
/* Convert to RA and Dec */
ctan = tan (vimoswcs->plate_dec);
ccos = cos (vimoswcs->plate_dec);
raoff = atan2 (xir / ccos, 1.0 - etar * ctan);
ra = raoff + vimoswcs->plate_ra;
if (ra < 0.0) ra = ra + twopi;
*xpos = ra / cond2r;
dec = atan (cos (raoff) * ((etar + ctan) / (1.0 - (etar * ctan))));
*ypos = dec / cond2r;
return 0;
}
int
dsspix (xpos, ypos, vimoswcs, xpix, ypix)
/* Routine to determine pixel coordinates for sky position */
/* returns 0 if successful otherwise 1 = angle too large for projection; */
/* based on amdinv() from getimage */
/* Input: */
double xpos; /* Right ascension or longitude in degrees */
double ypos; /* Declination or latitude in degrees */
struct WorldCoor *vimoswcs; /* WCS parameter structure */
/* Output: */
double *xpix; /* x pixel number (RA or long without rotation) */
double *ypix; /* y pixel number (dec or lat without rotation) */
{
double div,xi,eta,x,y,xy,x2,y2,x2y,y2x,x3,y3,x4,y4,x2y2,cjunk,dx,dy;
double sypos,cypos,syplate,cyplate,sxdiff,cxdiff;
double f,fx,fy,g,gx,gy, xmm, ymm;
double conr2s = 206264.8062470964;
double tolerance = 0.0000005;
int max_iterations = 50;
int i;
double xr, yr; /* position in radians */
*xpix = 0.0;
*ypix = 0.0;
/* Convert RA and Dec in radians to standard coordinates on a plate */
xr = degrad (xpos);
yr = degrad (ypos);
sypos = sin (yr);
cypos = cos (yr);
if (vimoswcs->plate_dec == 0.0)
vimoswcs->plate_dec = degrad (vimoswcs->yref);
syplate = sin (vimoswcs->plate_dec);
cyplate = cos (vimoswcs->plate_dec);
if (vimoswcs->plate_ra == 0.0)
vimoswcs->plate_ra = degrad (vimoswcs->yref);
sxdiff = sin (xr - vimoswcs->plate_ra);
cxdiff = cos (xr - vimoswcs->plate_ra);
div = (sypos * syplate) + (cypos * cyplate * cxdiff);
if (div == 0.0)
return (1);
xi = cypos * sxdiff * conr2s / div;
eta = ((sypos * cyplate) - (cypos * syplate * cxdiff)) * conr2s / div;
/* Set initial value for x,y */
if (vimoswcs->plate_scale == 0.0)
return (1);
xmm = xi / vimoswcs->plate_scale;
ymm = eta / vimoswcs->plate_scale;
/* Iterate by Newton's method */
for (i = 0; i < max_iterations; i++) {
/* X plate model */
xy = xmm * ymm;
x2 = xmm * xmm;
y2 = ymm * ymm;
x2y = x2 * ymm;
y2x = y2 * xmm;
x2y2 = x2 + y2;
cjunk = x2y2 * x2y2;
x3 = x2 * xmm;
y3 = y2 * ymm;
x4 = x2 * x2;
y4 = y2 * y2;
f = vimoswcs->x_coeff[0]*xmm + vimoswcs->x_coeff[1]*ymm +
vimoswcs->x_coeff[2] + vimoswcs->x_coeff[3]*x2 +
vimoswcs->x_coeff[4]*xy + vimoswcs->x_coeff[5]*y2 +
vimoswcs->x_coeff[6]*x2y2 + vimoswcs->x_coeff[7]*x3 +
vimoswcs->x_coeff[8]*x2y + vimoswcs->x_coeff[9]*y2x +
vimoswcs->x_coeff[10]*y3 + vimoswcs->x_coeff[11]*xmm*x2y2 +
vimoswcs->x_coeff[12]*xmm*cjunk;
/* magnitude and color terms ignored
+ vimoswcs->x_coeff[13]*mag +
vimoswcs->x_coeff[14]*mag*mag + vimoswcs->x_coeff[15]*mag*mag*mag +
vimoswcs->x_coeff[16]*mag*xmm + vimoswcs->x_coeff[17]*mag*(x2+y2) +
vimoswcs->x_coeff[18]*mag*xmm*(x2+y2) + vimoswcs->x_coeff[19]*color;
*/
/* Derivative of X model wrt x */
fx = vimoswcs->x_coeff[0] + vimoswcs->x_coeff[3]*2.0*xmm +
vimoswcs->x_coeff[4]*ymm + vimoswcs->x_coeff[6]*2.0*xmm +
vimoswcs->x_coeff[7]*3.0*x2 + vimoswcs->x_coeff[8]*2.0*xy +
vimoswcs->x_coeff[9]*y2 + vimoswcs->x_coeff[11]*(3.0*x2+y2) +
vimoswcs->x_coeff[12]*(5.0*x4 +6.0*x2*y2+y4);
/* magnitude and color terms ignored
vimoswcs->x_coeff[16]*mag + vimoswcs->x_coeff[17]*mag*2.0*xmm +
vimoswcs->x_coeff[18]*mag*(3.0*x2+y2);
*/
/* Derivative of X model wrt y */
fy = vimoswcs->x_coeff[1] + vimoswcs->x_coeff[4]*xmm +
vimoswcs->x_coeff[5]*2.0*ymm + vimoswcs->x_coeff[6]*2.0*ymm +
vimoswcs->x_coeff[8]*x2 + vimoswcs->x_coeff[9]*2.0*xy +
vimoswcs->x_coeff[10]*3.0*y2 + vimoswcs->x_coeff[11]*2.0*xy +
vimoswcs->x_coeff[12]*4.0*xy*x2y2;
/* magnitude and color terms ignored
vimoswcs->x_coeff[17]*mag*2.0*ymm +
vimoswcs->x_coeff[18]*mag*2.0*xy;
*/
/* Y plate model */
g = vimoswcs->y_coeff[0]*ymm + vimoswcs->y_coeff[1]*xmm +
vimoswcs->y_coeff[2] + vimoswcs->y_coeff[3]*y2 +
vimoswcs->y_coeff[4]*xy + vimoswcs->y_coeff[5]*x2 +
vimoswcs->y_coeff[6]*x2y2 + vimoswcs->y_coeff[7]*y3 +
vimoswcs->y_coeff[8]*y2x + vimoswcs->y_coeff[9]*x2y +
vimoswcs->y_coeff[10]*x3 + vimoswcs->y_coeff[11]*ymm*x2y2 +
vimoswcs->y_coeff[12]*ymm*cjunk;
/* magnitude and color terms ignored
vimoswcs->y_coeff[13]*mag + vimoswcs->y_coeff[14]*mag*mag +
vimoswcs->y_coeff[15]*mag*mag*mag + vimoswcs->y_coeff[16]*mag*ymm +
vimoswcs->y_coeff[17]*mag*x2y2 +
vimoswcs->y_coeff[18]*mag*ymm*x2y2 + vimoswcs->y_coeff[19]*color;
*/
/* Derivative of Y model wrt x */
gx = vimoswcs->y_coeff[1] + vimoswcs->y_coeff[4]*ymm +
vimoswcs->y_coeff[5]*2.0*xmm + vimoswcs->y_coeff[6]*2.0*xmm +
vimoswcs->y_coeff[8]*y2 + vimoswcs->y_coeff[9]*2.0*xy +
vimoswcs->y_coeff[10]*3.0*x2 + vimoswcs->y_coeff[11]*2.0*xy +
vimoswcs->y_coeff[12]*4.0*xy*x2y2;
/* magnitude and color terms ignored
vimoswcs->y_coeff[17]*mag*2.0*xmm +
vimoswcs->y_coeff[18]*mag*ymm*2.0*xmm;
*/
/* Derivative of Y model wrt y */
gy = vimoswcs->y_coeff[0] + vimoswcs->y_coeff[3]*2.0*ymm +
vimoswcs->y_coeff[4]*xmm + vimoswcs->y_coeff[6]*2.0*ymm +
vimoswcs->y_coeff[7]*3.0*y2 + vimoswcs->y_coeff[8]*2.0*xy +
vimoswcs->y_coeff[9]*x2 + vimoswcs->y_coeff[11]*(x2+3.0*y2) +
vimoswcs->y_coeff[12]*(5.0*y4 + 6.0*x2*y2 + x4);
/* magnitude and color terms ignored
vimoswcs->y_coeff[16]*mag + vimoswcs->y_coeff[17]*mag*2.0*ymm +
vimoswcs->y_coeff[18]*mag*(x2+3.0*y2);
*/
f = f - xi;
g = g - eta;
dx = ((-f * gy) + (g * fy)) / ((fx * gy) - (fy * gx));
dy = ((-g * fx) + (f * gx)) / ((fx * gy) - (fy * gx));
xmm = xmm + dx;
ymm = ymm + dy;
if ((fabs(dx) < tolerance) && (fabs(dy) < tolerance)) break;
}
/* Convert mm from plate center to plate pixels */
if (vimoswcs->x_pixel_size == 0.0 || vimoswcs->y_pixel_size == 0.0)
return (1);
x = (vimoswcs->ppo_coeff[2] - xmm*1000.0) / vimoswcs->x_pixel_size;
y = (vimoswcs->ppo_coeff[5] + ymm*1000.0) / vimoswcs->y_pixel_size;
/* Convert from plate pixels to image pixels */
*xpix = x - vimoswcs->x_pixel_offset + 1.0 - 0.5;
*ypix = y - vimoswcs->y_pixel_offset + 1.0 - 0.5;
/* If position is off of the image, return offscale code */
if (*xpix < 0.5 || *xpix > vimoswcs->nxpix+0.5)
return -1;
if (*ypix < 0.5 || *ypix > vimoswcs->nypix+0.5)
return -1;
return 0;
}
/* Mar 6 1995 Original version of this code
* May 4 1995 Fix eta cross terms which were all in y
* Jun 21 1995 Add inverse routine
* Oct 17 1995 Fix inverse routine (degrees -> radians)
* Nov 7 1995 Add half pixel to image coordinates to get astrometric
* plate coordinates
* Feb 26 1996 Fix plate to image pixel conversion error
*
* Mar 23 1998 Change names from plate*() to dss*()
* Apr 7 1998 Change amd_i_coeff to i_coeff
* Sep 4 1998 Fix possible divide by zero in dsspos() from Allen Harris, SAO
* Sep 10 1998 Fix possible divide by zero in dsspix() from Allen Harris, SAO
*
* Oct 21 1999 Drop declaration of cond2r in dsspix()
*/
|