IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 24, 2011, 2:18:18 PM (15 years ago)
Author:
bills
Message:

Adapt Pavlos' code to work within the IPP framework and include it in psvideoLoop.c
Gets results similar to his original version when the star is fully within the
boundaries of the frame. His version examined pixels in the BIAS region of the chip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/haf_branches/ppimage2011/psvideophot/src/psvideoLoop.c

    r31290 r31713  
    44
    55#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
    613
    714#define ESCAPE(MESSAGE) { \
     
    1219}
    1320
     21// XXX: move these to another file
     22static double SubSum (psImage *image, double xy[2], double median);
     23static void Centering(psImage *image, long edge, double *pSum, double xy[], double median);
     24
    1425bool psvideophotLoop(pmConfig *config, psvideophotOptions *options)
    1526{
    1627    psMetadata *stats = NULL;           // Statistics to output
    17     float timeDetrend = 0;              // Amount of time spent in detrend
    1828    float timePhot = 0;                 // Amount of time spent in photometry
    1929
    2030    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);
    2333    }
    2434
     
    3343    }
    3444
     45
    3546    pmConfigCamerasCull(config, NULL);
    3647    pmConfigRecipesCull(config, "PSVIDEOPHOT,PPSTATS,PSPHOT,MASKS,PSASTRO,JPEG");
     
    5465        }
    5566
    56 
    57         psTimerStart(TIMER_DETREND);
     67        double threshold = THRESHOLD;
     68
     69        psTimerStart(TIMER_PHOT);
    5870        pmCell *cell;                   // Cell from chip
    5971        while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
     
    7385            }
    7486
    75             // XXX for now, skip the video cells (cell->readouts->n > 1)
    7687            if (cell->readouts->n <2) {
    77               psWarning("Skipping Non-Video Cell for psvideophotDetrendReadout");
    7888              continue;
    7989            }
    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                );
    81102
    82103            // process each of the readouts
     104            int frame = 0;
    83105            pmReadout *readout;         // Readout from cell
    84106            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
    85               if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     107                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    86108                    ESCAPE("load failure for Readout");
    87               }
    88              
     109                }
     110                if (++frame < SKIP) {
     111                    continue;
     112                }
    89113                if (!readout->data_exists) {
    90114                    continue;
    91115                }
    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        }
    100144
    101145        // we perform photometry on the readouts of this chip in the output
    102146
    103         psTimerStart(TIMER_PHOT);
    104147        timePhot += psTimerClear(TIMER_PHOT);
    105148
    106149        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         //}
    119150
    120151        // Close chip
     
    123154        }
    124155    }
     156    psFree (stats);
    125157   
    126158    if (psTraceGetLevel("psvideophot") >= 3) {
     
    141173    }
    142174
    143 
    144     psFree (stats);
    145 
    146175    return true;
    147176}
     177
     178// calculate the sum of pixel values inside the window
     179static 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
     193static 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
     215double 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.