Changeset 27437
- Timestamp:
- Mar 24, 2010, 1:59:47 PM (16 years ago)
- Location:
- branches/pap_stack/ppViz/src/ppCoord
- Files:
-
- 5 edited
-
ppCoord.h (modified) (1 diff)
-
ppCoordArguments.c (modified) (1 diff)
-
ppCoordCamera.c (modified) (1 diff)
-
ppCoordData.c (modified) (2 diffs)
-
ppCoordLoop.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_stack/ppViz/src/ppCoord/ppCoord.h
r26377 r27437 10 10 typedef struct { 11 11 psString astromName; // Filename with astrometry 12 psString rawName; // Filename with raw image (or NULL) 12 13 psString pixelsName; // Filename with pixel coordinates 13 14 psString chipName; // Name of chip of interest 14 15 psString radecName; // Filename with sky coordinates 15 16 pmConfig *config; // Configuration 17 bool radians; // RA,Dec are in radians? 18 bool all; // Only all coordinates? 16 19 } ppCoordData; 17 20 -
branches/pap_stack/ppViz/src/ppCoord/ppCoordArguments.c
r26377 r27437 47 47 psMetadata *arguments = psMetadataAlloc(); // Command-line arguments 48 48 psMetadataAddStr(arguments, PS_LIST_TAIL, "-astrom", 0, "Filename with astrometry", NULL); 49 psMetadataAddStr(arguments, PS_LIST_TAIL, "-raw", 0, "Filename with raw data", NULL); 49 50 psMetadataAddStr(arguments, PS_LIST_TAIL, "-pixels", 0, "Filename with pixel coordinates", NULL); 50 51 psMetadataAddStr(arguments, PS_LIST_TAIL, "-chip", 0, "Chip for pixel coordinates", NULL); 51 psMetadataAddStr(arguments, PS_LIST_TAIL, "-radec", 0, "Filename with RA, Dec", NULL); 52 psMetadataAddStr(arguments, PS_LIST_TAIL, "-radec", 0, "Filename with RA,Dec (default decimal degrees)", NULL); 53 psMetadataAddBool(arguments, PS_LIST_TAIL, "-radians", 0, "RA,Dec in radians?", NULL); 54 psMetadataAddBool(arguments, PS_LIST_TAIL, "-all", 0, "Output all coordinates?", NULL); 52 55 if (!psArgumentParse(arguments, &argc, argv) || argc != 1) { 53 56 usage(argv[0], arguments, data); 54 57 } 55 58 56 bool mdok; // Status of MD lookup57 59 data->astromName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-astrom")); 60 data->rawName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-raw")); 58 61 data->pixelsName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-pixels")); 59 62 data->chipName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-chip")); 60 data->radecName = psMemIncrRefCounter(psMetadataLookupStr(&mdok, arguments, "-radec")); 63 data->radecName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-radec")); 64 data->radians = psMetadataLookupBool(NULL, arguments, "-radians"); 65 data->all = psMetadataLookupBool(NULL, arguments, "-all"); 61 66 // psMetadataAddStr(data->config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Output root name", data->outRoot); 62 67 -
branches/pap_stack/ppViz/src/ppCoord/ppCoordCamera.c
r26377 r27437 39 39 } 40 40 41 if (data->rawName) { 42 fileArguments("RAW", data->rawName, "Input raw image", data->config); 43 pmFPAfile *raw = pmFPAfileDefineFromArgs(&status, data->config, "PPIMAGE.INPUT", "RAW"); // File 44 if (!status || !raw) { 45 psError(PS_ERR_IO, false, "Failed to build file from PPIMAGE.INPUT"); 46 return false; 47 } 48 } 49 41 50 #if 0 42 51 // Now the camera has been determined, we can read the recipe -
branches/pap_stack/ppViz/src/ppCoord/ppCoordData.c
r26377 r27437 14 14 { 15 15 psFree(data->astromName); 16 psFree(data->rawName); 16 17 psFree(data->pixelsName); 17 18 psFree(data->chipName); … … 28 29 29 30 data->astromName = NULL; 31 data->rawName = NULL; 30 32 data->pixelsName = NULL; 31 33 data->chipName = NULL; -
branches/pap_stack/ppViz/src/ppCoord/ppCoordLoop.c
r26377 r27437 20 20 } 21 21 22 pmFPAfile *rawFile = data->rawName ? pmFPAfileSelectSingle(config->files, "PPIMAGE.INPUT", 0) : 23 NULL; // File with raw image 24 22 25 psArray *pixels = NULL, *radec = NULL; // Array of vectors with coordinates 23 26 psArray *radecOut = NULL; // Output for sky coordinates … … 25 28 pixels = psVectorsReadFromFile(data->pixelsName, "%f %f"); 26 29 if (!pixels || pixels->n != 2) { 27 psError( PS_ERR_UNKNOWN, false, "Unable to read pixel coordinates");30 psError(psErrorCodeLast(), false, "Unable to read pixel coordinates"); 28 31 return false; 29 32 } … … 32 35 radec = psVectorsReadFromFile(data->radecName, "%lf %lf"); 33 36 if (!radec || radec->n != 2) { 34 psError( PS_ERR_UNKNOWN, false, "Unable to read sky coordinates");37 psError(psErrorCodeLast(), false, "Unable to read sky coordinates"); 35 38 return false; 36 39 } 37 40 psVector *ra = radec->data[0]; // RA coordinates 38 41 long num = ra->n; // Number of coordinates 39 radecOut = psArrayAlloc( 3);42 radecOut = psArrayAlloc(4); 40 43 radecOut->data[0] = psArrayAlloc(num); 41 44 radecOut->data[1] = psVectorAlloc(num, PS_TYPE_F32); 42 45 radecOut->data[2] = psVectorAlloc(num, PS_TYPE_F32); 46 radecOut->data[3] = psArrayAlloc(num); 43 47 psVectorInit(radecOut->data[1], NAN); 44 48 psVectorInit(radecOut->data[2], NAN); … … 61 65 if (bilevelAstrometry) { 62 66 if (!pmAstromReadBilevelMosaic(astromFile->fpa, phu->header)) { 63 psError( PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA.");67 psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA."); 64 68 psFree(view); 65 69 return false; … … 72 76 continue; 73 77 } 78 if (rawFile) { 79 pmChip *rawChip = pmFPAviewThisChip(view, rawFile->fpa); // Chip with raw data 80 if (!rawChip || !rawChip->file_exists) { 81 continue; 82 } 83 } 74 84 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip 75 85 if (data->chipName && strcmp(chipName, data->chipName) != 0) { 76 continue;86 continue; 77 87 } 78 88 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 79 psError( PS_ERR_UNKNOWN, false, "Error loading data from files.");89 psError(psErrorCodeLast(), false, "Error loading data from files."); 80 90 return false; 81 91 } … … 89 99 if (bilevelAstrometry) { 90 100 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 91 psError( PS_ERR_UNKNOWN, false, "Unable to read bilevel chip astrometry for input FPA.");101 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA."); 92 102 psFree(view); 93 103 return false; … … 97 107 psWarning("Reading WCS astrometry for chip %s.", chipName); 98 108 if (!pmAstromReadWCS(astromFile->fpa, chip, hdu->header, 1.0)) { 99 psError( PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for input FPA.");109 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 100 110 psFree(view); 101 111 return false; … … 120 130 psDeproject(sky, tp, astromFile->fpa->toSky); 121 131 132 if (!data->radians) { 133 sky->r *= M_PI / 180.0; 134 sky->d *= M_PI / 180.0; 135 } 136 122 137 fprintf(stdout, "%s %.3f %.3f --> %.10lf %.10lf\n", chipName, pix->x, pix->y, sky->r, sky->d); 123 138 } … … 129 144 130 145 if (radec) { 146 pmChip *rawChip = rawFile ? pmFPAviewThisChip(view, rawFile->fpa) : NULL; // Chip with raw 147 psArray *cellBounds = NULL; // Bounds of each cell 148 psArray *cellNames = NULL; // Names of each cell 149 psVector *cellParityX = NULL, *cellParityY = NULL; // Parity for each cell 150 psVector *cellX0 = NULL, *cellY0 = NULL; // Offset for each cell 151 psVector *cellBinX = NULL, *cellBinY = NULL; // Binning for each cell 152 if (rawChip) { 153 if (!rawChip->data_exists) { 154 // Not interested in this chip 155 continue; 156 } 157 int numCells = rawChip->cells->n; // Number of cells 158 159 cellBounds = psArrayAlloc(numCells); 160 cellNames = psArrayAlloc(numCells); 161 cellParityX = psVectorAlloc(numCells, PS_TYPE_S32); 162 cellParityY = psVectorAlloc(numCells, PS_TYPE_S32); 163 cellX0 = psVectorAlloc(numCells, PS_TYPE_S32); 164 cellY0 = psVectorAlloc(numCells, PS_TYPE_S32); 165 cellBinX = psVectorAlloc(numCells, PS_TYPE_S32); 166 cellBinY = psVectorAlloc(numCells, PS_TYPE_S32); 167 168 pmCell *rawCell; // Cell with raw data 169 while ((rawCell = pmFPAviewNextCell(view, rawFile->fpa, 1))) { 170 if (!rawCell->data_exists) { 171 continue; 172 } 173 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 174 psError(psErrorCodeLast(), false, "Error loading data from files."); 175 return false; 176 } 177 psRegion *region = pmCellExtent(rawCell); // Bounds of cell 178 if (!region) { 179 psError(psErrorCodeLast(), false, "Unable to determine extent of cell."); 180 return false; 181 } 182 cellBounds->data[view->cell] = region; 183 cellNames->data[view->cell] = psMemIncrRefCounter(psMetadataLookupStr(NULL, 184 rawCell->concepts, "CELL.NAME")); 185 cellParityX->data.S32[view->cell] = psMetadataLookupS32(NULL, rawCell->concepts, "CELL.XPARITY"); 186 cellParityY->data.S32[view->cell] = psMetadataLookupS32(NULL, rawCell->concepts, "CELL.YPARITY"); 187 cellX0->data.S32[view->cell] = psMetadataLookupS32(NULL, rawCell->concepts, "CELL.X0"); 188 cellY0->data.S32[view->cell] = psMetadataLookupS32(NULL, rawCell->concepts, "CELL.Y0"); 189 cellBinX->data.S32[view->cell] = psMetadataLookupS32(NULL, rawCell->concepts, "CELL.XBIN"); 190 cellBinY->data.S32[view->cell] = psMetadataLookupS32(NULL, rawCell->concepts, "CELL.YBIN"); 191 if (cellParityX->data.S32[view->cell] == 0 || cellParityY->data.S32[view->cell] == 0 || 192 cellBinX->data.S32[view->cell] == 0 || cellBinY->data.S32[view->cell] == 0) { 193 psError(PM_ERR_CONCEPTS, true, "Concepts aren't set: %d %d %d %d %d %d\n", 194 cellParityX->data.S32[view->cell], cellParityY->data.S32[view->cell], 195 cellX0->data.S32[view->cell], cellY0->data.S32[view->cell], 196 cellBinX->data.S32[view->cell], cellBinY->data.S32[view->cell]); 197 return false; 198 } 199 200 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 201 psError(psErrorCodeLast(), false, "Error freeing data from files."); 202 return false; 203 } 204 } 205 } 206 131 207 psVector *ra = radec->data[0], *dec = radec->data[1]; // Pixel coordinates 132 208 long num = ra->n; // Number of coordinates … … 135 211 int numRows = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS2"); // Number of rows 136 212 if (numCols <= 0 || numRows <= 0) { 137 psError( PS_ERR_UNKNOWN, false, "Unable to read size of chip.");213 psError(psErrorCodeLast(), false, "Unable to read size of chip."); 138 214 return false; 139 215 } … … 147 223 psVector *xPix = radecOut->data[1]; // x coordinate for pixels 148 224 psVector *yPix = radecOut->data[2]; // y coordinate for pixels 225 psArray *cellPix = radecOut->data[3]; // Cell for pixels 149 226 150 227 for (long i = 0; i < num; i++) { 151 228 sky->r = ra->data.F64[i]; 152 229 sky->d = dec->data.F64[i]; 230 231 if (!data->radians) { 232 sky->r *= M_PI / 180.0; 233 sky->d *= M_PI / 180.0; 234 } 153 235 154 236 psProject(tp, sky, astromFile->fpa->toSky); … … 162 244 } 163 245 246 if (rawChip) { 247 psString cellName = NULL; // Name of cell 248 int numCells = rawChip->cells->n; // Number of cells 249 for (int i = 0; i < numCells && !cellName; i++) { 250 psRegion *region = cellBounds->data[i]; // Bounds of cell 251 if (x >= region->x0 && x < region->x1 && y >= region->y0 && y < region->y1) { 252 cellName = psStringCopy(cellNames->data[i]); 253 // Transform chip coordinates to cell coordinates 254 x = (x - cellX0->data.S32[i]) / 255 (float)(cellParityX->data.S32[i] * cellBinX->data.S32[i]); 256 y = (y - cellY0->data.S32[i]) / 257 (float)(cellParityY->data.S32[i] * cellBinY->data.S32[i]); 258 } 259 } 260 cellPix->data[i] = cellName; 261 } 262 164 263 chipPix->data[i] = psStringCopy(chipName); 165 264 xPix->data.F32[i] = x; … … 170 269 psFree(tp); 171 270 psFree(sky); 271 psFree(cellNames); 272 psFree(cellBounds); 273 psFree(cellParityX); 274 psFree(cellParityY); 275 psFree(cellBinX); 276 psFree(cellBinY); 277 psFree(cellX0); 278 psFree(cellY0); 172 279 } 173 280 174 281 // Chip 175 282 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 176 psError( PS_ERR_UNKNOWN, false, "Error saving data to files.");283 psError(psErrorCodeLast(), false, "Error saving data to files."); 177 284 return false; 178 285 } … … 180 287 // FPA 181 288 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 182 psError( PS_ERR_UNKNOWN, false, "Error saving data to files.");289 psError(psErrorCodeLast(), false, "Error saving data to files."); 183 290 return false; 184 291 } … … 188 295 psVector *xPix = radecOut->data[1]; // x coordinate for pixels 189 296 psVector *yPix = radecOut->data[2]; // y coordinate for pixels 297 psArray *cellPix = radecOut->data[3]; // Cell for pixels 190 298 psVector *ra = radec->data[0]; // RA coordinate 191 299 psVector *dec = radec->data[1]; // Dec coordinate … … 193 301 for (long i = 0; i < chipPix->n; i++) { 194 302 const char *chipName = chipPix->data[i]; // Name of chip 195 fprintf(stdout, "%.10lf %.10lf --> %.3f %.3f %s\n", 303 const char *cellName = cellPix->data[i]; // Name of cell, or NULL 304 if (!data->all && (!isfinite(xPix->data.F32[i]) || !isfinite(yPix->data.F32[i]) || 305 !chipName || (rawFile && !cellName))) { 306 continue; 307 } 308 fprintf(stdout, "%.10lf %.10lf --> %.3f %.3f %s%s%s\n", 196 309 ra->data.F64[i], dec->data.F64[i], xPix->data.F32[i], yPix->data.F32[i], 197 chipName ? chipName : "UNKNOWN"); 310 chipName ? chipName : "UNKNOWN", 311 rawFile ? " " : "", 312 rawFile && cellName ? cellName : (rawFile ? "UNKNOWN" : "")); 198 313 } 199 314 }
Note:
See TracChangeset
for help on using the changeset viewer.
