Changeset 12771
- Timestamp:
- Apr 5, 2007, 5:38:16 PM (19 years ago)
- Location:
- trunk/pswarp/src
- Files:
-
- 5 edited
-
pswarpArguments.c (modified) (2 diffs)
-
pswarpDataLoad.c (modified) (6 diffs)
-
pswarpDataSave.c (modified) (3 diffs)
-
pswarpParseCamera.c (modified) (4 diffs)
-
pswarpTransformReadout_Opt.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarpArguments.c
r12567 r12771 47 47 } 48 48 49 49 50 psArray *array; 50 51 … … 58 59 psFree (array); 59 60 61 62 // Parse the recipe and format into the arguments 63 { 64 65 // Select the appropriate recipe 66 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 67 if (!recipe) { 68 psError(PSWARP_ERR_CONFIG, true, "Can't find %s recipe!\n", PSWARP_RECIPE); 69 return false; 70 } 71 72 // Get grid size 73 bool status; // Status of MD lookup 74 int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX"); 75 if (!status) nGridX = 128; 76 int nGridY = psMetadataLookupS32 (&status, recipe, "GRID.NY"); 77 if (!status) nGridY = 128; 78 79 // Get interpolation mode 80 psImageInterpolateMode interpolationMode; // Mode for interpolation 81 const char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE"); // Name of interp mode 82 if (!name) { 83 interpolationMode = PS_INTERPOLATE_BILINEAR; 84 psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n"); 85 } else { 86 interpolationMode = psImageInterpolateModeFromString (name); 87 if (interpolationMode == PS_INTERPOLATE_NONE) { 88 interpolationMode = PS_INTERPOLATE_BILINEAR; 89 psLogMsg ("pswarp", 3, 90 "Unknown interpolation mode %s, defaulting to bilinear interpolation\n", name); 91 } 92 } 93 94 // Get mask parameters 95 psMaskType maskIn = psMetadataLookupU8(&status, recipe, "MASK.IN"); // Mask for input data 96 if (!status) { 97 maskIn = 0x00; 98 psWarning("MASK.IN is not set in the %s recipe --- defaulting to %x.", PSWARP_RECIPE, maskIn); 99 } 100 psMaskType maskPoor = psMetadataLookupU8(&status, recipe, "MASK.POOR"); // Mask for "poor" warped data 101 if (!status) { 102 maskPoor = 0x00; 103 psWarning("MASK.POOR is not set in the %s recipe --- defaulting to %x.", PSWARP_RECIPE, maskPoor); 104 } 105 psMaskType maskBad = psMetadataLookupU8(&status, recipe, "MASK.IN"); // Mask for bad warped data 106 if (!status) { 107 maskBad = 0x00; 108 psWarning("MASK.BAD is not set in the %s recipe --- defaulting to %x.", PSWARP_RECIPE, maskBad); 109 } 110 float poorFrac = psMetadataLookupF32(&status, recipe, "POOR.FRAC"); // Frac of bad flux for a "poor" 111 if (!status) { 112 poorFrac = 0.0; 113 psWarning("POOR.FRAC is not set in the %s recipe --- defaulting to %f.", PSWARP_RECIPE, poorFrac); 114 } 115 116 // Set recipe values in the arguments 117 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NX", 0, 118 "Iso-astrom grid spacing in x", nGridX); 119 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NY", 0, 120 "Iso-astrom grid spacing in x", nGridX); 121 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.MODE", 0, 122 "Interpolation mode", interpolationMode); 123 psMetadataAddU8(config->arguments, PS_LIST_TAIL, "MASK.IN", 0, 124 "Mask for input data", maskIn); 125 psMetadataAddU8(config->arguments, PS_LIST_TAIL, "MASK.POOR", 0, 126 "Mask for poor warped data", maskPoor); 127 psMetadataAddU8(config->arguments, PS_LIST_TAIL, "MASK.BAD", 0, 128 "Mask for bad warped data", maskBad); 129 psMetadataAddF32(config->arguments, PS_LIST_TAIL, "POOR.FRAC", 0, 130 "Fraction of bad flux for a pixel to be marked as poor", poorFrac); 131 } 132 60 133 psTrace("pswarp", 1, "Done with pswarpArguments...\n"); 61 134 return (config); -
trunk/pswarp/src/pswarpDataLoad.c
r12526 r12771 17 17 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSWARP.INPUT"); 18 18 if (!input) { 19 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");20 return false;19 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n"); 20 return false; 21 21 } 22 22 … … 24 24 pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSWARP.ASTROM"); 25 25 if (!astrom) { 26 astrom = input;26 astrom = input; 27 27 } 28 28 29 29 // select the output readout 30 30 view = pmFPAviewAlloc (0); … … 34 34 pmReadout *output = pmFPAfileThisReadout (config->files, view, "PSWARP.OUTPUT"); 35 35 if (!output) { 36 psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n");37 return false;36 psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n"); 37 return false; 38 38 } 39 39 psFree (view); … … 42 42 pmFPAfileActivate (config->files, false, "PSWARP.SKYCELL"); 43 43 pmFPAfileActivate (config->files, false, "PSWARP.OUTPUT"); 44 pmFPAfileActivate (config->files, false, "PSWARP.OUTPUT.MASK"); 45 pmFPAfileActivate (config->files, false, "PSWARP.OUTPUT.WEIGHT"); 44 46 45 47 view = pmFPAviewAlloc (0); … … 52 54 pmHDU *phu = pmFPAviewThisPHU (view, astrom->fpa); 53 55 if (phu) { 54 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");55 if (ctype) {56 bilevelAstrometry = !strcmp (&ctype[4], "-DIS");57 }56 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1"); 57 if (ctype) { 58 bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 59 } 58 60 } 59 61 if (bilevelAstrometry) { 60 pmAstromReadBilevelMosaic (input->fpa, phu->header);61 } 62 pmAstromReadBilevelMosaic (input->fpa, phu->header); 63 } 62 64 63 65 // files associated with the science image … … 67 69 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 68 70 if (!chip->process || !chip->file_exists) { continue; } 69 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);71 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 70 72 71 73 // read WCS data from the corresponding header 72 pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa);73 if (bilevelAstrometry) {74 pmAstromReadBilevelChip (chip, hdu->header); 75 } else {76 // we use a default FPA pixel scale of 1.077 pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0);78 }74 pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa); 75 if (bilevelAstrometry) { 76 pmAstromReadBilevelChip (chip, hdu->header); 77 } else { 78 // we use a default FPA pixel scale of 1.0 79 pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0); 80 } 79 81 80 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {82 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 81 83 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 82 84 if (!cell->process || !cell->file_exists) { continue; } 83 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);85 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 84 86 85 // process each of the readouts86 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {87 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);88 if (! readout->data_exists) { continue; }87 // process each of the readouts 88 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 89 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 90 if (! readout->data_exists) { continue; } 89 91 90 // XXX _Opt version uses locally-linear map91 // pswarpTransformReadout (output, readout, config);92 pswarpTransformReadout_Opt (output, readout, config);92 // XXX _Opt version uses locally-linear map 93 // pswarpTransformReadout (output, readout, config); 94 pswarpTransformReadout_Opt (output, readout, config); 93 95 94 pmFPAfileIOChecks (config, view, PM_FPA_AFTER);95 }96 pmFPAfileIOChecks (config, view, PM_FPA_AFTER);97 }98 pmFPAfileIOChecks (config, view, PM_FPA_AFTER);96 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 97 } 98 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 99 } 100 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 99 101 } 100 102 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); -
trunk/pswarp/src/pswarpDataSave.c
r10946 r12771 16 16 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSWARP.INPUT"); 17 17 if (!input) { 18 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");19 return false;18 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n"); 19 return false; 20 20 } 21 21 … … 23 23 pmFPAfileActivate (config->files, false, NULL); 24 24 pmFPAfileActivate (config->files, true, "PSWARP.OUTPUT"); 25 pmFPAfileActivate (config->files, true, "PSWARP.OUTPUT.MASK"); 26 pmFPAfileActivate (config->files, true, "PSWARP.OUTPUT.WEIGHT"); 25 27 pmFPAview *view = pmFPAviewAlloc (0); 26 28 … … 31 33 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 32 34 if (!chip->process || !chip->file_exists) { continue; } 33 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);35 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 34 36 35 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {37 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 36 38 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 37 39 if (!cell->process || !cell->file_exists) { continue; } 38 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);40 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 39 41 40 // process each of the readouts41 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {42 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);43 if (! readout->data_exists) { continue; }42 // process each of the readouts 43 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 44 pmFPAfileIOChecks (config, view, PM_FPA_BEFORE); 45 if (! readout->data_exists) { continue; } 44 46 45 // pswarpConvertReadout (readout, config);47 // pswarpConvertReadout (readout, config); 46 48 47 pmFPAfileIOChecks (config, view, PM_FPA_AFTER);48 }49 pmFPAfileIOChecks (config, view, PM_FPA_AFTER);50 }51 pmFPAfileIOChecks (config, view, PM_FPA_AFTER);49 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 50 } 51 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 52 } 53 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); 52 54 } 53 55 pmFPAfileIOChecks (config, view, PM_FPA_AFTER); -
trunk/pswarp/src/pswarpParseCamera.c
r12526 r12771 11 11 pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PSWARP.INPUT", "INPUT"); 12 12 if (!input) { 13 psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.INPUT");14 return false;13 psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.INPUT"); 14 return false; 15 15 } 16 16 … … 19 19 pmFPAfileDefineFromArgs (&status, config, "PSWARP.ASTROM", "ASTROM"); 20 20 if (status) { 21 psLogMsg ("pswarp", 3, "using supplied astrometry\n");21 psLogMsg ("pswarp", 3, "using supplied astrometry\n"); 22 22 } else { 23 psLogMsg ("pswarp", 3, "using header astrometry\n");23 psLogMsg ("pswarp", 3, "using header astrometry\n"); 24 24 } 25 25 26 26 // the mask is not required - but must conform to input camera 27 if (!pmFPAfileBindFromArgs (NULL, input, config, "PSWARP.MASK", "MASK")) { 28 psLogMsg ("pswarp", 3, "no mask supplied\n"); 29 } 27 pmFPAfile *inMask = pmFPAfileBindFromArgs(NULL, input, config, "PSWARP.MASK", "MASK"); 28 if (!inMask) { 29 psLogMsg ("pswarp", 3, "no mask supplied\n"); 30 } 30 31 31 if (!pmFPAfileBindFromArgs (NULL, input, config, "PSWARP.WEIGHT", "WEIGHT")) { 32 psLogMsg ("pswarp", 3, "no weight supplied\n"); 33 } 32 pmFPAfile *inWeight = pmFPAfileBindFromArgs(NULL, input, config, "PSWARP.WEIGHT", "WEIGHT"); 33 if (!inWeight) { 34 psLogMsg ("pswarp", 3, "no weight supplied\n"); 35 } 34 36 35 37 // the input skycell is a required argument: it defines the output image … … 37 39 status = pswarpDefineSkycell (&skycell, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL"); 38 40 if (!status) { 39 psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.SKYCELL");40 return false;41 psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.SKYCELL"); 42 return false; 41 43 } 42 44 … … 45 47 // if (!pmFPAfileDefineFromFPA (skyConfig, skycell->fpa, 1, 1, "PSWARP.OUTPUT")) { 46 48 if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT")) { 47 psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT"); 48 return false; 49 psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT"); 50 return false; 51 } 52 if (inMask) { 53 if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT.MASK")) { 54 psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.MASK"); 55 return false; 56 } 57 } 58 if (inWeight) { 59 if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT.WEIGHT")) { 60 psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.WEIGHT"); 61 return false; 62 } 49 63 } 50 64 51 65 // Chip selection: turn on only the chips specified 52 char *chipLine = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS"); 66 char *chipLine = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS"); 53 67 psArray *chips = psStringSplitArray (chipLine, ",", false); 54 68 if (chips->n > 0) { 55 pmFPASelectChip (input->fpa, -1, true); // deselect all chips56 for (int i = 0; i < chips->n; i++) {57 int chipNum = atoi(chips->data[i]);58 if (! pmFPASelectChip(input->fpa, chipNum, false)) {59 psError(PSWARP_ERR_CONFIG, true, "Chip number %d doesn't exist in camera.\n", chipNum);60 return false;61 }69 pmFPASelectChip (input->fpa, -1, true); // deselect all chips 70 for (int i = 0; i < chips->n; i++) { 71 int chipNum = atoi(chips->data[i]); 72 if (! pmFPASelectChip(input->fpa, chipNum, false)) { 73 psError(PSWARP_ERR_CONFIG, true, "Chip number %d doesn't exist in camera.\n", chipNum); 74 return false; 75 } 62 76 } 63 77 } -
trunk/pswarp/src/pswarpTransformReadout_Opt.c
r12744 r12771 2 2 3 3 // NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT 4 bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config) { 5 6 bool status; 7 int minX, minY, maxX, maxY; 8 int gridXo, gridX, gridY, nextGridXo, nextGridX, nextGridY; 9 pswarpMap *map = NULL; 10 psImageInterpolateMode interpolationMode = PS_INTERPOLATE_NONE; 11 4 bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config) 5 { 12 6 // XXX this implementation currently ignores the use of the region 13 7 psImage *region = NULL; … … 15 9 psTimerStart ("warp"); 16 10 17 // select the current recipe 18 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 19 if (!recipe) { 20 psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n"); 21 return false; 22 } 23 24 int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX"); 25 if (!status) nGridX = 128; 26 int nGridY = psMetadataLookupS32 (&status, recipe, "GRID.NY"); 27 if (!status) nGridY = 128; 28 29 char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE"); 30 if (!name) { 31 interpolationMode = PS_INTERPOLATE_BILINEAR; 32 psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n"); 33 } else { 34 interpolationMode = psImageInterpolateModeFromString (name); 35 if (interpolationMode == PS_INTERPOLATE_NONE) { 36 interpolationMode = PS_INTERPOLATE_BILINEAR; 37 psLogMsg ("pswarp", 3, "unknown interpolation mode %s, defaulting to bilinear interpolation\n", name); 38 } 39 } 40 41 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 42 psImage *inImage = input->image; 43 psF32 **outData = output->image->data.F32; 11 // Get grid size 12 int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX"); 13 int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY"); 14 psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments, 15 "INTERPOLATION.MODE"); 16 psMaskType maskIn = psMetadataLookupU8(NULL, config->arguments, "MASK.IN"); // Mask for input data 17 psMaskType maskPoor = psMetadataLookupU8(NULL, config->arguments, "MASK.POOR"); // Mask for "poor" data 18 psMaskType maskBad = psMetadataLookupU8(NULL, config->arguments, "MASK.IN"); // Mask for bad data 19 float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); // Flux fraction for "poor" 44 20 45 21 // we need to apply the offset to convert parent coordinates to child coordinates for … … 54 30 55 31 // find the output pixel range 32 int minX, minY, maxX, maxY; 56 33 pswarpMatchRange (&minX, &minY, &maxX, &maxY, input, output); 57 34 … … 64 41 psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError); 65 42 43 int gridX, gridY, nextGridX, nextGridY; 66 44 pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY); 67 45 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY); 68 map = grid->maps[gridX][gridY];46 pswarpMap *map = grid->maps[gridX][gridY]; 69 47 70 48 assert ((int)(minX - outCol0) >= 0); … … 73 51 assert ((int)(maxY - outRow0) <= output->image->numRows); 74 52 75 gridXo = gridX;76 nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);53 int gridXo = gridX; 54 int nextGridXo = pswarpMapGridNextGrid_X (grid, gridX); 77 55 78 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage, 79 NULL, NULL, 0, NAN, NAN, 0, 0, 0.0); 56 psImage *inImage = input->image; // Input image 57 psImage *inVar = input->weight; // Input weight map 58 psImage *inMask = input->mask; // Input mask 59 60 // Interpolation options 61 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(interpolationMode, inImage, 62 inVar, inMask, maskIn, NAN, NAN, 63 maskPoor, maskBad, poorFrac); 64 65 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 66 psF32 **outImageData = output->image->data.F32; // Output image pixels 67 psF32 **outVarData; // Output variance pixels 68 psMaskType **outMaskData; // Output mask pixels 69 if (inVar) { 70 if (!output->weight) { 71 output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32); 72 } 73 outVarData = output->weight->data.F32; 74 } 75 if (inMask) { 76 if (!output->mask) { 77 output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK); 78 } 79 outMaskData = output->mask->data.PS_TYPE_MASK_DATA; 80 } 80 81 81 82 // Iterate over the output image pixels (parent frame) … … 112 113 // XXX apply scale and offset? 113 114 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 114 double value; 115 if (!psImageInterpolate(&value, NULL, NULL, inPix->x - inCol0, inPix->y - inRow0, interp)) { 115 double imageValue, varValue; 116 psMaskType maskValue; 117 if (!psImageInterpolate(&imageValue, &varValue, &maskValue, 118 inPix->x - inCol0, inPix->y - inRow0, interp)) { 116 119 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 117 120 psFree(interp); … … 120 123 return false; 121 124 } 122 outData[y-outRow0][x-outCol0] = value; 125 outImageData[y-outRow0][x-outCol0] = imageValue; 126 if (inVar) { 127 outVarData[y-outRow0][x-outCol0] = varValue; 128 } 129 if (inMask) { 130 outMaskData[y-outRow0][x-outCol0] = maskValue; 131 } 123 132 } 124 133 }
Note:
See TracChangeset
for help on using the changeset viewer.
