Changeset 23992 for trunk/ppSkycell/src/ppSkycellLoop.c
- Timestamp:
- Apr 28, 2009, 3:31:25 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ppSkycell/src/ppSkycellLoop.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSkycell/src/ppSkycellLoop.c
r23982 r23992 11 11 #define BUFFER 16 // Size of buffer for projections 12 12 13 static psRegion *skycellRegion(psRegion *region, // Current region of skycell, or NULL 14 pmAstromWCS *wcs, // World Coordinate System 13 // List of input files 14 static const char *inFiles[] = { "PPSKYCELL.IMAGE", "PPSKYCELL.MASK", NULL }; 15 16 // List of output files 17 //static const char *outFiles[] = { "PPSKYCELL.JPEG1", "PPSKYCELL.JPEG2", NULL }; 18 19 20 static void regionMinMax(psRegion *base,// Base region; modified 21 const psRegion *compare // Comparison region 22 ) 23 { 24 base->x0 = PS_MIN(base->x0, compare->x0); 25 base->x1 = PS_MAX(base->x1, compare->x1); 26 base->y0 = PS_MIN(base->y0, compare->y0); 27 base->y1 = PS_MAX(base->y1, compare->y1); 28 return; 29 } 30 31 static psRegion *skycellRegion(pmAstromWCS *wcs, // World Coordinate System 15 32 int numCols, int numRows // Size of image 16 33 ) 17 34 { 18 35 psPlane *fromCoords = psPlaneAlloc(), *toCoords = psPlaneAlloc(); // Coordinates for transforms 19 if (!region) { 20 region = psRegionAlloc(INFINITY, -INFINITY, INFINITY, -INFINITY); 21 } 36 psRegion *region = psRegionAlloc(INFINITY, -INFINITY, INFINITY, -INFINITY); // Region for skycell 22 37 23 38 // Limit the region using the nominated point (X,Y) … … 25 40 fromCoords->x = (X); \ 26 41 fromCoords->y = (Y); \ 27 psPlaneTransform (toCoords, wcs->transform, fromCoords); \42 psPlaneTransformApply(toCoords, wcs->trans, fromCoords); \ 28 43 toCoords->x += wcs->crpix1; \ 29 44 toCoords->y += wcs->crpix2; \ … … 33 48 region->y1 = PS_MAX(region->y1, toCoords->y); 34 49 35 REGION_RANGE(0, 0);// Lower left36 REGION_RANGE(0, numRows);// Upper left37 REGION_RANGE(numCols, 0);// Lower right38 REGION_RANGE(numCols, numRows);// Upper right50 REGION_RANGE(0, 0); // Lower left 51 REGION_RANGE(0, numRows); // Upper left 52 REGION_RANGE(numCols, 0); // Lower right 53 REGION_RANGE(numCols, numRows); // Upper right 39 54 40 55 return region; 56 } 57 58 // Activate/deactivate a single element for a list 59 void fileActivationSingle(pmConfig *config, // Configuration 60 const char **files, // Files to turn on/off 61 bool state, // Activation state 62 int num // Number of file in sequence 63 ) 64 { 65 assert(config); 66 for (int i = 0; files[i] != NULL; i++) { 67 pmFPAfileActivateSingle(config->files, state, files[i], num); // Activated file 68 } 69 return; 70 } 71 72 // Iterate down the hierarchy, loading files; we can get away with this because we're working on skycells 73 static pmFPAview *filesIterateDown(pmConfig *config // Configuration 74 ) 75 { 76 assert(config); 77 78 pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy 79 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 80 return NULL; 81 } 82 view->chip = 0; 83 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 84 return NULL; 85 } 86 view->cell = 0; 87 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 88 return NULL; 89 } 90 view->readout = 0; 91 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 92 return NULL; 93 } 94 return view; 95 } 96 97 // Iterate up the hierarchy, writing files; we can get away with this because we're working on skycells 98 static bool filesIterateUp(pmConfig *config // Configuration 99 ) 100 { 101 assert(config); 102 103 pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy 104 view->chip = view->cell = view->readout = 0; 105 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 106 return false; 107 } 108 view->readout = -1; 109 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 110 return false; 111 } 112 view->cell = -1; 113 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 114 return false; 115 } 116 view->chip = -1; 117 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 118 return false; 119 } 120 psFree(view); 121 return true; 41 122 } 42 123 … … 49 130 psVector *cdelt1 = psVectorAllocEmpty(BUFFER, PS_TYPE_F64); // CDELT1 values 50 131 psVector *cdelt2 = psVectorAllocEmpty(BUFFER, PS_TYPE_F64); // CDELT2 values 51 psArray * regions = psArrayAllocEmpty(BUFFER); // Region for projection132 psArray *projRegions = psArrayAllocEmpty(BUFFER); // Region for projection 52 133 int numProj = 0; // Number of projections 53 134 54 135 psVector *target = psVectorAlloc(data->numInputs, PS_TYPE_S32); // Target for each input 136 psArray *imageRegions = psArrayAlloc(data->numInputs); // Region for image 55 137 56 138 for (int i = 0; i < data->numInputs; i++) { … … 68 150 int numRows = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows 69 151 70 double xLow = wcs->crpix1 / fabs(wcs->crpix1) + wcs->cdelt2 / fabs(wcs->crpix2)71 double xHigh = numCols + wcs->crpix1 / fabs(wcs->crpix1) + numRows * wcs->cdelt2 / fabs(wcs->crpix2);72 73 152 pmAstromWCS *wcs = pmAstromWCSfromHeader(hdu->header); // World Coordinate System 74 153 if (!wcs) { … … 76 155 return false; 77 156 } 157 158 psRegion *region = imageRegions->data[i] = skycellRegion(wcs, numCols, numRows); // Region of image 78 159 79 160 bool found = false; // Found a projection? … … 83 164 wcs->cdelt1 == cdelt1->data.F64[j] && 84 165 wcs->cdelt2 == cdelt1->data.F64[j]) { 85 skycellRegion(regions->data[j], wcs, numCols, numRows);166 regionMinMax(projRegions->data[j], region); 86 167 target->data.S32[i] = j; 168 skycellRegion(wcs, numCols, numRows); 87 169 found = true; 88 170 } … … 94 176 psVectorAppend(cdelt1, wcs->cdelt1); 95 177 psVectorAppend(cdelt2, wcs->cdelt2); 96 psArrayAdd( regions, regions->n, skycellRegion(NULL, wcs, numCols, numRows))178 psArrayAdd(projRegions, projRegions->n, region); 97 179 target->data.S32[i] = numProj; 98 180 … … 101 183 } 102 184 185 pmFPAfileActivate(data->config->files, false, NULL); 186 187 for (int i = 0; i < numProj; i++) { 188 psRegion *projRegion = projRegions->data[i]; // Region for skycell projection 189 int xSize = projRegion->x1 - projRegion->x0; // Size of unbinned image 190 int ySize = projRegion->y1 - projRegion->y0; // Size of unbinned image 191 // Size of binned image 1 192 int numCols1 = xSize / (float)data->bin1 + 0.5, numRows1 = ySize / (float)data->bin1 + 0.5; 193 // Size of binned image 2 194 int numCols2 = numCols1 / (float)data->bin2 + 0.5, numRows2 = numRows2 / (float)data->bin1 + 0.5; 195 196 psImage *image1 = psImageAlloc(numCols1, numRows1, PS_TYPE_F32); // Binned image 197 psImage *image2 = psImageAlloc(numCols2, numRows2, PS_TYPE_F32); // Binned image 198 psImageInit(image1, 0); 199 psImageInit(image2, 0); 200 201 for (int j = 0; j < data->numInputs; j++) { 202 if (target->data.S32[j] != i) { 203 continue; 204 } 205 206 fileActivationSingle(data->config, inFiles, true, j); 207 pmFPAview *view = filesIterateDown(data->config); // View to readout 208 if (!view) { 209 psError(psErrorCodeLast(), false, "Unable to iterate down."); 210 // XXX Cleanup 211 return false; 212 } 213 214 pmFPAfile *file = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.IMAGE", j); 215 pmReadout *inRO = pmFPAviewThisReadout(view, file->fpa); // Readout with input 216 psFree(view); 217 218 pmReadout *bin1RO = pmReadoutAlloc(NULL), *bin2RO = pmReadoutAlloc(NULL); // Binned readouts 219 if (!pmReadoutRebin(bin1RO, inRO, data->maskVal, data->bin1, data->bin1)) { 220 psError(psErrorCodeLast(), false, "Unable to rebin image"); 221 // XXX Cleanup 222 return false; 223 } 224 if (!pmReadoutRebin(bin2RO, bin1RO, data->maskVal, data->bin2, data->bin2)) { 225 psError(psErrorCodeLast(), false, "Unable to rebin image"); 226 // XXX Cleanup 227 return false; 228 } 229 230 psRegion *imageRegion = imageRegions->data[j]; // Region for image 231 // Offsets for image on skycell 232 int xOffset1 = (imageRegion->x0 - projRegion->x0) / (float)data->bin1 + 0.5; 233 int yOffset1 = (imageRegion->y0 - projRegion->y0) / (float)data->bin1 + 0.5; 234 int xOffset2 = xOffset1 / (float)data->bin2 + 0.5, yOffset2 = yOffset1 / (float)data->bin2 + 0.5; 235 236 // XXX Completely neglecting rotations 237 // The skycells are divided up neatly with them all having the same orientation 238 psImageOverlaySection(image1, bin1RO->image, xOffset1, yOffset1, "="); 239 psImageOverlaySection(image2, bin2RO->image, xOffset2, yOffset2, "="); 240 241 psFree(bin1RO); 242 psFree(bin2RO); 243 filesIterateUp(data->config); 244 } 245 246 { 247 psString filename = NULL; // Filename for image 248 psStringAppend(&filename, "skycell_%d_1.fits", i); 249 psFits *fits = psFitsOpen(filename, "w"); 250 psFree(filename); 251 psFitsWriteImage(fits, NULL, image1, 0, NULL); 252 psFitsClose(fits); 253 } 254 255 { 256 psString filename = NULL; // Filename for image 257 psStringAppend(&filename, "skycell_%d_2.fits", i); 258 psFits *fits = psFitsOpen(filename, "w"); 259 psFree(filename); 260 psFitsWriteImage(fits, NULL, image2, 0, NULL); 261 psFitsClose(fits); 262 } 263 264 psFree(image1); 265 psFree(image2); 266 } 267 268 // XXX Cleanup 269 return true; 270 }
Note:
See TracChangeset
for help on using the changeset viewer.
