- Timestamp:
- Apr 13, 2021, 12:55:39 PM (5 years ago)
- Location:
- trunk/psastro/src
- Files:
-
- 2 edited
-
psastroLoadCrosstalk.c (modified) (4 diffs)
-
psastroMaskUpdates.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroLoadCrosstalk.c
r41434 r41551 85 85 } 86 86 // Activate the reference mask to generate an FPA structure we can use to map stars down to cells 87 88 87 pmFPAfileActivate (config->files, false, NULL); 89 88 pmFPAfileActivate (config->files, true, "PSASTRO.REFMASK"); 90 91 // pmFPA *refFPA = refMask->fpa;92 89 93 90 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE; … … 108 105 SPIKE_MAX_MAG = psMetadataLookupF32(&status, recipe, "REFSTAR_MASK_BLEED_MAG_MAX"); 109 106 SPIKE_MAX_MAG += MagOffset; 107 108 //we will use one of the new keywords to differentiate between an old and new style crosstalk treatment 109 float crossCheck = 0; 110 char *crossFile = psMetadataLookupStr (&status, recipe, "CROSSTALK_FILE"); 111 if (!strcasecmp(crossFile, "NONE")) { 112 psLogMsg ("psastro", PS_LOG_INFO, "Assuming old-style crostalk masking, with small number of rules"); 113 crossCheck = 1; 114 } 115 110 116 // psTraceSetLevel("psastro.crosstalk",2); 111 117 psTrace("psastro.crosstalk",2,"%f %f %f %f\n",zeropt,exptime,MAX_MAG,MagOffset); … … 124 130 int X = chipName[2] - '0'; 125 131 int Y = chipName[3] - '0'; 132 int chipNum = (X*10)+Y ; 126 133 127 134 // Read each cell (at this stage, we should only have one of them) … … 135 142 if (! readout->data_exists) { continue; } 136 143 137 // If this chip doesn't crosstalk, skip to the next one. 138 if (! ((X == 2)||(X == 5))) { 139 psTrace ("psastro.crosstalk",2,"Chip (%d%d) not a known crosstalk source.",X,Y); 140 continue; 141 } 142 143 // To check for the presence of crosstalk we first make use the actual detections on this image. 144 // That way we can include things like movers creating crosstalk features. 145 psArray *calstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.CALSTARS"); 146 if (calstars == NULL) { continue; } 147 148 for (int i = 0; i < calstars->n; i++) { 149 pmAstromObj *cal = calstars->data[i]; 150 151 if (cal->Mag > INSTR_MAX_MAG) { 144 //old crosstalk method, with limited hard-coded rules 145 if(crossCheck) { 146 // If this chip doesn't crosstalk, skip to the next one. 147 if (! ((X == 2)||(X == 5))) { 148 psTrace ("psastro.crosstalk",2,"Chip (%d%d) not a known crosstalk source.",X,Y); 152 149 continue; 153 150 } 154 151 155 // Identify which cell holds the star 156 pmChip *CTsourceChip = refChip; 157 pmCell *CTsourceCell = pmCellInChip(refChip,cal->chip->x,cal->chip->y); 158 159 if (!CTsourceCell) { 160 continue; 152 // To check for the presence of crosstalk we first make use the actual detections on this image. 153 // That way we can include things like movers creating crosstalk features. 154 psArray *calstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.CALSTARS"); 155 if (calstars == NULL) { continue; } 156 157 for (int i = 0; i < calstars->n; i++) { 158 pmAstromObj *cal = calstars->data[i]; 159 160 if (cal->Mag > INSTR_MAX_MAG) { continue; } 161 162 // Identify which cell holds the star 163 pmChip *CTsourceChip = refChip; 164 pmCell *CTsourceCell = pmCellInChip(refChip,cal->chip->x,cal->chip->y); 165 166 if (!CTsourceCell) { continue; } 167 168 psTrace ("psastro.crosstalk",2,"DETEC: %d %f :: %f %f\n", 169 i,cal->Mag, cal->chip->x,cal->chip->y); 170 171 const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME"); 172 int U = cellName[2] - '0'; 173 int V = cellName[3] - '0'; 174 175 int Xt = X,Yt = Y,Ut = U,Vt = V; 176 float x_cell,y_cell; 177 float x_t_cell,y_t_cell; 178 179 float x_t_chip,y_t_chip; 180 // int faint_ct = 0; NOTE: not currently used 181 pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,cal->chip->x,cal->chip->y); 182 183 x_t_cell = x_cell; 184 y_t_cell = y_cell; 185 186 // 2020-10-21 TdB: Here is the list of known cross talks from the bright star analysis: 187 // The relationships work using OTA"XY"XY"UV" 188 // Inter-chip 189 // OTA2yXY3v => OTA3yXY3v 190 // OTA4yXY3v <= OTA5yXY3v 191 // Intra-chip 192 // OTA2yXY5v <=> OTA2yXY6v 193 // OTA5yXY5v <=> OTA5yXY6v 194 // One way fainter 195 // OTA2yXY7v => OTA3yXY2v 196 // OTA5yXY7v => OTA4yXY2v 197 // Determine if this combination of chip and cell produces a crosstalk artifact 198 if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))) { 199 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 200 psTrace ("psastro.crosstalk",2,"t1: %d t2: %d", 201 (X == 2), 202 (! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))); 203 continue; 204 } 205 if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))) { 206 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 207 continue; 208 } 209 210 // Calculate destination positions 211 if (X == 2) { 212 if (U == 3) { 213 Xt = 3; 214 } 215 if (U == 5) { 216 Ut = 6; 217 } 218 if (U == 6) { 219 Ut = 5; 220 } 221 if (U == 7) { 222 Xt = 3; 223 Ut = 2; 224 // faint_ct = 1; NOTE: not currently used 225 } 226 } 227 if (X == 5) { 228 if (U == 3) { 229 Xt = 4; 230 } 231 if (U == 5) { 232 Ut = 6; 233 } 234 if (U == 6) { 235 Ut = 5; 236 } 237 if (U == 7) { 238 Xt = 4; 239 Ut = 2; 240 // faint_ct = 1; NOTE: not currently used 241 } 242 } 243 244 // Convert target cell coordinates to target chip coordinates 245 psString targetChipName = NULL; 246 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt); 247 psString targetCellName = NULL; 248 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt); 249 250 psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", 251 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, 252 targetChipName,targetCellName); 253 254 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 255 if (!CTtargetCell) continue; 256 257 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 258 259 psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)", 260 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 261 262 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 263 pmChip *targetChip = getChipByName(fpa,targetChipName); 264 if (!targetChip) continue; 265 if (!targetChip->cells) continue; 266 if (!targetChip->cells->n) continue; 267 268 pmCell *targetCell = targetChip->cells->data[0]; 269 if (!targetCell) continue; 270 if (!targetCell->readouts) continue; 271 if (!targetCell->readouts->n) continue; 272 pmReadout *targetReadout = targetCell->readouts->data[0]; 273 if (!targetReadout) continue; 274 275 pmAstromObj *crosstalk = pmAstromObjAlloc(); 276 277 crosstalk->Mag = cal->Mag; 278 crosstalk->chip->x = x_t_chip; 279 crosstalk->chip->y = y_t_chip; 280 281 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS"); 282 if (crosstalks == NULL) { 283 crosstalks = psArrayAllocEmpty(100); 284 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 285 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 286 goto escape; 287 } 288 psFree(crosstalks); 289 } 290 psArrayAdd(crosstalks,100,crosstalk); 291 292 psFree(targetChipName); 293 psFree(targetCellName); 294 psFree(crosstalk); 295 296 // Determine if we need to add a spike mask. 297 // CZW 2014-04-15 I'm not adding the new faint CT to this operation. There's no evidence they produce such things. 298 if (cal->Mag < SPIKE_MAX_MAG) { 299 if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)))) { 300 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 301 continue; 302 } 303 if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)))) { 304 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 305 continue; 306 } 307 308 Xt = X; 309 Yt = Y; 310 Vt = V; 311 312 for (Ut = 0; Ut < 8; Ut++) { 313 psString targetChipName = NULL; 314 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt); 315 psString targetCellName = NULL; 316 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt); 317 318 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", 319 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, 320 targetChipName,targetCellName); 321 322 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 323 if (!CTtargetCell) continue; 324 325 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 326 327 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)", 328 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 329 330 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 331 pmChip *targetChip = getChipByName(fpa,targetChipName); 332 if (!targetChip) continue; 333 if (!targetChip->cells) continue; 334 if (!targetChip->cells->n) continue; 335 336 pmCell *targetCell = targetChip->cells->data[0]; 337 if (!targetCell) continue; 338 if (!targetCell->readouts) continue; 339 if (!targetCell->readouts->n) continue; 340 pmReadout *targetReadout = targetCell->readouts->data[0]; 341 if (!targetReadout) continue; 342 343 pmAstromObj *crosstalk = pmAstromObjAlloc(); 344 345 crosstalk->Mag = cal->Mag; 346 crosstalk->chip->x = x_t_chip; 347 crosstalk->chip->y = y_t_chip; 348 349 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES"); 350 if (crosstalks == NULL) { 351 crosstalks = psArrayAllocEmpty(100); 352 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 353 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 354 goto escape; 355 } 356 psFree(crosstalks); 357 } 358 psArrayAdd(crosstalks,100,crosstalk); 359 360 psFree(targetChipName); 361 psFree(targetCellName); 362 psFree(crosstalk); 363 } 364 } // End satspike crosstalks 365 161 366 } 162 163 psTrace ("psastro.crosstalk",2,"DETEC: %d %f :: %f %f\n", 164 i,cal->Mag, cal->chip->x,cal->chip->y); 165 166 const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME"); 167 int U = cellName[2] - '0'; 168 int V = cellName[3] - '0'; 169 170 int Xt = X,Yt = Y,Ut = U,Vt = V; 171 float x_cell,y_cell; 172 float x_t_cell,y_t_cell; 173 174 float x_t_chip,y_t_chip; 175 // int faint_ct = 0; NOTE: not currently used 176 pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,cal->chip->x,cal->chip->y); 177 178 x_t_cell = x_cell; 179 y_t_cell = y_cell; 180 181 // 2020-10-21 TdB: Here is the list of known cross talks from the bright star analysis: 182 // The relationships work using OTA"XY"XY"UV" 183 // Inter-chip 184 // OTA2yXY3v => OTA3yXY3v 185 // OTA4yXY3v <= OTA5yXY3v 186 // Intra-chip 187 // OTA2yXY5v <=> OTA2yXY6v 188 // OTA5yXY5v <=> OTA5yXY6v 189 // One way fainter 190 // OTA2yXY7v => OTA3yXY2v 191 // OTA5yXY7v => OTA4yXY2v 192 // Determine if this combination of chip and cell produces a crosstalk artifact 193 if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))) { 194 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 195 psTrace ("psastro.crosstalk",2,"t1: %d t2: %d", 196 (X == 2), 197 (! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))); 198 continue; 367 } 368 369 //----------------------------------------------------------------- 370 //----------------------------------------------------------------- 371 //new style crostalk masking, with crosstalk rules from the recipes 372 if(!crossCheck) { 373 // load ghost model metadata structure 374 psMetadata *crossModel = NULL; 375 if (!pmConfigFileRead (&crossModel, crossFile, "CROSS MODEL")) { 376 psError(PSASTRO_ERR_CONFIG, true, "Trouble loading crosstalk rules file"); 377 return false; 199 378 } 200 if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))) { 201 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 202 continue; 379 380 // get the set of crosstalk rules (CROSSTALK.RULE is a MULTI of METADATA items) 381 psMetadataItem *crossRules = psMetadataLookup (crossModel, "CROSSTALK.RULE"); 382 if (crossRules->type != PS_DATA_METADATA_MULTI) { 383 psWarning ("CROSSTALK.RULE is not a MULTI\n"); 384 return true; 203 385 } 204 386 205 // Calculate destination positions 206 if (X == 2) { 207 if (U == 3) { 208 Xt = 3; 209 } 210 if (U == 5) { 211 Ut = 6; 212 } 213 if (U == 6) { 214 Ut = 5; 215 } 216 if (U == 7) { 217 Xt = 3; 218 Ut = 2; 219 // faint_ct = 1; NOTE: not currently used 220 } 221 } 222 if (X == 5) { 223 if (U == 3) { 224 Xt = 4; 225 } 226 if (U == 5) { 227 Ut = 6; 228 } 229 if (U == 6) { 230 Ut = 5; 231 } 232 if (U == 7) { 233 Xt = 4; 234 Ut = 2; 235 // faint_ct = 1; NOTE: not currently used 236 } 237 } 238 239 // Convert target cell coordinates to target chip coordinates 240 psString targetChipName = NULL; 241 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt); 242 psString targetCellName = NULL; 243 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt); 244 245 psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", 246 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, 247 targetChipName,targetCellName); 248 249 250 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 251 if (!CTtargetCell) continue; 252 253 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 254 255 psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)", 256 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 257 258 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 259 pmChip *targetChip = getChipByName(fpa,targetChipName); 260 if (!targetChip) continue; 261 if (!targetChip->cells) continue; 262 if (!targetChip->cells->n) continue; 263 264 pmCell *targetCell = targetChip->cells->data[0]; 265 if (!targetCell) continue; 266 if (!targetCell->readouts) continue; 267 if (!targetCell->readouts->n) continue; 268 pmReadout *targetReadout = targetCell->readouts->data[0]; 269 if (!targetReadout) continue; 270 271 pmAstromObj *crosstalk = pmAstromObjAlloc(); 272 273 crosstalk->Mag = cal->Mag; 274 crosstalk->chip->x = x_t_chip; 275 crosstalk->chip->y = y_t_chip; 276 277 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS"); 278 if (crosstalks == NULL) { 279 crosstalks = psArrayAllocEmpty(100); 280 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 281 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 282 goto escape; 283 } 284 psFree(crosstalks); 285 } 286 psArrayAdd(crosstalks,100,crosstalk); 287 288 psFree(targetChipName); 289 psFree(targetCellName); 290 psFree(crosstalk); 291 } 292 293 294 // We also want to use the refstars to check for crosstalk. In particular, the detections 295 // do not do well for bright stars, and saturated detections will underestimate the size of the crostalk 296 // Get the array of reference stars we're concerned with. 297 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS"); 298 if (refstars == NULL) { return(true); } 299 300 // Check each reference star 301 for (int i = 0; i < refstars->n; i++) { 302 // This is the source of the ct. 303 pmAstromObj *ref = refstars->data[i]; 304 305 if (ref->Mag > MAX_MAG) { 306 continue; 307 } 308 309 // Identify which cell holds the star 310 pmChip *CTsourceChip = refChip; 311 pmCell *CTsourceCell = pmCellInChip(refChip,ref->chip->x,ref->chip->y); 312 313 if (!CTsourceCell) { 314 continue; 315 } 316 317 psTrace ("psastro.crosstalk",2,"REF: %d %f (%f %f) %f %f :: %f %f\n", 318 i,ref->Mag, ref->sky->r,ref->sky->d, ref->FP->x,ref->FP->y, ref->chip->x,ref->chip->y); 319 320 const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME"); 321 int U = cellName[2] - '0'; 322 int V = cellName[3] - '0'; 323 324 int Xt = X,Yt = Y,Ut = U,Vt = V; 325 float x_cell,y_cell; 326 float x_t_cell,y_t_cell; 327 328 float x_t_chip,y_t_chip; 329 // int faint_ct = 0; NOTE: not currently used 330 pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,ref->chip->x,ref->chip->y); 331 332 x_t_cell = x_cell; 333 y_t_cell = y_cell; 334 335 // 2020-10-21 TdB: Here is the list of known cross talks from the bright star analysis: 336 // The relationships work using OTA"XY"XY"UV" 337 // Inter-chip 338 // OTA2yXY3v => OTA3yXY3v 339 // OTA4yXY3v <= OTA5yXY3v 340 // Intra-chip 341 // OTA2yXY5v <=> OTA2yXY6v 342 // OTA5yXY5v <=> OTA5yXY6v 343 // One way fainter 344 // OTA2yXY7v => OTA3yXY2v 345 // OTA5yXY7v => OTA4yXY2v 346 // Determine if this combination of chip and cell produces a crosstalk artifact 347 if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))) { 348 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 349 psTrace ("psastro.crosstalk",2,"t1: %d t2: %d", 350 (X == 2), 351 (! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))); 352 continue; 353 } 354 if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)||(U == 7)))) { 355 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 356 continue; 357 } 358 359 // Calculate destination positions 360 if (X == 2) { 361 if (U == 3) { 362 Xt = 3; 363 } 364 if (U == 5) { 365 Ut = 6; 366 } 367 if (U == 6) { 368 Ut = 5; 369 } 370 if (U == 7) { 371 Xt = 3; 372 Ut = 2; 373 // faint_ct = 1; NOTE: not currently used 374 } 375 } 376 if (X == 5) { 377 if (U == 3) { 378 Xt = 4; 379 } 380 if (U == 5) { 381 Ut = 6; 382 } 383 if (U == 6) { 384 Ut = 5; 385 } 386 if (U == 7) { 387 Xt = 4; 388 Ut = 2; 389 // faint_ct = 1; NOTE: not currently used 390 } 391 } 392 393 // Convert target cell coordinates to target chip coordinates 394 psString targetChipName = NULL; 395 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt); 396 psString targetCellName = NULL; 397 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt); 398 399 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", 400 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, 401 targetChipName,targetCellName); 402 403 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 404 if (!CTtargetCell) continue; 405 406 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 407 408 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)", 409 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 410 411 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 412 pmChip *targetChip = getChipByName(fpa,targetChipName); 413 if (!targetChip) continue; 414 if (!targetChip->cells) continue; 415 if (!targetChip->cells->n) continue; 416 417 pmCell *targetCell = targetChip->cells->data[0]; 418 if (!targetCell) continue; 419 if (!targetCell->readouts) continue; 420 if (!targetCell->readouts->n) continue; 421 pmReadout *targetReadout = targetCell->readouts->data[0]; 422 if (!targetReadout) continue; 423 424 pmAstromObj *crosstalk = pmAstromObjAlloc(); 425 426 crosstalk->Mag = ref->Mag - MagOffset; 427 crosstalk->chip->x = x_t_chip; 428 crosstalk->chip->y = y_t_chip; 429 crosstalk->chip->y = y_t_chip; 430 431 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS"); 432 if (crosstalks == NULL) { 433 crosstalks = psArrayAllocEmpty(100); 434 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 435 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 436 goto escape; 437 } 438 psFree(crosstalks); 439 } 440 psArrayAdd(crosstalks,100,crosstalk); 441 442 psFree(targetChipName); 443 psFree(targetCellName); 444 psFree(crosstalk); 445 446 // Determine if we need to add a spike mask. 447 // CZW 2014-04-15 I'm not adding the new faint CT to this operation. There's no evidence they produce such things. 448 /* psWarning("BLAH: %g %g %g\n",ref->Mag,MagOffset,SPIKE_MAX_MAG); */ 449 if (ref->Mag < SPIKE_MAX_MAG) { 450 if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)))) { 451 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 387 pmDetEff *de = psMetadataLookupPtr(NULL, readout->analysis, PM_DETEFF_ANALYSIS); // Detection efficiency 388 if (isnan(de->magRef)) { continue; } 389 390 // find the CROSSTALK.RUKE this chip lands in (if any) 391 psListIterator *crossIter = psListIteratorAlloc(crossRules->data.list, PS_LIST_HEAD, false); 392 psMetadataItem *crossItem = NULL; 393 while ((crossItem = psListGetAndIncrement (crossIter))) { 394 if (crossItem->type != PS_DATA_METADATA) { 395 psWarning ("CROSSTALK.RULE entry is not a metadata folder"); 452 396 continue; 453 397 } 454 if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)))) { 455 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 398 399 int crossChip = psMetadataLookupS32 (&status, crossItem->data.md, "CHIP.SRC"); 400 int crossCell = psMetadataLookupS32 (&status, crossItem->data.md, "CELL.SRC"); 401 int crossChipOffset = psMetadataLookupS32 (&status, crossItem->data.md, "CHIP.OFFSET"); 402 int crossCellOffset = psMetadataLookupS32 (&status, crossItem->data.md, "CELL.OFFSET"); 403 float crossMagOff = psMetadataLookupF32 (&status, crossItem->data.md, "CROSS.MAGDIFF"); 404 psLogMsg ("psastro", PS_LOG_INFO, "RULE: %d %d %d %d %f ", 405 crossChip,crossCell,crossChipOffset,crossCellOffset,crossMagOff); 406 if (!status) { 407 psWarning ("CROSSTALK.RULE entry is missing necessary entry"); 456 408 continue; 457 409 } 410 411 if (!(X == crossChip)) { 412 psTrace ("psastro.crosstalk",2,"Chip (%d%d) not a known crosstalk source.",X,Y); 413 psLogMsg ("psastro", PS_LOG_INFO, "Chip (%d%d) not a known crosstalk source.",X,Y); 414 continue; 415 } 416 417 //the source star needs to be bright enough to produce a crosstalk feature on the target chip/cell that is above the refmag 418 float INSTR_CROSS_MAX_MAG = de->magRef - crossMagOff; 419 float CROSS_MAX_MAG = INSTR_CROSS_MAX_MAG + MagOffset; 420 421 // To check for the presence of crosstalk we first make use the actual detections on this image. 422 // That way we can include things like movers creating crosstalk features. 423 psArray *calstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.CALSTARS"); 424 if (calstars == NULL) { continue; } 425 426 for (int i = 0; i < calstars->n; i++) { 427 pmAstromObj *cal = calstars->data[i]; 428 //kick out stars too faint to produce crosstalk with this rule 429 if (cal->Mag > INSTR_CROSS_MAX_MAG) { continue; } 430 431 // Identify which cell holds the star 432 pmChip *CTsourceChip = refChip; 433 pmCell *CTsourceCell = pmCellInChip(refChip,cal->chip->x,cal->chip->y); 434 if (!CTsourceCell) { continue; } 435 436 psTrace ("psastro.crosstalk",2,"DETEC: %d %f :: %f %f\n", 437 i,cal->Mag, cal->chip->x,cal->chip->y); 438 439 const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME"); 440 int U = cellName[2] - '0'; 441 int V = cellName[3] - '0'; 442 int cellNum = (U*10)+V ; 443 444 float x_cell,y_cell; 445 float x_t_cell,y_t_cell; 446 447 float x_t_chip,y_t_chip; 448 // int faint_ct = 0; NOTE: not currently used 449 pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,cal->chip->x,cal->chip->y); 450 451 x_t_cell = x_cell; 452 y_t_cell = y_cell; 453 454 if (! (U == crossCell) ) { 455 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 456 continue; 457 } 458 459 int chipTarget = chipNum + crossChipOffset ; 460 int cellTarget = cellNum + crossCellOffset ; 461 462 // Convert target cell coordinates to target chip coordinates 463 psString targetChipName = NULL; 464 if(chipTarget > 8) { 465 psStringAppend(&targetChipName,"XY%2d",chipTarget); 466 } 467 if(chipTarget < 8) { 468 psStringAppend(&targetChipName,"XY0%1d",chipTarget); 469 } 470 psString targetCellName = NULL; 471 if(cellTarget > 8) { 472 psStringAppend(&targetCellName,"xy%2d",cellTarget); 473 } 474 if(cellTarget < 8) { 475 psStringAppend(&targetCellName,"xy0%1d",cellTarget); 476 } 477 478 psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f [%s %s]", 479 X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell, 480 targetChipName,targetCellName); 481 482 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 483 if (!CTtargetCell) continue; 484 485 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 486 487 psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f)", 488 X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 489 490 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 491 pmChip *targetChip = getChipByName(fpa,targetChipName); 492 if (!targetChip) continue; 493 if (!targetChip->cells) continue; 494 if (!targetChip->cells->n) continue; 495 496 pmCell *targetCell = targetChip->cells->data[0]; 497 if (!targetCell) continue; 498 if (!targetCell->readouts) continue; 499 if (!targetCell->readouts->n) continue; 500 pmReadout *targetReadout = targetCell->readouts->data[0]; 501 if (!targetReadout) continue; 502 503 //check if the crosstalk is above the target chip background level 504 pmDetEff *tarde = psMetadataLookupPtr(NULL, targetReadout->analysis, PM_DETEFF_ANALYSIS); // Detection efficiency 505 if (isnan(tarde->magRef)) { continue; } 506 507 float TARGET_CROSS_MAX_MAG = tarde->magRef-crossMagOff; 508 509 if (cal->Mag > TARGET_CROSS_MAX_MAG) { continue; } 510 511 pmAstromObj *crosstalk = pmAstromObjAlloc(); 512 513 psLogMsg ("psastro", PS_LOG_INFO, "CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f) %f", 514 X,Y,U,V,cal->chip->x,cal->chip->y,chipTarget,cellTarget,x_t_cell,y_t_cell,x_t_chip,y_t_chip,cal->Mag); 515 516 crosstalk->Mag = cal->Mag; 517 crosstalk->chip->x = x_t_chip; 518 crosstalk->chip->y = y_t_chip; 519 520 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS"); 521 if (crosstalks == NULL) { 522 crosstalks = psArrayAllocEmpty(100); 523 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 524 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 525 goto escape; 526 } 527 psFree(crosstalks); 528 } 529 psArrayAdd(crosstalks,100,crosstalk); 530 531 psFree(targetChipName); 532 psFree(targetCellName); 533 psFree(crosstalk); 534 535 // Determine if we need to add a spike mask. 536 // TdB20210304: This should not be relevant for faint crosstalk rules. Do this rather ad hoc right now by placing a limit at 8 mags of difference 537 if( crossMagOff > 8.) { continue; } 538 if (cal->Mag < SPIKE_MAX_MAG) { 539 int Xt = X; 540 int Yt = Y; 541 int Vt = V; 458 542 459 Xt = X; 460 Yt = Y; 461 Vt = V; 543 for (int Ut = 0; Ut < 8; Ut++) { 544 psString targetChipName = NULL; 545 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt); 546 psString targetCellName = NULL; 547 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt); 548 549 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", 550 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, 551 targetChipName,targetCellName); 552 553 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 554 if (!CTtargetCell) continue; 555 556 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 557 558 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)", 559 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 560 561 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 562 pmChip *targetChip = getChipByName(fpa,targetChipName); 563 if (!targetChip) continue; 564 if (!targetChip->cells) continue; 565 if (!targetChip->cells->n) continue; 566 567 pmCell *targetCell = targetChip->cells->data[0]; 568 if (!targetCell) continue; 569 if (!targetCell->readouts) continue; 570 if (!targetCell->readouts->n) continue; 571 pmReadout *targetReadout = targetCell->readouts->data[0]; 572 if (!targetReadout) continue; 573 574 pmAstromObj *crosstalk = pmAstromObjAlloc(); 575 576 crosstalk->Mag = cal->Mag; 577 crosstalk->chip->x = x_t_chip; 578 crosstalk->chip->y = y_t_chip; 579 580 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES"); 581 if (crosstalks == NULL) { 582 crosstalks = psArrayAllocEmpty(100); 583 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 584 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 585 goto escape; 586 } 587 psFree(crosstalks); 588 } 589 psArrayAdd(crosstalks,100,crosstalk); 590 591 psFree(targetChipName); 592 psFree(targetCellName); 593 psFree(crosstalk); 594 } 595 } // End satspike crosstalks 596 } // End calMags 597 598 599 // We also want to use the refstars to check for crosstalk. In particular, the detections 600 // do not do well for bright stars, and saturated detections will underestimate the size of the crostalk 601 // Get the array of reference stars we're concerned with. 602 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS"); 603 if (refstars == NULL) { return(true); } 604 605 // Check each reference star 606 for (int i = 0; i < refstars->n; i++) { 607 // This is the source of the ct. 608 pmAstromObj *ref = refstars->data[i]; 609 610 if (ref->Mag > CROSS_MAX_MAG) { continue; } 611 612 // Identify which cell holds the star 613 pmChip *CTsourceChip = refChip; 614 pmCell *CTsourceCell = pmCellInChip(refChip,ref->chip->x,ref->chip->y); 615 616 if (!CTsourceCell) { continue; } 617 618 psTrace ("psastro.crosstalk",2,"REF: %d %f (%f %f) %f %f :: %f %f\n", 619 i,ref->Mag, ref->sky->r,ref->sky->d, ref->FP->x,ref->FP->y, ref->chip->x,ref->chip->y); 620 621 const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME"); 622 int U = cellName[2] - '0'; 623 int V = cellName[3] - '0'; 624 int cellNum = (U*10)+V ; 625 626 float x_cell,y_cell; 627 float x_t_cell,y_t_cell; 628 629 float x_t_chip,y_t_chip; 630 // int faint_ct = 0; NOTE: not currently used 631 pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,ref->chip->x,ref->chip->y); 632 633 x_t_cell = x_cell; 634 y_t_cell = y_cell; 635 636 if (! (U == crossCell) ) { 637 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 638 continue; 639 } 640 641 int chipTarget = chipNum + crossChipOffset ; 642 int cellTarget = cellNum + crossCellOffset ; 643 644 // Convert target cell coordinates to target chip coordinates 645 psString targetChipName = NULL; 646 if(chipTarget > 8) { 647 psStringAppend(&targetChipName,"XY%2d",chipTarget); 648 } 649 if(chipTarget < 8) { 650 psStringAppend(&targetChipName,"XY0%1d",chipTarget); 651 } 652 psString targetCellName = NULL; 653 if(cellTarget > 8) { 654 psStringAppend(&targetCellName,"xy%2d",cellTarget); 655 } 656 if(cellTarget < 8) { 657 psStringAppend(&targetCellName,"xy0%1d",cellTarget); 658 } 659 660 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f [%s %s]", 661 X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell, 662 targetChipName,targetCellName); 663 664 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 665 if (!CTtargetCell) continue; 666 667 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 668 669 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f)", 670 X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 671 psLogMsg ("psastro", PS_LOG_INFO, "MAXREF2:OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f)", 672 X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 673 674 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 675 pmChip *targetChip = getChipByName(fpa,targetChipName); 676 if (!targetChip) continue; 677 if (!targetChip->cells) continue; 678 if (!targetChip->cells->n) continue; 679 680 pmCell *targetCell = targetChip->cells->data[0]; 681 if (!targetCell) continue; 682 if (!targetCell->readouts) continue; 683 if (!targetCell->readouts->n) continue; 684 pmReadout *targetReadout = targetCell->readouts->data[0]; 685 if (!targetReadout) continue; 686 687 //check if the crosstalk is above the target chip background level 688 pmDetEff *tarde = psMetadataLookupPtr(NULL, targetReadout->analysis, PM_DETEFF_ANALYSIS); // Detection efficiency 689 if (isnan(tarde->magRef)) { continue; } 690 691 float TARGET_CROSS_MAX_MAG = tarde->magRef-crossMagOff + MagOffset; 692 if (ref->Mag > TARGET_CROSS_MAX_MAG) { continue; } 693 694 psLogMsg ("psastro", PS_LOG_INFO, "CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f) %f", 695 X,Y,U,V,ref->chip->x,ref->chip->y,chipTarget,cellTarget,x_t_cell,y_t_cell,x_t_chip,y_t_chip,ref->Mag); 696 697 pmAstromObj *crosstalk = pmAstromObjAlloc(); 698 699 crosstalk->Mag = ref->Mag - MagOffset; 700 crosstalk->chip->x = x_t_chip; 701 crosstalk->chip->y = y_t_chip; 702 703 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS"); 704 if (crosstalks == NULL) { 705 crosstalks = psArrayAllocEmpty(100); 706 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 707 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 708 goto escape; 709 } 710 psFree(crosstalks); 711 } 712 psArrayAdd(crosstalks,100,crosstalk); 713 714 psFree(targetChipName); 715 psFree(targetCellName); 716 psFree(crosstalk); 717 718 // Determine if we need to add a spike mask. 719 // TdB20210304: This should not be relevant for faint crosstalk rules. Do this rather ad hoc right now by placing a limit at 8 mags of difference 720 if( crossMagOff > 8.) { continue; } 721 if (ref->Mag < SPIKE_MAX_MAG) { 722 int Xt = X; 723 int Yt = Y; 724 int Vt = V; 462 725 463 for (Ut = 0; Ut < 8; Ut++) { 464 465 psString targetChipName = NULL; 466 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt); 467 psString targetCellName = NULL; 468 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt); 469 470 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", 471 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, 472 targetChipName,targetCellName); 473 /* psWarning ("CT bleed ct @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", */ 474 /* X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, */ 475 /* targetChipName,targetCellName); */ 476 477 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 478 if (!CTtargetCell) continue; 479 480 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 481 482 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)", 483 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 484 485 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 486 pmChip *targetChip = getChipByName(fpa,targetChipName); 487 if (!targetChip) continue; 488 if (!targetChip->cells) continue; 489 if (!targetChip->cells->n) continue; 490 491 pmCell *targetCell = targetChip->cells->data[0]; 492 if (!targetCell) continue; 493 if (!targetCell->readouts) continue; 494 if (!targetCell->readouts->n) continue; 495 pmReadout *targetReadout = targetCell->readouts->data[0]; 496 if (!targetReadout) continue; 497 498 pmAstromObj *crosstalk = pmAstromObjAlloc(); 499 500 crosstalk->Mag = ref->Mag; 501 crosstalk->chip->x = x_t_chip; 502 crosstalk->chip->y = y_t_chip; 503 504 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES"); 505 if (crosstalks == NULL) { 506 crosstalks = psArrayAllocEmpty(100); 507 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 508 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 509 goto escape; 510 } 511 psFree(crosstalks); 512 } 513 psArrayAdd(crosstalks,100,crosstalk); 514 515 psFree(targetChipName); 516 psFree(targetCellName); 517 psFree(crosstalk); 518 } 519 } // End satspike crosstalks 520 521 522 } // refstars 726 for (int Ut = 0; Ut < 8; Ut++) { 727 psString targetChipName = NULL; 728 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt); 729 psString targetCellName = NULL; 730 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt); 731 732 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", 733 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, 734 targetChipName,targetCellName); 735 736 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 737 if (!CTtargetCell) continue; 738 739 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 740 741 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)", 742 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 743 744 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 745 pmChip *targetChip = getChipByName(fpa,targetChipName); 746 if (!targetChip) continue; 747 if (!targetChip->cells) continue; 748 if (!targetChip->cells->n) continue; 749 750 pmCell *targetCell = targetChip->cells->data[0]; 751 if (!targetCell) continue; 752 if (!targetCell->readouts) continue; 753 if (!targetCell->readouts->n) continue; 754 pmReadout *targetReadout = targetCell->readouts->data[0]; 755 if (!targetReadout) continue; 756 757 pmAstromObj *crosstalk = pmAstromObjAlloc(); 758 759 crosstalk->Mag = ref->Mag - MagOffset; 760 crosstalk->chip->x = x_t_chip; 761 crosstalk->chip->y = y_t_chip; 762 763 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES"); 764 if (crosstalks == NULL) { 765 crosstalks = psArrayAllocEmpty(100); 766 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 767 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 768 goto escape; 769 } 770 psFree(crosstalks); 771 } 772 psArrayAdd(crosstalks,100,crosstalk); 773 774 psFree(targetChipName); 775 psFree(targetCellName); 776 psFree(crosstalk); 777 } 778 } // End satspike crosstalks 779 } // End refMags 780 781 } 782 } 783 784 523 785 } // readout 524 786 } // cell -
trunk/psastro/src/psastroMaskUpdates.c
r41367 r41551 152 152 double REFSTAR_MASK_BLEED_MAG_SLOPE_Y = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_SLOPE_Y"); 153 153 154 double REFSTAR_MASK_CROSSTALK_MAG_MAX = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_MAX");155 double REFSTAR_MASK_CROSSTALK_MAG_SLOPE= psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_SLOPE");154 //double REFSTAR_MASK_CROSSTALK_MAG_MAX = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_MAX"); 155 //double REFSTAR_MASK_CROSSTALK_MAG_SLOPE= psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_SLOPE"); 156 156 157 157 // Mask stats variables … … 472 472 for (int i = 0; i < crosstalks->n; i++) { 473 473 pmAstromObj *ref = crosstalks->data[i]; 474 float radius = REFSTAR_MASK_CROSSTALK_MAG_SLOPE * (REFSTAR_MASK_CROSSTALK_MAG_MAX - ref->Mag); 474 //float radius = REFSTAR_MASK_CROSSTALK_MAG_SLOPE * (REFSTAR_MASK_CROSSTALK_MAG_MAX - ref->Mag); 475 float radius = REFSTAR_MASK_SATSTAR_RAD_OFFSET + pow(REFSTAR_MASK_SATSTAR_EXP,(REFSTAR_MASK_SATSTAR_MAG_MAX - (ref->Mag+MagOffset))); 476 475 477 psTrace("psastro.crosstalk",2,"Masking star on Chip %s @ (%f,%f) Magnitude: %f Radius %f\n", 476 478 psMetadataLookupStr(&status,readout->parent->parent->concepts,"CHIP.NAME"),
Note:
See TracChangeset
for help on using the changeset viewer.
