Changeset 7260 for trunk/ppMerge/src/ppMergeBackground.c
- Timestamp:
- Jun 1, 2006, 10:16:15 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/ppMerge/src/ppMergeBackground.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppMerge/src/ppMergeBackground.c
r7067 r7260 49 49 // Sanity checks 50 50 assert(!options->scale || scales); 51 assert(!scales || !*scales || ((*scales)->type.type == PS_TYPE_F 64&&51 assert(!scales || !*scales || ((*scales)->type.type == PS_TYPE_F32 && 52 52 (*scales)->numCols == data->numCells && 53 53 (*scales)->numRows == filenames->n)); 54 54 assert(!options->zero || zeros); 55 assert(!zeros || !*zeros || ((*zeros)->type.type == PS_TYPE_F 64&&55 assert(!zeros || !*zeros || ((*zeros)->type.type == PS_TYPE_F32 && 56 56 (*zeros)->numCols == data->numCells && 57 57 (*zeros)->numRows == filenames->n)); 58 58 59 psImage *background = psImageAlloc( filenames->n, data->numCells, PS_TYPE_F64); // Background measurements59 psImage *background = psImageAlloc(data->numCells, filenames->n, PS_TYPE_F32); // Background measurements 60 60 psImageInit(background, NAN); 61 61 psStats *bgStats = psStatsAlloc(options->background); // Statistic to measure the background … … 63 63 psImage *exptime = NULL; // The exposure time for each integration of each cell 64 64 if (options->scale) { 65 gains = psVectorAlloc(data->numCells, PS_TYPE_F64); 65 gains = psVectorAlloc(data->numCells, PS_TYPE_F32); 66 gains->n = data->numCells; 66 67 } 67 68 if (options->exptime) { 68 exptime = psImageAlloc(filenames->n, data->numCells, PS_TYPE_F 64);69 exptime = psImageAlloc(filenames->n, data->numCells, PS_TYPE_F32); 69 70 } 70 71 … … 75 76 continue; 76 77 } 78 psTrace(__func__, 9, "Opening %s to get background...\n", name); 77 79 psFits *inFile = psFitsOpen(filenames->data[i], "r"); // The FITS file to read 78 80 if (!inFile) { … … 107 109 if (options->exptime) { 108 110 bool mdok = true; // Status of MD lookup 109 exptime->data.F 64[i][cellNum] = psMetadataLookupF32(&mdok, cell->concepts,111 exptime->data.F32[i][cellNum] = psMetadataLookupF32(&mdok, cell->concepts, 110 112 "CELL.EXPOSURE"); 111 if (!mdok || isnan(exptime->data.F 64[i][cellNum])) {113 if (!mdok || isnan(exptime->data.F32[i][cellNum])) { 112 114 psLogMsg(__func__, PS_LOG_WARN, "CELL.EXPOSURE for file %s chip %d cell %d is not " 113 115 "set.\n", name, j, k); 114 exptime->data.F 64[i][cellNum] = NAN;116 exptime->data.F32[i][cellNum] = NAN; 115 117 status = false; 116 118 } … … 151 153 152 154 // Get the background 153 psImageStats(bgStats, image, readout->mask, options->combine->maskVal); 154 background->data.F64[i][cellNum] = getStat(bgStats, options->background); 155 int sampleSize = (image->numCols * image->numRows) / options->sample; // Size of sample 156 psVector *sample = psVectorAlloc(sampleSize, PS_TYPE_F32); // Sample of the image 157 sample->n = sampleSize; 158 psVector *sampleMask = NULL; // Mask for sample 159 if (readout->mask) { 160 sampleMask = psVectorAlloc(sampleSize, PS_TYPE_U8); 161 sampleMask->n = sampleSize; 162 } 163 psImage *mask = readout->mask; // The mask image 164 for (long i = 0; i < sampleSize; i++) { 165 int j = i * options->sample; // Index into image 166 int x = j % image->numCols; // x index 167 int y = j / image->numCols; // y index 168 sample->data.F32[i] = image->data.F32[y][x]; 169 if (readout->mask) { 170 sampleMask->data.U8[i] = mask->data.U8[y][x]; 171 } 172 } 173 psVectorStats(bgStats, sample, sampleMask, NULL, options->combine->maskVal); 174 psFree(sample); 175 psFree(sampleMask); 176 background->data.F32[i][cellNum] = getStat(bgStats, options->background); 177 psTrace(__func__, 3, "Background for %s, cell %d is %f\n", name, cellNum, 178 background->data.F32[i][cellNum]); 155 179 } 156 180 … … 167 191 // Need to normalize over the focal plane 168 192 bool converge = true; // Did we converge? 193 if (psTraceGetLevel(__func__) > 9) { 194 for (int i = 0; i < gains->n; i++) { 195 psTrace(__func__, 10, "Gain for cell %d is %f\n", i, gains->data.F32[i]); 196 } 197 } 169 198 psVector *fluxes = pmFlatNormalize(&converge, gains, background, MAX_ITER, TOLERANCE); 170 199 if (!converge || !fluxes) { … … 174 203 psFree(gains); 175 204 176 *scales = psImageCopy(*scales, background, PS_TYPE_F 64);205 *scales = psImageCopy(*scales, background, PS_TYPE_F32); 177 206 psImage *scalesDeref = *scales; // Dereference the pointer 178 207 179 208 for (int i = 0; i < scalesDeref->numRows; i++) { 180 psF 64 bg = fluxes->data.F64[i];209 psF32 bg = fluxes->data.F32[i]; 181 210 for (int j = 0; j < scalesDeref->numCols; j++) { 182 scalesDeref->data.F 64[i][j] = bg;211 scalesDeref->data.F32[i][j] = bg; 183 212 } 184 213 } … … 188 217 if (!options->scale) { 189 218 // Copy over the exposure times 190 psImageCopy(*scales, exptime, PS_TYPE_F 64);219 psImageCopy(*scales, exptime, PS_TYPE_F32); 191 220 } else { 192 221 psBinaryOp(*scales, *scales, "*", exptime); … … 199 228 *zeros = psMemIncrRefCounter(background); 200 229 } else { 201 *zeros = psImageCopy(*zeros, background, PS_TYPE_F64); 230 *zeros = psImageCopy(*zeros, background, PS_TYPE_F32); 231 } 232 } 233 234 // Diagnostic stuff 235 if (scales && *scales && psTraceGetLevel(__func__) > 9) { 236 psImage *scalesDeref = *scales; // Dereference the pointer 237 for (int i = 0; i < scalesDeref->numRows; i++) { 238 for (int j = 0; j < scalesDeref->numCols; j++) { 239 psTrace(__func__, 9, "Scale for exposure %d, cell %d is: %f\n", i, j, 240 scalesDeref->data.F32[i][j]); 241 } 242 } 243 } 244 if (zeros && *zeros && psTraceGetLevel(__func__) > 9) { 245 psImage *zerosDeref = *zeros; // Dereference the pointer 246 for (int i = 0; i < zerosDeref->numRows; i++) { 247 for (int j = 0; j < zerosDeref->numCols; j++) { 248 psTrace(__func__, 9, "Zero for exposure %d, cell %d is: %f\n", i, j, 249 zerosDeref->data.F32[i][j]); 250 } 202 251 } 203 252 }
Note:
See TracChangeset
for help on using the changeset viewer.
