Changeset 6124 for branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c
- Timestamp:
- Jan 21, 2006, 12:23:58 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c
r6113 r6124 131 131 } 132 132 133 134 // Set the concepts in the new cell, based on the values in the old one 135 static bool cellConcepts(pmCell *target,// Target cell 136 psArray *sources, // Source cells 137 int xBin, int yBin // Binning 138 ) 139 { 140 bool success = true; // Result of setting everything 141 float gain = 0.0; // Gain 142 float readnoise = 0.0; // Read noise 143 float saturation = 0.0; // Saturation level 144 float bad = 0.0; // Bad level 145 float exposure = 0.0; // Exposure time 146 float darktime = 0.0; // Dark time 147 double time = 0.0; // Time of observation 148 psTimeType timeSys = 0; // Time system 149 150 int nCells = 0; // Number of cells; 151 for (int i = 0; i < sources->n; i++) { 152 pmCell *cell = sources->data[i];// The cell of interest 153 if (!cell) { 154 continue; 155 } 156 nCells++; 157 gain += psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); 158 readnoise += psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE"); 159 saturation += psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION"); 160 bad += psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD"); 161 exposure += psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE"); 162 darktime += psMetadataLookupF32(NULL, cell->concepts, "CELL.DARKTIME"); 163 time += psTimeToMJD(psMetadataLookupPtr(NULL, cell->concepts, "CELL.TIME")); 164 if (i == 0) { 165 timeSys = psMetadataLookupS32(NULL, cell->concepts, "CELL.TIMESYS"); 166 } else if (timeSys != psMetadataLookupS32(NULL, cell->concepts, "CELL.TIMESYS")) { 167 psLogMsg(__func__, PS_LOG_ERROR, "Differing time systems in use: %d vs %d\n", timeSys, 168 psMetadataLookupS32(NULL, cell->concepts, "CELL.TIMESYS")); 169 success = false; 170 } 171 } 172 gain /= (float)nCells; 173 readnoise /= (float)nCells; 174 saturation /= (float)nCells; 175 bad /= (float)nCells; 176 exposure /= (float)nCells; 177 darktime /= (float)nCells; 178 psTime *timePtr = psTimeFromMJD(time/(double)nCells); 179 timePtr = psTimeConvert(timePtr, timeSys); 180 181 // XXX *REALLY* need a generic "concept update" function that handles the type and comments transparently. 182 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.GAIN", PS_META_REPLACE, "Gain (e/ADU)", gain); 183 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.READNOISE", PS_META_REPLACE, "Read noise (e)", readnoise); 184 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.SATURATION", PS_META_REPLACE, "Saturation level (ADU)", saturation); 185 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.BAD", PS_META_REPLACE, "Bad level (ADU)", bad); 186 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.EXPOSURE", PS_META_REPLACE, "Exposure time (sec)", exposure); 187 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.DARKTIME", PS_META_REPLACE, "Time since last CCD flush (sec)", darktime); 188 psMetadataAddPtr(target->concepts, PS_LIST_TAIL, "CELL.TIME", PS_DATA_TIME | PS_META_REPLACE, "Time of observation", timePtr); 189 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.TIMESYS", PS_META_REPLACE, "Time system", timeSys); 190 psFree(timePtr); 191 192 // Now fill in the ones I know by other means 193 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.X0", PS_META_REPLACE, "Position of (0,0) on the chip", 0); 194 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.Y0", PS_META_REPLACE, "Position of (0,0) on the chip", 0); 195 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.XPARITY", PS_META_REPLACE, "Orientation in x compared to the rest of the FPA", 1); 196 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.YPARITY", PS_META_REPLACE, "Orientation in x compared to the rest of the FPA", 1); 197 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.XBIN", PS_META_REPLACE, "Binning in x", xBin); 198 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.YBIN", PS_META_REPLACE, "Binning in x", yBin); 199 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.READDIR", PS_META_REPLACE, "Read direction (faked)", 1); 200 psRegion *trimsec = psMetadataLookupPtr(NULL, target->concepts, "CELL.TRIMSEC"); 201 trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0.0; 202 203 return success; 204 } 205 206 207 133 208 // Mosaic a chip together into a single image 134 209 int pmChipMosaic(pmChip *chip,// Chip to mosaic … … 152 227 for (int i = 0; i < cells->n; i++) { 153 228 pmCell *cell = cells->data[i]; // The cell of interest 229 if (!cell) { 230 continue; 231 } 154 232 x0->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0"); 155 233 y0->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0"); … … 206 284 psFree(masks); 207 285 int nCells = cells->n; 286 287 // Modify the "original" pixels 288 if (chip->parent->hdu) { 289 psLogMsg(__func__, PS_LOG_WARN, "The original format has the entire FPA in a single extension. " 290 "The FPA hierarchy may be invalid following the pmChipMosaic.\n"); 291 } else { 292 if (! chip->hdu) { 293 psString chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); 294 chip->hdu = p_pmHDUAlloc(chipName); 295 } 296 p_pmHDU *hdu = chip->hdu; 297 psArrayElementsFree(hdu->images); 298 psArrayElementsFree(hdu->weights); 299 psArrayElementsFree(hdu->masks); 300 hdu->images = psArrayAlloc(1); 301 hdu->weights = psArrayAlloc(1); 302 hdu->masks = psArrayAlloc(1); 303 hdu->images->data[0] = image; 304 hdu->weights->data[0] = weight; 305 hdu->masks->data[0] = mask; 306 psMetadataAddS32(hdu->header, PS_LIST_TAIL, "NAXIS1", PS_META_REPLACE, "Number of columns", image->numCols); 307 psMetadataAddS32(hdu->header, PS_LIST_TAIL, "NAXIS2", PS_META_REPLACE, "Number of rows", image->numRows); 308 } 309 310 // Chop off all the component cells, and put in a new one 311 chip->cells = psArrayAlloc(0); 312 pmCell *cell = pmCellAlloc(chip, NULL, __func__); // New cell 313 cellConcepts(cell, cells, xBinChip, yBinChip); 208 314 psFree(cells); 209 210 // Chop off all the component cells, and put in a new one211 315 212 316 #if 1 … … 214 318 // the double free is coming from. I'm going to drop the pointers on the array and create a memory 215 319 // leak. We can clean this up later, when we're not under as much pressure. 216 chip->cells = psArrayAlloc(0);217 320 #else 218 321 219 322 psArrayElementsFree(chip->cells); 220 chip->cells = psArrayRealloc(chip->cells, 0);221 323 chip->cells->n = 0; 222 324 #endif 223 325 224 pmCell *cell = pmCellAlloc(chip, NULL, __func__); // New cell225 326 cell->exists = true; 226 327 cell->process = true; 227 328 pmReadout *readout = pmReadoutAlloc(cell); // New readout 228 readout->image = image; 229 readout->weight = weight; 230 readout->mask = mask; 231 //psFree(readout); 329 psRegion entire = {0.0, 0.0, 0.0, 0.0}; 330 // Want the readouts to contain a subimage, but that subimage is the whole image. 331 // This preserves the relationship there was before, where freeing the parent frees the child. 332 readout->image = psImageSubset(image, entire); 333 readout->weight = psImageSubset(weight, entire); 334 readout->mask = psImageSubset(mask, entire); 335 psFree(readout); 336 337 // Well, we've stuffed around with the camera configuration, so it's no longer valid... 338 #if 0 339 340 psFree(chip->parent->camera); 341 chip->parent->camera = NULL; 342 #endif 232 343 233 344 return nCells;
Note:
See TracChangeset
for help on using the changeset viewer.
