IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31813


Ignore:
Timestamp:
Jul 1, 2011, 11:22:48 AM (15 years ago)
Author:
bills
Message:

read the video extension table. print out the camera's measurements of flux. Change frame # and coordinates to be zero offset values rather than fits (fortran) style.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psvideophot/src/psvideoLoop.c

    r31713 r31813  
    55#include "psvideophot.h"
    66
    7 // XXX: get these from a recipe
    8 #define DX 20
    9 #define DY 10
     7// XXX: derive these from a recipe perhaps basing them on seeing
     8#define DX 10
     9#define DY 5
    1010#define SKIP 0
    1111#define EDGE 3
     
    2222static double SubSum (psImage *image, double xy[2], double median);
    2323static void Centering(psImage *image, long edge, double *pSum, double xy[], double median);
     24static psArray *readVideoTable(pmFPAfile *input, psString video_extension_name);
    2425
    2526bool psvideophotLoop(pmConfig *config, psvideophotOptions *options)
     
    9091
    9192            psString cellName = psMetadataLookupStr(&status, cell->concepts, "CELL.NAME");
    92             psWarning("Found video cell %s %d\n", cellName, view->cell);
     93            psLogMsg("psvideophotLoop", 1, "Found video cell %s %d\n", cellName, view->cell);
     94
     95            // get the position of this cell on the chip
     96            int cellX0 = psMetadataLookupS32(&status, cell->concepts, "CELL.X0");
     97            int cellY0 = psMetadataLookupS32(&status, cell->concepts, "CELL.Y0");
     98            int xParity = psMetadataLookupS32(&status, cell->concepts, "CELL.XPARITY");
     99            int yParity = psMetadataLookupS32(&status, cell->concepts, "CELL.YPARITY");
     100            int xBin = psMetadataLookupS32(&status, cell->concepts, "CELL.XBIN");
     101            int yBin = psMetadataLookupS32(&status, cell->concepts, "CELL.YBIN");
     102
     103            // avoid errors about unused variables
     104            (void) xParity; (void) yParity; (void) cellX0; (void)cellY0;
    93105
    94106            psStats *stats = psStatsAlloc(
     
    101113                );
    102114
     115            // go find the video extension data
     116            psString video_extension_name = NULL;
     117            psStringAppend(&video_extension_name, "video_table_%s", cellName);
     118            psArray *video_table = readVideoTable(input, video_extension_name);
     119            if (!video_table) {
     120                psError(PS_ERR_UNKNOWN, false, "failed to find video extension:%s", video_extension_name);
     121                ESCAPE("invalid image file");
     122            }
     123            psMetadataAddArray(cell->analysis, PS_LIST_TAIL, "VIDEO_DATA", 0, "", video_table);
     124
     125            if (cell->readouts->n != video_table->n) {
     126                psError(PS_ERR_UNKNOWN, true, "number of readouts %ld does not match length of video extension: %ld",
     127                    cell->readouts->n, video_table->n);
     128                ESCAPE("invalid data");
     129            }
     130
    103131            // process each of the readouts
    104             int frame = 0;
    105132            pmReadout *readout;         // Readout from cell
    106133            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
     
    108135                    ESCAPE("load failure for Readout");
    109136                }
    110                 if (++frame < SKIP) {
     137                int frame = view->readout;
     138                if (frame < SKIP - 1) {
    111139                    continue;
    112140                }
     
    114142                    continue;
    115143                }
     144
     145                psMetadata *row = video_table->data[frame];
     146                if (!row) {
     147                    psError(PS_ERR_UNKNOWN, true, "video_table row for frame %d is null", frame);
     148                    // XXX: rather than fail, should we just skip this frame
     149                    ESCAPE(" ");
     150                }
     151
     152                // extract the camera's measurements from the video table
     153                // We should probably get the column names from a configuration file so that we can
     154                // handle any changes more gracefully
     155                // Time at which frame was completely received from controller
     156                double frame_start = psMetadataLookupF64(&status, row, "frame_start_time");
     157                // Time at which frame was completely received from controller
     158                double frame_complete = psMetadataLookupF64(&status, row, "frame_complete_time");
     159                // star centriod, x axis
     160                double centroid_x = psMetadataLookupF32(&status, row, "centroid_x");
     161                // star centriod, y axis
     162                double centroid_y = psMetadataLookupF64(&status, row, "centroid_y");
     163                // star full width at half maximum
     164                double fwhm = psMetadataLookupF64(&status, row, "fwhm");
     165                // star full width at half maximum, x axis
     166                double fwhm_x = psMetadataLookupF64(&status, row, "fwhm_x");
     167                // star full width at half maximum, y axis
     168                double fwhm_y = psMetadataLookupF64(&status, row, "fwhm_y");
     169                // calculated sky level
     170                double sky = psMetadataLookupF64(&status, row, "sky");
     171                // flux from star
     172                double flux = psMetadataLookupF64(&status, row, "flux");
     173                // signal to noise ration of video frame
     174                double snr = psMetadataLookupF64(&status, row, "snr");
     175                // number of parallel row shits before integration (cleans)
     176                double rowpre = psMetadataLookupS32(&status, row, "rowpre");
     177                // number of cols skipped before video readout
     178                double cnpix1 = psMetadataLookupS32(&status, row, "cnpix1");
     179                // number of rows skipped before video readout
     180                double cnpix2 = psMetadataLookupS32(&status, row, "cnpix2");
     181
     182                (void) frame_start; (void) frame_complete;
     183                (void) rowpre; (void) cnpix1; (void) cnpix2; (void) fwhm_x; (void) fwhm_y; (void) fwhm;
     184
     185                double star_chip_x = cellX0 + (centroid_x * xParity);
     186                double star_chip_y = cellY0 + (centroid_y * yParity);
     187                (void) star_chip_x; (void) star_chip_y;
     188
     189                // measured position of star in readout coordinates
     190                double star_readout_x = (centroid_x - cnpix1) / xBin;
     191                double star_readout_y = (centroid_y - cnpix2) / yBin;
     192
     193                printf("%4d %9.2f %9.2f %9.2f %.1f %.1f %9.6f %6.3f %6.3f %6.3f\n",
     194                        frame, flux, snr, sky, star_readout_x, star_readout_y, frame_complete - frame_start,
     195                            fwhm, fwhm_x, fwhm_y);
    116196
    117197                psStatsInit(stats);
     
    120200                    psError(PS_ERR_UNKNOWN, false, "unable to generate image stats for cell %d readout %d\n",
    121201                        view->cell, view->readout);
     202                    // XXX: rather than fail, should we just skip this frame
    122203                    ESCAPE("failed to generate stats");
    123204                }
     
    131212                    double xy[2];
    132213                    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);
     214                    double ourFlux;
     215                    ourFlux = SubSum(readout->image, xy, median);
     216
     217                    printf("%4d %9.2f %9.2f %9.2f %.1f %.1f %9.2f\n",
     218                             frame, ourFlux, ourFlux/stddev, median, xy[0], xy[1], stddev);
    138219                } else {
    139220                    printf("%4d %9.2f %9.2f %8.2f\n",
     
    141222                }
    142223            }
     224            psLogMsg ("psvideophotLoop", 5, "Done processing video cell");
    143225        }
    144226
     
    205287        }
    206288    }
    207     xy[0] = edge-1+sxf/sum;
     289    xy[0] = edge-2+sxf/sum;
    208290    xy[1] = edge-2+syf/sum;
     291    xy[0] = sxf/sum;
     292    xy[1] = syf/sum;
    209293    *pSum = sum;
    210294    //printf("%f %f\n", xc, yc);
     
    238322    return(sum);
    239323}
     324static psArray *readVideoTable(pmFPAfile *input, psString video_extension_name)
     325{
     326    if (!psFitsMoveExtName(input->fits, video_extension_name)) {
     327        psError(PS_ERR_UNKNOWN, false, "Failed to move to video extension: %s", video_extension_name);
     328        return NULL;
     329    }
     330
     331    return psFitsReadTable(input->fits);
     332}
Note: See TracChangeset for help on using the changeset viewer.