Changeset 26174 for trunk/psastro
- Timestamp:
- Nov 17, 2009, 4:43:05 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroLoadCrosstalk.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroLoadCrosstalk.c
r26173 r26174 1 1 /** @file psastroMaskUpdates.c 2 2 * 3 * @brief 3 * @brief 4 4 * 5 5 * @ingroup libpsastro … … 42 42 } 43 43 44 44 45 45 bool psastroLoadCrosstalk (pmConfig *config) { 46 46 … … 50 50 pmReadout *readout = NULL; 51 51 52 pmFPAview *view = pmFPAviewAlloc (0); 53 pmFPAview *viewMask = pmFPAviewAlloc (0); 54 52 55 float zeropt, exptime, MAX_MAG; 53 56 54 57 psLogMsg ("psastro", PS_LOG_INFO, "determine crosstalk positions"); 55 58 … … 66 69 return(true); 67 70 } 68 71 69 72 // select the input astrometry data (also carries the refstars) 70 73 pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); … … 82 85 } 83 86 // Activate teh reference mask to generate an FPA structure we can use to map stars down to cells 84 87 85 88 pmFPAfileActivate (config->files, true, "PSASTRO.REFMASK"); 86 89 87 90 // pmFPA *refFPA = refMask->fpa; 88 89 pmFPAview *view = pmFPAviewAlloc (0);90 pmFPAview *viewMask = pmFPAviewAlloc (0);91 91 92 92 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE; … … 103 103 float MagOffset = zeropt + 2.5*log10(exptime); 104 104 MAX_MAG += MagOffset; 105 105 106 106 psTrace("psastro.crosstalk",2,"%f %f %f %f\n",zeropt,exptime,MAX_MAG,MagOffset); 107 108 // Load each chip. 107 108 // Load each chip. 109 109 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) { 110 110 psTrace ("psastro.crosstalk", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); … … 122 122 // Read each cell (at this stage, we should only have one of them) 123 123 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 124 psTrace ("psastro.crosstalk", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);125 126 if (!cell->process || !cell->file_exists) { continue; }127 128 // Read each readout (similarly, we should only have one of these, too)129 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {130 if (! readout->data_exists) { continue; }131 132 // If this chip doesn't crosstalk, skip to the next one.133 if (! ((X == 2)||(X == 3)||(X == 4)||(X == 5))) {134 psTrace ("psastro.crosstalk",2,"Chip (%d%d) not a known crosstalk source.",X,Y);135 continue;136 }137 138 // Get the array of reference stars we're concerned with.139 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS");140 if (refstars == NULL) { return(true); }141 142 // Check each reference star143 for (int i = 0; i < refstars->n; i++) {144 pmAstromObj *ref = refstars->data[i];145 146 if (ref->Mag > MAX_MAG) {147 continue;148 }149 150 // Identify which cell holds the cell151 pmChip *CTsourceChip = refChip;152 pmCell *CTsourceCell = pmCellInChip(refChip,ref->chip->x,ref->chip->y);153 154 if (!CTsourceCell) {155 continue;156 }157 158 psTrace ("psastro.crosstalk",2,"REF: %d %f (%f %f) %f %f :: %f %f\n",159 i,ref->Mag, ref->sky->r,ref->sky->d, ref->FP->x,ref->FP->y, ref->chip->x,ref->chip->y);160 161 162 const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME");163 int U = cellName[2] - '0';164 int V = cellName[3] - '0';165 166 int Xt = X,Yt = Y,Ut = U,Vt = V;167 float x_cell,y_cell;168 float x_t_cell,y_t_cell;169 170 float x_t_chip,y_t_chip;171 172 pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,ref->chip->x,ref->chip->y);173 174 x_t_cell = x_cell;175 y_t_cell = y_cell;176 177 // Determine if this combination of chip and cell produces a crosstalk artifact178 if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)))) {179 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);180 continue;181 }182 if ((X == 3)&&(! ((U == 3)))) {183 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);184 continue;185 }186 if ((X == 4)&&(! ((U == 3)))) {187 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);188 continue;189 }190 if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)))) {191 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);192 continue;193 }194 195 // Calculate destination positions196 if (X == 2) {197 if (U == 3) {198 Xt = 3;199 }200 if (U == 5) {201 Ut = 6;202 }203 if (U == 6) {204 Ut = 5;205 }206 }207 else if (X == 3) {208 Xt = 2;209 }210 else if (X == 4) {211 Xt = 5;212 }213 if (X == 5) {214 if (U == 3) {215 Xt = 4;216 }217 if (U == 5) {218 Ut = 6;219 }220 if (U == 6) {221 Ut = 5;222 }223 }224 225 // Convert target cell coordinates to target chip coordinates 226 psString targetChipName = NULL;227 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt);228 psString targetCellName = NULL;229 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt);230 231 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]",232 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,233 targetChipName,targetCellName);234 235 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);236 if (!CTtargetCell) continue;237 238 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);239 240 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)",241 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip);242 243 // Hunt down the readout for the target, and save the chip position and magnitude of source star.244 pmChip *targetChip = getChipByName(fpa,targetChipName);245 if (!targetChip) continue;246 if (!targetChip->cells) continue;247 if (!targetChip->cells->n) continue;248 249 pmCell *targetCell = targetChip->cells->data[0];250 if (!targetCell) continue;251 if (!targetCell->readouts) continue;252 if (!targetCell->readouts->n) continue;253 pmReadout *targetReadout = targetCell->readouts->data[0];254 if (!targetReadout) continue;255 256 pmAstromObj *crosstalk = pmAstromObjAlloc();257 258 crosstalk->Mag = ref->Mag - MagOffset;259 crosstalk->chip->x = x_t_chip;260 crosstalk->chip->y = y_t_chip;261 262 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS");263 if (crosstalks == NULL) {264 crosstalks = psArrayAllocEmpty(100);265 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {266 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");267 goto escape;268 }269 psFree(crosstalks);270 }271 psArrayAdd(crosstalks,100,crosstalk);272 273 psFree(targetChipName);274 psFree(targetCellName);275 psFree(crosstalk);276 } // refstars277 } // readout124 psTrace ("psastro.crosstalk", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 125 126 if (!cell->process || !cell->file_exists) { continue; } 127 128 // Read each readout (similarly, we should only have one of these, too) 129 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) { 130 if (! readout->data_exists) { continue; } 131 132 // If this chip doesn't crosstalk, skip to the next one. 133 if (! ((X == 2)||(X == 3)||(X == 4)||(X == 5))) { 134 psTrace ("psastro.crosstalk",2,"Chip (%d%d) not a known crosstalk source.",X,Y); 135 continue; 136 } 137 138 // Get the array of reference stars we're concerned with. 139 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS"); 140 if (refstars == NULL) { return(true); } 141 142 // Check each reference star 143 for (int i = 0; i < refstars->n; i++) { 144 pmAstromObj *ref = refstars->data[i]; 145 146 if (ref->Mag > MAX_MAG) { 147 continue; 148 } 149 150 // Identify which cell holds the cell 151 pmChip *CTsourceChip = refChip; 152 pmCell *CTsourceCell = pmCellInChip(refChip,ref->chip->x,ref->chip->y); 153 154 if (!CTsourceCell) { 155 continue; 156 } 157 158 psTrace ("psastro.crosstalk",2,"REF: %d %f (%f %f) %f %f :: %f %f\n", 159 i,ref->Mag, ref->sky->r,ref->sky->d, ref->FP->x,ref->FP->y, ref->chip->x,ref->chip->y); 160 161 162 const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME"); 163 int U = cellName[2] - '0'; 164 int V = cellName[3] - '0'; 165 166 int Xt = X,Yt = Y,Ut = U,Vt = V; 167 float x_cell,y_cell; 168 float x_t_cell,y_t_cell; 169 170 float x_t_chip,y_t_chip; 171 172 pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,ref->chip->x,ref->chip->y); 173 174 x_t_cell = x_cell; 175 y_t_cell = y_cell; 176 177 // Determine if this combination of chip and cell produces a crosstalk artifact 178 if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)))) { 179 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 180 continue; 181 } 182 if ((X == 3)&&(! ((U == 3)))) { 183 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 184 continue; 185 } 186 if ((X == 4)&&(! ((U == 3)))) { 187 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 188 continue; 189 } 190 if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)))) { 191 psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y); 192 continue; 193 } 194 195 // Calculate destination positions 196 if (X == 2) { 197 if (U == 3) { 198 Xt = 3; 199 } 200 if (U == 5) { 201 Ut = 6; 202 } 203 if (U == 6) { 204 Ut = 5; 205 } 206 } 207 else if (X == 3) { 208 Xt = 2; 209 } 210 else if (X == 4) { 211 Xt = 5; 212 } 213 if (X == 5) { 214 if (U == 3) { 215 Xt = 4; 216 } 217 if (U == 5) { 218 Ut = 6; 219 } 220 if (U == 6) { 221 Ut = 5; 222 } 223 } 224 225 // Convert target cell coordinates to target chip coordinates 226 psString targetChipName = NULL; 227 psStringAppend(&targetChipName,"XY%d%d",Xt,Yt); 228 psString targetCellName = NULL; 229 psStringAppend(&targetCellName,"xy%d%d",Ut,Vt); 230 231 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", 232 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, 233 targetChipName,targetCellName); 234 235 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName); 236 if (!CTtargetCell) continue; 237 238 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell); 239 240 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)", 241 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip); 242 243 // Hunt down the readout for the target, and save the chip position and magnitude of source star. 244 pmChip *targetChip = getChipByName(fpa,targetChipName); 245 if (!targetChip) continue; 246 if (!targetChip->cells) continue; 247 if (!targetChip->cells->n) continue; 248 249 pmCell *targetCell = targetChip->cells->data[0]; 250 if (!targetCell) continue; 251 if (!targetCell->readouts) continue; 252 if (!targetCell->readouts->n) continue; 253 pmReadout *targetReadout = targetCell->readouts->data[0]; 254 if (!targetReadout) continue; 255 256 pmAstromObj *crosstalk = pmAstromObjAlloc(); 257 258 crosstalk->Mag = ref->Mag - MagOffset; 259 crosstalk->chip->x = x_t_chip; 260 crosstalk->chip->y = y_t_chip; 261 262 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS"); 263 if (crosstalks == NULL) { 264 crosstalks = psArrayAllocEmpty(100); 265 if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) { 266 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout"); 267 goto escape; 268 } 269 psFree(crosstalks); 270 } 271 psArrayAdd(crosstalks,100,crosstalk); 272 273 psFree(targetChipName); 274 psFree(targetCellName); 275 psFree(crosstalk); 276 } // refstars 277 } // readout 278 278 } // cell 279 279 // } 280 280 281 281 // File cleanup code. 282 *viewMask = *view; 282 *viewMask = *view; 283 283 while ((cell = pmFPAviewNextCell (viewMask, refMask->fpa, 1)) != NULL) { 284 284 psTrace ("psastro", 4, "Mask Cell %d: %x %x\n", viewMask->cell, cell->file_exists, cell->process); 285 285 if (!cell->process || !cell->file_exists) { continue; } 286 286 287 287 while ((readout = pmFPAviewNextReadout (viewMask, refMask->fpa, 1)) != NULL) { 288 if (! readout->data_exists) { continue; }289 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;288 if (! readout->data_exists) { continue; } 289 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE; 290 290 } 291 291 if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE; … … 303 303 escape: 304 304 psFree(view); 305 psFree(viewMask); 305 306 return(false); 306 307 }
Note:
See TracChangeset
for help on using the changeset viewer.
