Changeset 12592
- Timestamp:
- Mar 26, 2007, 5:36:18 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
dvoTools/src/dvoMakeCorrUnbin.c (modified) (3 diffs)
-
ppImage/src/ppImageRebinReadout.c (modified) (1 diff)
-
psphot/src/psphotImageLoop.c (modified) (1 diff)
-
psphot/src/psphotImageMedian.c (modified) (14 diffs)
-
psphot/src/psphotMagnitudes.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dvoTools/src/dvoMakeCorrUnbin.c
r11805 r12592 26 26 assert (trimsec); 27 27 28 // dimensions of input image: 29 int nx = inData->image->numCols; 30 int ny = inData->image->numRows; 28 // I have the fine and ruff image sizes, determine the binning factor 29 psImageBinning *binning = psImageBinningAlloc(); 30 binning->nXruff = inData->numCols; 31 binning->nYruff = inData->numRows; 32 binning->nXfine = trimsec->x1 - trimsec->x0; 33 binning->nYfine = trimsec->y1 - trimsec->y0; 34 psImageBinningSetBinning (binning, PS_IMAGE_BINNING_CENTER); 35 psImageBinningSetSkip(binning, inData); 31 36 32 // dimensions of output image: 33 int Nx = trimsec->x1 - trimsec->x0; 34 int Ny = trimsec->y1 - trimsec->y0; 35 36 // choose the binning factor which would yield nx,ny pixels from Nx,Ny 37 int DX = Nx / nx; // 36 / 3 = 12, 35 / 3 = 11, 34 / 3 = 11 38 if (Nx % nx) DX ++; // 36, 35, 34 -> DX = 12 39 int xOffset = (Nx % nx) / 2; // for nx = 3, xOffset = 0 or 1 40 41 int DY = Ny / ny; 42 if (Ny % ny) DY ++; 43 int yOffset = (Ny % ny) / 2; 44 37 // construct the supporing pmFPA/pmChip/pmCell structures 45 38 pmReadout *outData = pmFPAviewThisReadout (view, outFile->fpa); 46 39 if (outData == NULL) { … … 48 41 pmChip *outChip = pmFPAviewThisChip (view, outFile->fpa); 49 42 50 pmChipCopyStructure (outChip, inChip, DX, DY);43 pmChipCopyStructure (outChip, inChip, binning->nXbin, binning->nYbin); 51 44 outData = pmFPAviewThisReadout (view, outFile->fpa); 52 45 assert (outData != NULL); 53 46 } 54 47 55 psImageRecycle (outData->image, Nx, Ny, PS_TYPE_F32); 48 // generate the output (fine-scale) image array 49 psImageRecycle (outData->image, binning->nXfine, binning->nYfine, PS_TYPE_F32); 56 50 57 // linear interpolation to full -scale58 if (!psImageUnbin (outData->image, inData->image, DX, DY, xOffset, yOffset)) {51 // linear interpolation to full fine scale 52 if (!psImageUnbin (outData->image, inData->image, binning)) { 59 53 psError (PS_ERR_UNKNOWN, true, "failed to unbin image"); 54 psFree (binning); 60 55 return false; 61 56 } … … 74 69 // exit (0); 75 70 71 psFree (binning); 76 72 return true; 77 73 } -
trunk/ppImage/src/ppImageRebinReadout.c
r10589 r12592 63 63 } 64 64 65 // XXX this should be made consistent with psImageBinning 65 66 bool ppImageRebinReadout (pmReadout *output, pmReadout *input, pmFPAfile *outFile) 66 67 { -
trunk/psphot/src/psphotImageLoop.c
r12587 r12592 63 63 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 64 64 psLogMsg ("psphot", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 65 // XXX who should be setting cell->process? 65 66 // if (! cell->process || ! cell->file_exists) { continue; } 66 if (! cell->process) { continue; }67 // if (! cell->process) { continue; } 67 68 68 69 // process each of the readouts -
trunk/psphot/src/psphotImageMedian.c
r12587 r12592 1 1 # include "psphot.h" 2 // # define TESTSAVE 2 3 3 4 // generate the median in NxN boxes, clipping heavily … … 8 9 pmFPA *inFPA; 9 10 pmFPAfile *file; 10 psRegion region;11 11 static char *defaultStatsName = "FITTED_MEAN"; 12 12 … … 85 85 psImage *mask = readout->mask; 86 86 87 // dimensions of input & output image 88 int Nx = image->numCols; 89 int Ny = image->numRows; 90 91 // scaling factor 92 int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN"); 93 int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN"); 94 95 // overhang : we will balance this evenly 96 int xExtra = (Nx % DX) / 2; 97 int yExtra = (Ny % DY) / 2; 98 int xOffset = (xExtra > 0) ? DX - xExtra : 0; 99 int yOffset = (yExtra > 0) ? DY - yExtra : 0; 100 xOffset -= image->col0; 101 yOffset -= image->row0; 102 103 // dimensions of binned image 104 int nx, ny; 105 if (Nx % DX == 0) { 106 nx = Nx / DX; 107 } else { 108 nx = (xExtra) ? (Nx / DX) + 2 : (Nx / DX) + 1; 109 } 110 if (Ny % DY == 0) { 111 ny = Ny / DY; 112 } else { 113 ny = (yExtra) ? (Ny / DY) + 2 : (Ny / DY) + 1; 114 } 87 // I have the fine image size, I know the binning factor, determine the ruff image size 88 psImageBinning *binning = psImageBinningAlloc(); 89 binning->nXfine = image->numCols; 90 binning->nYfine = image->numRows; 91 binning->nXbin = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN"); 92 binning->nYbin = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN"); 93 94 psImageBinningSetRuffSize(binning, PS_IMAGE_BINNING_CENTER); 95 psImageBinningSetSkip(binning, image); 96 status = psMetadataAddPtr(recipe, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN, "Background binning", binning); 97 if (!status) { 98 psError (PSPHOT_ERR_PROG, false, "failed to save bininnng"); 99 return false; 100 } 101 102 // we save the binning structure for use in psphotMagnitudes 115 103 116 104 // we have 4 possibilities: (INTERNAL or I/O file) and (exists or not) … … 119 107 if (file == NULL) { 120 108 // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version 121 model = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKMDL", nx, ny, PS_TYPE_F32);109 model = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKMDL", binning->nXruff, binning->nYruff, PS_TYPE_F32); 122 110 } else { 123 111 if (file->mode == PM_FPA_MODE_INTERNAL) { … … 130 118 // readout does not yet exist: create from input 131 119 // XXX we have an inconsistency in this calculation here and in pmFPACopy 132 pmFPAfileCopyStructureView (file->fpa, inFPA, DX, DY, view); 120 // XXX use the psImageBinning functions to set the output image size 121 pmFPAfileCopyStructureView (file->fpa, inFPA, binning->nXbin, binning->nYbin, view); 133 122 model = pmFPAviewThisReadout (view, file->fpa); 134 if ((nx != model->image->numCols) || (ny != model->image->numRows)) { 135 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for model dimensions"); 136 return false; 137 } 123 assert (binning->nXruff == model->image->numCols); 124 assert (binning->nYruff == model->image->numRows); 138 125 } 139 126 } … … 141 128 psF32 **modelData = model->image->data.F32; 142 129 143 assert(model->analysis != NULL);144 psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.XBIN", PS_DATA_S32 | PS_META_REPLACE,145 "Background x-binsize", DX);146 psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.YBIN", PS_DATA_S32 | PS_META_REPLACE,147 "Background x-binsize", DY);148 psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.XOFF", PS_DATA_S32 | PS_META_REPLACE,149 "Background x-overhang", xOffset);150 psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.YOFF", PS_DATA_S32 | PS_META_REPLACE,151 "Background y-overhang", yOffset);152 153 154 130 // measure clipped median for subimages 155 for (int iy = 0; iy < ny; iy++) { 156 for (int ix = 0; ix < nx; ix++) { 157 // sx, sy are in parent coords 158 int sx = ix*DX - xOffset; 159 int sy = iy*DY - yOffset; 160 161 // XXX test override 162 // sx = 1955; 163 // sy = 4; 164 165 region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY); 166 region = psRegionForImage (image, region); 167 psImage *subset = psImageSubset (image, region); 131 psRegion ruffRegion = {0,0,0,0}; 132 psRegion fineRegion = {0,0,0,0}; 133 for (int iy = 0; iy < model->image->numRows; iy++) { 134 for (int ix = 0; ix < model->image->numCols; ix++) { 135 136 // convert the ruff grid cell to the equivalent fine grid cell 137 // XXX we need to watch out for row0,col0 138 ruffRegion = psRegionSet (ix, ix + 2, iy, iy + 2); 139 fineRegion = psImageBinningSetFineRegion (binning, ruffRegion); 140 fineRegion = psRegionForImage (image, fineRegion); 141 142 psImage *subset = psImageSubset (image, fineRegion); 168 143 if (!subset->numCols || !subset->numRows) { 169 144 psFree (subset); 170 145 continue; 171 146 } 172 psImage *submask = psImageSubset (mask, region);147 psImage *submask = psImageSubset (mask, fineRegion); 173 148 174 149 // reset the default values … … 210 185 211 186 // patch over bad regions (use average of 8 possible neighbor pixels) 212 // XXX consider testing pixels against the 8 neighbors and replacing outliers...187 // XXX consider testing all pixels against the 8 neighbors and replacing outliers... 213 188 float Count = 0; 214 189 float Value = 0; 215 for (int iy = 0; iy < ny; iy++) {216 for (int ix = 0; ix < nx; ix++) {190 for (int iy = 0; iy < model->image->numRows; iy++) { 191 for (int ix = 0; ix < model->image->numCols; ix++) { 217 192 if (!isnan(modelData[iy][ix])) { 218 193 Value += modelData[iy][ix]; … … 224 199 for (int jy = iy - 1; jy <= iy + 1; jy++) { 225 200 if (jy < 0) continue; 226 if (jy >= ny) continue;201 if (jy >= model->image->numRows) continue; 227 202 for (int jx = ix - 1; jx <= ix + 1; jx++) { 228 203 if (!jx && !jy) continue; 229 204 if (jx < 0) continue; 230 if (jx >= nx) continue;205 if (jx >= model->image->numCols) continue; 231 206 value += modelData[jy][jx]; 232 207 count += 1.0; … … 240 215 241 216 // patch over remaining bad regions (use global average) 242 for (int iy = 0; iy < ny; iy++) {243 for (int ix = 0; ix < nx; ix++) {217 for (int iy = 0; iy < model->image->numRows; iy++) { 218 for (int ix = 0; ix < model->image->numCols; ix++) { 244 219 if (!isnan(modelData[iy][ix])) continue; 245 220 modelData[iy][ix] = Value; … … 253 228 psImageStats (statsBck, model->image, NULL, 0); 254 229 psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MEAN", PS_DATA_F32 | PS_META_REPLACE, "sky model mean", statsBck->sampleMean); 255 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYSTDEV", PS_DATA_F32 | PS_META_REPLACE, "sky model stdev", statsBck->sampleStdev);230 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYSTDEV", PS_DATA_F32 | PS_META_REPLACE, "sky model stdev", statsBck->sampleStdev); 256 231 psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MAX", PS_DATA_F32 | PS_META_REPLACE, "sky model maximum value", statsBck->max); 257 232 psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MIN", PS_DATA_F32 | PS_META_REPLACE, "sky model minimum value", statsBck->min); 258 psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NX", PS_DATA_S32 | PS_META_REPLACE, "sky model size (x)", nx);259 psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NY", PS_DATA_S32 | PS_META_REPLACE, "sky model size (y)", ny);233 psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NX", PS_DATA_S32 | PS_META_REPLACE, "sky model size (x)", model->image->numCols); 234 psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NY", PS_DATA_S32 | PS_META_REPLACE, "sky model size (y)", model->image->numRows); 260 235 psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f", 261 236 statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev); … … 275 250 pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view); 276 251 background = pmFPAviewThisReadout (view, file->fpa); 277 if (( Nx != background->image->numCols) || (Ny!= background->image->numRows)) {252 if ((image->numCols != background->image->numCols) || (image->numRows != background->image->numRows)) { 278 253 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for background dimensions"); 279 254 return false; … … 281 256 } 282 257 } else { 283 background = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", Nx, Ny, PS_TYPE_F32);258 background = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32); 284 259 } 285 260 psF32 **backData = background->image->data.F32; 286 261 287 262 // linear interpolation to full-scale 288 if (!psImageUnbin (background->image, model->image, DX, DY, xOffset, yOffset)) {289 psError (PSPHOT_ERR_PROG, true, "failed to build background i amge");263 if (!psImageUnbin (background->image, model->image, binning)) { 264 psError (PSPHOT_ERR_PROG, true, "failed to build background image"); 290 265 return false; 291 266 } … … 330 305 psFree(stats); 331 306 psFree(statsDefaults); 307 psFree(binning); 332 308 psFree(rng); 333 309 … … 335 311 return true; 336 312 } 313 314 315 # if (0) 316 317 // dimensions of input & output image 318 int Nx = image->numCols; 319 int Ny = image->numRows; 320 321 // scaling factor 322 int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN"); 323 int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN"); 324 325 // overhang : we will balance this evenly 326 int xExtra = (Nx % DX) / 2; 327 int yExtra = (Ny % DY) / 2; 328 int xOffset = (xExtra > 0) ? DX - xExtra : 0; 329 int yOffset = (yExtra > 0) ? DY - yExtra : 0; 330 xOffset -= image->col0; 331 yOffset -= image->row0; 332 333 // dimensions of binned image 334 int nx, ny; 335 if (Nx % DX == 0) { 336 nx = Nx / DX; 337 } else { 338 nx = (xExtra) ? (Nx / DX) + 2 : (Nx / DX) + 1; 339 } 340 if (Ny % DY == 0) { 341 ny = Ny / DY; 342 } else { 343 ny = (yExtra) ? (Ny / DY) + 2 : (Ny / DY) + 1; 344 } 345 346 // we have 4 possibilities: (INTERNAL or I/O file) and (exists or not) 347 // select model pixels (from output background model file, or create internal file) 348 file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKMDL"); 349 if (file == NULL) { 350 // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version 351 model = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKMDL", nx, ny, PS_TYPE_F32); 352 } else { 353 if (file->mode == PM_FPA_MODE_INTERNAL) { 354 // we are not using PSPHOT.BACKMDL as an I/O file: already defined above 355 model = file->readout; 356 } else { 357 // we are using PSPHOT.BACKMDL as an I/O file: select readout or create 358 model = pmFPAviewThisReadout (view, file->fpa); 359 if (model == NULL) { 360 // readout does not yet exist: create from input 361 // XXX we have an inconsistency in this calculation here and in pmFPACopy 362 pmFPAfileCopyStructureView (file->fpa, inFPA, DX, DY, view); 363 model = pmFPAviewThisReadout (view, file->fpa); 364 if ((nx != model->image->numCols) || (ny != model->image->numRows)) { 365 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for model dimensions"); 366 return false; 367 } 368 } 369 } 370 } 371 psF32 **modelData = model->image->data.F32; 372 373 374 375 // sx, sy are in parent coords 376 int sx = ix*DX - xOffset; 377 int sy = iy*DY - yOffset; 378 region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY); 379 380 # endif -
trunk/psphot/src/psphotMagnitudes.c
r11312 r12592 18 18 // Get enough information to return sky level 19 19 assert(background != NULL); 20 assert(background->analysis != NULL); 21 int DX = psMetadataLookupS32(&status, background->analysis, "PSPHOT.BACKGROUND.XBIN"); 22 assert (status == true); 23 int DY = psMetadataLookupS32(&status, background->analysis, "PSPHOT.BACKGROUND.YBIN"); 24 assert (status == true); 25 int dx = psMetadataLookupS32(&status, background->analysis, "PSPHOT.BACKGROUND.XOFF"); 26 assert (status == true); 27 int dy = psMetadataLookupS32(&status, background->analysis, "PSPHOT.BACKGROUND.YOFF"); 20 21 // the binning details are saved on the analysis metadata 22 psImageBinning *binning = psMetadataLookupPtr(&status, recipe, "PSPHOT.BACKGROUND.BINNING"); 28 23 assert (status == true); 29 24 … … 40 35 if (status) Nap ++; 41 36 42 source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, background->image, DX, DY, dx, dy);37 source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, background->image, binning); 43 38 if (isnan(source->sky) && false) { 44 39 psError(PSPHOT_ERR_SKY, false, "Setting pmSource.sky");
Note:
See TracChangeset
for help on using the changeset viewer.
