Changeset 12523
- Timestamp:
- Mar 21, 2007, 12:09:22 PM (19 years ago)
- Location:
- trunk/pswarp/src
- Files:
-
- 6 edited
-
pswarp.h (modified) (1 diff)
-
pswarpDataLoad.c (modified) (3 diffs)
-
pswarpDefine.c (modified) (2 diffs)
-
pswarpMapGrid.c (modified) (5 diffs)
-
pswarpMatchRange.c (modified) (2 diffs)
-
pswarpTransformReadout_Opt.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarp.h
r12505 r12523 48 48 pswarpMapGrid *pswarpMapGridFromImage (pmReadout *dest, pmReadout *src, int nXpix, int nYpix); 49 49 bool pswarpMapGridSetGrid (pswarpMapGrid *grid, int ix, int iy, int *gridX, int *gridY); 50 bool pswarpMapGridNextGrid_X (pswarpMapGrid *grid, int gridX, int *nextX);51 bool pswarpMapGridNextGrid_Y (pswarpMapGrid *grid, int gridY, int *nextY);50 int pswarpMapGridNextGrid_X (pswarpMapGrid *grid, int gridX); 51 int pswarpMapGridNextGrid_Y (pswarpMapGrid *grid, int gridY); 52 52 double pswarpMapGridMaxError (pswarpMapGrid *grid); 53 53 bool pswarpMapApply (double *outX, double *outY, pswarpMap *map, double inX, double inY); -
trunk/pswarp/src/pswarpDataLoad.c
r12505 r12523 9 9 bool pswarpDataLoad (pmConfig *config) { 10 10 11 bool status;12 11 pmChip *chip; 13 12 pmCell *cell; 14 13 pmReadout *readout; 15 14 pmFPAview *view; 16 17 // select the current recipe18 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE);19 if (!recipe) {20 psError(PSWARP_ERR_CONFIG, false, "Can't find PSASTRO recipe needed for pixel scale!\n");21 return false;22 }23 24 // physical pixel scale in microns per pixel25 double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");26 if (!status) {27 psError(PS_ERR_IO, false, "Failed to lookup pixel scale");28 return false;29 }30 15 31 16 // select the input data sources … … 61 46 view = pmFPAviewAlloc (0); 62 47 48 // XXX need to read only the headers for the skycell 49 // XXX these pmAstromReadBilevel functions seem to be broken 50 63 51 // find the FPA phu 64 // XXX wrap the test below into a function65 // XXX need to read only the headers for the skycell66 // XXX need to optionally load the astrometry datafile67 52 bool bilevelAstrometry = false; 68 53 pmHDU *phu = pmFPAviewThisPHU (view, astrom->fpa); 69 54 if (phu) { 70 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");71 if (ctype) {72 bilevelAstrometry = !strcmp (&ctype[4], "-DIS");73 }55 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1"); 56 if (ctype) { 57 bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 58 } 74 59 } 75 60 if (bilevelAstrometry) { 76 pmAstromReadBilevelMosaic (input->fpa, phu->header, pixelScale);61 pmAstromReadBilevelMosaic (input->fpa, phu->header); 77 62 } 78 63 … … 88 73 pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa); 89 74 if (bilevelAstrometry) { 90 pmAstromReadBilevelChip (chip, hdu->header);75 pmAstromReadBilevelChip (chip, hdu->header); 91 76 } else { 92 pmAstromReadWCS (input->fpa, chip, hdu->header, pixelScale); 77 // we use a default FPA pixel scale of 1.0 78 pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0); 93 79 } 94 80 -
trunk/pswarp/src/pswarpDefine.c
r12505 r12523 4 4 bool pswarpDefine (pmConfig *config) { 5 5 6 bool status;7 psMetadata *recipe = NULL;8 9 // load the pixel scale from the PSASTRO recipe10 recipe = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE);11 if (!recipe) {12 psError(PSWARP_ERR_CONFIG, false, "Can't find PSASTRO recipe needed for pixel scale!\n");13 return false;14 }15 // physical pixel scale in microns per pixel16 double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");17 if (!status) {18 psError(PS_ERR_IO, false, "Failed to lookup pixel scale");19 return false;20 }21 22 6 // load the PSWARP recipe 23 recipe= psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);7 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 24 8 if (!recipe) { 25 9 psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n"); … … 46 30 bool bilevelAstrometry = false; 47 31 if (phu) { 48 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");49 if (ctype) {50 bilevelAstrometry = !strcmp (&ctype[4], "-DIS");51 }32 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1"); 33 if (ctype) { 34 bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 35 } 52 36 } 53 37 if (bilevelAstrometry) { 54 pmAstromReadBilevelMosaic (skycell->fpa, phu->header, pixelScale);55 pmAstromReadBilevelChip (chip, hdu->header);38 pmAstromReadBilevelMosaic (skycell->fpa, phu->header); 39 pmAstromReadBilevelChip (chip, hdu->header); 56 40 } else { 57 pmAstromReadWCS (skycell->fpa, chip, hdu->header, pixelScale); 41 // we use a default FPA pixel scale of 1.0 42 pmAstromReadWCS (skycell->fpa, chip, hdu->header, 1.0); 58 43 } 59 44 -
trunk/pswarp/src/pswarpMapGrid.c
r12505 r12523 1 1 # include "pswarp.h" 2 2 3 // construct a grid with superpixel spacing of nXpix, nYpix 4 // XXX for the moment, ignore readout->cell->chip offsets 3 // pswarpMapGridFromImage builds a set (a grid) of locally-linear maps which convert the source 4 // coordinates (src) to destination coordinates (dest). we construct a grid with superpixel 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. 5 7 pswarpMapGrid *pswarpMapGridFromImage (pmReadout *dest, pmReadout *src, int nXpix, int nYpix) { 6 8 … … 8 10 int j, nj; 9 11 10 // XXX I was trying to match the grids too closely 11 // split the difference of the remainder 12 // int xMin = 0.5*(src->image->numCols % nXpix); 13 // int yMin = 0.5*(src->image->numRows % nYpix); 14 int xMin = 0; 15 int yMin = 0; 16 17 int nXpts = src->image->numCols / nXpix + 1; 18 if (src->image->numCols % nXpix) nXpts ++; 19 int nYpts = src->image->numRows / nYpix + 1; 20 if (src->image->numRows % nYpix) nYpts ++; 21 12 // start counting from the center of the superpixels 13 int xMin = 0.5*nXpix; 14 int yMin = 0.5*nYpix; 15 16 // the map is defined for coordinates in the image parent frame. 17 int Nx = src->image->numCols + src->image->col0; 18 int Ny = src->image->numRows + src->image->row0; 19 20 // allocate an extra superpixel to carry the remainder 21 int nXpts = Nx / nXpix; 22 int nYpts = Ny / nYpix; 23 if (Nx % nXpix) nXpts ++; 24 if (Ny % nYpix) nYpts ++; 25 26 // create the grid of maps 22 27 pswarpMapGrid *grid = pswarpMapGridAlloc (nXpts, nYpts); 23 28 29 // measure the map for the center of each superpixel 24 30 for (ni = 0, i = xMin; ni < nXpts; i += nXpix, ni++) { 25 31 for (nj = 0, j = yMin; nj < nYpts; j += nYpix, nj++) { … … 35 41 } 36 42 43 // set the grid coordinate (gridX,gridY) for the given source image coordinate (ix,iy) 37 44 bool pswarpMapGridSetGrid (pswarpMapGrid *grid, int ix, int iy, int *gridX, int *gridY) { 38 45 39 *gridX = (ix - grid->xMin + 0.5*grid->nXpix) /grid->nXpix;40 *gridY = (iy - grid->yMin + 0.5*grid->nYpix) /grid->nYpix;46 *gridX = 0.5 + (ix - grid->xMin) / (double) grid->nXpix; 47 *gridY = 0.5 + (iy - grid->yMin) / (double) grid->nYpix; 41 48 return true; 42 49 } 43 50 44 bool pswarpMapGridNextGrid_X (pswarpMapGrid *grid, int gridX, int *nextX) { 45 46 *nextX = gridX*grid->nXpix + grid->xMin + 0.5*grid->nXpix; 47 return true; 48 } 49 50 bool pswarpMapGridNextGrid_Y (pswarpMapGrid *grid, int gridY, int *nextY) { 51 52 *nextY = gridY*grid->nYpix + grid->yMin + 0.5*grid->nYpix; 53 return true; 54 } 55 56 // measure the max error accumulated in appling one grid point to its neighbors 51 // given the specified grid coordinate (gridX), return the x-coordinate for the source image 52 // corresponding to the next grid cell 53 int pswarpMapGridNextGrid_X (pswarpMapGrid *grid, int gridX) { 54 55 int nextX = (gridX + 0.5)*grid->nXpix + grid->xMin; 56 return nextX; 57 } 58 59 // given the specified grid coordinate (gridY), return the y-coordinate for the source image 60 // corresponding to the next grid cell 61 int pswarpMapGridNextGrid_Y (pswarpMapGrid *grid, int gridY) { 62 63 int nextY = (gridY + 0.5)*grid->nYpix + grid->yMin; 64 return nextY; 65 } 66 67 // measure the max error accumulated in applying one grid point to its neighbors 68 // XXX double-check this 57 69 double pswarpMapGridMaxError (pswarpMapGrid *grid) { 58 70 … … 76 88 } 77 89 90 // given the source coordinate (inX,inY), return the destination coordinate (outX,outY) 78 91 bool pswarpMapApply (double *outX, double *outY, pswarpMap *map, double inX, double inY) { 79 92 … … 84 97 } 85 98 86 // determine the map for the given pixel from src to dest. pixel is in src coords 99 // determine the (linear) map for the given pixel (ix,iy) from source image (src) to the destination image (dest) 100 // pixel is in src coords. input and output pixel coordinates are in the parent frame of the image (Note that the 101 // astrometric transformations are supplied for the parent image coordinate frame. 87 102 bool pswarpMapSetLocalModel (pswarpMap *map, pmReadout *dest, pmReadout *src, int ix, int iy) { 88 103 -
trunk/pswarp/src/pswarpMatchRange.c
r10958 r12523 2 2 3 3 # define TEST_MINMAX \ 4 psPlaneTransformApply(FP, chipDest->toFPA, destPix); \ 5 psPlaneTransformApply (TP, fpaDest->toTPA, FP); \ 6 psDeproject (sky, TP, fpaDest->toSky); \ 7 psProject (TP, sky, fpaSrc->toSky); \ 8 psPlaneTransformApply (FP, fpaSrc->fromTPA, TP); \ 9 psPlaneTransformApply (srcPix, chipSrc->fromFPA, FP); \ 4 psPlaneTransformApply(destFP, chipDest->toFPA, destPix); \ 5 psPlaneTransformApply (destTP, fpaDest->toTPA, destFP); \ 6 psDeproject (sky, destTP, fpaDest->toSky); \ 7 psProject (srcTP, sky, fpaSrc->toSky); \ 8 psPlaneTransformApply (srcFP, fpaSrc->fromTPA, srcTP); \ 9 psPlaneTransformApply (srcPix, chipSrc->fromFPA, srcFP); \ 10 fprintf (stderr, "%6.1f,%6.1f -> ", srcPix->x, srcPix->y); \ 10 11 *minX = PS_MIN (*minX, srcPix->x); \ 11 12 *minY = PS_MIN (*minY, srcPix->y); \ 12 13 *maxX = PS_MAX (*maxX, srcPix->x); \ 13 *maxY = PS_MAX (*maxY, srcPix->y); 14 *maxY = PS_MAX (*maxY, srcPix->y); \ 15 fprintf (stderr, "%4d,%4d - %4d,%4d\n", *minX, *minY, *maxX, *maxY); 14 16 15 17 // we are warping from src to dest. find the max overlapping pixels in the INPUT (src) 16 // coordinate frame 18 // coordinate frame. NOTE: these are in the parent pixel frame since the astrometric 19 // transformation refers to the parent frame 17 20 bool pswarpMatchRange (int *minX, int *minY, int *maxX, int *maxY, pmReadout *dest, pmReadout *src) { 18 21 … … 30 33 pmFPA *fpaDest = chipDest->parent; 31 34 32 *minX = src->image->numCols; 33 *minY = src->image->numRows; 34 *maxX = 0; 35 *maxY = 0; 35 *minX = src->image->numCols + src->image->col0 - 1; 36 *minY = src->image->numRows + src->image->row0 - 1; 37 *maxX = src->image->col0; 38 *maxY = src->image->row0; 39 fprintf (stderr, "%4d,%4d - %4d,%4d\n", *minX, *minY, *maxX, *maxY); 36 40 37 41 // XXX save these as static for speed? 38 42 psPlane *srcPix = psPlaneAlloc(); 43 psPlane *srcFP = psPlaneAlloc(); 44 psPlane *srcTP = psPlaneAlloc(); 45 39 46 psPlane *destPix = psPlaneAlloc(); 47 psPlane *destFP = psPlaneAlloc(); 48 psPlane *destTP = psPlaneAlloc(); 40 49 41 psPlane *FP = psPlaneAlloc();42 psPlane *TP = psPlaneAlloc();43 50 psSphere *sky = psSphereAlloc(); 44 51 45 destPix->x = 0;46 destPix->y = 0;52 destPix->x = dest->image->col0; 53 destPix->y = dest->image->row0; 47 54 TEST_MINMAX; 48 55 49 destPix->x = dest->image-> numCols;50 destPix->y = 0;56 destPix->x = dest->image->col0 + dest->image->numCols; 57 destPix->y = dest->image->row0; 51 58 TEST_MINMAX; 52 59 53 destPix->x = dest->image-> numCols;54 destPix->y = dest->image-> numRows;60 destPix->x = dest->image->col0 + dest->image->numCols; 61 destPix->y = dest->image->row0 + dest->image->numRows; 55 62 TEST_MINMAX; 56 63 57 destPix->x = 0;58 destPix->y = dest->image-> numRows;64 destPix->x = dest->image->col0; 65 destPix->y = dest->image->row0 + dest->image->numRows; 59 66 TEST_MINMAX; 60 67 61 destPix->x = 0.5*dest->image->numCols;62 destPix->y = 0.0;68 destPix->x = dest->image->col0 + 0.5*dest->image->numCols; 69 destPix->y = dest->image->row0; 63 70 TEST_MINMAX; 64 71 65 destPix->x = 0.0;66 destPix->y = 0.5*dest->image->numRows;72 destPix->x = dest->image->col0; 73 destPix->y = dest->image->row0 + 0.5*dest->image->numRows; 67 74 TEST_MINMAX; 68 75 69 destPix->x = 0.5*dest->image->numCols;70 destPix->y = dest->image-> numRows;76 destPix->x = dest->image->col0 + 0.5*dest->image->numCols; 77 destPix->y = dest->image->row0; 71 78 TEST_MINMAX; 72 79 73 destPix->x = dest->image-> numCols;74 destPix->y = 0.5*dest->image->numRows;80 destPix->x = dest->image->col0; 81 destPix->y = dest->image->row0 + 0.5*dest->image->numRows; 75 82 TEST_MINMAX; 76 83 77 *minX = PS_MAX (*minX, 0); 78 *minY = PS_MAX (*minY, 0); 79 *maxX = PS_MIN (*maxX, src->image->numCols); 80 *maxY = PS_MIN (*maxY, src->image->numRows); 84 *minX = PS_MAX (*minX, src->image->col0); 85 *minY = PS_MAX (*minY, src->image->row0); 86 *maxX = PS_MIN (*maxX, src->image->numCols + src->image->col0); 87 *maxY = PS_MIN (*maxY, src->image->numRows + src->image->row0); 88 89 // demo forward and backward transformation 90 srcPix->x = *minX; 91 srcPix->y = *minY; 92 psPlaneTransformApply(srcFP, chipSrc->toFPA, srcPix); 93 psPlaneTransformApply (srcTP, fpaSrc->toTPA, srcFP); 94 psDeproject (sky, srcTP, fpaSrc->toSky); 95 psProject (destTP, sky, fpaDest->toSky); 96 psPlaneTransformApply (destFP, fpaDest->fromTPA, destTP); 97 psPlaneTransformApply (destPix, chipDest->fromFPA, destFP); 98 99 fprintf (stderr, "%f,%f -> %f,%f ", srcPix->x, srcPix->y, destPix->x, destPix->y); 100 101 psPlaneTransformApply(destFP, chipDest->toFPA, destPix); 102 psPlaneTransformApply (destTP, fpaDest->toTPA, destFP); 103 psDeproject (sky, destTP, fpaDest->toSky); 104 psProject (srcTP, sky, fpaSrc->toSky); 105 psPlaneTransformApply (srcFP, fpaSrc->fromTPA, srcTP); 106 psPlaneTransformApply (srcPix, chipSrc->fromFPA, srcFP); 107 108 fprintf (stderr, "-> %f,%f ", srcPix->x, srcPix->y); 81 109 82 110 psFree (srcPix); 111 psFree (srcFP); 112 psFree (srcTP); 113 83 114 psFree (destPix); 84 psFree (FP); 85 psFree (TP); 115 psFree (destFP); 116 psFree (destTP); 117 86 118 psFree (sky); 87 119 -
trunk/pswarp/src/pswarpTransformReadout_Opt.c
r12505 r12523 5 5 6 6 int minX, minY, maxX, maxY; 7 int gridXo, gridX, gridY, nextGridX , nextGridY;7 int gridXo, gridX, gridY, nextGridXo, nextGridX, nextGridY; 8 8 pswarpMap *map = NULL; 9 9 … … 18 18 psF32 **outData = output->image->data.F32; 19 19 20 // we need to apply the offset to convert parent coordinates to child coordinates for 21 // psImagePixelInterpolate below 22 int inCol0 = input->image->col0; 23 int inRow0 = input->image->row0; 24 int outCol0 = output->image->col0; 25 int outRow0 = output->image->row0; 26 20 27 // we might want to do the rectangular regions outside of the selection independently 21 28 // psImageInit (output->image, NAN); … … 24 31 pswarpMatchRange (&minX, &minY, &maxX, &maxY, input, output); 25 32 33 // pswarpMapGridFromImage builds a set of locally-linear maps which convert the 34 // output coordinates to input coordinates 26 35 pswarpMapGrid *grid = pswarpMapGridFromImage (input, output, 128, 128); 27 36 … … 31 40 32 41 pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY); 33 pswarpMapGridNextGrid_Y (grid, gridY, &nextGridY);42 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY); 34 43 map = grid->maps[gridX][gridY]; 35 44 36 // Iterate over the output image pixels 45 assert ((int)(minX - outCol0) >= 0); 46 assert ((int)(maxX - outCol0) <= output->image->numCols); 47 assert ((int)(minY - outRow0) >= 0); 48 assert ((int)(maxY - outRow0) <= output->image->numRows); 49 50 gridXo = gridX; 51 nextGridXo = pswarpMapGridNextGrid_X (grid, gridX); 52 53 // Iterate over the output image pixels (parent frame) 37 54 for (int y = minY; y < maxY; y++) { 38 55 if (y >= nextGridY) { 39 56 gridY ++; 40 pswarpMapGridNextGrid_Y (grid, gridY, &nextGridY);57 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY); 41 58 map = grid->maps[gridX][gridY]; 42 59 } 43 60 44 gridXo = gridX; 61 gridX = gridXo; 62 nextGridX = nextGridXo; 63 map = grid->maps[gridX][gridY]; 45 64 for (int x = minX; x < maxX; x++) { 46 65 if (x >= nextGridX) { 47 66 gridX ++; 48 pswarpMapGridNextGrid_X (grid, gridX, &nextGridX);67 nextGridX = pswarpMapGridNextGrid_X (grid, gridX); 49 68 map = grid->maps[gridX][gridY]; 50 69 } … … 53 72 if (region && region->data.U8[y][x]) continue; 54 73 55 // XXX double check this 1/2 pixel offset56 // XXX subtract 0.5,0.5 from result?74 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate. 75 // both are in the parent frames of the input and output images. 57 76 pswarpMapApply (&inPix->x, &inPix->y, map, x + 0.5, y + 0.5); 77 78 if (inPix->x - inCol0 < 0) continue; 79 if (inPix->x - inCol0 >= inImage->numCols) continue; 80 if (inPix->y - inRow0 < 0) continue; 81 if (inPix->y - inRow0 >= inImage->numRows) continue; 58 82 59 83 // XXX get interpolation method from the recipe 60 84 // XXX include mask 61 85 // XXX apply scale and offset? 62 outData[y][x] = (psF32)psImagePixelInterpolate(inImage, inPix->x, inPix->y, NULL, 1, NAN, PS_INTERPOLATE_BILINEAR); 86 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 87 outData[y-outRow0][x-outCol0] = (psF32)psImagePixelInterpolate(inImage, inPix->x - inCol0, inPix->y - inRow0, NULL, 1, NAN, PS_INTERPOLATE_BILINEAR); 63 88 } 64 gridX = gridXo;65 pswarpMapGridNextGrid_X (grid, gridX, &nextGridX);66 map = grid->maps[gridX][gridY];67 89 } 68 90 … … 71 93 return true; 72 94 } 73 74 # if (0)75 if (error) {76 // Error is actually the variance77 outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error,78 detector->x,79 detector->y,80 mask, 1, NAN);81 }82 if (error) {83 outError->data.F32[y][x] = outError->data.F32[y][x] / SQUARE(scale);84 }85 # endif86 87
Note:
See TracChangeset
for help on using the changeset viewer.
