- Timestamp:
- Feb 2, 2009, 2:37:06 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_20090128/psModules/src/camera/pmFPARead.c
r21264 r21269 9 9 #include <pslib.h> 10 10 11 #include "pmConfig.h" 12 #include "pmConfigMask.h" 11 13 #include "pmHDU.h" 12 14 #include "pmFPA.h" … … 732 734 return NULL; 733 735 } 734 735 if (type == FPA_READ_TYPE_VARIANCE && hdu->covariances) {736 psArray *covariances = hdu->covariances; // Covariances in HDU737 for (int i = 0; i < covariances->n; i++) {738 pmHDUCovariances *covar = covariances->data[i]; // Covariance information739 740 736 psFree(readout); // Drop reference 741 737 } … … 1143 1139 PS_ASSERT_FITS_NON_NULL(fits, false); 1144 1140 1145 return cellRead(cell, fits, config, FPA_READ_TYPE_VARIANCE); 1141 if (!cellRead(cell, fits, config, FPA_READ_TYPE_VARIANCE)) { 1142 return false; 1143 } 1144 return pmCellReadCovariance(cell, fits); 1146 1145 } 1147 1146 … … 1151 1150 PS_ASSERT_FITS_NON_NULL(fits, false); 1152 1151 1153 return chipRead(chip, fits, config, FPA_READ_TYPE_VARIANCE); 1152 if (!chipRead(chip, fits, config, FPA_READ_TYPE_VARIANCE)) { 1153 return false; 1154 } 1155 return pmChipReadCovariance(chip, fits); 1154 1156 } 1155 1157 … … 1159 1161 PS_ASSERT_FITS_NON_NULL(fits, false); 1160 1162 1161 return fpaRead(fpa, fits, config, FPA_READ_TYPE_VARIANCE); 1163 if (!fpaRead(fpa, fits, config, FPA_READ_TYPE_VARIANCE)) { 1164 return false; 1165 } 1166 return pmFPAReadCovariance(fpa, fits); 1162 1167 } 1163 1168 … … 1285 1290 return numRead; 1286 1291 } 1292 1293 1294 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1295 // Reading covariance matrices 1296 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1297 1298 bool pmCellReadCovariance(pmCell *cell, psFits *fits) 1299 { 1300 PS_ASSERT_PTR_NON_NULL(cell, false); 1301 PS_ASSERT_FITS_NON_NULL(fits, false); 1302 1303 const char *chipName = psMetadataLookupStr(NULL, cell->parent->concepts, "CHIP.NAME"); // Name of chip 1304 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell 1305 psString extname = NULL; // Extension name 1306 psStringAppend(&extname, "COVAR_%s_%s", chipName, cellName); 1307 1308 if (!psFitsMoveExtName(fits, extname)) { 1309 psError(PS_ERR_IO, false, "Unable to move to extension %s\n", extname); 1310 psFree(extname); 1311 return false; 1312 } 1313 psFree(extname); 1314 1315 psMetadata *header = psFitsReadHeader(NULL, fits); // The FITS header 1316 if (!header) { 1317 psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", extname); 1318 psFree(header); 1319 return false; 1320 } 1321 1322 bool mdok; // Status of MD lookup 1323 int x0 = psMetadataLookupS32(&mdok, header, "COVARIANCE.CENTRE.X"); // Centre of matrix in x 1324 if (!mdok) { 1325 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to read covariance centre"); 1326 psFree(header); 1327 return false; 1328 } 1329 int y0 = psMetadataLookupS32(&mdok, header, "COVARIANCE.CENTRE.Y"); // Centre of matrix in y 1330 if (!mdok) { 1331 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to read covariance centre"); 1332 psFree(header); 1333 return false; 1334 } 1335 psFree(header); 1336 1337 psArray *images = psFitsReadImageCube(fits, psRegionSet(0,0,0,0)); // Covariance matrices 1338 if (!images) { 1339 psError(PS_ERR_IO, false, "Unable to read covariance matrices for chip %s, cell %s", 1340 chipName, cellName); 1341 return false; 1342 } 1343 1344 psArray *readouts = cell->readouts; // Readouts of cell 1345 if (images->n != readouts->n) { 1346 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 1347 "Number of covariance matrices (%ld) doesn't match number of readouts (%ld)", 1348 images->n, readouts->n); 1349 psFree(images); 1350 return false; 1351 } 1352 1353 for (int i = 0; i < readouts->n; i++) { 1354 pmReadout *ro = readouts->data[i]; // Readout of interest 1355 psImage *image = images->data[i]; // Image of interest 1356 if (ro->covariance) { 1357 psWarning("Clobbering extant covariance matrix in chip %s, cell %s, readout %d", 1358 chipName, cellName, i); 1359 psFree(ro->covariance); 1360 } 1361 ro->covariance = psKernelAllocFromImage(image, x0, y0); 1362 } 1363 psFree(images); 1364 1365 return true; 1366 } 1367 1368 1369 bool pmChipReadCovariance(pmChip *chip, psFits *fits) 1370 { 1371 PS_ASSERT_PTR_NON_NULL(chip, false); 1372 PS_ASSERT_FITS_NON_NULL(fits, false); 1373 1374 psArray *cells = chip->cells; // Array of cells 1375 for (int i = 0; i < cells->n; i++) { 1376 pmCell *cell = cells->data[i]; // Cell of interest 1377 if (!pmCellReadCovariance(cell, fits)) { 1378 return false; 1379 } 1380 } 1381 1382 return true; 1383 } 1384 1385 1386 bool pmFPAReadCovariance(pmFPA *fpa, psFits *fits) 1387 { 1388 PS_ASSERT_PTR_NON_NULL(fpa, false); 1389 PS_ASSERT_FITS_NON_NULL(fits, false); 1390 1391 psArray *chips = fpa->chips; // Array of chips 1392 for (int i = 0; i < chips->n; i++) { 1393 pmChip *chip = chips->data[i]; // Chip of interest 1394 if (!pmChipReadCovariance(chip, fits)) { 1395 return false; 1396 } 1397 } 1398 1399 return true; 1400 }
Note:
See TracChangeset
for help on using the changeset viewer.
