Changeset 18753
- Timestamp:
- Jul 27, 2008, 12:41:58 PM (18 years ago)
- Location:
- branches/eam_branch_20080719/pswarp/src
- Files:
-
- 1 added
- 11 edited
-
Makefile.am (modified) (1 diff)
-
pswarp.c (modified) (1 diff)
-
pswarp.h (modified) (5 diffs)
-
pswarpArguments.c (modified) (1 diff)
-
pswarpCleanup.c (modified) (1 diff)
-
pswarpLoop.c (modified) (1 diff)
-
pswarpMapGrid.c (modified) (3 diffs)
-
pswarpThreadLauncher.c (modified) (1 diff)
-
pswarpTransformReadout.c (modified) (1 diff)
-
pswarpTransformReadout_Threaded.c (modified) (4 diffs)
-
pswarpTransformSources.c (added)
-
pswarpTransformTile.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080719/pswarp/src/Makefile.am
r18752 r18753 17 17 pswarpSetMaskBits.c \ 18 18 pswarpThreadLauncher.c \ 19 pswarpTransformReadout_Opt.c \ 20 pswarpTransformReadout_Threaded.c \ 21 pswarpTransformReadout_Unthreaded.c \ 19 pswarpTransformReadout.c \ 20 pswarpTransformSources.c \ 22 21 pswarpTransformTile.c \ 23 22 pswarpVersion.c -
branches/eam_branch_20080719/pswarp/src/pswarp.c
r18752 r18753 17 17 psLibInit(NULL); 18 18 19 // create the thread pool with 4 threads, supplying our thread launcher function20 // XXX need to determine the number of threads from the config data21 psThreadPoolInit (4, &pswarpThreadLauncher);22 23 19 // model inits are needed in pmSourceIO 24 20 // models defined in psphot/src/models are not available in psastro -
branches/eam_branch_20080719/pswarp/src/pswarp.h
r18752 r18753 10 10 #include <psmodules.h> 11 11 #include <psphot.h> 12 13 #define THREADED 1 12 14 13 15 #include "pswarpErrorCodes.h" … … 33 35 int nXpts, nYpts; // number of x,y samples in the grid 34 36 int nXpix, nYpix; // x,y spacing in src image pixels of grid samples 35 int xMin, yMin;// coordinate of first grid sample37 double xMin, yMin; // coordinate of first grid sample 36 38 } pswarpMapGrid; 37 39 … … 52 54 } pswarpTransformTileArgs; 53 55 54 bool pswarpTransformReadout_Unthreaded(pmReadout *output, pmReadout *input, pmConfig *config);55 bool pswarpTransformReadout_Threaded(pmReadout *output, pmReadout *input, pmConfig *config);56 57 56 pswarpTransformTileArgs *pswarpTransformTileArgsAlloc(); 58 57 bool pswarpTransformTile (pswarpTransformTileArgs *args); … … 66 65 void pswarpCleanup (pmConfig *config); 67 66 bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config); 68 bool pswarpTransform Readout_Opt(pmReadout *output, pmReadout *input, pmConfig *config);67 bool pswarpTransformSources(pmReadout *output, pmReadout *input, pmConfig *config); 69 68 70 69 bool pswarpMatchRange (int *minX, int *minY, int *maxX, int *maxY, pmReadout *dest, pmReadout *src); … … 75 74 pswarpMapGrid *pswarpMapGridFromImage (pmReadout *dest, pmReadout *src, int nXpix, int nYpix); 76 75 bool pswarpMapGridSetGrid (pswarpMapGrid *grid, int ix, int iy, int *gridX, int *gridY); 76 bool pswarpMapGridCoordRange (pswarpMapGrid *grid, int gridX, int gridY, psPlane *min, psPlane *max); 77 77 int pswarpMapGridNextGrid_X (pswarpMapGrid *grid, int gridX); 78 78 int pswarpMapGridNextGrid_Y (pswarpMapGrid *grid, int gridY); -
branches/eam_branch_20080719/pswarp/src/pswarpArguments.c
r18622 r18753 39 39 "Filename for statistics of output image", argv[N]); 40 40 psArgumentRemove(N, &argc, argv); 41 } 42 43 // Number of threads 44 if ((N = psArgumentGet(argc, argv, "-threads"))) { 45 psArgumentRemove(N, &argc, argv); 46 int nThreads = atoi(argv[N]); 47 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "NTHREADS", 0, "number of warp threads", nThreads); 48 psArgumentRemove(N, &argc, argv); 49 50 // create the thread pool with number of desired threads, supplying our thread launcher function 51 // XXX need to determine the number of threads from the config data 52 psThreadPoolInit (nThreads, &pswarpThreadLauncher); 41 53 } 42 54 -
branches/eam_branch_20080719/pswarp/src/pswarpCleanup.c
r14641 r18753 9 9 pmModelClassCleanup (); 10 10 psTimeFinalize (); 11 psThreadPoolFinalize (); 11 12 pmConceptsDone (); 12 13 pmConfigDone (); -
branches/eam_branch_20080719/pswarp/src/pswarpLoop.c
r18622 r18753 241 241 } 242 242 243 pswarpTransformReadout _Opt(output, readout, config);243 pswarpTransformReadout(output, readout, config); 244 244 245 245 pmFPAfileIOChecks(config, view, PM_FPA_AFTER); -
branches/eam_branch_20080719/pswarp/src/pswarpMapGrid.c
r12523 r18753 4 4 // coordinates (src) to destination coordinates (dest). we construct a grid with superpixel 5 5 // spacing of nXpix, nYpix. The transformation for each grid cell is valid for the superpixel. 6 // The grid over-fills the source image so ever source image pixel is guaranteed to have a map.6 // The grid over-fills the source image so every source image pixel is guaranteed to have a map. 7 7 pswarpMapGrid *pswarpMapGridFromImage (pmReadout *dest, pmReadout *src, int nXpix, int nYpix) { 8 8 … … 11 11 12 12 // start counting from the center of the superpixels 13 intxMin = 0.5*nXpix;14 intyMin = 0.5*nYpix;13 double xMin = 0.5*nXpix; 14 double yMin = 0.5*nYpix; 15 15 16 16 // the map is defined for coordinates in the image parent frame. … … 42 42 43 43 // set the grid coordinate (gridX,gridY) for the given source image coordinate (ix,iy) 44 // XXX return true if the result is on the src image, false otherwise (???) 44 45 bool pswarpMapGridSetGrid (pswarpMapGrid *grid, int ix, int iy, int *gridX, int *gridY) { 45 46 46 47 *gridX = 0.5 + (ix - grid->xMin) / (double) grid->nXpix; 47 48 *gridY = 0.5 + (iy - grid->yMin) / (double) grid->nYpix; 49 50 return true; 51 } 52 53 // given the specified grid coordinate (gridX, gridY), return the min and max coordinates for the tile 54 bool pswarpMapGridCoordRange (pswarpMapGrid *grid, int gridX, int gridY, psPlane *min, psPlane *max) { 55 56 min->x = (gridX - 0.5)*grid->nXpix + grid->xMin; 57 min->y = (gridY - 0.5)*grid->nYpix + grid->yMin; 58 59 max->x = min->x + grid->nXpix; 60 max->y = min->y + grid->nYpix; 61 48 62 return true; 49 63 } -
branches/eam_branch_20080719/pswarp/src/pswarpThreadLauncher.c
r18752 r18753 1 1 # include "pswarp.h" 2 // XXX add in a thread exit api (set a local 'exit' variable) 2 3 3 4 bool pswarpThreadTest (psArray *args) { -
branches/eam_branch_20080719/pswarp/src/pswarpTransformReadout.c
r12744 r18753 1 1 # include "pswarp.h" 2 2 3 bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config) { 4 3 // NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT 4 bool pswarpTransformReadout(pmReadout *output, pmReadout *input, pmConfig *config) 5 { 5 6 // XXX this implementation currently ignores the use of the region 6 7 psImage *region = NULL; 7 pmCell *cell = NULL;8 8 9 // select the current recipe 10 // psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 9 psTimerStart ("warp"); 11 10 12 int outNx = output->image->numCols; 13 int outNy = output->image->numRows; 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"); 14 16 15 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 16 psPlane *outPix = psPlaneAlloc(); // Coordinates on the output detector 17 // load the recipe 18 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 19 psAssert (recipe, "missing recipe %s", PSWARP_RECIPE); 17 20 18 psPlane *FP = psPlaneAlloc(); // Coordinates on the focal plane 19 psPlane *TP = psPlaneAlloc(); // Coordinates on the tangent plane 20 psSphere *sky = psSphereAlloc(); // Coordinates on the sky 21 // output mask bits 22 psMaskType maskIn = psMetadataLookupU8(&mdok, recipe, "MASK.INPUT"); 23 psMaskType maskPoor = pmConfigMaskGet("POOR.WARP", config); 24 psMaskType maskBad = pmConfigMaskGet("BAD.WARP", config); 25 psAssert (mdok, "MASK.INPUT was not defined"); 21 26 22 cell = input->parent; 23 pmChip *chipInput = cell->parent; 24 pmFPA *fpaInput = chipInput->parent; 27 int nThreads = psMetadataLookupS32 (&mdok, config->arguments, "NTHREADS"); 28 if (!mdok) nThreads = 0; 25 29 26 cell = output->parent; 27 pmChip *chipOutput = cell->parent; 28 pmFPA *fpaOutput = chipOutput->parent; 30 // Flux fraction for "poor" 31 float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); 29 32 30 psF32 **outData = output->image->data.F32; 31 psImage *inImage = input->image; 33 // pswarpMapGridFromImage builds a set of locally-linear maps which convert the 34 // output coordinates to input coordinates 35 pswarpMapGrid *grid = pswarpMapGridFromImage (input, output, nGridX, nGridY); 32 36 33 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage, 34 NULL, NULL, 0, NAN, NAN, 0, 0, 0.0); 37 // 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); 35 40 36 // Iterate over the output image pixels 37 for (int y = 0; y < outNy; y++) { 38 for (int x = 0; x < outNx; x++) { 39 // Only transform those pixels requested 40 if (region && region->data.U8[y][x]) continue; 41 // 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); 41 43 42 // XXX double check this 1/2 pixel offset 43 outPix->x = (double)x + 0.5; 44 outPix->y = (double)y + 0.5; 44 if (input->weight && !output->weight) { 45 output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32); 46 psImageInit(output->weight, NAN); 47 } 48 if ((input->mask || maskPoor || maskBad) && !output->mask) { 49 output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK); 50 psImageInit(output->mask, maskBad); 51 } 45 52 46 psPlaneTransformApply(FP, chipOutput->toFPA, outPix); 47 psPlaneTransformApply (TP, fpaOutput->toTPA, FP); 48 psDeproject (sky, TP, fpaOutput->toSky); 53 // total number of good pixels across all tiles (summed below) 54 int goodPixels = 0; 49 55 50 psProject (TP, sky, fpaInput->toSky);51 psPlaneTransformApply (FP, fpaInput->fromTPA, TP);52 psPlaneTransformApply (inPix, chipInput->fromFPA, FP); 56 // create jobs and supply them to the threads 57 for (int gridY = 0; gridY < grid->nYpts; gridY++) { 58 for (int gridX = 0; gridX < grid->nXpts; gridX++) { 53 59 54 // XXX get interpolation method from the recipe 55 double value; 56 if (!psImageInterpolate(&value, NULL, NULL, inPix->x, inPix->y, interp)) { 57 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 58 psFree(interp); 59 psFree(inPix); 60 psFree(outPix); 61 psFree(FP); 62 psFree(TP); 63 psFree(sky); 64 return false; 65 } 60 pswarpTransformTileArgs *args = pswarpTransformTileArgsAlloc(); 66 61 67 outData[y][x] = value; 68 // modify zero and scale? 62 // these items are just views to the data; they are not freed with args 63 args->input = input; 64 args->output = output; 65 args->grid = grid; 66 args->interp = interp; 67 args->region = region; 68 69 args->gridX = gridX; 70 args->gridY = gridY; 71 args->goodPixels = 0; 72 73 if (nThreads) { 74 // allocate a job 75 psThreadJob *job = psThreadJobAlloc ("PSWARP_TRANSFORM_TILE", 0); 76 77 // construct the arguments for this job 78 // job is pswarpTransformTile (gridX, gridY); 79 psArrayAdd (job->args, 1, args); 80 // fprintf (stderr, "adding job %d,%d, Nargs: %ld\n", gridX, gridY, job->args->n); 81 psThreadJobAddPending (job); 82 } else { 83 pswarpTransformTile (args); 84 goodPixels += args->goodPixels; 85 } 86 psFree (args); 87 } 88 } 89 90 // wait for the threads to finish and manage results 91 if (nThreads) { 92 // wait here for the threaded jobs to finish 93 if (!psThreadPoolWait ()) { 94 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 95 return false; 96 } 97 fprintf (stderr, "success for threaded jobs\n"); 98 99 // each job records its own goodPixel values; sum them here 100 // we have only supplied one type of job, so we can assume the types here 101 psThreadJob *job = NULL; 102 while ((job = psThreadJobGetDone()) != NULL) { 103 if (job->args->n < 1) { 104 fprintf (stderr, "error with job\n"); 105 } else { 106 pswarpTransformTileArgs *args = job->args->data[0]; 107 // fprintf (stderr, "finished job %d,%d, Nargs: %ld\n", args->gridX, args->gridY, job->args->n); 108 goodPixels += args->goodPixels; 109 } 110 psFree (job); 111 } 112 } 113 psFree(interp); 114 psFree(grid); 115 116 117 // Store the variance factor and number of good pixels 118 if (goodPixels > 0) { 119 // Variance factor: large factor --> small scale 120 float varFactor = psImageInterpolateVarianceFactor(input->image->numCols / 2.0 + input->image->col0, input->image->numRows / 2.0 + input->image->row0, interp); 121 psMetadataItem *vfItem = psMetadataLookup(output->analysis, PSWARP_ANALYSIS_VARFACTOR); 122 if (vfItem) { 123 psMetadataItem *goodpixItem = psMetadataLookup(output->analysis, PSWARP_ANALYSIS_GOODPIX); 124 psAssert(goodpixItem, "It should be where we left it!"); 125 psAssert(vfItem->type == PS_TYPE_F32 && goodpixItem->type == PS_TYPE_S64, 126 "Should be the type we said."); 127 128 vfItem->data.F32 += varFactor * goodPixels; 129 goodpixItem->data.S64 += goodPixels; 130 } else { 131 psMetadataAddF32(output->analysis, PS_LIST_TAIL, PSWARP_ANALYSIS_VARFACTOR, 0, 132 "Variance factor weighted by the good pixels", varFactor * goodPixels); 133 psMetadataAddS64(output->analysis, PS_LIST_TAIL, PSWARP_ANALYSIS_GOODPIX, 0, 134 "Number of good pixels", goodPixels); 69 135 } 70 136 } 71 psFree(interp); 72 psFree(inPix); 73 psFree(outPix); 74 psFree(FP); 75 psFree(TP); 76 psFree(sky); 137 138 if (goodPixels > 0) { 139 if (!pswarpTransformSources (output, input, config)) { 140 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 141 return false; 142 } 143 } 144 145 // XXX should we not write anything out if there are no good pixels? 146 output->data_exists = true; 147 output->parent->data_exists = true; 148 output->parent->parent->data_exists = true; 149 150 psLogMsg ("pswarp", 3, "warping analysis: %f sec\n", psTimerMark ("warp")); 77 151 78 152 return true; -
branches/eam_branch_20080719/pswarp/src/pswarpTransformReadout_Threaded.c
r18752 r18753 1 1 # include "pswarp.h" 2 2 3 #define SOURCE_ARRAY_BUFFER 100 // Size to grow the array of sources at a time 3 # define THREADED 1 4 # define SOURCE_ARRAY_BUFFER 100 // Size to grow the array of sources at a time 4 5 5 6 // NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT … … 90 91 args->goodPixels = 0; 91 92 93 # if (THREADED) 92 94 // allocate a job 93 95 psThreadJob *job = psThreadJobAlloc ("PSWARP_TRANSFORM_TILE", 0); … … 97 99 psArrayAdd (job->args, 1, args); 98 100 psThreadJobAddPending (job); 101 # else 102 pswarpTransformTile (args); 103 goodPixels += args->goodPixels; 104 # endif 99 105 psFree (args); 100 106 } 101 107 } 108 109 # if (THREADED) 102 110 // wait here for the threaded jobs to finish 103 111 if (!psThreadPoolWait ()) { … … 115 123 psFree (job); 116 124 } 125 # endif 117 126 psFree(interp); 118 127 psFree(grid); 128 119 129 120 130 // Store the variance factor and number of good pixels -
branches/eam_branch_20080719/pswarp/src/pswarpTransformTile.c
r18752 r18753 37 37 // int outNrow = args->output->image->numRows; 38 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); 39 // get the coordinate range for this grid tile 40 psPlane minPt, maxPt; 41 pswarpMapGridCoordRange (args->grid, args->gridX, args->gridY, &minPt, &maxPt); 44 42 45 psF32 **outImageData = args->output->image->data.F32;46 psF32 **outVarData = args->output->weight->data.F32;47 psMaskType **outMaskData = args->output->mask->data.U8;43 psF32 **outImageData = (args->output->image) ? args->output->image->data.F32 : NULL; 44 psF32 **outVarData = (args->output->weight) ? args->output->weight->data.F32 : NULL; 45 psMaskType **outMaskData = (args->output->mask) ? args->output->mask->data.U8 : NULL; 48 46 49 47 pswarpMap *map = args->grid->maps[args->gridX][args->gridY]; … … 60 58 // Iterate over the output image pixels (parent frame) 61 59 long goodPixels = 0; // Number of input pixels landing on the output image 62 for (int y = min Y; y < maxY; y++) {63 for (int x = min X; x < maxX; x++) {60 for (int y = minPt.y; y < maxPt.y; y++) { 61 for (int x = minPt.x; x < maxPt.x; x++) { 64 62 65 63 // Only transform those pixels requested
Note:
See TracChangeset
for help on using the changeset viewer.
