IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2012, 5:19:48 PM (14 years ago)
Author:
mhuber
Message:

merging latest r33407 trunk changes to meh_branches/ppstack_test

Location:
branches/meh_branches/ppstack_test
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/psvideophot

  • branches/meh_branches/ppstack_test/psvideophot/src

    • Property svn:ignore
      •  

        old new  
        11psvideophot
         2dumpvideo
        23Makefile
        34Makefile.in
         
        910psvideophotVersionDefinitions.h
        1011
         12
  • branches/meh_branches/ppstack_test/psvideophot/src/Makefile.am

    r31713 r33415  
    1 bin_PROGRAMS = psvideophot
     1bin_PROGRAMS =  psvideophot \
     2                dumpvideo
    23
    34noinst_HEADERS = \
     
    4041        psvideophotVersion.c
    4142
     43dumpvideo_CFLAGS = $(PSVIDEOPHOT_CFLAGS) $(PPSTATS_CFLAGS) $(PSASTRO_CFLAGS) $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     44dumpvideo_LDFLAGS = $(PSVIDEOPHOT_LIBS) $(PSASTRO_LIBS) $(PPSTATS_LIBS) $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
     45dumpvideo_SOURCES = \
     46        dumpvideo.c
     47
    4248CLEANFILES = *~
    4349
  • branches/meh_branches/ppstack_test/psvideophot/src/psvideoLoop.c

    r31813 r33415  
    4444    }
    4545
     46    psString class_id = psMetadataLookupStr(&status, config->arguments, "CLASS_ID");
     47    psString cell_id = psMetadataLookupStr(&status, config->arguments, "CELL_ID");
     48
    4649
    4750    pmConfigCamerasCull(config, NULL);
     
    5659    }
    5760
     61    psArray *output = NULL;
     62
    5863    pmChip *chip;                       // Chip from FPA
    5964    while ((chip = pmFPAviewNextChip(view, input->fpa, 1)) != NULL) {
    6065        psLogMsg ("psvideophotLoop", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     66        psString chipName = psMetadataLookupStr(&status, chip->concepts, "CHIP.NAME");
     67        if (strcmp(chipName, class_id)) {
     68            continue;
     69        }
    6170        if (!chip->process || !chip->file_exists) {
    62             continue;
     71            ESCAPE("target chip has no data");
    6372        }
    6473        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    6574            ESCAPE("load failure for Chip");
    6675        }
     76        (void) class_id;
    6777
    6878        double threshold = THRESHOLD;
     
    7282        while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
    7383            psLogMsg ("psvideophotLoop", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     84            psString cellName = psMetadataLookupStr(&status, cell->concepts, "CELL.NAME");
     85            if (strcmp(cellName, cell_id)) {
     86                continue;
     87            }
    7488            if (!cell->process || !cell->file_exists) {
    75                 continue;
     89                ESCAPE("target cell has no data");
    7690            }
    7791            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    7892                ESCAPE("load failure for Cell");
    7993            }
     94
     95            psLogMsg("psvideophotLoop", 1, "Found target cell %s %d. %ld readouts\n", cellName, view->cell, cell->readouts->n);
    8096
    8197            // Put version information into the header
     
    87103
    88104            if (cell->readouts->n <2) {
    89               continue;
     105              psLogMsg("psvideophotLoop", 1, "cell %s has only %ld readouts\n", cellName, cell->readouts->n);
     106              ESCAPE("invalid video Cell");
    90107            }
    91 
    92             psString cellName = psMetadataLookupStr(&status, cell->concepts, "CELL.NAME");
    93             psLogMsg("psvideophotLoop", 1, "Found video cell %s %d\n", cellName, view->cell);
    94108
    95109            // get the position of this cell on the chip
     
    114128
    115129            // go find the video extension data
    116             psString video_extension_name = NULL;
    117             psStringAppend(&video_extension_name, "video_table_%s", cellName);
     130            psString video_extension_name = psMetadataLookupStr(&status, config->arguments, "VIDEOEXTNAME");
     131            if (!video_extension_name) {
     132                psStringAppend(&video_extension_name, "video_table_%s", cellName);
     133            }
    118134            psArray *video_table = readVideoTable(input, video_extension_name);
    119135            if (!video_table) {
     
    121137                ESCAPE("invalid image file");
    122138            }
    123             psMetadataAddArray(cell->analysis, PS_LIST_TAIL, "VIDEO_DATA", 0, "", video_table);
     139            psFree(video_extension_name);
     140            // psMetadataAddArray(cell->analysis, PS_LIST_TAIL, "VIDEO_DATA", 0, "", video_table);
     141
     142            output = (psArray *) psMemIncrRefCounter(video_table);
    124143
    125144            if (cell->readouts->n != video_table->n) {
     
    180199                double cnpix2 = psMetadataLookupS32(&status, row, "cnpix2");
    181200
     201                // avoid errors from unused variables
    182202                (void) frame_start; (void) frame_complete;
    183203                (void) rowpre; (void) cnpix1; (void) cnpix2; (void) fwhm_x; (void) fwhm_y; (void) fwhm;
     
    191211                double star_readout_y = (centroid_y - cnpix2) / yBin;
    192212
     213#ifdef notdef
    193214                printf("%4d %9.2f %9.2f %9.2f %.1f %.1f %9.6f %6.3f %6.3f %6.3f\n",
    194215                        frame, flux, snr, sky, star_readout_x, star_readout_y, frame_complete - frame_start,
    195216                            fwhm, fwhm_x, fwhm_y);
    196 
     217#endif
    197218                psStatsInit(stats);
    198219
     
    206227                double stddev = stats->sampleStdev;
    207228                double median = stats->sampleMedian;
     229                double vpFlux = 0;
     230                double vpSum = 0;
     231                double xy[2] = {0, 0};
    208232                if (stddev > threshold) {
    209233
    210                     double sum = 0;
    211                     // XXX: use a point data type
    212                     double xy[2];
    213                     Centering(readout->image, EDGE, &sum, xy, median);
    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);
     234                    Centering(readout->image, EDGE, &vpSum, xy, median);
     235
     236                    if (isfinite(xy[0]) && isfinite(xy[1])) {
     237                        vpFlux = SubSum(readout->image, xy, median);
     238                    }
     239
     240//                    printf("%4d %9.2f %9.2f %9.2f %.1f %.1f %9.2f\n",
     241//                             frame, vpFlux, vpFlux/median, median, xy[0], xy[1], stddev);
    219242                } else {
    220                     printf("%4d %9.2f %9.2f %8.2f\n",
    221                             frame, 0.0,   stddev, median);
    222                 }
     243//                    printf("%4d %9.2f %9.2f %8.2f\n",
     244//                            frame, 0.0,   stddev, median);
     245                }
     246                if (frame % 60 == 0) {
     247                    printf("frame  flux        sky       snr     X    Y     dt        fwhm   fwhm_x fwhm_y  vp_flux   vp_median vp_sum    vp_stddev vp_x vp_y\n");
     248                }
     249                printf("%4d   %9.2f %9.2f %9.2f %.1f %.1f %9.6f %6.3f %6.3f %6.3f   %9.2f %9.2f %9.2f %9.2f %.1f %.1f\n",
     250                        frame, flux, sky, snr, star_readout_x, star_readout_y, frame_complete - frame_start,
     251                            fwhm, fwhm_x, fwhm_y,
     252                            vpFlux, median, vpSum, stddev, xy[0], xy[1]);
     253                psMetadataAddF32(row, PS_LIST_TAIL, "vp_flux", 0, "vp flux", vpFlux);
     254                psMetadataAddF32(row, PS_LIST_TAIL, "vp_median", 0, "vp meidan", median);
     255                psMetadataAddF32(row, PS_LIST_TAIL, "vp_stddev", 0, "vp meidan", stddev);
     256                psMetadataAddF32(row, PS_LIST_TAIL, "vp_sum", 0, "vp sum of source", vpSum);
     257                psMetadataAddF32(row, PS_LIST_TAIL, "vp_x", 0, "centroid x from vp", xy[0]);
     258                psMetadataAddF32(row, PS_LIST_TAIL, "vp_y", 0, "centroid y from vp", xy[1]);
    223259            }
    224260            psLogMsg ("psvideophotLoop", 5, "Done processing video cell");
     
    247283    psFree(view);
    248284
    249     // Dump configuration
    250     psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");
    251     if (dump_file) {
    252         if (!pmConfigDump(config, dump_file)) {
    253             ESCAPE("Unable to dump configuration.");
    254         }
    255     }
     285    psString outputName = psMetadataLookupStr(&status, config->arguments, "OUTPUT");
     286    psString realName = pmConfigConvertFilename(outputName, config, true, true);
     287    if (!realName) {
     288        psError(PS_ERR_UNKNOWN, false, "failed to convert filename for %s", outputName);
     289        ESCAPE("cannot save output");
     290    }
     291    psFits *outFits = psFitsOpen(realName, "w");
     292    if (!outFits) {
     293        psError(PS_ERR_UNKNOWN, false, "failed to open output filename for %s", outputName);
     294        ESCAPE(" ");
     295    }
     296
     297    psMetadata *outputHeader = lastHDU ? lastHDU->header : NULL;
     298    if (!psFitsWriteTable(outFits, outputHeader, output, "videophotemetry")) {
     299        psError(PS_ERR_UNKNOWN, false, "failed to write videophotometry table");
     300        ESCAPE("cannot write output");
     301    }
     302    psFitsClose(outFits);
    256303
    257304    return true;
  • branches/meh_branches/ppstack_test/psvideophot/src/psvideophotArguments.c

    r31290 r33415  
    66
    77static void usage (void) {
    8     fprintf(stderr, "USAGE: psvideophot [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n\n");
     8    fprintf(stderr, "USAGE: psvideophot [-file INPUT.fits] [-list INPUT.txt] OUTPUT -class_id CLASS_ID -cell_id CELL_ID\n\n");
    99    fprintf(stderr, "Optional arguments:\n");
    1010    fprintf(stderr, "\t-stats STATS.mdc: Output statistics into STATS.mdc\n");
    11     fprintf(stderr, "\t-isfringe: The input image contains fringe data.\n");
    12     fprintf(stderr, "\t-isdark: The input image contains dark data.\n");
    13     fprintf(stderr, "\t-usemask MASKVAL: Use this mask value (override recipe).\n");
    14     fprintf(stderr, "\t-chip CHIPNUM: Only process this chip number.\n");
    15     fprintf(stderr, "\t-norm VALUE: Divide through by this value when done.\n");
    16     fprintf(stderr, "\t-normlist file.mdc: normalizations by class_id.\n");
    17     fprintf(stderr, "\t-video: process video cells\n");
     11    fprintf(stderr, "\t-video_extname VIDEOEXTNAME: EXTNAME for video table\n");
    1812    fprintf(stderr, "\n");
    1913    fprintf(stderr, "Input options (single file / file list):\n");
    20     fprintf(stderr, "\t-noisemap/-noisemaplist: Noise Map image.\n");
    21     fprintf(stderr, "\t-bias/-biaslist: Bias image.\n");
    22     fprintf(stderr, "\t-dark/-darklist: Dark image.\n");
    23     fprintf(stderr, "\t-shutter/-shutterlist: Shutter image.\n");
    24     fprintf(stderr, "\t-flat/-flatlist: Flat image.\n");
    25     fprintf(stderr, "\t-mask/-masklist: Mask image.\n");
    26     fprintf(stderr, "\t-fringe/-fringelist: Fringe image and data.\n");
    27     fprintf(stderr, "\t-linearity/-linearlist: linearity correction file.\n");
    2814    fprintf(stderr, "\n");
    2915    exit (2);
     
    6349    // psMetadata *options = psMetadataAlloc ();
    6450    // psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "PSVIDEOPHOT.OPTIONS",  PS_DATA_METADATA, "", options);
     51
     52    if ((argnum = psArgumentGet(argc, argv, "-class_id"))) {
     53        psArgumentRemove(argnum, &argc, argv);
     54        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "CLASS_ID", PS_META_REPLACE,
     55                         "Chip to process", argv[argnum]);
     56        psArgumentRemove(argnum, &argc, argv);
     57    } else {
     58        fprintf(stderr, "-class_id is required\n");
     59        usage();
     60    }
     61    if ((argnum = psArgumentGet(argc, argv, "-cell_id"))) {
     62        psArgumentRemove(argnum, &argc, argv);
     63        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "CELL_ID", PS_META_REPLACE,
     64                         "Cell to process", argv[argnum]);
     65        psArgumentRemove(argnum, &argc, argv);
     66    } else {
     67        fprintf(stderr, "-cell_id is required\n");
     68        usage();
     69    }
     70    if ((argnum = psArgumentGet(argc, argv, "-video_extname"))) {
     71        psArgumentRemove(argnum, &argc, argv);
     72        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "VIDEOEXTNAME", PS_META_REPLACE,
     73                         "EXTNAME of video table", argv[argnum]);
     74        psArgumentRemove(argnum, &argc, argv);
     75    }
    6576
    6677    if ((argnum = psArgumentGet(argc, argv, "-stats"))) {
     
    117128    // the input file is a required argument; if not found, we will exit
    118129    pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
     130    pmConfigFileSetsMD (config->arguments, &argc, argv, "ASTROM", "-astrom", "-astromlist");
    119131
    120132    // if these command-line options are supplied, load the file name lists into config->arguments
     
    168180
    169181    // Add the input and output images (which remain on the command-line) to the arguments list
    170     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]);
     182    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output table", argv[1]);
    171183
    172184    return config;
  • branches/meh_branches/ppstack_test/psvideophot/src/psvideophotParseCamera.c

    r31290 r33415  
    77psvideophotOptions *psvideophotParseCamera(pmConfig *config)
    88{
    9     bool status = false;
    10 
    119    if (!psvideophotDefineFile(config, NULL, "PSVIDEOPHOT.INPUT", "INPUT", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_NONE)) {
    1210        psError(PS_ERR_IO, false, "Can't find an input image source");
     
    1614    psAssert(input, "We just put it there!");
    1715
     16#ifdef notyet
    1817    // add recipe options supplied on command line
     18    bool status = false;
    1919    psMetadata *recipe  = psMetadataLookupPtr(&status, config->recipes, RECIPE_NAME);
     20#endif
    2021
    2122    // parse the options from the metadata format to the psvideophotOptions structure
    2223    psvideophotOptions *options = psvideophotOptionsParse(config);
    2324
    24     // the following are defined from the argument list, if given,
    25     // otherwise they revert to the config information
    26     // not all input or output images are used in a given recipe
    27    
    28     int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS");
    29     if (nThreads > 0) {
    30         int nScanRows = psMetadataLookupS32(&status, recipe, "SCAN.ROWS");
    31         pmDetrendSetThreadTasks(nScanRows);
    32     }
    33 
    34     // the following files are output targets
    35     pmFPAfile *outImage = pmFPAfileDefineOutput(config, input->fpa, "PSVIDEOPHOT.OUTPUT");
    36     if (!outImage) {
    37         psError(PS_ERR_IO, false, _("Unable to generate output file from PSVIDEOPHOT.OUTPUT"));
    38         psFree(options);
    39         return NULL;
    40     }
    41     if (outImage->type != PM_FPA_FILE_OBJ) {
    42         psError(PS_ERR_IO, true, "PSVIDEOPHOT.OUTPUT is not of type OBJ");
    43         psFree(options);
    44         return NULL;
    45     }
    46    
    47     // XXX should these be bound explicitly to the outImage->fpa rather than the input->fpa?
    48     pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PSVIDEOPHOT.CHIP");
    49     if (!chipImage) {
    50         psError(PS_ERR_IO, false, _("Unable to generate new file from PSVIDEOPHOT.CHIP"));
    51         psFree(options);
    52         return NULL;
    53     }
    54     if (chipImage->type != PM_FPA_FILE_OBJ) {
    55         psError(PS_ERR_IO, true, "PSVIDEOPHOT.CHIP is not of type OBJ");
    56         psFree(options);
    57         return NULL;
    58     }
    59    
    60 
    61     // chipImage    -> psphotInput  (pmFPAfileDefineFromFile)       : fpa is constructed
    62     // psphotInput  -> psphotOutput (pmFPAfileDefineOutputFromFile) : fpa is equated
    63     // psphotOutput -> psastroInput (pmFPAfileDefineInput)          : fpa is ref-copied
    64     // psastroInput -> psastroModel (pmFPAfileDefineFromArgs        : fpa is ref-copied
    65     // psastroInput -> psastroModel (pmFPAfileDefineFromConf        : fpa is constructed
    66     // psastroInput -> psastroModel (pmFPAfileDefineFromDetDB       : fpa is constructed (pmDetrendSelect uses input concepts )
    67 
    68     // For photometry, we operate on the chip-mosaicked image
    69     // we create a copy of the mosaicked image for psphot so we can write out a clean image
    70    
    71 
    72         // this file is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by
    73         // psphotDefineFiles
    74         pmFPAfile *psphotInput = pmFPAfileDefineFromFile (config, chipImage, 1, 1, "PSPHOT.INPUT");
    75         PS_ASSERT (psphotInput, false);
    76 
    77         // specify the number of psphot input images
    78         psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);
    79 
    80         // define associated psphot input/output files
    81         if (!psphotDefineFiles (config, psphotInput)) {
    82             psError(PSPHOT_ERR_CONFIG, false,
    83                     "Trouble defining the additional input/output files for psphot");
    84             return false;
    85         }
    86    
    87 
    88     // For photometry, we operate on the chip-mosaicked image
    89    
    90 
    91     // save any of these files?
    92     outImage->save   = options->BaseFITS;
    93    
    94 
    95     chipImage->save  = options->ChipFITS;
    96    
    97 
    98    
    99     // outImage is used as a carrier: input to chipImage -> require the data to remain at the CHIP level
    100     outImage->freeLevel = PS_MIN(outImage->freeLevel, PM_FPA_LEVEL_CHIP);
    101     outImage->dataLevel = outImage->freeLevel;
    102     outImage->fileLevel = PS_MIN(outImage->fileLevel, outImage->dataLevel);
    103 
    104     // outMask and outVariance must be freed at the same level as outImage (all freed by pmFPAFreeData)
    105    
    106 
    107     // the input data is the same as the outImage data : force the free levels to match
    108     input->freeLevel = PS_MIN(outImage->freeLevel, input->freeLevel);
    109 
    110     // define the binned target files (which may just be carriers for some camera configurations)
    111    
    112     // Chip selection: turn on only the chips specified (pass status to suppress missing-key log msg)
    113     char *chipLine = psMetadataLookupStr(&status, config->arguments, "CHIP_SELECTIONS");
    114     psArray *chips = psStringSplitArray(chipLine, ",", false);
    115     if (chips->n > 0) {
    116         pmFPASelectChip (input->fpa, -1, true); // deselect all chips
    117         for (int i = 0; i < chips->n; i++) {
    118             int chipNum = atoi(chips->data[i]);
    119             if (! pmFPASelectChip(input->fpa, chipNum, false)) {
    120                 psError(PS_ERR_IO, false, "Chip number %d doesn't exist in camera.\n", chipNum);
    121                 psFree(options);
    122                 return false;
    123             }
    124         }
    125     }
    126     psFree (chips);
    127 
    128     if (psMetadataLookupBool(NULL, config->arguments, "INPUT_IS_FRINGE")) {
    129         // It's a fringe file, so change the file type
    130         input->type = PM_FPA_FILE_FRINGE;
    131         outImage->type = PM_FPA_FILE_FRINGE;
    132     }
    133     if (psMetadataLookupBool(NULL, config->arguments, "INPUT_IS_DARK")) {
    134         // It's a dark file, so change the file type
    135         input->type = PM_FPA_FILE_DARK;
    136         outImage->type = PM_FPA_FILE_DARK;
    137         // Turn off compression --- there are just too many nasties that can happen
    138         psFree(outImage->compression);
    139         outImage->compression = NULL;
    140         psFree(outImage->options);
    141         outImage->options = NULL;
    142     }
    143 
    144     // Turn off mask and variance output if we're not doing anything interesting
    145    
    146     if (psTraceGetLevel("psvideophot.config") > 0) {
    147         // Get a look inside all the files.
    148         psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL);
    149         psMetadataItem *item;               // Item from iteration
    150         fprintf(stderr, "Files:\n");
    151         while ((item = psMetadataGetAndIncrement(filesIter))) {
    152             pmFPAfile *file = item->data.V; // File of interest
    153             fprintf(stderr, "%s: %p %p %p (%p) %p\n", file->name,
    154                     file->src, file->fpa,
    155                     file->camera, file->fpa->camera, file->format);
    156         }
    157         psFree(filesIter);
    158     }
    159 
    160     // Change the input dark type between the old (IMAGE) and new (multi-DARK).
    161     // Hopefully this is a temporary change until we all move over to using the new dark types
    162     bool mdok;                          // Status of MD lookup
    163     if (options->doDark && psMetadataLookupBool(&mdok, recipe, "OLDDARK")) {
    164         pmFPAfile *dark = psMetadataLookupPtr(NULL, config->files, "PSVIDEOPHOT.DARK");
    165         assert(dark);
    166         dark->type = PM_FPA_FILE_IMAGE;
    167     }
    168 
    16925    return (options);
    17026}
Note: See TracChangeset for help on using the changeset viewer.