Changeset 13195
- Timestamp:
- May 3, 2007, 10:43:07 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAMosaic.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAMosaic.c
r13190 r13195 14 14 #include "pmConceptsAverage.h" 15 15 #include "pmHDUUtils.h" 16 #include "pmConfig.h" 17 #include "pmAstrometryWCS.h" 18 16 19 #include "pmFPAMosaic.h" 17 #include "pmConfig.h" 18 19 #define CELL_LIST_BUFFER 50 // Buffer size for cell lists20 21 22 #define CELL_LIST_BUFFER 10 // Buffer size for cell lists 20 23 21 24 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 634 637 if (!mdok || xBin->data.S32[index] == 0) { 635 638 psError(PS_ERR_UNKNOWN, true, "CELL.XBIN for cell is not set.\n"); 636 return false;639 return false; 637 640 } else if (xBin->data.S32[index] < *xBinMin) { 638 641 *xBinMin = xBin->data.S32[index]; … … 641 644 if (!mdok || yBin->data.S32[index] == 0) { 642 645 psError(PS_ERR_UNKNOWN, true, "CELL.YBIN for cell is not set.\n"); 643 return false;646 return false; 644 647 } else if (yBin->data.S32[index] < *yBinMin) { 645 648 *yBinMin = yBin->data.S32[index]; … … 650 653 if (!mdok || (xParityCell != 1 && xParityCell != -1)) { 651 654 psError(PS_ERR_UNKNOWN, true, "CELL.XPARITY for cell is not set.\n"); 652 return false;655 return false; 653 656 } 654 657 int yParityCell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.YPARITY"); 655 658 if (!mdok || (yParityCell != 1 && yParityCell != -1)) { 656 659 psError(PS_ERR_UNKNOWN, true, "CELL.YPARITY for cell is not set.\n"); 657 return false;660 return false; 658 661 } 659 662 … … 665 668 if (!mdok || (xParityChip != 1 && xParityChip != -1)) { 666 669 psError(PS_ERR_UNKNOWN, true, "CHIP.XPARITY for chip is not set.\n"); 667 return false;670 return false; 668 671 } 669 672 yParityChip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.YPARITY"); 670 673 if (!mdok || (yParityChip != 1 && yParityChip != -1)) { 671 674 psError(PS_ERR_UNKNOWN, true, "CHIP.YPARITY for chip is not set.\n"); 672 return false;675 return false; 673 676 } 674 677 } … … 751 754 FIX_CONCEPT(targetCell->concepts, "CELL.Y0", S32, 0); 752 755 } 753 int xParity CellTarget = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.XPARITY");754 if (!mdok || (xParity CellTarget != -1 && xParityCellTarget != 1)) {756 int xParityTarget = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.XPARITY"); 757 if (!mdok || (xParityTarget != -1 && xParityTarget != 1)) { 755 758 psLogMsg(__func__, PS_LOG_WARN, "CELL.XPARITY is not set for the target cell; assuming 1.\n"); 756 759 FIX_CONCEPT(targetCell->concepts, "CELL.XPARITY", S32, 1); 757 xParity CellTarget = 1;758 } 759 int yParity CellTarget = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.YPARITY");760 if (!mdok || (yParity CellTarget != -1 && yParityCellTarget != 1)) {760 xParityTarget = 1; 761 } 762 int yParityTarget = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.YPARITY"); 763 if (!mdok || (yParityTarget != -1 && yParityTarget != 1)) { 761 764 psLogMsg(__func__, PS_LOG_WARN, "CELL.YPARITY is not set for the target cell; assuming 1.\n"); 762 765 FIX_CONCEPT(targetCell->concepts, "CELL.YPARITY", S32, 1); 763 yParityCellTarget = 1; 764 } 765 # if (0) 766 int xParityChipTarget = psMetadataLookupS32(&mdok, targetCell->parent->concepts, "CHIP.XPARITY"); 767 if (!mdok || (xParityChipTarget != -1 && xParityChipTarget != 1)) { 768 psLogMsg(__func__, PS_LOG_WARN, "CHIP.XPARITY is not set for the target chip; assuming 1.\n"); 769 FIX_CONCEPT(targetCell->parent->concepts, "CHIP.XPARITY", S32, 1); 770 xParityChipTarget = 1; 771 } 772 int yParityChipTarget = psMetadataLookupS32(&mdok, targetCell->parent->concepts, "CHIP.YPARITY"); 773 if (!mdok || (yParityChipTarget != -1 && yParityChipTarget != 1)) { 774 psLogMsg(__func__, PS_LOG_WARN, "CHIP.YPARITY is not set for the target chip; assuming 1.\n"); 775 FIX_CONCEPT(targetCell->parent->concepts, "CHIP.YPARITY", S32, 1); 776 yParityChipTarget = 1; 777 } 778 int xParityTarget = xParityChipTarget * xParityCellTarget; 779 int yParityTarget = yParityChipTarget * yParityCellTarget; 780 # endif 781 int xParityTarget = xParityCellTarget; 782 int yParityTarget = yParityCellTarget; 766 yParityTarget = 1; 767 } 783 768 784 769 // Binning for the mosaicked chip is the minimum binning allowed by the cells … … 1105 1090 } 1106 1091 if (!targetPHU->header) { 1107 // if we don't yet have a header, copy this one.1108 // XXX do we need to create an empty one if the levels do not match??1109 if (true) {1110 targetPHU->header = psMetadataCopy(targetPHU->header, sourcePHU->header);1111 } else {1112 targetPHU->header = psMetadataAlloc();1113 }1092 // if we don't yet have a header, copy this one. 1093 // XXX do we need to create an empty one if the levels do not match?? 1094 if (true) { 1095 targetPHU->header = psMetadataCopy(targetPHU->header, sourcePHU->header); 1096 } else { 1097 targetPHU->header = psMetadataAlloc(); 1098 } 1114 1099 } 1115 1100 … … 1118 1103 return false; 1119 1104 } 1120 1121 // this code extracts the WCS information from the header of one of the cells and applies it to 1122 // the mosaicked chip. XXX EAM : I am leaving it at this point for PAP to get the binning, etc 1123 // from the concepts 1124 # if (0) 1125 // if the cells contain the headers, we need to apply the WCS terms from (one of?) the cells 1105 1106 // If the cells contain the headers, we need to apply the WCS terms from (one of?) the cells 1126 1107 for (int i = 0; i < source->cells->n; i++) { 1127 pmCell *cell = source->cells->data[i]; 1128 if (cell == NULL) continue; 1129 if (cell->hdu == NULL) continue; 1130 1131 // extract the WCS terms from this cell 1132 pmAstromWCS *wcs = pmAstromWCSfromHeader (cell->hdu->header); 1133 1134 // modify the wcs terms for the cell offset, binning, and parity 1135 xBinRatio = xBinCell / xBinChip; 1136 if (xFlip) { 1137 wcs->crpix1 = xCell - wcs->crpix1*xBinRatio; 1138 wcs->cdelt1 *= -1; 1139 } else { 1140 wcs->crpix1 = xCell + wcs->crpix1*xBinRatio; 1141 } 1142 wcs->cdelt1 *= xBinRatio; 1143 1144 yBinRatio = yBinCell / yBinChip; 1145 if (yFlip) { 1146 wcs->crpix2 = yCell - wcs->crpix2*yBinRatio; 1147 wcs->cdelt2 *= -1; 1148 } else { 1149 wcs->crpix2 = xCell + wcs->crpix2*yBinRatio; 1150 } 1151 wcs->cdelt2 *= yBinRatio; 1152 1153 pmAstromWCStoHeader (targetHDU->header); 1154 break; 1155 // XXX rather than quitting at this point, we could save this wcs structure and compare 1156 // its values to the equivalent version from one of the other cells. 1157 } 1158 # endif 1108 pmCell *cell = source->cells->data[i]; 1109 if (!cell || !cell->hdu || !cell->hdu->header) { 1110 continue; 1111 } 1112 1113 pmAstromWCS *wcs = pmAstromWCSfromHeader(cell->hdu->header); // WCS terms for this cell 1114 if (!wcs) { 1115 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to read cell WCS to generate chip WCS."); 1116 return false; 1117 } 1118 1119 int xBinCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.XBIN"); // Cell binning in x 1120 if (xBinCell == 0) { 1121 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "CELL.XBIN is not set."); 1122 return false; 1123 } 1124 int xParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.XPARITY"); // Cell parity in x 1125 if (xParityCell != -1 && xParityCell != 1) { 1126 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "CELL.XPARITY is not set."); 1127 return false; 1128 } 1129 int xParityChip = psMetadataLookupS32(NULL, cell->concepts, "CHIP.XPARITY"); // Chip parity in x 1130 if (xParityChip != -1 && xParityChip != 1) { 1131 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "CHIP.XPARITY is not set."); 1132 return false; 1133 } 1134 bool xFlip = (xParityCell == xParityChip ? false : true); // Flip the x sense of the WCS? 1135 int x0Cell = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0"); // Cell offset in x 1136 1137 // Modify the wcs terms for the cell offset, binning, and parity 1138 float xBinRatio = (float)xBinCell / (float)xBin; 1139 if (xFlip) { 1140 wcs->crpix1 = x0Cell - wcs->crpix1 * xBinRatio; 1141 wcs->cdelt1 *= -1; 1142 } else { 1143 wcs->crpix1 = x0Cell + wcs->crpix1 * xBinRatio; 1144 } 1145 wcs->cdelt1 *= xBinRatio; 1146 1147 int yBinCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YBIN"); // Cell binning in y 1148 if (yBinCell == 0) { 1149 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "CELL.YBIN is not set."); 1150 return false; 1151 } 1152 int yParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YPARITY"); // Cell parity in y 1153 if (yParityCell != -1 && yParityCell != 1) { 1154 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "CELL.YPARITY is not set."); 1155 return false; 1156 } 1157 int yParityChip = psMetadataLookupS32(NULL, cell->concepts, "CHIP.YPARITY"); // Chip parity in y 1158 if (yParityChip != -1 && yParityChip != 1) { 1159 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "CHIP.YPARITY is not set."); 1160 return false; 1161 } 1162 bool yFlip = (yParityCell == yParityChip ? false : true); // Flip the y sense of the WCS? 1163 int y0Cell = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0"); // Cell offset in y 1164 1165 float yBinRatio = (float)yBinCell / (float)yBin; 1166 if (yFlip) { 1167 wcs->crpix2 = y0Cell - wcs->crpix2 * yBinRatio; 1168 wcs->cdelt2 *= -1; 1169 } else { 1170 wcs->crpix2 = y0Cell + wcs->crpix2 * yBinRatio; 1171 } 1172 wcs->cdelt2 *= yBinRatio; 1173 1174 if (!pmAstromWCStoHeader(targetHDU->header, wcs)) { 1175 psError(PS_ERR_UNKNOWN, false, "Unable to generate chip WCS from cell WCS."); 1176 psFree(wcs); 1177 return false; 1178 } 1179 psFree(wcs); 1180 1181 // XXX rather than quitting at this point, we could save this wcs structure and compare 1182 // its values to the equivalent version from one of the other cells. 1183 break; 1184 } 1159 1185 1160 1186 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
