- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/psModules
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psModules merged eligible /branches/eam_branches/stackphot.20100406/psModules 27623-27653 /branches/pap_delete/psModules 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/simtest_nebulous_branches/psModules/src/camera/pmFPAMosaic.c
r21363 r27840 626 626 bool good = true; // Is everything good? 627 627 628 const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell 629 const char *chipName = psMetadataLookupStr(NULL, cell->parent->concepts, "CHIP.NAME"); // Name of chip 630 628 631 // Offset of the cell on the chip 629 632 int x0Cell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.X0"); 630 633 if (!mdok) { 631 psError(PS_ERR_UNKNOWN, true, "CELL.X0 for cell is not set.\n");634 psError(PS_ERR_UNKNOWN, true, "CELL.X0 for cell %s,%s is not set.\n", chipName, cellName); 632 635 good = false; 633 636 } 634 637 int y0Cell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.Y0"); 635 638 if (!mdok) { 636 psError(PS_ERR_UNKNOWN, true, "CELL.Y0 for cell is not set.\n");639 psError(PS_ERR_UNKNOWN, true, "CELL.Y0 for cell %s,%s is not set.\n", chipName, cellName); 637 640 good = false; 638 641 } 639 psTrace("psModules.camera", 5, "Cell %ld: x0=%d y0=%d\n", index, x0Cell, y0Cell); 642 psTrace("psModules.camera", 5, "Cell %s,%s (%ld): x0=%d y0=%d\n", 643 chipName, cellName, index, x0Cell, y0Cell); 640 644 641 645 // Offset of the chip on the FPA … … 649 653 x0Chip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.X0"); 650 654 if (!mdok) { 651 psError(PS_ERR_UNKNOWN, true, "CHIP.X0 for chip is not set.\n");655 psError(PS_ERR_UNKNOWN, true, "CHIP.X0 for chip %s is not set.\n", chipName); 652 656 good = false; 653 657 } 654 658 y0Chip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.Y0"); 655 659 if (!mdok) { 656 psError(PS_ERR_UNKNOWN, true, "CHIP.Y0 for chip is not set.\n");660 psError(PS_ERR_UNKNOWN, true, "CHIP.Y0 for chip %s is not set.\n", chipName); 657 661 good = false; 658 662 } … … 662 666 xBin->data.S32[index] = psMetadataLookupS32(&mdok, cell->concepts, "CELL.XBIN"); 663 667 if (!mdok || xBin->data.S32[index] == 0) { 664 psError(PS_ERR_UNKNOWN, true, "CELL.XBIN for cell is not set.\n");668 psError(PS_ERR_UNKNOWN, true, "CELL.XBIN for cell %s,%s is not set.\n", chipName, cellName); 665 669 return false; 666 670 } else if (xBin->data.S32[index] < *xBinMin) { … … 669 673 yBin->data.S32[index] = psMetadataLookupS32(&mdok, cell->concepts, "CELL.YBIN"); 670 674 if (!mdok || yBin->data.S32[index] == 0) { 671 psError(PS_ERR_UNKNOWN, true, "CELL.YBIN for cell is not set.\n");675 psError(PS_ERR_UNKNOWN, true, "CELL.YBIN for cell %s,%s is not set.\n", chipName, cellName); 672 676 return false; 673 677 } else if (yBin->data.S32[index] < *yBinMin) { … … 678 682 int xParityCell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.XPARITY"); 679 683 if (!mdok || (xParityCell != 1 && xParityCell != -1)) { 680 psError(PS_ERR_UNKNOWN, true, "CELL.XPARITY for cell is not set.\n");684 psError(PS_ERR_UNKNOWN, true, "CELL.XPARITY for cell %s,%s is not set.\n", chipName, cellName); 681 685 return false; 682 686 } 683 687 int yParityCell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.YPARITY"); 684 688 if (!mdok || (yParityCell != 1 && yParityCell != -1)) { 685 psError(PS_ERR_UNKNOWN, true, "CELL.YPARITY for cell is not set.\n");689 psError(PS_ERR_UNKNOWN, true, "CELL.YPARITY for cell %s,%s is not set.\n", chipName, cellName); 686 690 return false; 687 691 } … … 693 697 xParityChip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.XPARITY"); 694 698 if (!mdok || (xParityChip != 1 && xParityChip != -1)) { 695 psError(PS_ERR_UNKNOWN, true, "CHIP.XPARITY for chip is not set.\n");699 psError(PS_ERR_UNKNOWN, true, "CHIP.XPARITY for chip %s is not set.\n", chipName); 696 700 return false; 697 701 } 698 702 yParityChip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.YPARITY"); 699 703 if (!mdok || (yParityChip != 1 && yParityChip != -1)) { 700 psError(PS_ERR_UNKNOWN, true, "CHIP.YPARITY for chip is not set.\n");704 psError(PS_ERR_UNKNOWN, true, "CHIP.YPARITY for chip %s is not set.\n", chipName); 701 705 return false; 702 706 } … … 740 744 static bool chipMosaic(psImage **mosaicImage, // The mosaic image, to be returned 741 745 psImage **mosaicMask, // The mosaic mask, to be returned 742 psImage **mosaicVariance s, // The mosaic variances, to be returned746 psImage **mosaicVariance, // The mosaic variance, to be returned 743 747 int *xBinChip, int *yBinChip, // The binning in x and y, to be returned 744 748 const pmChip *chip, // Chip to mosaic … … 749 753 assert(mosaicImage); 750 754 assert(mosaicMask); 751 assert(mosaicVariance s);755 assert(mosaicVariance); 752 756 assert(xBinChip); 753 757 assert(yBinChip); … … 826 830 if (allGood) { 827 831 *mosaicImage = imageMosaic(images, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, BLANK_VALUE); 828 *mosaicVariance s= imageMosaic(variances, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, BLANK_VALUE);832 *mosaicVariance = imageMosaic(variances, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, BLANK_VALUE); 829 833 *mosaicMask = imageMosaic(masks, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, blank); 830 834 } … … 847 851 static bool fpaMosaic(psImage **mosaicImage, // The mosaic image, to be returned 848 852 psImage **mosaicMask, // The mosaic mask, to be returned 849 psImage **mosaicVariance s, // The mosaic variances, to be returned853 psImage **mosaicVariance, // The mosaic variance, to be returned 850 854 int *xBinFPA, int *yBinFPA, // The binning in x and y, to be returned 851 855 const pmFPA *fpa, // FPA to mosaic … … 857 861 assert(mosaicImage); 858 862 assert(mosaicMask); 859 assert(mosaicVariance s);863 assert(mosaicVariance); 860 864 assert(xBinFPA); 861 865 assert(yBinFPA); … … 960 964 if (allGood) { 961 965 *mosaicImage = imageMosaic(images, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, BLANK_VALUE); 962 *mosaicVariance s= imageMosaic(variances, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, BLANK_VALUE);966 *mosaicVariance = imageMosaic(variances, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, BLANK_VALUE); 963 967 *mosaicMask = imageMosaic(masks, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, blank); 964 968 } … … 1025 1029 psImage *mosaicImage = NULL; // The mosaic image 1026 1030 psImage *mosaicMask = NULL; // The mosaic mask 1027 psImage *mosaicVariance s= NULL; // The mosaic variances1031 psImage *mosaicVariance = NULL; // The mosaic variances 1028 1032 1029 1033 // Find the HDU … … 1052 1056 } 1053 1057 if (hdu->variances) { 1054 mosaicVariance s= psImageSubset(hdu->variances->data[0], bounds);1055 if (!mosaicVariance s) {1058 mosaicVariance = psImageSubset(hdu->variances->data[0], bounds); 1059 if (!mosaicVariance) { 1056 1060 psError(PS_ERR_UNKNOWN, false, "Unable to select variance pixels.\n"); 1057 1061 return false; … … 1061 1065 // Case 2 --- we need to mosaic by cut and paste 1062 1066 psTrace("psModules.camera", 1, "Case 2 mosaicking: cut and paste.\n"); 1063 if (!chipMosaic(&mosaicImage, &mosaicMask, &mosaicVariance s, &xBin, &yBin, source, targetCell, blank)) {1067 if (!chipMosaic(&mosaicImage, &mosaicMask, &mosaicVariance, &xBin, &yBin, source, targetCell, blank)) { 1064 1068 psError(PS_ERR_UNKNOWN, false, "Unable to mosaic cells.\n"); 1065 1069 return false; … … 1069 1073 } 1070 1074 psTrace("psModules.camera", 1, "xBin,yBin: %d,%d\n", xBin, yBin); 1075 1071 1076 1072 1077 // Set the concepts for the target cell … … 1090 1095 target->parent->concepts = psMetadataCopy(target->parent->concepts, source->parent->concepts); // FPA lvl 1091 1096 1097 // Average the covariances 1098 psList *covariances = psListAlloc(NULL); // Input covariance matrices 1099 for (int i = 0; i < source->cells->n; i++) { 1100 pmCell *cell = source->cells->data[i]; // Cell of interest 1101 if (!cell || !cell->data_exists) { 1102 continue; 1103 } 1104 pmReadout *ro = cell->readouts->data[0]; // Readout of interest 1105 if (!ro || !ro->covariance) { 1106 continue; 1107 } 1108 psListAdd(covariances, PS_LIST_TAIL, ro->covariance); 1109 } 1110 psKernel *mosaicCovariance = NULL; // Covariance for mosaic 1111 if (psListLength(covariances) > 0) { 1112 psArray *covarArray = psListToArray(covariances); // Array with covariances 1113 mosaicCovariance = psImageCovarianceAverage(covarArray); 1114 psFree(covarArray); 1115 } 1116 psFree(covariances); 1117 1092 1118 // Now make a new readout to go in the target cell 1093 1119 pmReadout *newReadout = pmReadoutAlloc(targetCell); // New readout 1094 1120 newReadout->image = mosaicImage; 1095 1121 newReadout->mask = mosaicMask; 1096 newReadout->variance = mosaicVariances; 1122 newReadout->variance = mosaicVariance; 1123 newReadout->covariance = mosaicCovariance; 1097 1124 psFree(newReadout); // Drop reference 1098 1125 … … 1334 1361 target->concepts = psMetadataCopy(target->concepts, source->concepts); 1335 1362 1363 // Average the covariances 1364 psList *covariances = psListAlloc(NULL); // Input covariance matrices 1365 for (int i = 0; i < covariances->n; i++) { 1366 pmChip *chip = chips->data[i]; // Chip of interest 1367 if (!chip || !chip->data_exists) { 1368 continue; 1369 } 1370 psArray *cells = chip->cells; // Cells in chip 1371 for (long j = 0; j < cells->n; j++) { 1372 pmCell *cell = cells->data[i]; // Cell of interest 1373 if (!cell || !cell->data_exists) { 1374 continue; 1375 } 1376 pmReadout *ro = cell->readouts->data[0]; // Readout of interest 1377 if (!ro || !ro->covariance) { 1378 continue; 1379 } 1380 psListAdd(covariances, PS_LIST_TAIL, ro->covariance); 1381 } 1382 } 1383 psKernel *mosaicCovariances = NULL; // Covariance for mosaic 1384 if (psListLength(covariances) > 0) { 1385 psArray *covarArray = psListToArray(covariances); // Array with covariances 1386 mosaicCovariances = psImageCovarianceAverage(covarArray); 1387 psFree(covarArray); 1388 } 1389 psFree(covariances); 1390 1336 1391 // Now make a new readout to go in the new cell 1337 1392 pmReadout *newReadout = pmReadoutAlloc(targetCell); // New readout … … 1339 1394 newReadout->mask = mosaicMask; 1340 1395 newReadout->variance = mosaicVariances; 1396 newReadout->covariance = mosaicCovariances; 1341 1397 psFree(newReadout); // Drop reference 1342 1398
Note:
See TracChangeset
for help on using the changeset viewer.
