Changeset 19395 for trunk/pswarp/src/pswarpTransformReadout.c
- Timestamp:
- Sep 5, 2008, 12:37:59 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/pswarp/src/pswarpTransformReadout.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarpTransformReadout.c
r19391 r19395 1 # include "pswarp.h"1 #include "pswarp.h" 2 2 3 3 // NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT … … 5 5 { 6 6 // XXX this implementation currently ignores the use of the region 7 psImage *region = NULL; 7 psImage *region = NULL; // Region to transform 8 8 9 psTimerStart ("warp");9 psTimerStart("warp"); 10 10 11 11 // Get warp parameters 12 bool mdok; 13 int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX"); 14 int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY"); 15 psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments, "INTERPOLATION.MODE"); 12 bool mdok; // Status of MD lookup 13 int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX"); // Number of grid points in x 14 int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY"); // Number of grid points in y 15 psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments, 16 "INTERPOLATION.MODE"); // Mode for interp 16 17 17 18 // load the recipe 18 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);19 psMetadata *recipe = psMetadataLookupPtr(NULL, config->recipes, PSWARP_RECIPE); 19 20 psAssert (recipe, "missing recipe %s", PSWARP_RECIPE); 20 21 … … 23 24 psMaskType maskPoor = pmConfigMaskGet("POOR.WARP", config); 24 25 psMaskType maskBad = pmConfigMaskGet("BAD.WARP", config); 25 psAssert (mdok, "MASK.INPUT was not defined");26 psAssert(mdok, "MASK.INPUT was not defined"); 26 27 27 int nThreads = psMetadataLookupS32 (&mdok, config->arguments, "NTHREADS");28 if (!mdok) nThreads = 0;29 30 // Flux fraction for "poor"31 float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); 28 int nThreads = psMetadataLookupS32(&mdok, config->arguments, "NTHREADS"); // Number of threads 29 if (!mdok) { 30 nThreads = 0; 31 } 32 float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); // Flux fraction for "poor" 32 33 33 34 // pswarpMapGridFromImage builds a set of locally-linear maps which convert the 34 35 // output coordinates to input coordinates 35 pswarpMapGrid *grid = pswarpMapGridFromImage (input, output, nGridX, nGridY);36 pswarpMapGrid *grid = pswarpMapGridFromImage(input, output, nGridX, nGridY); 36 37 37 38 // XXX optionally modify the grid based on this result and force the maxError < XXX 38 double maxError = pswarpMapGridMaxError (grid); 39 psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError); 39 double maxError = pswarpMapGridMaxError(grid); // Maximum (positional) error from using grid 40 psLogMsg("pswarp", 3, "maximum error using this grid sampling: %lf\n", maxError); 41 42 // Get range of interest 43 int xOutMin, xOutMax, yOutMin, yOutMax; // Output pixel range 44 pswarpMatchRange(&xOutMin, &yOutMin, &xOutMax, &yOutMax, input, output); 45 46 // Check the range of the grid coordinates 47 #define CHECK_GRID_RANGE() { \ 48 xGridMin = PS_MIN(xGridMin, xGrid); \ 49 xGridMax = PS_MAX(xGridMax, xGrid); \ 50 yGridMin = PS_MIN(yGridMin, yGrid); \ 51 yGridMax = PS_MAX(yGridMax, yGrid); \ 52 } 53 54 int xGridMin = nGridX, xGridMax = 0, yGridMin = nGridY, yGridMax = 0; // Grid range 55 int xGrid, yGrid; // Grid coordinates 56 pswarpMapGridSetGrid(grid, xOutMin, yOutMin, &xGrid, &yGrid); 57 CHECK_GRID_RANGE(); 58 pswarpMapGridSetGrid(grid, xOutMin, yOutMax, &xGrid, &yGrid); 59 CHECK_GRID_RANGE(); 60 pswarpMapGridSetGrid(grid, xOutMax, yOutMin, &xGrid, &yGrid); 61 CHECK_GRID_RANGE(); 62 pswarpMapGridSetGrid(grid, xOutMax, yOutMax, &xGrid, &yGrid); 63 CHECK_GRID_RANGE(); 40 64 41 65 // Interpolation options : move these from the arguments to explicit assignments 42 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(interpolationMode, input->image, input->weight, input->mask, maskIn, NAN, NAN, maskBad, maskPoor, poorFrac); 66 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(interpolationMode, input->image, 67 input->weight, input->mask, maskIn, 68 NAN, NAN, maskBad, maskPoor, poorFrac); 43 69 44 70 if (input->weight && !output->weight) { … … 51 77 } 52 78 53 static int maskNum = 0;54 {55 psString name = NULL;56 psStringAppend(&name, "mask_%d.fits", maskNum++);57 psFits *fits = psFitsOpen(name, "w");58 psFree(name);59 psFitsWriteImage(fits, NULL, output->mask, 0, NULL);60 psFitsClose(fits);61 }62 63 // total number of good pixels across all tiles (summed below)64 int goodPixels = 0;65 66 79 // create jobs and supply them to the threads 67 for (int gridY = 0; gridY < grid->nYpts; gridY++) { 68 for (int gridX = 0; gridX < grid->nXpts; gridX++) { 69 80 for (int gridY = yGridMin; gridY < yGridMax; gridY++) { 81 for (int gridX = xGridMin; gridX < xGridMax; gridX++) { 70 82 pswarpTransformTileArgs *args = pswarpTransformTileArgsAlloc(); 71 72 // these items are just views to the data; they are not freed with args 73 args->input = input; 74 args->output = output; 75 args->grid = grid; 76 args->interp = interp; 77 args->region = region; 83 args->input = psMemIncrRefCounter(input); 84 args->output = psMemIncrRefCounter(output); 85 args->grid = psMemIncrRefCounter(grid); 86 args->interp = psMemIncrRefCounter(interp); 87 args->region = psMemIncrRefCounter(region); 78 88 79 89 args->gridX = gridX; … … 83 93 // allocate a job 84 94 psThreadJob *job = psThreadJobAlloc ("PSWARP_TRANSFORM_TILE"); 85 86 // construct the arguments for this job 87 // job is pswarpTransformTile (gridX, gridY); 88 psArrayAdd (job->args, 1, args); 89 // fprintf (stderr, "adding job %d,%d, Nargs: %ld\n", gridX, gridY, job->args->n); 90 91 // call: pswarpTransformTile (args); 92 if (!psThreadJobAddPending (job)) { 95 psArrayAdd(job->args, 1, args); 96 if (!psThreadJobAddPending(job)) { 93 97 psError(PS_ERR_UNKNOWN, false, "Unable to warp image."); 94 98 return false; … … 109 113 // we have only supplied one type of job, so we can assume the types here 110 114 psThreadJob *job = NULL; 115 int xMin = output->image->numCols, xMax = 0, yMin = output->image->numRows, yMax = 0; // Bounds 116 int goodPixels = 0; // total number of good pixels across all tiles 111 117 while ((job = psThreadJobGetDone()) != NULL) { 112 118 if (job->args->n < 1) { … … 116 122 // fprintf (stderr, "finished job %d,%d, Nargs: %ld\n", args->gridX, args->gridY, job->args->n); 117 123 goodPixels += args->goodPixels; 124 xMin = PS_MIN(args->xMin, xMin); 125 xMax = PS_MAX(args->xMax, xMax); 126 yMin = PS_MIN(args->yMin, yMin); 127 yMax = PS_MAX(args->yMax, yMax); 118 128 } 119 psFree (job);129 psFree(job); 120 130 } 121 131 psFree(interp); 122 132 psFree(grid); 123 133 134 if (xMin < xMax && yMin < yMax) { 135 psTrace("pswarp.transform", 1, "Bounds [%d:%d,%d:%d]\n", xMin, xMax, yMin, yMax); 136 } else { 137 psTrace("pswarp.transform", 1, "No overlap\n"); 138 } 124 139 125 140 // Store the variance factor and number of good pixels 126 141 if (goodPixels > 0) { 127 142 // Variance factor: large factor --> small scale 128 float varFactor = psImageInterpolateVarianceFactor(input->image->numCols / 2.0 + input->image->col0, input->image->numRows / 2.0 + input->image->row0, interp); 143 float varFactor = psImageInterpolateVarianceFactor(input->image->numCols / 2.0 + input->image->col0, 144 input->image->numRows / 2.0 + input->image->row0, 145 interp); 129 146 psMetadataItem *vfItem = psMetadataLookup(output->analysis, PSWARP_ANALYSIS_VARFACTOR); 130 147 if (vfItem) { … … 145 162 146 163 if (goodPixels > 0) { 147 if (!pswarpTransformSources (output, input, config)) {164 if (!pswarpTransformSources(output, input, config)) { 148 165 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 149 166 return false; 150 167 } 168 169 // Data is only written out if there are good pixels 170 output->data_exists = true; 171 output->parent->data_exists = true; 172 output->parent->parent->data_exists = true; 151 173 } 152 174 153 // XXX should we not write anything out if there are no good pixels? 154 output->data_exists = true; 155 output->parent->data_exists = true; 156 output->parent->parent->data_exists = true; 157 158 { 159 psString name = NULL; 160 psStringAppend(&name, "mask_%d.fits", maskNum++); 161 psFits *fits = psFitsOpen(name, "w"); 162 psFree(name); 163 psFitsWriteImage(fits, NULL, output->mask, 0, NULL); 164 psFitsClose(fits); 165 } 166 167 psLogMsg ("pswarp", 3, "warping analysis: %f sec\n", psTimerMark ("warp")); 175 psLogMsg("pswarp", 3, "warping analysis: %f sec\n", psTimerMark ("warp")); 168 176 169 177 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
