Changeset 9325
- Timestamp:
- Oct 5, 2006, 3:29:58 PM (20 years ago)
- Location:
- trunk/ppMerge/src
- Files:
-
- 4 edited
-
ppMergeCombine.c (modified) (2 diffs)
-
ppMergeOptions.c (modified) (5 diffs)
-
ppMergeOptions.h (modified) (1 diff)
-
ppMergeScaleZero.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppMerge/src/ppMergeCombine.c
r8847 r9325 123 123 } 124 124 125 #if 1 126 // Read bit by bit 127 128 int numRead; // Number of inputs read 129 int numScan = 0; 130 do { 131 numRead = 0; 125 // Building a shutter correction 126 if (options->shutter) { 127 // Read in the pixels 128 int numRead = 0; // Number of inputs read 129 psVector *exptimes = psVectorAlloc(filenames->n, PS_TYPE_F32); // Reference measurements 130 exptimes->n = filenames->n; 131 psVectorInit(exptimes, 0); 132 psArray *images = psArrayAlloc(filenames->n); // Array of images 133 psArray *masks = psArrayAlloc(filenames->n); // Array of masks 134 images->n = masks->n = filenames->n; 132 135 for (int i = 0; i < filenames->n; i++) { 133 136 if (! filenames->data[i] || strlen(filenames->data[i]) == 0) { … … 136 139 psFits *fits = data->files->data[i]; // FITS file handle 137 140 if (!fits) { 138 psError(PS_ERR_IO, false, "Unable to open input file %s --- ignored.\n", 139 (char*)filenames->data[i]); 140 continue; 141 } 142 143 if (!stack->data[i]) { 144 pmFPA *fpaIn = data->in->data[i]; // Input FPA 145 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 146 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 147 stack->data[i] = pmReadoutAlloc(cellIn); // Input readout 148 } 149 150 // Only reading and writing the first readout in each cell (plane 0) 151 if (pmReadoutReadNext(stack->data[i], fits, 0, options->rows)) { 152 // For anything except BIAS and DARK, we want a mask 153 if (options->scale || options->zero) { 154 pmReadoutSetMask(stack->data[i]); 141 continue; 142 } 143 pmFPA *fpaIn = data->in->data[i]; // Input FPA 144 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 145 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 146 if (!cellIn->file_exists) { 147 // || !cellIn->data_exists) { 148 continue; 149 } 150 if (!pmCellRead(cellIn, fits, config->database) || cellIn->readouts->n == 0) { 151 continue; 152 } 153 if (cellIn->readouts->n > 1) { 154 psWarning("Multiple readouts in file %d, chip %d, cell %d --- " 155 "only the first will be used.\n", i, view->chip, view->cell); 156 } 157 float exptime = psMetadataLookupF32(NULL, cellIn->concepts, "CELL.EXPOSURE"); 158 if (!isfinite(exptime)) { 159 psWarning("File %d, chip %d, cell %d has bad exposure time.\n", 160 i, view->chip, view->cell); 161 } 162 exptimes->data.F32[i] = exptime; 163 pmReadout *readoutIn = cellIn->readouts->data[0]; 164 images->data[i] = psMemIncrRefCounter(readoutIn->image); 165 masks->data[i] = psMemIncrRefCounter(readoutIn->mask); 166 numRead++; 167 } 168 if (numRead > 1) { 169 readout->image = pmShutterCorrectionMeasure(exptimes, images, masks, 170 options->shutterSize, options->mean, 171 options->stdev, options->combine->maskVal); 172 psTrace(__func__, 5, "Chip %d, cell %d\n", view->chip, view->cell); 173 } else { 174 psError(PS_ERR_UNKNOWN, true, "Not enough images to combine: %d\n", numRead); 175 psFree(images); 176 psFree(exptimes); 177 return false; 178 } 179 psFree(images); 180 psFree(exptimes); 181 } else { 182 #if 1 183 // Read bit by bit 184 185 int numRead; // Number of inputs read 186 int numScan = 0; 187 do { 188 numRead = 0; 189 for (int i = 0; i < filenames->n; i++) { 190 if (! filenames->data[i] || strlen(filenames->data[i]) == 0) { 191 continue; 155 192 } 156 numRead++; 157 } 193 psFits *fits = data->files->data[i]; // FITS file handle 194 if (!fits) { 195 continue; 196 } 197 198 if (!stack->data[i]) { 199 pmFPA *fpaIn = data->in->data[i]; // Input FPA 200 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 201 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 202 stack->data[i] = pmReadoutAlloc(cellIn); // Input readout 203 } 204 205 // Only reading and writing the first readout in each cell (plane 0) 206 if (pmReadoutReadNext(stack->data[i], fits, 0, options->rows)) { 207 // For anything except BIAS and DARK, we want a mask 208 if (options->scale || options->zero) { 209 pmReadoutSetMask(stack->data[i]); 210 } 211 numRead++; 212 } 213 } 214 215 if (numRead > 0) { 216 pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine); 217 psTrace(__func__, 5, "Chip %d, cell %d, scan %d\n", view->chip, view->cell, numScan); 218 } 219 numScan++; 220 221 } while (numRead > 0); 222 223 #else 224 // Read whole cells at a time 225 226 printf("Chip %d, cell %d\n", view->chip, view->cell); 227 int numRead = 0; // Number of inputs read 228 for (int i = 0; i < filenames->n; i++) { 229 if (! filenames->data[i] || strlen(filenames->data[i]) == 0) { 230 continue; 231 } 232 psFits *fits = data->files->data[i]; // FITS file handle 233 if (!fits) { 234 continue; 235 } 236 pmFPA *fpaIn = data->in->data[i]; // Input FPA 237 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 238 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 239 if (!cellIn->file_exists || !cellIn->data_exists) { 240 continue; 241 } 242 if (!pmCellRead(cellIn, fits, config->database) || cellIn->readouts->n == 0) { 243 continue; 244 } 245 stack->data[i] = cellIn->readouts->data[0]; 246 numRead++; 158 247 } 159 160 248 if (numRead > 0) { 161 249 pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine); 162 psTrace(__func__, 5, "Chip %d, cell %d , scan %d\n", view->chip, view->cell, numScan);250 psTrace(__func__, 5, "Chip %d, cell %d\n", view->chip, view->cell); 163 251 } 164 numScan++; 165 166 } while (numRead > 0); 167 168 #else 169 // Read whole cells at a time 170 171 printf("Chip %d, cell %d\n", view->chip, view->cell); 172 int numRead = 0; // Number of inputs read 173 for (int i = 0; i < filenames->n; i++) { 174 if (! filenames->data[i] || strlen(filenames->data[i]) == 0) { 175 continue; 176 } 177 psFits *fits = data->files->data[i]; // FITS file handle 178 if (!fits) { 179 psError(PS_ERR_IO, false, "Unable to open input file %s --- ignored.\n", 180 filenames->data[i]); 181 continue; 182 } 183 pmFPA *fpaIn = data->in->data[i]; // Input FPA 184 pmChip *chipIn = fpaIn->chips->data[view->chip]; // Input chip 185 pmCell *cellIn = chipIn->cells->data[view->cell]; // Input cell 186 if (!cellIn->file_exists || !cellIn->data_exists) { 187 continue; 188 } 189 if (!pmCellRead(cellIn, fits, config->database) || cellIn->readouts->n == 0) { 190 continue; 191 } 192 stack->data[i] = cellIn->readouts->data[0]; 193 numRead++; 194 } 195 if (numRead > 0) { 196 pmReadoutCombine(readout, stack, cellZeros, cellScales, options->combine); 197 psTrace(__func__, 5, "Chip %d, cell %d\n", view->chip, view->cell); 198 } 199 200 memCheck(); 252 253 memCheck(); 201 254 #endif 255 } 202 256 203 257 psFree(readout); // Drop reference -
trunk/ppMerge/src/ppMergeOptions.c
r8847 r9325 35 35 options->scale = false; 36 36 options->exptime = false; 37 options->shutter = false; 37 38 options->sample = 1; 38 options->background = PS_STAT_SAMPLE_MEDIAN; 39 options->mean = PS_STAT_SAMPLE_MEDIAN; 40 options->stdev = PS_STAT_SAMPLE_STDEV; 41 options->shutterSize = 10; 39 42 options->onOff = 0; 40 43 options->combine = pmCombineParamsAlloc(PS_STAT_SAMPLE_MEAN); … … 72 75 return 0; 73 76 } 74 if (strcasecmp(stat, "MEAN") == 0 || strcasecmp(stat, "SAMPLE_MEAN") == 0) { 75 return PS_STAT_SAMPLE_MEAN; 76 } 77 if (strcasecmp(stat, "MEDIAN") == 0 || strcasecmp(stat, "SAMPLE_MEDIAN") == 0) { 78 return PS_STAT_SAMPLE_MEDIAN; 79 } 80 if (strcasecmp(stat, "ROBUST") == 0 || strcasecmp(stat, "ROBUST_MEDIAN") == 0) { 81 return PS_STAT_ROBUST_MEDIAN; 82 } 83 if (strcasecmp(stat, "FITTED") == 0 || strcasecmp(stat, "FITTED_MEAN") == 0) { 84 return PS_STAT_FITTED_MEAN; 85 } 86 if (strcasecmp(stat, "CLIPPED") == 0 || strcasecmp(stat, "CLIPPED_MEAN") == 0) { 87 return PS_STAT_CLIPPED_MEAN; 88 } 89 90 psError(PS_ERR_IO, true, "Unable to interpret statistic: %s\n", name); 91 return 0; 77 return psStatsOptionFromString(stat); 92 78 } 93 79 … … 143 129 OPTION_PARSE(options->combine->nKeep, recipe, "NKEEP", S32 ); 144 130 OPTION_PARSE(options->combine->maskVal, recipe, "MASKVAL", S32 ); 131 OPTION_PARSE(options->shutterSize, recipe, "SHUTTERSIZE", S32 ); 145 132 options->combine->combine = parseStat(recipe, "COMBINE"); 146 options->background = parseStat(recipe, "BACKGROUND"); 133 options->mean = parseStat(recipe, "MEAN"); 134 options->stdev = parseStat(recipe, "STDEV"); 147 135 148 136 // Now the command-line options. These are parameters that depend on what type of frame is being combined … … 155 143 options->scale = false; 156 144 options->exptime = false; 145 options->shutter = false; 157 146 } else if (strcasecmp(type, "DARK") == 0) { 158 147 options->zero = false; 159 148 options->scale = false; 160 149 options->exptime = true; 150 options->shutter = false; 161 151 } else if (strcasecmp(type, "FLAT") == 0) { 162 152 options->zero = false; 163 153 options->scale = true; 164 154 options->exptime = false; 155 options->shutter = false; 165 156 } else if (strcasecmp(type, "FRINGE") == 0) { 166 157 options->zero = true; 167 158 options->scale = true; 168 159 options->exptime = false; 160 options->shutter = false; 161 } else if (strcasecmp(type, "SHUTTER") == 0) { 162 options->zero = false; 163 options->scale = false; 164 options->exptime = false; 165 options->shutter = true; 169 166 } else { 170 167 psLogMsg(__func__, PS_LOG_WARN, "Unrecognised image type: %s --- assuming BIAS.\n", type); … … 172 169 options->scale = false; 173 170 options->exptime = false; 171 options->shutter = false; 174 172 } 175 173 } else { -
trunk/ppMerge/src/ppMergeOptions.h
r7073 r9325 22 22 bool scale; // Scale by the background before combining? 23 23 bool exptime; // Normalise by the exposure time? 24 bool shutter; // Generate shutter correction? 24 25 unsigned int sample; // Sampling factor for measuring the background 25 psStatsOptions background; // Statistic to use to measure the background 26 psStatsOptions mean; // Statistic to use to measure the mean 27 psStatsOptions stdev; // Statistic to use to measure the stdev 28 int shutterSize; // Size for shutter measurement regions 26 29 ppOnOff onOff; // On/off pairs? 27 30 pmCombineParams *combine; // Combination parameters -
trunk/ppMerge/src/ppMergeScaleZero.c
r8847 r9325 159 159 psImage *background = psImageAlloc(data->numCells, filenames->n, PS_TYPE_F32); // Background measurements 160 160 psImageInit(background, NAN); 161 psStats *bgStats = psStatsAlloc(options-> background); // Statistic to measure the background161 psStats *bgStats = psStatsAlloc(options->mean); // Statistic to measure the background 162 162 psVector *gains = NULL; // The gains for each cell 163 163 psImage *exptime = NULL; // The exposure time for each integration of each cell … … 265 265 psFree(sample); 266 266 psFree(sampleMask); 267 background->data.F32[i][cellNum] = getStat(bgStats, options-> background);267 background->data.F32[i][cellNum] = getStat(bgStats, options->mean); 268 268 psTrace(__func__, 3, "Background for %s, cell %d is %f\n", name, cellNum, 269 269 background->data.F32[i][cellNum]);
Note:
See TracChangeset
for help on using the changeset viewer.
