Changeset 20960
- Timestamp:
- Dec 11, 2008, 10:40:26 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroMaskUpdates.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroMaskUpdates.c
r20950 r20960 6 6 return false; \ 7 7 } 8 8 9 9 pmCell *pmCellInChip (pmChip *chip, float x, float y); 10 10 bool pmCellCoordsForChip (float *xCell, float *yCell, pmCell *cell, float xChip, float yChip); … … 17 17 void psastroMaskRectangle (psImage *mask, char value, int x0, int y0, int x1, int y1); 18 18 19 // create a mask or mask regions based on the collection of reference stars that are 19 // create a mask or mask regions based on the collection of reference stars that are 20 20 // in the vicinity of each chip 21 21 bool psastroMaskUpdates (pmConfig *config) { … … 57 57 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); 58 58 if (!input) { 59 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");60 return false;59 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data"); 60 return false; 61 61 } 62 62 pmFPA *fpa = input->fpa; … … 64 64 // really error-out here? or just skip? 65 65 if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) { 66 psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");67 return false;66 psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe"); 67 return false; 68 68 } 69 69 … … 79 79 pmFPAfile *outMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.OUTPUT.MASK"); 80 80 if (!outMask) { 81 psError(PSASTRO_ERR_CONFIG, true, "Can't find output mask");82 return false;81 psError(PSASTRO_ERR_CONFIG, true, "Can't find output mask"); 82 return false; 83 83 } 84 84 pmFPA *fpaMask = outMask->fpa; … … 87 87 pmFPAfile *refMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.REFMASK"); 88 88 if (!refMask) { 89 psError(PSASTRO_ERR_CONFIG, true, "Can't find mask reference");90 return false;91 } 92 93 // double POSANGLE = PM_RAD_DEG * psMetadataLookupF64 (&status, fpa->concepts, "FPA.POSANGLE"); 89 psError(PSASTRO_ERR_CONFIG, true, "Can't find mask reference"); 90 return false; 91 } 92 93 // double POSANGLE = PM_RAD_DEG * psMetadataLookupF64 (&status, fpa->concepts, "FPA.POSANGLE"); 94 94 // psAssert (status, "POSANGLE missing"); 95 double ROTANGLE = PM_RAD_DEG * psMetadataLookupF64 (&status, fpa->concepts, "FPA.ROTANGLE"); 95 double ROTANGLE = PM_RAD_DEG * psMetadataLookupF64 (&status, fpa->concepts, "FPA.ROTANGLE"); 96 96 psAssert (status, "ROTANGLE missing"); 97 97 … … 112 112 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 113 113 if (!chip->process || !chip->file_exists) { continue; } 114 if (!chip->fromFPA) { continue; }115 116 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;117 118 // text region files for testing119 FILE *f = NULL;120 if (REFSTAR_MASK_REGIONS) {121 char *filename = NULL;122 char *chipname = psMetadataLookupStr (&status, chip->concepts, "CHIP.NAME");123 psStringAppend (&filename, "refstars.mask.%s.dat", chipname);124 FILE *f = fopen (filename, "w");125 if (!f) {126 psWarning ("cannot create refstar mask file %s\n", filename);127 continue;128 }129 psFree (filename);130 }131 132 pmChip *refChip = pmFPAviewThisChip (view, refMask->fpa);133 134 // load sequence for mask corresponding to this chip (XXX this is needed if the input mask is not the same format as the astrometry file135 *viewMask = *view;114 if (!chip->fromFPA) { continue; } 115 116 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE; 117 118 // text region files for testing 119 FILE *f = NULL; 120 if (REFSTAR_MASK_REGIONS) { 121 char *filename = NULL; 122 char *chipname = psMetadataLookupStr (&status, chip->concepts, "CHIP.NAME"); 123 psStringAppend (&filename, "refstars.mask.%s.dat", chipname); 124 FILE *f = fopen (filename, "w"); 125 if (!f) { 126 psWarning ("cannot create refstar mask file %s\n", filename); 127 continue; 128 } 129 psFree (filename); 130 } 131 132 pmChip *refChip = pmFPAviewThisChip (view, refMask->fpa); 133 134 // load sequence for mask corresponding to this chip (XXX this is needed if the input mask is not the same format as the astrometry file 135 *viewMask = *view; 136 136 while ((cell = pmFPAviewNextCell (viewMask, fpaMask, 1)) != NULL) { 137 137 psTrace ("psastro", 4, "Mask Cell %d: %x %x\n", viewMask->cell, cell->file_exists, cell->process); 138 138 if (!cell->process || !cell->file_exists) { continue; } 139 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE;140 139 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE; 140 141 141 while ((readout = pmFPAviewNextReadout (viewMask, fpaMask, 1)) != NULL) { 142 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE;142 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE; 143 143 if (! readout->data_exists) { continue; } 144 }145 }144 } 145 } 146 146 147 147 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { … … 149 149 if (!cell->process || !cell->file_exists) { continue; } 150 150 151 // the input mask is a chip-mosaic image152 // the output mask is a chip-mosaic image153 // we mark the masked pixels in the chip space, BUT154 // we need to find the ends of the cells for the bleeds155 156 // we mask pixels on the input mask image (chip-mosaic)157 pmCell *cellMask = pmFPAviewThisCell(view, outMask->fpa);158 pmReadout *readoutMask = NULL;159 if (cellMask->readouts->n) {160 readoutMask = cellMask->readouts->data[0];161 }151 // the input mask is a chip-mosaic image 152 // the output mask is a chip-mosaic image 153 // we mark the masked pixels in the chip space, BUT 154 // we need to find the ends of the cells for the bleeds 155 156 // we mask pixels on the input mask image (chip-mosaic) 157 pmCell *cellMask = pmFPAviewThisCell(view, outMask->fpa); 158 pmReadout *readoutMask = NULL; 159 if (cellMask->readouts->n) { 160 readoutMask = cellMask->readouts->data[0]; 161 } 162 162 163 163 // process each of the readouts … … 170 170 if (refstars == NULL) { continue; } 171 171 172 // we need to generate the following masks regions:173 // 1) circle around the saturated stars (scaled by magnitude)174 // 2) diffraction spikes in direction ROT - ROTo175 // 3) bleed trail in the direction of the readout176 177 // XXX for the moment, let's just generate mana region-file objects in chip pixel space178 for (int i = 0; i < refstars->n; i++) {179 pmAstromObj *ref = refstars->data[i];180 if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue;181 182 // XXX convert ref->Mag to instrumental mags183 184 // CIRCLE around the stars (scaled by magnitude)185 float radius = REFSTAR_MASK_SATSTAR_MAG_SLOPE * (REFSTAR_MASK_SATSTAR_MAG_MAX - ref->Mag);186 187 if (REFSTAR_MASK_REGIONS) {188 fprintf (f, "CIRCLE %f %f %f %f\n", ref->chip->x, ref->chip->y, radius, radius);189 }190 191 // XXX for now, assume cell binning is 1x1 relative to chip192 if (readoutMask) {193 psastroMaskCircle (readoutMask->mask, maskValue, ref->chip->x, ref->chip->y, radius, radius);194 }195 196 // LINE for boundaries of the saturation spikes (scaled by magnitude)197 float spikeLength = REFSTAR_MASK_SATSPIKE_MAG_SLOPE * (REFSTAR_MASK_SATSPIKE_MAG_MAX - ref->Mag);198 float spikeWidth = REFSTAR_MASK_SATSPIKE_WIDTH;199 200 for (float theta = 0.0; theta < 2*M_PI; theta += M_PI / 2.0) {201 float x0, y0, x1, y1, dx, dy;202 203 float Theta = ROTANGLE - REFSTAR_MASK_SATSTAR_POS_ZERO + theta;204 205 if (REFSTAR_MASK_REGIONS) {206 // lower side 207 x0 = ref->chip->x + spikeWidth*sin(Theta);208 y0 = ref->chip->y - spikeWidth*cos(Theta);209 x1 = ref->chip->x + spikeLength*cos(Theta) + spikeWidth*sin(Theta);210 y1 = ref->chip->y + spikeLength*sin(Theta) - spikeWidth*cos(Theta);211 dx = x1 - x0;212 dy = y1 - y0;213 214 fprintf (f, "LINE %f %f %f %f\n", x0, y0, dx, dy);215 216 // upper side 217 x0 = ref->chip->x - spikeWidth*sin(Theta);218 y0 = ref->chip->y + spikeWidth*cos(Theta);219 x1 = ref->chip->x + spikeLength*cos(Theta) - spikeWidth*sin(Theta);220 y1 = ref->chip->y + spikeLength*sin(Theta) + spikeWidth*cos(Theta);221 dx = x1 - x0;222 dy = y1 - y0;223 fprintf (f, "LINE %f %f %f %f\n", x0, y0, dx, dy);224 }225 226 if (readoutMask) {227 psastroMaskBox (readoutMask->mask, maskValue, ref->chip->x, ref->chip->y, spikeLength, spikeWidth, Theta);228 }229 }230 231 // convert x,y chip coordinates to cells in maskChip232 pmCell *refCell = pmCellInChip (refChip, ref->chip->x, ref->chip->y);233 234 // LINE for boundaries of the bleed lines235 if (REFSTAR_MASK_REGIONS) {236 fprintf (f, "LINE %f %f %f %f\n", ref->chip->x, ref->chip->y, 0.0, -100.0);237 }238 239 if (readoutMask && refCell) {240 float xCell = 0.0;241 float yCell = 0.0;242 float xEnd = 0.0;243 float yEnd = 0.0;244 // find coordinate of star on cell245 pmCellCoordsForChip (&xCell, &yCell, refCell, ref->chip->x, ref->chip->y);246 // find coordinate of end-point on chip247 248 int ySize = psMetadataLookupS32(NULL, refCell->concepts, "CELL.YSIZE");249 pmChipCoordsForCell (&xEnd, &yEnd, refCell, xCell, ySize);250 251 float width = REFSTAR_MASK_BLEED_MAG_SLOPE*(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag);252 psastroMaskRectangle (readoutMask->mask, maskValue, (int) ref->chip->x-0.5*width, (int) ref->chip->y, (int) ref->chip->x+0.5*width+1, yEnd);253 }254 }172 // we need to generate the following masks regions: 173 // 1) circle around the saturated stars (scaled by magnitude) 174 // 2) diffraction spikes in direction ROT - ROTo 175 // 3) bleed trail in the direction of the readout 176 177 // XXX for the moment, let's just generate mana region-file objects in chip pixel space 178 for (int i = 0; i < refstars->n; i++) { 179 pmAstromObj *ref = refstars->data[i]; 180 if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue; 181 182 // XXX convert ref->Mag to instrumental mags 183 184 // CIRCLE around the stars (scaled by magnitude) 185 float radius = REFSTAR_MASK_SATSTAR_MAG_SLOPE * (REFSTAR_MASK_SATSTAR_MAG_MAX - ref->Mag); 186 187 if (REFSTAR_MASK_REGIONS) { 188 fprintf (f, "CIRCLE %f %f %f %f\n", ref->chip->x, ref->chip->y, radius, radius); 189 } 190 191 // XXX for now, assume cell binning is 1x1 relative to chip 192 if (readoutMask) { 193 psastroMaskCircle (readoutMask->mask, maskValue, ref->chip->x, ref->chip->y, radius, radius); 194 } 195 196 // LINE for boundaries of the saturation spikes (scaled by magnitude) 197 float spikeLength = REFSTAR_MASK_SATSPIKE_MAG_SLOPE * (REFSTAR_MASK_SATSPIKE_MAG_MAX - ref->Mag); 198 float spikeWidth = REFSTAR_MASK_SATSPIKE_WIDTH; 199 200 for (float theta = 0.0; theta < 2*M_PI; theta += M_PI / 2.0) { 201 float x0, y0, x1, y1, dx, dy; 202 203 float Theta = theta - ROTANGLE - REFSTAR_MASK_SATSTAR_POS_ZERO; 204 205 if (REFSTAR_MASK_REGIONS) { 206 // lower side 207 x0 = ref->chip->x + spikeWidth*sin(Theta); 208 y0 = ref->chip->y - spikeWidth*cos(Theta); 209 x1 = ref->chip->x + spikeLength*cos(Theta) + spikeWidth*sin(Theta); 210 y1 = ref->chip->y + spikeLength*sin(Theta) - spikeWidth*cos(Theta); 211 dx = x1 - x0; 212 dy = y1 - y0; 213 214 fprintf (f, "LINE %f %f %f %f\n", x0, y0, dx, dy); 215 216 // upper side 217 x0 = ref->chip->x - spikeWidth*sin(Theta); 218 y0 = ref->chip->y + spikeWidth*cos(Theta); 219 x1 = ref->chip->x + spikeLength*cos(Theta) - spikeWidth*sin(Theta); 220 y1 = ref->chip->y + spikeLength*sin(Theta) + spikeWidth*cos(Theta); 221 dx = x1 - x0; 222 dy = y1 - y0; 223 fprintf (f, "LINE %f %f %f %f\n", x0, y0, dx, dy); 224 } 225 226 if (readoutMask) { 227 psastroMaskBox (readoutMask->mask, maskValue, ref->chip->x, ref->chip->y, spikeLength, spikeWidth, Theta); 228 } 229 } 230 231 // convert x,y chip coordinates to cells in maskChip 232 pmCell *refCell = pmCellInChip (refChip, ref->chip->x, ref->chip->y); 233 234 // LINE for boundaries of the bleed lines 235 if (REFSTAR_MASK_REGIONS) { 236 fprintf (f, "LINE %f %f %f %f\n", ref->chip->x, ref->chip->y, 0.0, -100.0); 237 } 238 239 if (readoutMask && refCell) { 240 float xCell = 0.0; 241 float yCell = 0.0; 242 float xEnd = 0.0; 243 float yEnd = 0.0; 244 // find coordinate of star on cell 245 pmCellCoordsForChip (&xCell, &yCell, refCell, ref->chip->x, ref->chip->y); 246 // find coordinate of end-point on chip 247 248 int ySize = psMetadataLookupS32(NULL, refCell->concepts, "CELL.YSIZE"); 249 pmChipCoordsForCell (&xEnd, &yEnd, refCell, xCell, ySize); 250 251 float width = REFSTAR_MASK_BLEED_MAG_SLOPE*(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag); 252 psastroMaskRectangle (readoutMask->mask, maskValue, (int) ref->chip->x-0.5*width, (int) ref->chip->y, (int) ref->chip->x+0.5*width+1, yEnd); 253 } 254 } 255 255 } 256 256 } 257 257 258 // output sequence for mask corresponding to this chip259 *viewMask = *view;258 // output sequence for mask corresponding to this chip 259 *viewMask = *view; 260 260 while ((cell = pmFPAviewNextCell (viewMask, outMask->fpa, 1)) != NULL) { 261 261 psTrace ("psastro", 4, "Mask Cell %d: %x %x\n", viewMask->cell, cell->file_exists, cell->process); 262 262 if (!cell->process || !cell->file_exists) { continue; } 263 263 264 264 while ((readout = pmFPAviewNextReadout (viewMask, outMask->fpa, 1)) != NULL) { 265 265 if (! readout->data_exists) { continue; } 266 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;267 }268 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;269 }270 271 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;272 if (REFSTAR_MASK_REGIONS) {273 fclose (f);274 }266 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE; 267 } 268 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE; 269 } 270 271 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE; 272 if (REFSTAR_MASK_REGIONS) { 273 fclose (f); 274 } 275 275 } 276 276 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE; … … 299 299 int yBin = 1; 300 300 301 // Position on the cell 301 // Position on the cell 302 302 float xCell = PM_CHIP_TO_CELL(xChip, x0Cell, xParityCell, xBin); 303 303 float yCell = PM_CHIP_TO_CELL(yChip, y0Cell, yParityCell, yBin); … … 306 306 for (int i = 0; i < chip->cells->n; i++) { 307 307 308 pmCell *cell = chip->cells->data[i];309 psRegion *region = pmCellExtent (cell);310 311 if (x < region->x0) goto skip;312 if (x > region->x1) goto skip;313 if (y < region->y0) goto skip;314 if (y > region->y1) goto skip;315 316 psFree (region);317 return cell;308 pmCell *cell = chip->cells->data[i]; 309 psRegion *region = pmCellExtent (cell); 310 311 if (x < region->x0) goto skip; 312 if (x > region->x1) goto skip; 313 if (y < region->y0) goto skip; 314 if (y > region->y1) goto skip; 315 316 psFree (region); 317 return cell; 318 318 319 319 skip: 320 psFree (region);320 psFree (region); 321 321 } 322 322 return NULL; … … 337 337 int yBin = 1; 338 338 339 // Position on the cell 339 // Position on the cell 340 340 // ((pos)*(binning)*(cellParity) + (cell0)) 341 341 // XXX this is probably totally wrong now.... … … 361 361 int yBin = 1; 362 362 363 // Position on the cell 363 // Position on the cell 364 364 // ((pos)*(binning)*(cellParity) + (cell0)) 365 365 // XXX this is probably totally wrong now.... 366 366 // ((pos) - (cell0))*(cellParity)/(binning)) 367 *xChip = xCell*xBin*xParityCell + x0Cell; 368 *yChip = yCell*yBin*yParityCell + y0Cell; 367 *xChip = xCell*xBin*xParityCell + x0Cell; 368 *yChip = yCell*yBin*yParityCell + y0Cell; 369 369 370 370 return true; … … 376 376 // XXX need to worry about row0, col0 377 377 for (int ix = -dX; ix <= +dX; ix++) { 378 int jx = ix + x0;379 if (jx < 0) continue;380 if (jx >= mask->numCols) continue;381 for (int iy = -dY; iy <= +dY; iy++) {382 int jy = iy + y0;383 if (jy < 0) continue;384 if (jy >= mask->numRows) continue;385 386 double r2 = PS_SQR(ix/dX) + PS_SQR(iy/dY);387 if (r2 > 1.0) continue;388 389 mask->data.U8[jy][jx] |= value;390 }378 int jx = ix + x0; 379 if (jx < 0) continue; 380 if (jx >= mask->numCols) continue; 381 for (int iy = -dY; iy <= +dY; iy++) { 382 int jy = iy + y0; 383 if (jy < 0) continue; 384 if (jy >= mask->numRows) continue; 385 386 double r2 = PS_SQR(ix/dX) + PS_SQR(iy/dY); 387 if (r2 > 1.0) continue; 388 389 mask->data.U8[jy][jx] |= value; 390 } 391 391 } 392 392 return true; … … 415 415 416 416 /* rather than draw the line from float positions, we find the closest 417 integer end-points and draw the line between those pixels */ 417 integer end-points and draw the line between those pixels */ 418 418 419 419 X1 = ROUND(x1); … … 449 449 e = 0; 450 450 for (X = X1; X <= X2; X++) { 451 if (X > 0) {452 if (swapcoords) {453 if (X >= mask->numRows) continue;454 for (int y = Y - dW; y <= Y + dW; y++) {455 if (y < 0) continue;456 if (y >= mask->numCols) continue;457 mask->data.U8[X][y] |= value;458 }459 } else {460 if (X >= mask->numCols) continue;461 for (int y = Y - dW; y <= Y + dW; y++) {462 if (y < 0) continue;463 if (y >= mask->numRows) continue;464 mask->data.U8[y][X] |= value;465 }466 }467 }468 e += dY;469 e2 = 2 * e;470 if (e2 > dX) {471 Y++;472 e -= dX;473 } 474 if (e2 < -dX) {475 Y--;476 e += dX;477 }451 if (X > 0) { 452 if (swapcoords) { 453 if (X >= mask->numRows) continue; 454 for (int y = Y - dW; y <= Y + dW; y++) { 455 if (y < 0) continue; 456 if (y >= mask->numCols) continue; 457 mask->data.U8[X][y] |= value; 458 } 459 } else { 460 if (X >= mask->numCols) continue; 461 for (int y = Y - dW; y <= Y + dW; y++) { 462 if (y < 0) continue; 463 if (y >= mask->numRows) continue; 464 mask->data.U8[y][X] |= value; 465 } 466 } 467 } 468 e += dY; 469 e2 = 2 * e; 470 if (e2 > dX) { 471 Y++; 472 e -= dX; 473 } 474 if (e2 < -dX) { 475 Y--; 476 e += dX; 477 } 478 478 } 479 479 return; … … 481 481 482 482 void psastroMaskRectangle (psImage *mask, char value, int x0, int y0, int x1, int y1) { 483 483 484 484 int xs = PS_MAX (0, PS_MIN (mask->numCols, PS_MIN (x0, x1))); 485 485 int xe = PS_MAX (0, PS_MIN (mask->numCols, PS_MAX (x0, x1))); … … 488 488 489 489 for (int iy = ys; iy < ye; iy++) { 490 for (int ix = xs; ix < xe; ix++) {491 mask->data.U8[iy][ix] |= value;492 }493 } 494 } 495 490 for (int ix = xs; ix < xe; ix++) { 491 mask->data.U8[iy][ix] |= value; 492 } 493 } 494 } 495
Note:
See TracChangeset
for help on using the changeset viewer.
