Changeset 16798
- Timestamp:
- Mar 4, 2008, 12:18:13 PM (18 years ago)
- Location:
- branches/eam_branch_20080223/Ohana/src/relastro
- Files:
-
- 2 added
- 9 edited
-
Makefile (modified) (1 diff)
-
include/relastro.h (modified) (4 diffs)
-
src/FitMosaic.c (modified) (1 diff)
-
src/FitSimple.c (modified) (2 diffs)
-
src/GetAstromError.c (added)
-
src/ImageOps.c (modified) (7 diffs)
-
src/UpdateMeasures.c (added)
-
src/UpdateObjects.c (modified) (1 diff)
-
src/fitpoly.c (modified) (7 diffs)
-
src/mkpolyterm.c (modified) (3 diffs)
-
src/relastro.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080223/Ohana/src/relastro/Makefile
r16040 r16798 37 37 $(SRC)/UpdateObjects.$(ARCH).o \ 38 38 $(SRC)/UpdateSimple.$(ARCH).o \ 39 $(SRC)/UpdateMeasures.$(ARCH).o \ 40 $(SRC)/GetAstromError.$(ARCH).o \ 39 41 $(SRC)/args.$(ARCH).o \ 40 42 $(SRC)/bcatalog.$(ARCH).o \ -
branches/eam_branch_20080223/Ohana/src/relastro/include/relastro.h
r16060 r16798 10 10 } CoordMode; 11 11 12 typedef enum {ERROR_MODE_RA, ERROR_MODE_DEC, ERROR_MODE_POS} ErrorMode; 13 12 14 typedef struct { 13 15 double R, D; /* Sky Coords - degrees */ … … 15 17 double L, M; /* Focal Plane - pixels */ 16 18 double X, Y; /* Chip Coords - pixels */ 17 double Mag, dMag; 19 double Mag; 20 double dMag; 21 double dPos; 18 22 int mask; 19 23 } StarData; … … 263 267 void fit_add (CoordFit *fit, double x1, double y1, double x2, double y2, double wt); 264 268 void fit_eval (CoordFit *fit); 269 void fit_apply (CoordFit *fit, double *x2, double *y2, double x1, double y1); 265 270 double **poly2d_dx (double **poly, int Nx, int Ny); 266 271 double **poly2d_dy (double **poly, int Nx, int Ny); 267 272 double **poly2d_copy (double **poly, int Nx, int Ny); 268 273 double poly2d_eval (double **poly, int Nx, int Ny, double x, double y); 269 voidfit_apply_coords (CoordFit *fit, Coords *coords);274 CoordFit *fit_apply_coords (CoordFit *fit, Coords *coords); 270 275 int CoordsGetCenter (CoordFit *fit, double tol, double *xo, double *yo); 271 276 CoordFit *CoordsSetCenter (CoordFit *input, double Xo, double Yo); … … 278 283 int UpdateChips (Catalog *catalog, int Ncatalog); 279 284 int UpdateMosaic (Catalog *catalog, int Ncatalog); 285 int UpdateMeasures (Catalog *catalog, int Ncatalog); 286 void fixImageRaw (Catalog *catalog, int Ncatalog, int im); 287 280 288 int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon); 281 289 int ParFactor (double *pR, double *pD, double R, double D, time_t T); -
branches/eam_branch_20080223/Ohana/src/relastro/src/FitMosaic.c
r15238 r16798 5 5 int i; 6 6 CoordFit *fit; 7 double dP, dQ, dR; 7 8 8 9 fit = fit_init (coords[0].Npolyterms); 9 10 for (i = 0; i < Nmatch; i++) { 10 11 if (raw[i].mask) continue; 12 13 // require radius of XXX arcsec 14 dP = raw[i].P - ref[i].P; 15 dQ = raw[i].Q - ref[i].Q; 16 dR = 3600.0 * hypot (dP, dQ); 17 18 // XXX the value needs to be set in a more intelligent way 19 if (dR > 0.15) continue; 20 11 21 fit_add (fit, raw[i].L, raw[i].M, ref[i].P, ref[i].Q, 1.0); 22 } 23 if (fit[0].Npts == 0) { 24 fit_free (fit); 25 return; 12 26 } 13 27 fit_eval (fit); -
branches/eam_branch_20080223/Ohana/src/relastro/src/FitSimple.c
r16785 r16798 5 5 int i; 6 6 CoordFit *fit; 7 double dP, dQ, dR; 7 8 8 9 fit = fit_init (coords[0].Npolyterms); 9 10 for (i = 0; i < Nmatch; i++) { 10 11 if (raw[i].mask) continue; 12 13 // require radius of XXX arcsec 14 dP = raw[i].P - ref[i].P; 15 dQ = raw[i].Q - ref[i].Q; 16 dR = 3600.0 * hypot (dP, dQ); 17 18 // XXX the value needs to be set in a more intelligent way 19 if (dR > 0.15) continue; 20 11 21 fit_add (fit, raw[i].X, raw[i].Y, ref[i].P, ref[i].Q, 1.0); 22 } 23 if (fit[0].Npts == 0) { 24 fit_free (fit); 25 return; 12 26 } 13 27 fit_eval (fit); … … 35 49 36 50 /* XXX I'm not using the errors at all : this could at least be done with the dMag values */ 51 52 /* XXX See notes in FitChips.c */ -
branches/eam_branch_20080223/Ohana/src/relastro/src/ImageOps.c
r16060 r16798 33 33 34 34 for (i = 0; i < Nimage; i++) { 35 start[i] = image[i].tzero - MAX(0.0 5*image[i].trate*image[i].NY, 1);36 stop[i] = image[i].tzero + MAX(1.0 5*image[i].trate*image[i].NY, 1);35 start[i] = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1); 36 stop[i] = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1); 37 37 } 38 38 } … … 81 81 82 82 int i, j; 83 char *name; 83 84 84 85 for (i = 0; i < Ncatalog; i++) { … … 87 88 } 88 89 } 90 91 for (i = 0; VERBOSE && (i < Nimage); i++) { 92 name = GetPhotcodeNamebyCode (image[i].photcode); 93 fprintf (stderr, "image %d has %d measures (%s, %s)\n", i, Nlist[i], 94 ohana_sec_to_date(image[i].tzero), name); 95 } 89 96 } 90 97 … … 182 189 // return StarData values for detections in the specified image, converting coordinates from the 183 190 // chip positions: X,Y -> L,M -> P,Q -> R,D 191 void fixImageRaw (Catalog *catalog, int Ncatalog, int im) { 192 193 int i, m, c, n; 194 double X, Y, L, M, P, Q, R, D, dR, dD; 195 196 Mosaic *mosaic; 197 Coords *moscoords, *imcoords; 198 199 moscoords = NULL; 200 mosaic = getMosaicForImage (im); 201 if (mosaic != NULL) { 202 moscoords = &mosaic[0].coords; 203 } 204 imcoords = &image[im].coords; 205 206 for (i = 0; i < Nlist[im]; i++) { 207 m = mlist[im][i]; 208 c = clist[im][i]; 209 210 X = catalog[c].measure[m].Xccd; 211 Y = catalog[c].measure[m].Yccd; 212 n = catalog[c].measure[m].averef; 213 214 if (moscoords == NULL) { 215 // this is a Simple image (not a mosaic) 216 // note that for a Simple image, L,M = P,Q 217 XY_to_LM (&L, &M, X, Y, imcoords); 218 LM_to_RD (&R, &D, L, M, imcoords); 219 } else { 220 XY_to_LM (&L, &M, X, Y, imcoords); 221 XY_to_LM (&P, &Q, L, M, moscoords); 222 LM_to_RD (&R, &D, P, Q, moscoords); 223 } 224 225 // new dR, dD : test 226 dR = 3600.0*(catalog[c].average[n].R - R); 227 dD = 3600.0*(catalog[c].average[n].D - D); 228 229 if (fabs(catalog[c].measure[m].dR - dR) > 10.0) { 230 // XXXXX running into this still for last megacam exposure: wrong mosaic? 231 // ???? inconsistently hitting this???? 232 fprintf (stderr, "!"); 233 abort (); 234 } 235 if (fabs(catalog[c].measure[m].dD - dD) > 10.0) { 236 fprintf (stderr, "*"); 237 abort (); 238 } 239 240 catalog[c].measure[m].dR = dR; 241 catalog[c].measure[m].dD = dD; 242 243 if (catalog[c].measure[m].dR > +180.0*3600.0) { 244 // average on high end of boundary, move star up 245 R += 360.0; 246 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R); 247 } 248 if (catalog[c].measure[m].dR < -180.0*3600.0) { 249 // average on low end of boundary, move star down 250 R -= 360.0; 251 catalog[c].measure[m].dR = 3600.0*(catalog[c].average[n].R - R); 252 } 253 } 254 return; 255 } 256 257 // return StarData values for detections in the specified image, converting coordinates from the 258 // chip positions: X,Y -> L,M -> P,Q -> R,D 184 259 StarData *getImageRaw (Catalog *catalog, int Ncatalog, int im, int *Nstars, CoordMode mode) { 185 260 186 int i, m, c ;261 int i, m, c, n; 187 262 188 263 Mosaic *mosaic; … … 213 288 raw[i].Mag = catalog[c].measure[m].M; 214 289 raw[i].dMag = catalog[c].measure[m].dM; 290 raw[i].dPos = GetAstromError (&catalog[c].measure[m], ERROR_MODE_POS); 291 292 n = catalog[c].measure[m].averef; 215 293 216 294 raw[i].mask = FALSE; 295 if (catalog[c].average[n].Nmeasure < 2) { 296 raw[i].mask = TRUE; 297 } 217 298 218 299 switch (mode) { … … 273 354 ref[i].Mag = catalog[c].measure[m].M; 274 355 ref[i].dMag = catalog[c].measure[m].dM; 356 ref[i].dPos = GetAstromError (&catalog[c].measure[m], ERROR_MODE_POS); 275 357 276 358 ref[i].mask = FALSE; … … 286 368 case MODE_MOSAIC: 287 369 RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, moscoords); 288 LM_to_XY (&ref[i]. M, &ref[i].L, ref[i].P, ref[i].Q, moscoords);370 LM_to_XY (&ref[i].L, &ref[i].M, ref[i].P, ref[i].Q, moscoords); 289 371 LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords); 290 372 break; -
branches/eam_branch_20080223/Ohana/src/relastro/src/UpdateObjects.c
r16787 r16798 37 37 ALLOCATE (pY, double, MAX (1, Nmax)); 38 38 } 39 40 enum {ERROR_MODE_RA, ERROR_MODE_DEC};41 42 float GetAstromError (Measure *measure, int mode) {43 44 PhotCode *code;45 float dPobs, dPsys, dPtotal, dM, AS, MS;46 47 switch (mode) {48 case ERROR_MODE_RA:49 dPobs = measure[0].dXccd; // need to redefine this as RAerr50 break;51 case ERROR_MODE_DEC:52 dPobs = measure[0].dYccd; // need to redefine this as RAerr53 break;54 default:55 abort();56 }57 58 /* the astrometric errors are not being carried yet (but should be!) */59 /* we use the photometric mag error as a weighting term */60 61 code = GetPhotcodebyCode (measure[0].photcode);62 AS = code[0].astromErrScale;63 MS = code[0].astromErrMagScale;64 dPsys = code[0].astromErrSys;65 dM = measure[0].dM;66 67 dPtotal = sqrt(SQ(dPsys) + AS*SQ(dPobs) + MS*SQ(dM));68 dPtotal = MAX (dPtotal, MIN_ERROR);69 70 return (dPtotal);71 }72 39 73 40 int UpdateObjects (Catalog *catalog, int Ncatalog) { -
branches/eam_branch_20080223/Ohana/src/relastro/src/fitpoly.c
r16060 r16798 128 128 matrix[i][j] = fit[0].sum[ix+jx][iy+jy]; 129 129 } 130 131 // mask the terms not represented by the Coords terms 132 if (ix + iy > fit[0].Norder) { 133 for (j = 0; j < fit[0].Nelems; j++) { 134 matrix[i][j] = 0.0; 135 } 136 vector[i][0] = 0.0; 137 vector[i][1] = 0.0; 138 matrix[i][i] = 1.0; 139 } 130 140 } 131 141 … … 133 143 ix = i % fit[0].Nterms; 134 144 iy = i / fit[0].Nterms; 135 fprintf (stderr, "x2 : x^%dy^%d: %10.4g y2 : x^%dy^%d: %10.4g \n",136 ix, iy, vector[i][0], ix, iy, vector[i][1]);145 // fprintf (stderr, "x2 : x^%dy^%d: %10.4g y2 : x^%dy^%d: %10.4g \n", 146 // ix, iy, vector[i][0], ix, iy, vector[i][1]); 137 147 } 138 148 … … 142 152 ix = i % fit[0].Nterms; 143 153 iy = i / fit[0].Nterms; 144 fprintf (stderr, "x2 : x^%dy^%d: %10.4g y2 : x^%dy^%d: %10.4g \n",145 ix, iy, vector[i][0], ix, iy, vector[i][1]);154 // fprintf (stderr, "x2 : x^%dy^%d: %10.4g y2 : x^%dy^%d: %10.4g \n", 155 // ix, iy, vector[i][0], ix, iy, vector[i][1]); 146 156 } 147 157 … … 158 168 } 159 169 170 void fit_apply (CoordFit *fit, double *x2, double *y2, double x1, double y1) { 171 172 int ix, iy; 173 double xterm, yterm, term; 174 double x, y; 175 176 x = 0.0; 177 y = 0.0; 178 179 xterm = 1; 180 for (ix = 0; ix < fit[0].Nterms; ix++) { 181 yterm = 1; 182 for (iy = 0; iy < fit[0].Nterms; iy++) { 183 term = xterm*yterm; 184 x += fit[0].xfit[ix][iy]*term; 185 y += fit[0].yfit[ix][iy]*term; 186 yterm *= y1; 187 } 188 xterm *= x1; 189 } 190 *x2 = x; 191 *y2 = y; 192 } 193 160 194 // Nx, Ny is the number of terms in x and in y 161 195 double **poly2d_dx (double **poly, int Nx, int Ny) { … … 209 243 for (i = 0; i < Nx; i++) { 210 244 for (j = 0; j < Ny; j++) { 211 out[i][j] = poly[i][j +1];245 out[i][j] = poly[i][j]; 212 246 } 213 247 } … … 237 271 /* this should only apply to the polynomial, not the projection terms */ 238 272 /* compare with psastro supporting code */ 239 voidfit_apply_coords (CoordFit *fit, Coords *coords) {273 CoordFit *fit_apply_coords (CoordFit *fit, Coords *coords) { 240 274 241 275 double c11, c12; 242 276 double c21, c22; 243 double Xo, Yo, R ;277 double Xo, Yo, R1, R2; 244 278 CoordFit *modfit; 245 279 … … 256 290 modfit = CoordsSetCenter (fit, Xo, Yo); 257 291 292 /* we do not modify crval1,2: these are kept at the default values */ 293 294 // set cdelt1, cdelt2 295 coords[0].cdelt1 = hypot (modfit[0].xfit[1][0], modfit[0].xfit[0][1]); 296 coords[0].cdelt2 = hypot (modfit[0].yfit[1][0], modfit[0].yfit[0][1]); 297 R1 = 1 / coords[0].cdelt1; 298 R2 = 1 / coords[0].cdelt2; 299 258 300 // set pc1_1, pc1_2, pc2_1, pc2_2 (cd1,cd2 = 1.0) 259 coords[0].pc1_1 = modfit[0].xfit[1][0] ;260 coords[0].pc1_2 = modfit[0].xfit[0][1] ;261 coords[0].pc2_1 = modfit[0].yfit[1][0] ;262 coords[0].pc2_2 = modfit[0].yfit[0][1] ;301 coords[0].pc1_1 = modfit[0].xfit[1][0] * R1; 302 coords[0].pc1_2 = modfit[0].xfit[0][1] * R2; 303 coords[0].pc2_1 = modfit[0].yfit[1][0] * R1; 304 coords[0].pc2_2 = modfit[0].yfit[0][1] * R2; 263 305 264 306 // set the polyterm elements 265 307 if (coords->Npolyterms > 1) { 266 coords[0].polyterms[0][0] = modfit[0].xfit[2][0] ;267 coords[0].polyterms[1][0] = modfit[0].xfit[1][1] ;268 coords[0].polyterms[2][0] = modfit[0].xfit[0][2] ;269 270 coords[0].polyterms[0][1] = modfit[0].yfit[2][0] ;271 coords[0].polyterms[1][1] = modfit[0].yfit[1][1] ;272 coords[0].polyterms[2][1] = modfit[0].yfit[0][2] ;308 coords[0].polyterms[0][0] = modfit[0].xfit[2][0]*R1*R1; 309 coords[0].polyterms[1][0] = modfit[0].xfit[1][1]*R1*R2; 310 coords[0].polyterms[2][0] = modfit[0].xfit[0][2]*R2*R2; 311 312 coords[0].polyterms[0][1] = modfit[0].yfit[2][0]*R1*R1; 313 coords[0].polyterms[1][1] = modfit[0].yfit[1][1]*R1*R2; 314 coords[0].polyterms[2][1] = modfit[0].yfit[0][2]*R2*R2; 273 315 } 274 316 275 317 // I need to validate Norder 276 318 if (coords->Npolyterms > 2) { 277 coords[0].polyterms[3][0] = modfit[0].xfit[3][0]; 278 coords[0].polyterms[4][0] = modfit[0].xfit[2][1]; 279 coords[0].polyterms[5][0] = modfit[0].xfit[1][2]; 280 coords[0].polyterms[6][0] = modfit[0].xfit[0][3]; 281 282 coords[0].polyterms[3][1] = modfit[0].yfit[3][0]; 283 coords[0].polyterms[4][1] = modfit[0].yfit[2][1]; 284 coords[0].polyterms[5][1] = modfit[0].yfit[1][2]; 285 coords[0].polyterms[6][1] = modfit[0].yfit[0][3]; 286 } 287 288 /* we do not modify crval1,2: these are kept at the default values */ 289 290 /* normalize pc11,etc */ 291 c11 = coords[0].pc1_1; 292 c21 = coords[0].pc1_1; 293 c12 = coords[0].pc1_1; 294 c22 = coords[0].pc1_1; 295 coords[0].cdelt1 = coords[0].cdelt2 = sqrt(fabs(c11*c22 - c12*c21)); 296 R = 1 / coords[0].cdelt1; 297 298 coords[0].pc1_1 = c11*R; 299 coords[0].pc2_1 = c21*R; 300 coords[0].pc1_2 = c12*R; 301 coords[0].pc2_2 = c22*R; 319 coords[0].polyterms[3][0] = modfit[0].xfit[3][0]*R1*R1*R1; 320 coords[0].polyterms[4][0] = modfit[0].xfit[2][1]*R1*R1*R2; 321 coords[0].polyterms[5][0] = modfit[0].xfit[1][2]*R1*R2*R2; 322 coords[0].polyterms[6][0] = modfit[0].xfit[0][3]*R2*R2*R2; 323 324 coords[0].polyterms[3][1] = modfit[0].yfit[3][0]*R1*R1*R1; 325 coords[0].polyterms[4][1] = modfit[0].yfit[2][1]*R1*R1*R2; 326 coords[0].polyterms[5][1] = modfit[0].yfit[1][2]*R1*R2*R2; 327 coords[0].polyterms[6][1] = modfit[0].yfit[0][3]*R2*R2*R2; 328 } 302 329 303 330 fit_free (modfit); -
branches/eam_branch_20080223/Ohana/src/relastro/src/mkpolyterm.c
r16060 r16798 20 20 21 21 int i, Nx, Ny; 22 double R, Xo, Yo, dPos ;22 double R, Xo, Yo, dPos, dPosRef; 23 23 double **XdX, **XdY, **YdX, **YdY, **alpha, **beta; 24 24 double **xfit, **yfit; … … 51 51 */ 52 52 dPos = tol + 1; 53 dPosRef = dPos; 53 54 for (i = 0; (dPos > tol) && (i < 20); i++) { 54 55 // NOTE: order for alpha is: [y][x] … … 66 67 Yo -= beta[1][0]; 67 68 dPos = hypot(beta[0][0], beta[1][0]); 69 if (i == 0) { 70 dPosRef = dPos; 71 } 72 } 73 if (dPos > dPosRef) { 74 fprintf (stderr, "*** warning : non-convergence in model conversion (mkpolyterm.c;73) *** \n"); 68 75 } 69 76 array_free (alpha, 2); -
branches/eam_branch_20080223/Ohana/src/relastro/src/relastro.c
r16788 r16798 61 61 if (!UPDATE) exit (0); 62 62 63 save_catalogs (catalog, Ncatalog); 63 if (FIT_TARGET == TARGET_OBJECTS) { 64 save_catalogs (catalog, Ncatalog); 65 } else { 66 // XXX for now, reload all catalogs at once; as memory use gets large, reload one-at-a-time 64 67 65 if (FIT_TARGET != TARGET_OBJECTS) { 68 // load catalog data from region files : do not subselect 69 catalog = load_catalogs (skylist, &Ncatalog, FALSE); 70 71 // match measurements with images 72 initImageBins (catalog, Ncatalog); 73 findImages (catalog, Ncatalog); 74 75 // update the detection coordinates using the new image parameters 76 UpdateMeasures (catalog, Ncatalog); 77 78 // write the updated detections to disk 79 save_catalogs (catalog, Ncatalog); 80 81 // save the updated image parameters 66 82 dvo_image_update (&db, VERBOSE); 67 83 dvo_image_unlock (&db);
Note:
See TracChangeset
for help on using the changeset viewer.
