Changeset 14864
- Timestamp:
- Sep 17, 2007, 10:17:21 AM (19 years ago)
- Location:
- branches/eam_branch_20070830/psLib
- Files:
-
- 4 edited
-
src/imageops/psImageMap.c (modified) (6 diffs)
-
src/imageops/psImageMap.h (modified) (2 diffs)
-
src/imageops/psImageMapFit.c (modified) (5 diffs)
-
test/imageops/tap_psImageMapFit.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20070830/psLib/src/imageops/psImageMap.c
r14774 r14864 7 7 * @author Eugene Magnier, IfA 8 8 * 9 * @version $Revision: 1.1.2. 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-09- 07 20:19:35$9 * @version $Revision: 1.1.2.6 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-17 20:17:21 $ 11 11 * 12 12 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 39 39 40 40 psFree (map->map); 41 // psFree (map->field); XXX ??? this should be freed here, but that causes an error... 41 psFree (map->error); 42 psFree (map->field); // XXX ??? this should be freed here, but that causes an error... 42 43 psFree (map->stats); 43 44 psFree (map->binning); … … 57 58 map->field = psMemIncrRefCounter (field); 58 59 map->stats = psMemIncrRefCounter (stats); 60 59 61 map->map = psImageAlloc (binning->nXruff, binning->nYruff, PS_TYPE_F32); 62 psImageInit (map->map, 0.0); 63 64 map->error = psImageAlloc (binning->nXruff, binning->nYruff, PS_TYPE_F32); 65 psImageInit (map->error, 0.0); 60 66 61 67 psImageBinningSetScale (map->binning, PS_IMAGE_BINNING_CENTER); … … 73 79 74 80 psImageRecycle (map->map, nXruff, nYruff, PS_TYPE_F32); 81 psImageRecycle (map->error, nXruff, nYruff, PS_TYPE_F32); 75 82 76 83 psImageBinningSetScale (map->binning, PS_IMAGE_BINNING_CENTER); … … 257 264 } 258 265 266 // x,y are in fractional pixel coords of the fine image (pixel center: 0.5) 259 267 double psImageMapEval (psImageMap *map, float x, float y) { 260 268 261 269 double result; 262 270 263 result = psImageUnbinPixel (x, y, map->map, map->binning);271 result = psImageUnbinPixel_V2(x, y, map->map, map->binning); 264 272 265 273 return result; … … 276 284 277 285 for (int i = 0; i < x->n; i++) { 278 result->data.F32[i] = psImageUnbinPixel (x->data.F32[i], y->data.F32[i], map->map, map->binning);286 result->data.F32[i] = psImageUnbinPixel_V2(x->data.F32[i], y->data.F32[i], map->map, map->binning); 279 287 } 280 288 -
branches/eam_branch_20070830/psLib/src/imageops/psImageMap.h
r14859 r14864 7 7 * @author Eugene Magnier, IfA 8 8 * 9 * @version $Revision: 1.1.2. 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-09-1 5 19:43:43$9 * @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-17 20:17:21 $ 11 11 * 12 12 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 26 26 psStats *stats; 27 27 psImage *map; 28 psImage *error; 28 29 psImage *field; 29 30 psImageBinning *binning; -
branches/eam_branch_20070830/psLib/src/imageops/psImageMapFit.c
r14862 r14864 7 7 * @author Eugene Magnier, IfA 8 8 * 9 * @version $Revision: 1.1.2. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-09-17 01:14:52$9 * @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-17 20:17:21 $ 11 11 * 12 12 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 22 22 23 23 // XXX for testing 24 //#include "psFits.h"25 //#include "psFitsImage.h"24 #include "psFits.h" 25 #include "psFitsImage.h" 26 26 27 27 #include "psAssert.h" … … 238 238 // fprintf (stderr, "Total: %f\n", Total); 239 239 240 // write 1s in unused diagonal elements 241 // XXX for test only 242 # if (0) 243 for (int n = 0; n < Nx; n+=Nx-1) { 244 for (int m = 0; m < Ny; m++) { 245 I = n + Nx * m; 246 A->data.F32[I][I] = 1.0; 247 } 248 } 249 for (int n = 0; n < Nx; n++) { 250 for (int m = 0; m < Ny; m+=Ny-1) { 251 I = n + Nx * m; 252 A->data.F32[I][I] = 1.0; 253 } 254 } 255 # endif 256 257 // psFits *fits = psFitsOpen ("Agj.fits", "w"); 258 // psFitsWriteImage (fits, NULL, A, 0, NULL); 259 // psFitsClose (fits); 240 // test for empty diagonal elements (unconstained cells), mark, and set pivots to 1.0 241 psVector *Empty = psVectorAlloc (Nx*Ny, PS_TYPE_S8); 242 psVectorInit (Empty, 0); 243 for (int i = 0; i < Nx*Ny; i++) { 244 if (A->data.F32[i][i] == 0.0) { 245 Empty->data.S8[i] = 1; 246 for (int j = 0; j < Nx*Ny; j++) { 247 A->data.F32[i][j] = 0.0; 248 A->data.F32[j][i] = 0.0; 249 } 250 A->data.F32[i][i] = 1.0; 251 B->data.F32[i] = 0.0; 252 } 253 } 254 255 psFits *fits = psFitsOpen ("Agj.fits", "w"); 256 psFitsWriteImage (fits, NULL, A, 0, NULL); 257 psFitsClose (fits); 258 259 psImage *vector = psImageAlloc (1, B->n, PS_TYPE_F32); 260 for (int n = 0; n < B->n; n++) { 261 vector->data.F32[0][n] = B->data.F32[n]; 262 } 263 264 fits = psFitsOpen ("Bgj.fits", "w"); 265 psFitsWriteImage (fits, NULL, vector, 0, NULL); 266 psFitsClose (fits); 267 psFree (vector); 260 268 261 269 if (!psMatrixGJSolveF32(A, B)) { … … 267 275 } 268 276 277 // set bad values to NaN 278 for (int i = 0; i < Nx*Ny; i++) { 279 if (Empty->data.S8[i]) { 280 B->data.F32[i] = NAN; 281 } 282 } 283 284 269 285 for (int n = 0; n < Nx; n++) { 270 286 for (int m = 0; m < Ny; m++) { 271 287 I = n + Nx * m; 272 288 map->map->data.F32[m][n] = B->data.F32[I]; 289 map->error->data.F32[m][n] = sqrt(A->data.F32[I][I]); 273 290 } 274 291 } … … 276 293 psFree (A); 277 294 psFree (B); 295 psFree (Empty); 278 296 279 297 return true; -
branches/eam_branch_20070830/psLib/test/imageops/tap_psImageMapFit.c
r14863 r14864 25 25 # define TEST_9PT_3 1 26 26 # define TEST_9PT_4 1 27 # define TEST_9PT_5 1 27 28 28 29 int main (void) 29 30 { 30 31 31 plan_tests( 1);32 plan_tests(219); 32 33 33 34 // *** tests to demonstrate the validity of the algorithm or concept *** 35 36 // test with unconstrained cell: 3x3 grid fitted to 8 points with simple slope and scale difference 37 # if (TEST_9PT_5) 38 { 39 psMemId id = psMemGetId(); 40 41 psImageBinning *binning = psImageBinningAlloc(); 42 binning->nXfine = 6; 43 binning->nYfine = 6; 44 binning->nXruff = 3; 45 binning->nYruff = 3; 46 47 // generate a grid of test data points 48 psVector *x = psVectorAlloc (50, PS_TYPE_F32); 49 psVector *y = psVectorAlloc (50, PS_TYPE_F32); 50 psVector *f = psVectorAlloc (50, PS_TYPE_F32); 51 52 // the underlying field is f = ix + iy, where ix,iy are fine pixel coordinates 53 // place the measurement points exactly on the ruff reference pixel centers 54 int n = 0; 55 for (float ix = 1.0; ix < 6.0; ix += 2.0) { 56 for (float iy = 1.0; iy < 6.0; iy += 2.0) { 57 if ((ix == 1.0) && (iy == 1.0)) continue; 58 x->data.F32[n] = ix; 59 y->data.F32[n] = iy; 60 f->data.F32[n] = x->data.F32[n] + y->data.F32[n]; 61 n++; 62 } 63 } 64 x->n = n; 65 y->n = n; 66 f->n = n; 67 68 psImage *field = psImageAlloc(6, 6, PS_TYPE_F32); 69 for (int ix = 0; ix < 6; ix++) { 70 for (int iy = 0; iy < 6; iy++) { 71 field->data.F32[iy][ix] = (ix + 0.5) + (iy + 0.5); 72 } 73 } 74 75 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN); 76 77 // scale defines both field and map image sizes (nXfine, nXruff) 78 psImageMap *map = psImageMapAlloc (NULL, binning, stats); 79 80 // fit the data to the map 81 psImageMapFit (map, x, y, f, NULL); 82 83 psImage *model = psImageAlloc(field->numCols, field->numRows, PS_TYPE_F32); 84 for (int ix = 0; ix < model->numCols; ix++) { 85 for (int iy = 0; iy < model->numRows; iy++) { 86 model->data.F32[iy][ix] = psImageUnbinPixel_V2 (ix + 0.5, iy + 0.5, map->map, map->binning); 87 if ((ix < 3) && (iy < 3)) { 88 is_float (model->data.F32[iy][ix], NAN, "model matches expected NaN"); 89 } else { 90 is_float_tol (model->data.F32[iy][ix], field->data.F32[iy][ix], 1e-5, "model matches inputs"); 91 } 92 } 93 } 94 95 SaveImage (NULL, map->map, "map.fits"); 96 SaveImage (NULL, field, "field.fits"); 97 SaveImage (NULL, model, "model.fits"); 98 99 psFree (model); 100 psFree (binning); 101 psFree (map); 102 psFree (stats); 103 psFree (field); 104 psFree (x); 105 psFree (y); 106 psFree (f); 107 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 108 } 109 # endif 34 110 35 111 // test for more points: 3x3 grid fitted to 9 points with simple slope and scale difference
Note:
See TracChangeset
for help on using the changeset viewer.
