Changeset 20323
- Timestamp:
- Oct 21, 2008, 6:11:09 PM (18 years ago)
- Location:
- trunk/Ohana/src/relphot
- Files:
-
- 9 edited
-
include/relphot.h (modified) (2 diffs)
-
src/ConfigInit.c (modified) (1 diff)
-
src/GridOps.c (modified) (12 diffs)
-
src/ImageOps.c (modified) (3 diffs)
-
src/MosaicOps.c (modified) (6 diffs)
-
src/StarOps.c (modified) (2 diffs)
-
src/args.c (modified) (2 diffs)
-
src/bcatalog.c (modified) (1 diff)
-
src/relphot.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/relphot/include/relphot.h
r20185 r20323 63 63 64 64 int NLOOP; 65 int NGRID; 65 66 int RESET; 66 67 int UPDATE; … … 73 74 int MEAS_BAD; 74 75 int STAR_TOOFEW; 76 int GRID_TOOFEW; 75 77 int IMAGE_TOOFEW; 76 78 double IMAGE_GOOD_FRACTION; 77 79 int IMAGE_BAD; 78 80 int FREEZE_IMAGES; 81 int FREEZE_MOSAICS; 79 82 int USE_GRID; 80 83 char *OUTROOT; -
trunk/Ohana/src/relphot/src/ConfigInit.c
r19897 r20323 25 25 26 26 GetConfig (config, "STAR_CHISQ", "%lf", 0, &STAR_CHISQ); 27 GetConfig (config, "GRID_TOOFEW", "%d", 0, &GRID_TOOFEW); 27 28 GetConfig (config, "STAR_TOOFEW", "%d", 0, &STAR_TOOFEW); 28 29 GetConfig (config, "IMAGE_TOOFEW", "%d", 0, &IMAGE_TOOFEW); -
trunk/Ohana/src/relphot/src/GridOps.c
r20186 r20323 1 1 # include "relphot.h" 2 2 3 typedef enum { 4 GRID_FITTED, 5 GRID_FROZEN, 6 GRID_REFERENCE, 7 }; 8 3 9 static int Ngrid; 4 static float *gridM; 5 static float *gridS; 6 static int *gridN; 10 static float *gridM; // magnitude offset for this grid cell 11 static float *gridS; // stdev of the magnitude offset for this grid cell 12 static int *gridN; // number of stars used to measure the magnitude offset for this grid cell 13 static int *gridV; // data mode for this cell: fitted, frozen, reference 7 14 static int gridX; 8 15 static int gridY; … … 30 37 static char *config; 31 38 32 # ifdef GRID_V133 39 void initGrid (int dX, int dY) { 34 40 35 int i; 36 37 /* define mosaic 2d correction grid */ 38 gridX = dX / RELPHOT_GRID_BINNING + 1; 39 gridY = dY / RELPHOT_GRID_BINNING + 1; 40 Ngrid = gridX * gridY; 41 42 ALLOCATE (gridM, float, Ngrid); 43 ALLOCATE (gridS, float, Ngrid); 44 ALLOCATE (gridN, int, Ngrid); 45 bzero (gridM, Ngrid*sizeof(float)); 46 bzero (gridS, Ngrid*sizeof(float)); 47 bzero (gridN, Ngrid*sizeof(int)); 48 49 } 50 # endif 51 52 # ifdef GRID_V2 53 void initGrid (int dX, int dY) { 54 55 int i, N, ccdnum_max; 41 int i, N, ccdnum_max, refX, refY, refBin; 56 42 char *p, field[64], line[256]; 57 43 int *Fx, *Fy; /* chip flip */ … … 72 58 ScanConfig (config, "NAXIS1", "%d", 1, &camera.Nx); 73 59 ScanConfig (config, "NAXIS2", "%d", 1, &camera.Ny); 60 61 ScanConfig (config, "REFCELL.X", "%d", 1, &refX); 62 ScanConfig (config, "REFCELL.Y", "%d", 1, &refY); 74 63 75 64 // temporary storage … … 143 132 ALLOCATE (gridS, float, Ngrid); 144 133 ALLOCATE (gridN, int, Ngrid); 145 bzero (gridM, Ngrid*sizeof(float)); 146 bzero (gridS, Ngrid*sizeof(float)); 147 bzero (gridN, Ngrid*sizeof(int)); 148 149 } 150 # endif 134 ALLOCATE (gridV, int, Ngrid); 135 136 // the grid bins may have one of three possible states: fitted, frozen, reference 137 // set the initial values to indicate that the bins are frozen 138 for (i = 0; i < Ngrid; i++) { 139 gridM[i] = 0.0; 140 gridS[i] = 0.0; 141 gridN[i] = 0; 142 gridV[i] = GRID_FROZEN; 143 } 144 145 // refBin is the index of the grid cell which is kept at 0.0 (all others are relative to this) 146 refBin = refX + refY*gridX; 147 gridV[refBin] = GRID_REFERENCE; 148 } 151 149 152 150 void initGridBins (Catalog *catalog, int Ncatalog) { … … 208 206 } 209 207 210 # ifdef GRID_V1 211 int setGridMeasure (int meas, int cat, double X, double Y) { 212 213 int ix, iy, i; 214 215 ix = X / RELPHOT_GRID_BINNING; 216 iy = Y / RELPHOT_GRID_BINNING; 217 if (ix < 0) goto escape; 218 if (iy < 0) goto escape; 219 if (ix >= gridX) goto escape; 220 if (iy >= gridY) goto escape; 208 int setGridMeasure (int meas, int cat, double X, double Y, int ccdnum) { 209 210 int ix, iy, Cx, Cy, i; 211 double x, y; 212 213 /* X, Y are chip coords on chip ccdnum */ 214 215 /* normalize X & Y */ 216 x = X; 217 if (camera.Fx[ccdnum]) x = camera.Nx - X; 218 y = Y; 219 if (camera.Fy[ccdnum]) y = camera.Ny - Y; 220 221 /* grid coords on the chip */ 222 Cx = MIN (MAX ((x / camera.Nx) * RELPHOT_GRID_X, 0), RELPHOT_GRID_X - 1); 223 Cy = MIN (MAX ((y / camera.Ny) * RELPHOT_GRID_Y, 0), RELPHOT_GRID_Y - 1); 224 225 /* coordinates in the grid */ 226 ix = Cx + camera.Ox[ccdnum]*RELPHOT_GRID_X; 227 iy = Cy + camera.Oy[ccdnum]*RELPHOT_GRID_Y; 221 228 222 229 i = ix + iy*gridX; 223 230 224 231 bin[cat][meas] = i; 225 Xmeas[cat][meas] = X;226 Ymeas[cat][meas] = Y;232 Xmeas[cat][meas] = x + camera.Ox[ccdnum]*camera.Nx; 233 Ymeas[cat][meas] = y + camera.Oy[ccdnum]*camera.Ny; 227 234 clist[i][Nlist[i]] = cat; 228 235 mlist[i][Nlist[i]] = meas; … … 236 243 return (TRUE); 237 244 238 escape:239 245 fprintf (stderr, "error: star out of grid\n"); 240 246 exit (1); 241 247 } 242 # endif243 244 # ifdef GRID_V2245 int setGridMeasure (int meas, int cat, double X, double Y, int ccdnum) {246 247 int ix, iy, Cx, Cy, i;248 double x, y;249 250 /* X, Y are chip coords on chip ccdnum */251 252 /* normalize X & Y */253 x = X;254 if (camera.Fx[ccdnum]) x = camera.Nx - X;255 y = Y;256 if (camera.Fy[ccdnum]) y = camera.Ny - Y;257 258 /* grid coords on the chip */259 Cx = MIN (MAX ((x / camera.Nx) * RELPHOT_GRID_X, 0), RELPHOT_GRID_X - 1);260 Cy = MIN (MAX ((y / camera.Ny) * RELPHOT_GRID_Y, 0), RELPHOT_GRID_Y - 1);261 262 /* coordinates in the grid */263 ix = Cx + camera.Ox[ccdnum]*RELPHOT_GRID_X;264 iy = Cy + camera.Oy[ccdnum]*RELPHOT_GRID_Y;265 266 i = ix + iy*gridX;267 268 bin[cat][meas] = i;269 Xmeas[cat][meas] = x + camera.Ox[ccdnum]*camera.Nx;270 Ymeas[cat][meas] = y + camera.Oy[ccdnum]*camera.Ny;271 clist[i][Nlist[i]] = cat;272 mlist[i][Nlist[i]] = meas;273 274 Nlist[i] ++;275 if (Nlist[i] == NLIST[i]) {276 NLIST[i] += 100;277 REALLOCATE (clist[i], int, NLIST[i]);278 REALLOCATE (mlist[i], int, NLIST[i]);279 }280 return (TRUE);281 282 fprintf (stderr, "error: star out of grid\n");283 exit (1);284 }285 # endif286 248 287 249 float getMgrid (int meas, int cat) { … … 294 256 if (i == -1) return (NAN); 295 257 258 // during the grid annealing process, we skip over grid cells until they have enough 259 // valid stars to be fitted 260 if (gridV[i] == GRID_FROZEN) return (NAN); 261 296 262 value = gridM[i]; 297 263 return (value); … … 301 267 void setMgrid (Catalog *catalog) { 302 268 303 int i, j, m, c, n, N, Nmax, Nbad, Nmos, Ncal, Nrel, Nsys ;269 int i, j, m, c, n, N, Nmax, Nbad, Nmos, Ncal, Nrel, Nsys, Nfit; 304 270 double *list, *dlist; 305 271 float Msys, Mrel, Mcal, Mmos; … … 315 281 ALLOCATE (dlist, double, Nmax); 316 282 317 Nbad = Ncal = Nmos = Nrel = Nsys = 0;283 Nbad = Ncal = Nmos = Nrel = Nsys = Nfit = 0; 318 284 319 285 for (i = 0; i < Ngrid; i++) { … … 356 322 } 357 323 324 // the reference Cell is forced to have a value of 0.0, and is never changed to GRID_FITTED 325 if (gridV[i] == GRID_REFERENCE) { 326 gridM[i] = 0.0; 327 gridS[i] = 0.0; 328 gridN[i] = N; 329 continue; 330 } 331 332 // until we have enough valid measurements on this grid cell, skip it 333 if (N < GRID_TOOFEW) { 334 gridV[i] = GRID_FROZEN; 335 continue; 336 } 337 358 338 liststats (list, dlist, N, &stats); 359 339 gridM[i] = stats.mean; 360 340 gridS[i] = stats.sigma; 361 341 gridN[i] = N; 362 } 363 364 fprintf (stderr, "grid cells having too few measurements (Nbad: %d, Nmos: %d, Ncal: %d, Nrel: %d, Nsys: %d)\n", Nbad, Nmos, Ncal, Nrel, Nsys); 342 gridV[i] = GRID_FITTED; 343 Nfit++; 344 } 345 346 fprintf (stderr, "%d of %d grid cells fitted (+ reference cell) (Nbad: %d, Nmos: %d, Ncal: %d, Nrel: %d, Nsys: %d)\n", Nfit, Ngrid, Nbad, Nmos, Ncal, Nrel, Nsys); 365 347 366 348 free (list); … … 531 513 gfits_free_matrix (&matrix); 532 514 533 # ifdef GRID_V1534 /* calculate pixel values for each CCD pixel, write out CCD images */535 /* grid pixels are in RA,DEC coords, transform to image and interpolate */536 for (i = 0; i < Nimage; i++) {537 image = getimage (imlist[i]);538 pname = GetPhotcodeNamebyCode (image[0].photcode);539 540 /* this is kind of bogus... */541 /* pname is CAMERA.FILTER.CCD, grab the CCD */542 p = strrchr (pname, '.');543 if (p == (char *) NULL) {544 fprintf (stderr, "error parsing photcode %s\n", pname);545 exit (2);546 }547 p++;548 sprintf (ccdname, "ccd%s", p);549 550 gfits_modify (&theader, "EXTNAME", "%s", 1, ccdname);551 gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);552 gfits_modify (&theader, "PHOTCODE", "%s", 1, pname);553 gfits_modify (&theader, "NX", "%d", 1, image[i].NX);554 gfits_modify (&theader, "NY", "%d", 1, image[i].NY);555 write_coords (&theader, &image[0].coords);556 557 Nx = 2 * image[i].NX / RELPHOT_GRID_BINNING;558 Ny = 2 * image[i].NY / RELPHOT_GRID_BINNING;559 theader.Naxis[0] = Nx;560 theader.Naxis[1] = Ny;561 gfits_modify (&theader, "NAXIS1", "%d", 1, Nx);562 gfits_modify (&theader, "NAXIS2", "%d", 1, Ny);563 gfits_create_matrix (&theader, &matrix);564 565 InterpolateGrid ((float *)matrix.buffer, Nx, Ny, &image[0].coords, &refmosaic[0].coords);566 gfits_fwrite_header (f, &theader);567 gfits_fwrite_matrix (f, &matrix);568 gfits_free_matrix (&matrix);569 }570 # endif571 572 # ifdef GRID_V2573 515 /* calculate value for each CCD pixel, write out CCD images */ 574 516 /* grid pixels are tied to detector pixels, but are flipped to match focal plane */ … … 610 552 gfits_free_matrix (&matrix); 611 553 } 612 # endif613 554 614 555 free (filename); -
trunk/Ohana/src/relphot/src/ImageOps.c
r20187 r20323 178 178 if (measure[0].t > stop[i]) continue; 179 179 180 # ifdef GRID_V2 /* this section is added to support GridOps.v2.c */181 180 if (USE_GRID) { 182 181 … … 199 198 constructed, there will be null values for undefined ccdnums */ 200 199 201 # if (0) 202 /* add this measurement to the grid cell for this chip */ 203 ave = measure[0].averef; 204 ra = catalog[cat].average[ave].R - measure[0].dR / 3600.0; 205 dec = catalog[cat].average[ave].D - measure[0].dD / 3600.0; 206 207 /* X,Y always positive-definite in range 0,0 - dX, dY */ 208 RD_to_XY (&X, &Y, ra, dec, &image[i].coords); 209 # endif 200 // old code to add this measurement to the grid cell for this chip 201 // ave = measure[0].averef; 202 // ra = catalog[cat].average[ave].R - measure[0].dR / 3600.0; 203 // dec = catalog[cat].average[ave].D - measure[0].dD / 3600.0; 204 // RD_to_XY (&X, &Y, ra, dec, &image[i].coords); 210 205 211 206 // XXX we can now use these values (but need to be careful about old formats) … … 214 209 setGridMeasure (meas, cat, X, Y, ccdnum); 215 210 } 216 # endif217 211 218 212 bin[cat][meas] = i; -
trunk/Ohana/src/relphot/src/MosaicOps.c
r20192 r20323 320 320 321 321 if (!MOSAIC_ZEROPT) return (FALSE); 322 if (FREEZE_MOSAICS) return (FALSE); 322 323 323 324 image = getimages (&N); … … 453 454 bzero (&stats, sizeof (StatType)); 454 455 if (!MOSAIC_ZEROPT) return (stats); 456 if (FREEZE_MOSAICS) return (stats); 455 457 456 458 ALLOCATE (list, double, Nmosaic); … … 481 483 bzero (&stats, sizeof (StatType)); 482 484 if (!MOSAIC_ZEROPT) return (stats); 485 if (FREEZE_MOSAICS) return (stats); 483 486 484 487 ALLOCATE (list, double, Nmosaic); … … 523 526 bzero (&stats, sizeof (StatType)); 524 527 if (!MOSAIC_ZEROPT) return (stats); 528 if (FREEZE_MOSAICS) return (stats); 525 529 526 530 ALLOCATE (list, double, Nmosaic); … … 551 555 552 556 if (!MOSAIC_ZEROPT) return; 557 if (FREEZE_MOSAICS) return; 553 558 554 559 if (VERBOSE) fprintf (stderr, "marking poor mosaics\n"); … … 645 650 646 651 if (!MOSAIC_ZEROPT) return; 652 if (FREEZE_MOSAICS) return; 647 653 648 654 ALLOCATE (xlist, double, Nmosaic); -
trunk/Ohana/src/relphot/src/StarOps.c
r20192 r20323 85 85 N++; 86 86 } 87 if (N < STAR_TOOFEW) { /* too few measurements */ 87 88 // when performing the grid analysis, STAR_TOOFEW will be set to 1; 89 90 if (N <= STAR_TOOFEW) { /* too few measurements */ 88 91 catalog[i].average[j].code |= ID_STAR_FEW; 89 92 Nfew ++; … … 367 370 N++; 368 371 } 369 if (N < TOOFEW) continue;372 if (N <= TOOFEW) continue; 370 373 371 374 /* 3-sigma clip based on stats of inner 50% */ -
trunk/Ohana/src/relphot/src/args.c
r20188 r20323 93 93 remove_argument (N, &argc, argv); 94 94 } 95 if ((N = get_argument (argc, argv, "-nloop"))) { 96 remove_argument (N, &argc, argv); 97 NLOOP = atof (argv[N]); 98 remove_argument (N, &argc, argv); 99 } 100 101 NGRID = 8; 102 if ((N = get_argument (argc, argv, "-ngrid"))) { 103 remove_argument (N, &argc, argv); 104 NGRID = atof (argv[N]); 105 remove_argument (N, &argc, argv); 106 } 95 107 96 108 RESET = FALSE; … … 139 151 remove_argument (N, &argc, argv); 140 152 FREEZE_IMAGES = TRUE; 153 } 154 155 FREEZE_MOSAICS = FALSE; 156 if ((N = get_argument (argc, argv, "-mosfreeze"))) { 157 remove_argument (N, &argc, argv); 158 FREEZE_MOSAICS = TRUE; 141 159 } 142 160 -
trunk/Ohana/src/relphot/src/bcatalog.c
r20189 r20323 90 90 91 91 // XXXX test : what checks do I need to make elsewhere to avoid problems here? 92 if (Nm < STAR_TOOFEW) { /* enough measurements in band? */92 if (Nm <= STAR_TOOFEW) { /* enough measurements in band? */ 93 93 Nmeasure -= Nm; 94 94 continue; -
trunk/Ohana/src/relphot/src/relphot.c
r17242 r20323 70 70 } 71 71 72 // if we are measuring the flat-field correction grid, we need to perform a number of iterations first: 73 if (USE_GRID) { 74 int star_toofew; 75 76 // until we finish the grid analysis, do not reject stars out-of-hand based on ID_STAR_FEW 77 // XXX this is kind of poor: need to have a better distinctions about STAR_BAD in setMrel vs getMrel 78 star_toofew = STAR_TOOFEW; 79 for (i = 0; i < NGRID; i++) { 80 STAR_BAD = ID_STAR_POOR; 81 setMrel (catalog, Ncatalog); 82 STAR_BAD = ID_STAR_POOR | ID_STAR_FEW; 83 setMgrid (catalog); 84 } 85 STAR_BAD = ID_STAR_POOR | ID_STAR_FEW; 86 STAR_TOOFEW = star_toofew; 87 } 88 72 89 /* determine fit values */ 73 90 for (i = 0; i < NLOOP; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.
