Changeset 5371 for trunk/archive/scripts/src/phase2/pmFPARead.c
- Timestamp:
- Oct 18, 2005, 4:19:41 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/archive/scripts/src/phase2/pmFPARead.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/phase2/pmFPARead.c
r5105 r5371 17 17 18 18 // Read a FITS extension into a chip 19 static bool readExtension(p _pmHDU *hdu, // HDUto read19 static bool readExtension(pmPixelData *pixelData, // Pixel data into which to read 20 20 psFits *fits // The FITS file from which to read 21 21 ) 22 22 { 23 const char *extName = hdu->extname;// Extension name23 const char *extName = pixelData->extname; // Extension name 24 24 25 25 psTrace(__func__, 7, "Moving to extension %s...\n", extName); … … 74 74 if (image->type.type != PS_TYPE_F32) { 75 75 pixels->data[i] = psImageCopy(NULL, image, PS_TYPE_F32); 76 77 #ifndef PRODUCTION 78 // XXX: Temporary fix for writing images, until psFits gets cleaned up 79 psMetadataItem *bitpixItem = psMetadataLookup(header, "BITPIX"); 80 bitpixItem->data.S32 = -32; 81 psMetadataRemove(header, 0, "BZERO"); 82 psMetadataRemove(header, 0, "BSCALE"); 83 #endif 84 76 85 psFree(image); 77 86 } else { … … 86 95 87 96 // Update the HDU with the new data 88 hdu->pixels = pixels; 89 hdu->header = header; 97 pixelData->images = pixels; 98 pixelData->header = header; 99 100 // XXX: Insert mask and weight reading here 90 101 91 102 return true; 92 103 } 93 104 94 95 105 // Portion out an image into the cell 96 static bool portionCell(pmCell *cell,// The cell that gets its bits97 psArray *images // Array of images from which the readouts are assigned106 static bool generateReadouts(pmCell *cell, // The cell that gets its bits 107 pmPixelData *data // Pixel data, containing image, mask, weights 98 108 ) 99 109 { 100 bool mdStatus = false; // Status of MD lookup 101 102 // Get the trim and bias sections 103 psMetadataItem *mdItem = psMetadataLookup(cell->concepts, "CELL.TRIMSEC"); 104 psRegion *trimRegion = mdItem->data.V; 105 mdItem = psMetadataLookup(cell->concepts, "CELL.BIASSEC"); 106 psList *biasRegionList = mdItem->data.V; 107 110 psArray *images = data->images; // Array of images (each of which is a readout) 111 psArray *masks = data->masks; // Array of masks (one for each readout) 108 112 // Iterate over each of the image planes 109 113 for (int i = 0; i < images->n; i++) { 110 114 psImage *image = images->data[i]; // The i-th plane 111 112 // Convert from FITS standard to PS standard 113 // We don't touch the x1 and y1 values because they aren't included by psImageSubset. 114 //trimRegion->x0 -= 1; 115 //trimRegion->y0 -= 1; 116 117 psImage *trimImage = psImageSubset(image, *trimRegion); // Image from trim section 118 119 psList *biasImages = psListAlloc(NULL); // List of images from bias sections 120 psListIterator *biasRegionIter = psListIteratorAlloc(biasRegionList, PS_LIST_HEAD, true); // Iterator 121 psRegion *biasRegion = NULL; // Bias region from list 122 while (biasRegion = psListGetAndIncrement(biasRegionIter)) { 123 // Convert from FITS standard to PS standard 124 // We don't touch the x1 and y1 values because they aren't included by psImageSubset. 125 //biasRegion->x0 -= 1; 126 //biasRegion->y0 -= 1; 127 128 psImage *biasImage = psImageSubset(image, *biasRegion); // Image from bias section 129 psListAdd(biasImages, PS_LIST_TAIL, biasImage); 130 psFree(biasImage); 131 } 132 psFree(biasRegionIter); 133 134 pmReadout *readout = pmReadoutAlloc(cell, trimImage, biasImages, 0,0,0,0,1,1); 115 psImage *mask = NULL; // The mask 116 if (masks) { 117 mask = masks->data[i]; 118 } 119 120 pmReadout *readout = pmReadoutAlloc(cell, image, mask, 0,0,0,0,1,1); 135 121 psFree(readout); // This seems silly, but the alloc registers it with the cell, so we 136 122 // don't have to do anything with it. Perhaps we should change 137 123 // pmReadoutAlloc to pmReadoutAdd? 138 psFree(trimImage); 139 psFree(biasImages); 140 } 141 psFree(biasRegionList); 124 } 142 125 143 126 return true; … … 154 137 ) 155 138 { 156 p _pmHDU *hdu = NULL; // Current HDUfrom FITS file139 pmPixelData *pixelData = NULL; // Pixel data from FITS file 157 140 158 141 // Read the PHU, if required … … 169 152 // Read in.... 170 153 psTrace(__func__, 1, "Working on FPA...\n"); 171 if (fpa-> private) {172 hdu = fpa->private;173 psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", hdu->extname);174 if (! readExtension( hdu, fits)) {175 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);154 if (fpa->data) { 155 pixelData= fpa->data; 156 psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", pixelData->extname); 157 if (! readExtension(pixelData, fits)) { 158 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", pixelData->extname); 176 159 return false; 177 160 } … … 191 174 psTrace(__func__, 2, "Reading in chip %d...\n", i); 192 175 193 if (chip-> private) {194 hdu = chip->private;195 psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", hdu->extname, i);196 if (! readExtension( hdu, fits)) {197 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname);176 if (chip->data) { 177 pixelData = chip->data; 178 psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", pixelData->extname, i); 179 if (! readExtension(pixelData, fits)) { 180 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", pixelData->extname); 198 181 return false; 199 182 } … … 213 196 psTrace(__func__, 3, "Reading in cell %d...\n", j); 214 197 215 if (cell->private) { 216 hdu = cell->private; 217 psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", hdu->extname, j); 218 if (! readExtension(hdu, fits)) { 219 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", hdu->extname); 198 if (cell->data) { 199 pixelData = cell->data; 200 psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", pixelData->extname, 201 j); 202 if (! readExtension(pixelData, fits)) { 203 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", 204 pixelData->extname); 220 205 return false; 221 206 } … … 225 210 psTrace(__func__, 5, "Allocating readouts for chip %d cell %d...\n", 226 211 i, j); 227 portionCell(cell, hdu->pixels);212 generateReadouts(cell, pixelData); 228 213 } 229 214 }
Note:
See TracChangeset
for help on using the changeset viewer.
