Changeset 18752
- Timestamp:
- Jul 27, 2008, 8:00:23 AM (18 years ago)
- Location:
- branches/eam_branch_20080719/pswarp/src
- Files:
-
- 1 added
- 6 edited
-
Makefile.am (modified) (1 diff)
-
pswarp.c (modified) (1 diff)
-
pswarp.h (modified) (1 diff)
-
pswarpThreadLauncher.c (modified) (2 diffs)
-
pswarpTransformReadout_Threaded.c (modified) (6 diffs)
-
pswarpTransformReadout_Unthreaded.c (added)
-
pswarpTransformTile.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080719/pswarp/src/Makefile.am
r18748 r18752 16 16 pswarpPixelFraction.c \ 17 17 pswarpSetMaskBits.c \ 18 pswarpThreadLauncher.c \ 18 19 pswarpTransformReadout_Opt.c \ 19 pswarpThreadLauncher.c \ 20 pswarpTransformReadout_Threaded.c \ 21 pswarpTransformReadout_Unthreaded.c \ 22 pswarpTransformTile.c \ 20 23 pswarpVersion.c 21 24 -
branches/eam_branch_20080719/pswarp/src/pswarp.c
r18748 r18752 18 18 19 19 // create the thread pool with 4 threads, supplying our thread launcher function 20 // XXX need to determine the number of threads from the config data 20 21 psThreadPoolInit (4, &pswarpThreadLauncher); 21 22 22 srand48(0);23 24 for (int i = 0; i < 10; i++) {25 // allocate a job which takes two arguments26 // XXX probably don't need to pre-specify the number of args27 psThreadJob *job = psThreadJobAlloc ("THREAD_TEST", 2);28 29 // construct the arguments for this job30 char *arg1 = NULL;31 char *arg2 = NULL;32 psStringAppend (&arg1, "arg1.%d", i);33 psStringAppend (&arg2, "arg2.%d", i);34 psArrayAdd (job->args, 1, arg1);35 psArrayAdd (job->args, 1, arg2);36 37 psThreadJobAddToQueue (job);38 }39 if (!psThreadPoolWait ()) {40 fprintf (stderr, "error in a threaded job\n");41 exit (1);42 }43 fprintf (stderr, "success for threaded jobs\n");44 exit (0);45 46 23 // model inits are needed in pmSourceIO 47 24 // models defined in psphot/src/models are not available in psastro -
branches/eam_branch_20080719/pswarp/src/pswarp.h
r18748 r18752 36 36 } pswarpMapGrid; 37 37 38 typedef struct { 39 // values which are common to all tiles 40 pmReadout *input; 41 pmReadout *output; 42 pswarpMapGrid *grid; 43 psImageInterpolateOptions *interp; 44 psImage *region; 45 46 // input values for this tile 47 int gridX; 48 int gridY; 49 50 // output values for this tile 51 long goodPixels; 52 } pswarpTransformTileArgs; 53 54 bool pswarpTransformReadout_Unthreaded(pmReadout *output, pmReadout *input, pmConfig *config); 55 bool pswarpTransformReadout_Threaded(pmReadout *output, pmReadout *input, pmConfig *config); 56 57 pswarpTransformTileArgs *pswarpTransformTileArgsAlloc(); 58 bool pswarpTransformTile (pswarpTransformTileArgs *args); 59 38 60 pmConfig *pswarpArguments (int argc, char **argv); 39 61 bool pswarpOptions(pmConfig *config); -
branches/eam_branch_20080719/pswarp/src/pswarpThreadLauncher.c
r18747 r18752 33 33 // we have to lock here so the job queue cannot be empty yet no threads busy 34 34 psThreadLock(); 35 while ((job = psThreadJobGet ()) == NULL) {35 while ((job = psThreadJobGetPending ()) == NULL) { 36 36 psThreadUnlock(); 37 37 usleep (10000); … … 50 50 continue; 51 51 } 52 53 // list all allowed job types here 54 if (!strcmp (job->type, "PSWARP_TRANSFORM_TILE")) { 55 pswarpTransformTileArgs *args = job->args->data[0]; 56 bool status = pswarpTransformTile (args); 57 if (!status) { 58 self->fault = true; 59 } 60 // we do not have to lock here because this transition is not tied to the job queue 61 self->busy = false; 62 continue; 63 } 52 64 } 53 65 } -
branches/eam_branch_20080719/pswarp/src/pswarpTransformReadout_Threaded.c
r18666 r18752 15 15 int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX"); 16 16 int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY"); 17 psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments, 18 "INTERPOLATION.MODE"); 17 psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments, "INTERPOLATION.MODE"); 18 19 19 // load the recipe 20 20 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 21 if (!recipe) { 22 psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE); 23 return false; 24 } 21 psAssert (recipe, "missing recipe %s", PSWARP_RECIPE); 25 22 26 23 // output mask bits … … 30 27 psAssert (mdok, "MASK.INPUT was not defined"); 31 28 32 float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); // Flux fraction for "poor" 33 34 // we need to apply the offset to convert parent coordinates to child coordinates for 35 // psImagePixelInterpolate below 36 int inCol0 = input->image->col0; 37 int inRow0 = input->image->row0; 38 int outCol0 = output->image->col0; 39 int outRow0 = output->image->row0; 40 41 // we might want to do the rectangular regions outside of the selection independently 42 // psImageInit (output->image, NAN); 29 // Flux fraction for "poor" 30 float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); 43 31 44 32 // find the output pixel range … … 54 42 psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError); 55 43 56 int gridX, gridY , nextGridX, nextGridY;44 int gridX, gridY; 57 45 pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY); 58 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY); 59 pswarpMap *map = grid->maps[gridX][gridY]; 60 46 # if (0) 47 // XXX these asserts probably belong in the function (don't have outCol0,Row0 anyway) 61 48 assert ((int)(minX - outCol0) >= 0); 62 49 assert ((int)(maxX - outCol0) <= output->image->numCols); 63 50 assert ((int)(minY - outRow0) >= 0); 64 51 assert ((int)(maxY - outRow0) <= output->image->numRows); 65 66 int gridXo = gridX; 67 int nextGridXo = pswarpMapGridNextGrid_X (grid, gridX); 52 # endif 68 53 69 54 psImage *inImage = input->image; // Input image … … 76 61 maskBad, maskPoor, poorFrac); 77 62 78 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 79 psF32 **outImageData = output->image->data.F32; // Output image pixels 80 psF32 **outVarData = NULL; // Output variance pixels 81 psMaskType **outMaskData = NULL; // Output mask pixels 82 if (inVar) { 83 if (!output->weight) { 84 output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32); 85 psImageInit(output->weight, NAN); 86 } 87 outVarData = output->weight->data.F32; 88 } 89 if (inMask || maskPoor || maskBad) { 90 if (!output->mask) { 91 output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK); 92 psImageInit(output->mask, maskBad); 93 } 94 outMaskData = output->mask->data.PS_TYPE_MASK_DATA; 95 } 96 97 // create N threads 98 for (gridY = gridYmin; gridY < gridYmax; gridY++) { 99 for (gridX = gridXmin; gridX < gridXmax; gridX++) { 100 pswarpTransformTile (gridX, gridY); 101 // send function and arguments to thread manager 102 // threadFunction (pswarpTransformTile) 103 // while (threadFull()) { 104 // usleep (50000); 105 // } 63 if (inVar && !output->weight) { 64 output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32); 65 psImageInit(output->weight, NAN); 66 } 67 if ((inMask || maskPoor || maskBad) && !output->mask) { 68 output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK); 69 psImageInit(output->mask, maskBad); 70 } 71 72 // total number of good pixels across all tiles (summed below) 73 int goodPixels = 0; 74 75 // create jobs and supply them to the threads 76 for (gridY = 0; gridY < nGridX; gridY++) { 77 for (gridX = 0; gridX < nGridY; gridX++) { 78 79 pswarpTransformTileArgs *args = pswarpTransformTileArgsAlloc(); 80 81 // these items are just views to the data; they are not freed with args 82 args->input = input; 83 args->output = output; 84 args->grid = grid; 85 args->interp = interp; 86 args->region = region; 87 88 args->gridX = gridX; 89 args->gridY = gridY; 90 args->goodPixels = 0; 91 92 // allocate a job 93 psThreadJob *job = psThreadJobAlloc ("PSWARP_TRANSFORM_TILE", 0); 94 95 // construct the arguments for this job 96 // job is pswarpTransformTile (gridX, gridY); 97 psArrayAdd (job->args, 1, args); 98 psThreadJobAddPending (job); 99 psFree (args); 106 100 } 107 101 } 108 109 110 // Iterate over the output image pixels (parent frame) 111 long goodPixels = 0; // Number of input pixels landing on the output image 112 for (int y = minY; y < maxY; y++) { 113 if (y >= nextGridY) { 114 gridY ++; 115 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY); 116 map = grid->maps[gridX][gridY]; 117 } 118 119 gridX = gridXo; 120 nextGridX = nextGridXo; 121 map = grid->maps[gridX][gridY]; 122 int yOut = y - outRow0; // Position on image 123 for (int x = minX; x < maxX; x++) { 124 if (x >= nextGridX) { 125 gridX ++; 126 nextGridX = pswarpMapGridNextGrid_X (grid, gridX); 127 map = grid->maps[gridX][gridY]; 128 } 129 130 // Only transform those pixels requested 131 if (region && region->data.U8[y][x]) continue; 132 133 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate. 134 // both are in the parent frames of the input and output images. 135 pswarpMapApply (&inPix->x, &inPix->y, map, x + 0.5, y + 0.5); 136 137 if (inPix->x - inCol0 < 0) continue; 138 if (inPix->x - inCol0 >= inImage->numCols) continue; 139 if (inPix->y - inRow0 < 0) continue; 140 if (inPix->y - inRow0 >= inImage->numRows) continue; 141 142 goodPixels++; 143 144 // XXX include mask 145 // XXX apply scale and offset? 146 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 147 double imageValue, varValue; 148 psMaskType maskValue; 149 if (!psImageInterpolate(&imageValue, &varValue, &maskValue, 150 inPix->x - inCol0, inPix->y - inRow0, interp)) { 151 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 152 psFree(interp); 153 psFree(inPix); 154 psFree(grid); 155 return false; 156 } 157 int xOut = x - outCol0; // Position on image 158 outImageData[yOut][xOut] = imageValue; 159 if (inVar) { 160 outVarData[yOut][xOut] = varValue; 161 } 162 if (outMaskData) { 163 outMaskData[yOut][xOut] = maskValue; 164 } 165 } 102 // wait here for the threaded jobs to finish 103 if (!psThreadPoolWait ()) { 104 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 105 return false; 106 } 107 fprintf (stderr, "success for threaded jobs\n"); 108 109 // each job records its own goodPixel values; sum them here 110 // we have only supplied one type of job, so we can assume the types here 111 psThreadJob *job = NULL; 112 while ((job = psThreadJobGetDone()) != NULL) { 113 pswarpTransformTileArgs *args = job->args->data[0]; 114 goodPixels += args->goodPixels; 115 psFree (job); 166 116 } 167 117 psFree(interp); 168 psFree(inPix);169 118 psFree(grid); 170 119 171 120 // Store the variance factor and number of good pixels 172 121 if (goodPixels > 0) { 173 float varFactor = psImageInterpolateVarianceFactor(inImage->numCols / 2.0 + in Col0,174 inImage->numRows / 2.0 + in Row0,122 float varFactor = psImageInterpolateVarianceFactor(inImage->numCols / 2.0 + inImage->col0, 123 inImage->numRows / 2.0 + inImage->row0, 175 124 interp); // Variance factor: large --> small scale 176 125 psMetadataItem *vfItem = psMetadataLookup(output->analysis, PSWARP_ANALYSIS_VARFACTOR); … … 208 157 pmModel *model = source->modelPSF; // Model for this source 209 158 float xIn, yIn; // Coordinates of source 210 xIn = model->params->data.F32[PM_PAR_XPOS] - in Col0;211 yIn = model->params->data.F32[PM_PAR_YPOS] - in Row0;159 xIn = model->params->data.F32[PM_PAR_XPOS] - inImage->col0; 160 yIn = model->params->data.F32[PM_PAR_YPOS] - inImage->row0; 212 161 int xGrid, yGrid; // Grid coordinates for local map 213 162 if (!pswarpMapGridSetGrid(sourceGrid, xIn + 0.5, yIn + 0.5, &xGrid, &yGrid)) { … … 232 181 return false; 233 182 } 234 xOut += out Col0 - 0.5;235 yOut += out Row0 - 0.5;183 xOut += output->image->col0 - 0.5; 184 yOut += output->image->row0 - 0.5; 236 185 if (xOut < minX || xOut > maxX || yOut < minY || yOut > maxY) { 237 186 // It's not in the output image -
branches/eam_branch_20080719/pswarp/src/pswarpTransformTile.c
r18666 r18752 1 # include "pswarp.h" 1 2 2 // XXX need to determine all of the needed inputs and put them in a structure 3 void pswarpTransformTileArgsFree (pswarpTransformTileArgs *args) { 4 if (!args) return; 5 return; 6 } 3 7 4 typedef struct { 5 int gridX; 6 int gridY; 7 } pswarpTransformTileOpts; 8 pswarpTransformTileArgs *pswarpTransformTileArgsAlloc() { 8 9 9 pswarpTransformTile (int gridX, int gridY) { 10 pswarpTransformTileArgs *args = (pswarpTransformTileArgs *)psAlloc(sizeof(pswarpTransformTileArgs)); 11 psMemSetDeallocator(args, (psFreeFunc)pswarpTransformTileArgsFree); 10 12 11 minX = pswarpMapGridNextGrid_Y (grid, gridY); 12 minY = pswarpMapGridNextGrid_X (grid, gridX); 13 args->input = NULL; 14 args->output = NULL; 15 args->grid = NULL; 16 args->interp = NULL; 17 args->region = NULL; 13 18 14 maxX = pswarpMapGridNextGrid_Y (grid, gridY);15 maxY = pswarpMapGridNextGrid_X (grid, gridX);19 args->gridX = 0; 20 args->gridY = 0; 16 21 17 map = grid->maps[gridX][gridY];22 args->goodPixels = 0; 18 23 19 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 24 return args; 25 } 26 27 bool pswarpTransformTile (pswarpTransformTileArgs *args) { 28 29 // int inCol0 = args->input->image->col0; 30 // int inRow0 = args->input->image->row0; 31 int inNcol = args->input->image->numCols; 32 int inNrow = args->input->image->numRows; 33 34 int outCol0 = args->output->image->col0; 35 int outRow0 = args->output->image->row0; 36 // int outNcol = args->output->image->numCols; 37 // int outNrow = args->output->image->numRows; 38 39 // XXX these are wrong (min or max is wrong) 40 int minX = pswarpMapGridNextGrid_Y (args->grid, args->gridY); 41 int minY = pswarpMapGridNextGrid_X (args->grid, args->gridX); 42 int maxX = pswarpMapGridNextGrid_Y (args->grid, args->gridY); 43 int maxY = pswarpMapGridNextGrid_X (args->grid, args->gridX); 44 45 psF32 **outImageData = args->output->image->data.F32; 46 psF32 **outVarData = args->output->weight->data.F32; 47 psMaskType **outMaskData = args->output->mask->data.U8; 48 49 pswarpMap *map = args->grid->maps[args->gridX][args->gridY]; 50 51 psImage *region = args->region; 52 53 double xInRaw, yInRaw; 54 55 // output values for this pixel 56 double imageValue; 57 double varValue; 58 psMaskType maskValue; 20 59 21 60 // Iterate over the output image pixels (parent frame) 22 61 long goodPixels = 0; // Number of input pixels landing on the output image 23 62 for (int y = minY; y < maxY; y++) { 24 int yOut = y - outRow0; // Position on image25 63 for (int x = minX; x < maxX; x++) { 26 64 … … 30 68 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate. 31 69 // both are in the parent frames of the input and output images. 32 pswarpMapApply (& inPix->x, &inPix->y, map, x + 0.5, y + 0.5);70 pswarpMapApply (&xInRaw, &yInRaw, map, x + 0.5, y + 0.5); 33 71 34 if (inPix->x - inCol0 < 0) continue; 35 if (inPix->x - inCol0 >= inImage->numCols) continue; 36 if (inPix->y - inRow0 < 0) continue; 37 if (inPix->y - inRow0 >= inImage->numRows) continue; 72 double xIn = xInRaw - outCol0; // Position on input image 73 double yIn = yInRaw - outRow0; // Position on input image 74 75 if (xIn < 0) continue; 76 if (yIn >= inNcol) continue; 77 if (yIn < 0) continue; 78 if (yIn >= inNrow) continue; 38 79 39 80 goodPixels++; 40 81 41 // XXX include mask42 // XXX apply scale and offset?43 82 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 44 double imageValue, varValue; 45 psMaskType maskValue; 46 if (!psImageInterpolate(&imageValue, &varValue, &maskValue, 47 inPix->x - inCol0, inPix->y - inRow0, interp)) { 83 if (!psImageInterpolate(&imageValue, &varValue, &maskValue, xIn, yIn, args->interp)) { 48 84 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 49 psFree(interp);50 psFree(inPix);51 psFree(grid);52 85 return false; 53 86 } 54 int xOut = x - outCol0; // Position on image 55 outImageData[yOut][xOut] = imageValue; 56 if (inVar) { 87 88 int xOut = x - outCol0; // Position on output image 89 int yOut = y - outRow0; // Position on output image 90 91 // not all images need be transformed 92 if (outImageData) { 93 outImageData[yOut][xOut] = imageValue; 94 } 95 if (outVarData) { 57 96 outVarData[yOut][xOut] = varValue; 58 97 } … … 62 101 } 63 102 } 64 65 psFree(inPix);103 args->goodPixels = goodPixels; 104 return true; 66 105 }
Note:
See TracChangeset
for help on using the changeset viewer.
