Changeset 27838 for branches/tap_branches/psastro/src/psastroMaskUpdates.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psastro/src/psastroMaskUpdates.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psastro/src/psastroMaskUpdates.c
r24701 r27838 1 1 /** @file psastroMaskUpdates.c 2 2 * 3 * @brief 3 * @brief 4 4 * 5 5 * @ingroup libpsastro … … 34 34 psImageMaskType spikeMaskValue = pmConfigMaskGet("SPIKE", config); // Mask value for ghost pixels 35 35 psImageMaskType starMaskValue = pmConfigMaskGet("STARCORE", config); // Mask value for ghost pixels 36 psImageMaskType crosstalkMaskValue = pmConfigMaskGet("GHOST", config); // Mask value for crosstalk ghosts 36 37 37 38 // psImageMaskType maskBlank = pmConfigMaskGet("BLANK", config); // Mask value for blank pixels … … 47 48 bool REFSTAR_MASK = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK"); 48 49 if (!REFSTAR_MASK) return true; 50 51 // convert star positions to crosstalk artifact positions and add to the readout->analysis data 52 bool CROSSTALK_MASK = psMetadataLookupBool (&status, recipe, "CROSSTALK_MASK"); 53 if (CROSSTALK_MASK && !psastroLoadCrosstalk (config)) { 54 psError(PSASTRO_ERR_CONFIG, false, "Error loading crosstalk data"); 55 return(false); 56 } 49 57 50 58 // convert star positions to ghost positions and add to the readout->analysis data … … 73 81 double REFSTAR_MASK_SATSPIKE_MAG_MAX = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_SATSPIKE_MAG_MAX"); 74 82 double REFSTAR_MASK_SATSPIKE_WIDTH = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_SATSPIKE_WIDTH"); 83 double REFSTAR_MASK_SATSPIKE_OFFSET = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_SATSPIKE_OFFSET"); 75 84 double REFSTAR_MASK_BLEED_MAG_MAX = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_MAX"); 76 85 double REFSTAR_MASK_BLEED_MAG_SLOPE = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_SLOPE"); 86 87 double REFSTAR_MASK_CROSSTALK_MAG_MAX = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_MAX"); 88 double REFSTAR_MASK_CROSSTALK_MAG_SLOPE= psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_SLOPE"); 77 89 78 90 // select the input data sources … … 177 189 if (! readout->data_exists) { continue; } 178 190 179 // XXX why not do this? 180 pmReadout *readoutMask = pmFPAviewThisReadout (view, outMask->fpa);181 if (!readoutMask) continue;191 // XXX why not do this? 192 pmReadout *readoutMask = pmFPAviewThisReadout (view, outMask->fpa); 193 if (!readoutMask) continue; 182 194 183 195 // select the raw objects for this readout 196 // XXX : note that we place limits on the refstar sample in psastroChooseRefstars.c: 197 // 1) on chip and 2) < PSASTRO.MAX.NREF. magnitude limits and clump exclusion are only 198 // applied to the SUBSETs 184 199 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS"); 185 200 if (!refstars) continue; … … 189 204 // 2) diffraction spikes in direction ROT - ROTo 190 205 // 3) bleed trail in the direction of the readout 191 // update: with 'burntool' applied to the data, the bleed trail mask is not needed.206 // update: with 'burntool' applied to the data, the bleed trail mask is not needed. 192 207 193 208 for (int i = 0; i < refstars->n; i++) { 194 209 pmAstromObj *ref = refstars->data[i]; 195 196 if (COUNT_GHOSTS) {197 if (ref->Mag > GHOST_MAX_MAG) {198 nGhosts ++;199 }200 }210 211 if (COUNT_GHOSTS) { 212 if (ref->Mag > GHOST_MAX_MAG) { 213 nGhosts ++; 214 } 215 } 201 216 202 217 if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue; 203 218 204 // the reference magnitudes have been converted from the instrumental 205 // values supplied in the recipe to apparent mags (above) 219 220 // the reference magnitudes have been converted from the instrumental 221 // values supplied in the recipe to apparent mags (above) 206 222 207 223 // CIRCLE around the stars (scaled by magnitude) … … 209 225 210 226 // XXX for now, assume cell binning is 1x1 relative to chip 211 psastroMaskCircle (readoutMask->mask, starMaskValue, ref->chip->x, ref->chip->y, radius, radius);227 psastroMaskCircle (readoutMask->mask, starMaskValue, ref->chip->x, ref->chip->y, radius, radius); 212 228 213 229 for (float theta = 0.0; theta < 2*M_PI; theta += M_PI / 2.0) { … … 215 231 float Theta = theta - ROTANGLE - REFSTAR_MASK_SATSTAR_POS_ZERO; 216 232 217 // LINE for boundaries of the saturation spikes (scaled by magnitude) 218 // float MAG_MAX = (theta == 0.0) || (theta == M_PI) ? REFSTAR_MASK_SATSPIKE_MAG_MAX1 : REFSTAR_MASK_SATSPIKE_MAG_MAX2; 219 220 float MAG_MAX = REFSTAR_MASK_SATSPIKE_MAG_MAX; 221 float spikeLength = REFSTAR_MASK_SATSPIKE_MAG_SLOPE * (MAG_MAX - ref->Mag); 222 float spikeWidth = 0.5*REFSTAR_MASK_SATSPIKE_WIDTH; 223 // XXX we can make the width depend on the spike as well... 224 // The length should also be a function of the image background level 225 226 psastroMaskBox (readoutMask->mask, spikeMaskValue, ref->chip->x, ref->chip->y, spikeLength, spikeWidth, Theta); 227 } 228 229 // This masking option was needed for persistent charge trails in GPC1; it 230 // has since been replaced with 'burntool', which is applied upon readout 231 // by the camera software, and therefore is aware of the image sequence. 232 if (REFSTAR_MASK_BLEED) { 233 // convert x,y chip coordinates to cells in maskChip 234 pmCell *refCell = pmCellInChip (refChip, ref->chip->x, ref->chip->y); 235 236 // LINE for boundaries of the bleed lines 237 if (refCell) { 238 float xCell = 0.0; 239 float yCell = 0.0; 240 float xEnd = 0.0; 241 float yEnd = 0.0; 242 // find coordinate of star on cell 243 pmCellCoordsForChip (&xCell, &yCell, refCell, ref->chip->x, ref->chip->y); 244 // find coordinate of end-point on chip 245 246 int ySize = psMetadataLookupS32(NULL, refCell->concepts, "CELL.YSIZE"); 247 pmChipCoordsForCell (&xEnd, &yEnd, refCell, xCell, ySize); 248 249 float width = REFSTAR_MASK_BLEED_MAG_SLOPE*(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag); 250 psastroMaskRectangle (readoutMask->mask, spikeMaskValue, (int) ref->chip->x-0.5*width, (int) ref->chip->y, (int) ref->chip->x+0.5*width+1, yEnd); 233 // LINE for boundaries of the saturation spikes (scaled by magnitude) 234 // float MAG_MAX = (theta == 0.0) || (theta == M_PI) ? REFSTAR_MASK_SATSPIKE_MAG_MAX1 : REFSTAR_MASK_SATSPIKE_MAG_MAX2; 235 236 float MAG_MAX = REFSTAR_MASK_SATSPIKE_MAG_MAX; 237 float spikeLength = pow(10,REFSTAR_MASK_SATSPIKE_MAG_SLOPE * (MAG_MAX - ref->Mag)) - REFSTAR_MASK_SATSPIKE_OFFSET; 238 float spikeWidth = 0.5*REFSTAR_MASK_SATSPIKE_WIDTH; 239 if (spikeLength < 0.0) { 240 spikeLength = 0.0; 251 241 } 252 } 242 // XXX we can make the width depend on the spike as well... 243 // The length should also be a function of the image background level 244 245 psastroMaskBox (readoutMask->mask, spikeMaskValue, ref->chip->x, ref->chip->y, spikeLength, spikeWidth, Theta); 246 } 247 248 // This masking option was needed for persistent charge trails in GPC1; it 249 // has since been replaced with 'burntool', which is applied upon readout 250 // by the camera software, and therefore is aware of the image sequence. 251 if (REFSTAR_MASK_BLEED) { 252 // convert x,y chip coordinates to cells in maskChip 253 pmCell *refCell = pmCellInChip (refChip, ref->chip->x, ref->chip->y); 254 255 // LINE for boundaries of the bleed lines 256 if (refCell) { 257 float xCell = 0.0; 258 float yCell = 0.0; 259 float xEnd = 0.0; 260 float yEnd = 0.0; 261 // find coordinate of star on cell 262 pmCellCoordsForChip (&xCell, &yCell, refCell, ref->chip->x, ref->chip->y); 263 // find coordinate of end-point on chip 264 265 int ySize = psMetadataLookupS32(NULL, refCell->concepts, "CELL.YSIZE"); 266 pmChipCoordsForCell (&xEnd, &yEnd, refCell, xCell, ySize); 267 268 float width = REFSTAR_MASK_BLEED_MAG_SLOPE*(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag); 269 psastroMaskRectangle (readoutMask->mask, spikeMaskValue, (int) ref->chip->x-0.5*width, (int) ref->chip->y, (int) ref->chip->x+0.5*width+1, yEnd); 270 } 271 } 253 272 } 254 273 … … 259 278 // supplied here. 260 279 psArray *ghosts = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.GHOSTS"); 261 if (ghosts) { 262 // mask the ghosts on this readout263 for (int i = 0; i < ghosts->n; i++) {264 psastroGhost *ghost = ghosts->data[i];265 // XXX bright vs faint ghost bits? (OR with SUSPECT) 266 psastroMaskEllipticalAnnulus (readoutMask->mask, ghostMaskValue, ghost->chip->x, ghost->chip->y, ghost->inner, ghost->outer);267 }268 }280 if (ghosts) { 281 // mask the ghosts on this readout 282 for (int i = 0; i < ghosts->n; i++) { 283 psastroGhost *ghost = ghosts->data[i]; 284 // XXX bright vs faint ghost bits? (OR with SUSPECT) 285 psastroMaskEllipticalAnnulus (readoutMask->mask, ghostMaskValue, ghost->chip->x, ghost->chip->y, ghost->inner, ghost->outer); 286 } 287 } 269 288 270 289 // Select the glint mask regions for this readout (loaded in … … 275 294 psArray *glints = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.GLINTS"); 276 295 if (glints) { 277 // mask the glints on this readout 278 for (int i = 0; i < glints->n; i++) { 279 psRegion *glint = glints->data[i]; 280 psastroMaskRectangle (readoutMask->mask, glintMaskValue, glint->x0, glint->y0, glint->x1, glint->y1); 281 } 282 } 283 284 // this probably should move into a function of its own: 285 { 286 // select the raw objects for this readout, flag is they fall in a mask 287 psArray *inSources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES"); 288 if (inSources == NULL) continue; 289 290 // create a replacement output array: 291 // psArray *outSources = psAllocArrayEmpty(100); 292 293 // XXX finish this: raise a bit for stars that land on certain types of masks; 294 // others (eg, bright star core) should be ignored. 295 for (int i = 0; i < inSources->n; i++) { 296 pmSource *source = inSources->data[i]; 297 298 int xChip = source->peak->x; 299 int yChip = source->peak->y; 300 301 bool onChip = true; 302 onChip &= (xChip >= 0); 303 onChip &= (xChip < readoutMask->mask->numCols); 304 onChip &= (yChip >= 0); 305 onChip &= (yChip < readoutMask->mask->numRows); 306 if (!onChip) { 307 // if the source is off the edge of the chip, raise a different bit? 308 source->mode |= PM_SOURCE_MODE_OFF_CHIP; 309 continue; 310 } 311 312 psImageMaskType value = readoutMask->mask->data.PS_TYPE_IMAGE_MASK_DATA[yChip][xChip]; 313 if (value & ghostMaskValue) { 314 source->mode |= PM_SOURCE_MODE_ON_GHOST; 315 } 316 // XXX note that for now, glint and ghost are identical 317 pmSourceMode PM_SOURCE_MODE_ON_GLINT = PM_SOURCE_MODE_ON_GHOST; 318 if (value & glintMaskValue) { 319 source->mode |= PM_SOURCE_MODE_ON_GLINT; 320 } 321 if (value & spikeMaskValue) { 322 source->mode |= PM_SOURCE_MODE_ON_SPIKE; 323 } 324 } 325 } 296 // mask the glints on this readout 297 for (int i = 0; i < glints->n; i++) { 298 psRegion *glint = glints->data[i]; 299 psastroMaskRectangle (readoutMask->mask, glintMaskValue, glint->x0, glint->y0, glint->x1, glint->y1); 300 } 301 } 302 303 // Select the crosstalk artifact regions for this readout, and mask a circular region 304 // corresponding to the source star 305 306 psArray *crosstalks = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.CROSSTALKS"); 307 if (crosstalks) { 308 for (int i = 0; i < crosstalks->n; i++) { 309 pmAstromObj *ref = crosstalks->data[i]; 310 float radius = REFSTAR_MASK_CROSSTALK_MAG_SLOPE * (REFSTAR_MASK_CROSSTALK_MAG_MAX - ref->Mag); 311 psTrace("psastro.crosstalk",2,"Masking star on Chip %s @ (%f,%f) Magnitude: %f Radius %f\n", 312 psMetadataLookupStr(&status,readout->parent->parent->concepts,"CHIP.NAME"), 313 ref->chip->x,ref->chip->y,ref->Mag,radius); 314 // XXX for now, assume cell binning is 1x1 relative to chip 315 psastroMaskCircle (readoutMask->mask, crosstalkMaskValue, ref->chip->x, ref->chip->y, radius, radius); 316 } 317 } 318 319 // this probably should move into a function of its own: 320 { 321 // select the raw objects for this readout, flag is they fall in a mask 322 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 323 if (!detections) continue; 324 325 psArray *inSources = detections->allSources; 326 psAssert (inSources, "missing sources?"); 327 328 // create a replacement output array: 329 // psArray *outSources = psAllocArrayEmpty(100); 330 331 // XXX finish this: raise a bit for stars that land on certain types of masks; 332 // others (eg, bright star core) should be ignored. 333 for (int i = 0; i < inSources->n; i++) { 334 pmSource *source = inSources->data[i]; 335 336 int xChip = source->peak->x; 337 int yChip = source->peak->y; 338 339 bool onChip = true; 340 onChip &= (xChip >= 0); 341 onChip &= (xChip < readoutMask->mask->numCols); 342 onChip &= (yChip >= 0); 343 onChip &= (yChip < readoutMask->mask->numRows); 344 if (!onChip) { 345 // if the source is off the edge of the chip, raise a different bit? 346 source->mode |= PM_SOURCE_MODE_OFF_CHIP; 347 continue; 348 } 349 350 psImageMaskType value = readoutMask->mask->data.PS_TYPE_IMAGE_MASK_DATA[yChip][xChip]; 351 if (value & ghostMaskValue) { 352 source->mode |= PM_SOURCE_MODE_ON_GHOST; 353 } 354 // XXX note that for now, glint and ghost are identical 355 pmSourceMode PM_SOURCE_MODE_ON_GLINT = PM_SOURCE_MODE_ON_GHOST; 356 if (value & glintMaskValue) { 357 source->mode |= PM_SOURCE_MODE_ON_GLINT; 358 } 359 if (value & spikeMaskValue) { 360 source->mode |= PM_SOURCE_MODE_ON_SPIKE; 361 } 362 } 363 } 326 364 } 327 365 } … … 344 382 345 383 if (COUNT_GHOSTS) { 346 // save nGhosts to update header.347 psMetadata *updates = psMetadataLookupMetadata (&status, fpa->analysis, "PSASTRO.HEADER");348 if (!updates) {349 updates = psMetadataAlloc ();350 psMetadataAddMetadata (fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", updates);351 psFree (updates);352 }353 psMetadataAddS32 (updates, PS_LIST_TAIL, "NGHOSTS", PS_META_REPLACE, "total expected ghosts", nGhosts);384 // save nGhosts to update header. 385 psMetadata *updates = psMetadataLookupMetadata (&status, fpa->analysis, "PSASTRO.HEADER"); 386 if (!updates) { 387 updates = psMetadataAlloc (); 388 psMetadataAddMetadata (fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", updates); 389 psFree (updates); 390 } 391 psMetadataAddS32 (updates, PS_LIST_TAIL, "NGHOSTS", PS_META_REPLACE, "total expected ghosts", nGhosts); 354 392 } 355 393
Note:
See TracChangeset
for help on using the changeset viewer.
