- Timestamp:
- Jun 24, 2011, 2:18:18 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/haf_branches/ppimage2011/psvideophot/src/psvideoLoop.c
r31290 r31713 4 4 5 5 #include "psvideophot.h" 6 7 // XXX: get these from a recipe 8 #define DX 20 9 #define DY 10 10 #define SKIP 0 11 #define EDGE 3 12 #define THRESHOLD 100 6 13 7 14 #define ESCAPE(MESSAGE) { \ … … 12 19 } 13 20 21 // XXX: move these to another file 22 static double SubSum (psImage *image, double xy[2], double median); 23 static void Centering(psImage *image, long edge, double *pSum, double xy[], double median); 24 14 25 bool psvideophotLoop(pmConfig *config, psvideophotOptions *options) 15 26 { 16 27 psMetadata *stats = NULL; // Statistics to output 17 float timeDetrend = 0; // Amount of time spent in detrend18 28 float timePhot = 0; // Amount of time spent in photometry 19 29 20 30 if (options->doStats) { 21 stats= psMetadataAlloc();22 psMetadataAddS32(stats , PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);31 psMetadata *statsMD = psMetadataAlloc(); 32 psMetadataAddS32(statsMD, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0); 23 33 } 24 34 … … 33 43 } 34 44 45 35 46 pmConfigCamerasCull(config, NULL); 36 47 pmConfigRecipesCull(config, "PSVIDEOPHOT,PPSTATS,PSPHOT,MASKS,PSASTRO,JPEG"); … … 54 65 } 55 66 56 57 psTimerStart(TIMER_DETREND); 67 double threshold = THRESHOLD; 68 69 psTimerStart(TIMER_PHOT); 58 70 pmCell *cell; // Cell from chip 59 71 while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) { … … 73 85 } 74 86 75 // XXX for now, skip the video cells (cell->readouts->n > 1)76 87 if (cell->readouts->n <2) { 77 psWarning("Skipping Non-Video Cell for psvideophotDetrendReadout");78 88 continue; 79 89 } 80 psWarning("Found video cell\n"); 90 91 psString cellName = psMetadataLookupStr(&status, cell->concepts, "CELL.NAME"); 92 psWarning("Found video cell %s %d\n", cellName, view->cell); 93 94 psStats *stats = psStatsAlloc( 95 PS_STAT_SAMPLE_MEDIAN | 96 PS_STAT_SAMPLE_STDEV | 97 PS_STAT_ROBUST_MEDIAN | 98 PS_STAT_ROBUST_STDEV | 99 PS_STAT_MIN | PS_STAT_MAX | PS_STAT_SAMPLE_QUARTILE 100 | PS_STAT_SAMPLE_SKEWNESS | PS_STAT_SAMPLE_KURTOSIS 101 ); 81 102 82 103 // process each of the readouts 104 int frame = 0; 83 105 pmReadout *readout; // Readout from cell 84 106 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 85 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {107 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 86 108 ESCAPE("load failure for Readout"); 87 } 88 109 } 110 if (++frame < SKIP) { 111 continue; 112 } 89 113 if (!readout->data_exists) { 90 114 continue; 91 115 } 92 psWarning ( "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 93 } 94 95 96 97 } 98 // free detrend images potentially in use: MASK, BIAS, DARK, SHUTTER, FLAT 99 timeDetrend += psTimerClear(TIMER_DETREND); 116 117 psStatsInit(stats); 118 119 if (!psImageStats(stats, readout->image, NULL, 0)) { 120 psError(PS_ERR_UNKNOWN, false, "unable to generate image stats for cell %d readout %d\n", 121 view->cell, view->readout); 122 ESCAPE("failed to generate stats"); 123 } 124 125 double stddev = stats->sampleStdev; 126 double median = stats->sampleMedian; 127 if (stddev > threshold) { 128 129 double sum = 0; 130 // XXX: use a point data type 131 double xy[2]; 132 Centering(readout->image, EDGE, &sum, xy, median); 133 double sum2; 134 sum2 = SubSum(readout->image, xy, median); 135 136 printf("%4d %9.2f %9.2f %8.2f %.1f %.1f %9.2f\n", 137 frame, sum, stddev, median, xy[0], xy[1], sum2); 138 } else { 139 printf("%4d %9.2f %9.2f %8.2f\n", 140 frame, 0.0, stddev, median); 141 } 142 } 143 } 100 144 101 145 // we perform photometry on the readouts of this chip in the output 102 146 103 psTimerStart(TIMER_PHOT);104 147 timePhot += psTimerClear(TIMER_PHOT); 105 148 106 149 view->cell = -1; 107 psWarning ("Got here\n");108 // while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {109 // psWarning ( "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);110 // if (!cell->process || !cell->file_exists) {111 // continue;112 // }113 // psWarning ("Got here: inner loop\n");114 115 // if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {116 // ESCAPE("save failure for Cell");117 // }118 //}119 150 120 151 // Close chip … … 123 154 } 124 155 } 156 psFree (stats); 125 157 126 158 if (psTraceGetLevel("psvideophot") >= 3) { … … 141 173 } 142 174 143 144 psFree (stats);145 146 175 return true; 147 176 } 177 178 // calculate the sum of pixel values inside the window 179 static double Sum(psImage *image, long edge, double median) { 180 long x, y; 181 double sum=0; 182 for (y=edge; y<=image->numRows-edge+1; y++) { 183 // TYPE! 184 psF32 *row = image->data.F32[y]; 185 for (x=edge; x<= image->numCols - edge+1; x++) { 186 sum = sum + row[x] - median; 187 } 188 } 189 return(sum); 190 } 191 192 // find the star 193 static void Centering(psImage *image, long edge, double *pSum, double xy[], double median) { 194 long x, y; 195 double sum=0, sxf=0, syf=0; 196 197 sum=Sum(image, edge, median); 198 199 for (y=edge; y<= image->numRows -edge+1; y++) { 200 // TYPE!! 201 psF32 *row = image->data.F32[y]; 202 for (x=edge; x<=image->numCols -edge+1; x++) { 203 sxf=sxf+x*(row[x] - median); 204 syf=syf+y*(row[x] - median); 205 } 206 } 207 xy[0] = edge-1+sxf/sum; 208 xy[1] = edge-2+syf/sum; 209 *pSum = sum; 210 //printf("%f %f\n", xc, yc); 211 //return(0); 212 } 213 214 // calculate the sum of pixel values in an aperture around a point 215 double SubSum (psImage *image, double xy[2], double median) 216 { 217 double sum=0; 218 long x, y; 219 220 for (y = xy[1] - DY; y<= xy[1] + DY; y++) { 221 if (y < image->row0) { 222 continue; 223 } 224 if (y >= image->numRows) { 225 break; 226 } 227 psF32 *row = image->data.F32[y]; 228 for (x = xy[0] - DX; x<= xy[0] + DX; x++) { 229 if (x < image->col0) { 230 continue; 231 } 232 if (x >= image->numCols) { 233 break; 234 } 235 sum += row[x] - median; 236 } 237 } 238 return(sum); 239 }
Note:
See TracChangeset
for help on using the changeset viewer.
