IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5862


Ignore:
Timestamp:
Dec 30, 2005, 6:32:45 PM (20 years ago)
Author:
eugene
Message:

first pass on testing

Location:
trunk/ppMerge/src
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppMerge/src/ppMerge.c

    r5860 r5862  
    1 # include "ppImage.h"
     1# include "ppMerge.h"
    22
    33int main (int argc, char **argv) {
     
    66    ppConfig config;
    77    ppOptions options;
     8
    89
    910    psTimerStart("merge");
     
    1516    // Get camera configuration from header if not already defined
    1617    // Construct camera in preparation for reading
    17     ppMergeParseCamera (&data, &config, argv);
     18    ppMergeParseCamera (&data, &config);
    1819
    1920    // Set various tasks (define optional operations)
     
    2728
    2829    // output options
    29     // ppImageOutput (&data, &options, &config);
     30    ppMergeOutput (&data, &options, &config);
    3031
    3132    exit (0);
    3233}
     34
     35int speedTest (void)
     36{
     37    # define NTEST 10000000
     38    psStats *testData, *stats;
     39    stats = psStatsAlloc (PS_STAT_ROBUST_MEAN);
     40    psList *testList = psListAlloc (NULL);
     41    psArray *testArray = psArrayAlloc (NTEST);
     42
     43    psTimerStart("merge");
     44    for (int i = 0; i < NTEST; i++) {
     45        testArray->data[i] = stats;
     46    }
     47    fprintf (stderr, "added %d objects to array: %f usec / obj\n", NTEST, 1e6*psTimerMark ("merge")/NTEST);
     48
     49    psTimerStart("merge");
     50    for (int i = 0; i < NTEST; i++) {
     51        psListAdd (testList, PS_LIST_TAIL, stats);
     52    }
     53    fprintf (stderr, "added %d objects to list: %f usec / obj\n", NTEST, 1e6*psTimerMark ("merge")/NTEST);
     54
     55    psTimerStart("merge");
     56    for (int i = 0; i < NTEST; i++) {
     57        testData = testArray->data[i];
     58    }
     59    fprintf (stderr, "pulled %d objects from array: %f usec / obj\n", NTEST, 1e6*psTimerMark ("merge")/NTEST);
     60
     61    psTimerStart("merge");
     62    psListElem *tmpInput = (psListElem *) testList->head;
     63    while (tmpInput != NULL) {
     64        testData = tmpInput->data;
     65        tmpInput = tmpInput->next;
     66    }
     67    fprintf (stderr, "pulled %d objects from list: %f usec / obj\n", NTEST, 1e6*psTimerMark ("merge")/NTEST);
     68
     69    exit (0);
     70}
  • trunk/ppMerge/src/ppMerge.h

    r5860 r5862  
    1 #include <stdio.h>
    2 #include <strings.h>
     1# include <stdio.h>
     2# include <strings.h>
     3# include <glob.h>
    34
    4 #include "pslib.h"
     5# include "pslib.h"
    56
    6 #include "psAdditionals.h"
     7# include "psAdditionals.h"
    78
    8 #include "pmAstrometry.h"
    9 #include "pmReadout.h"
    10 #include "pmConfig.h"
    11 #include "pmFPAConstruct.h"
    12 #include "pmFPARead.h"
    13 #include "pmFPAConceptsGet.h"
    14 #include "pmFPAWrite.h"
     9# include "pmAstrometry.h"
     10# include "pmReadout.h"
     11# include "pmConfig.h"
     12# include "pmFPAConstruct.h"
     13# include "pmFPARead.h"
     14# include "pmFPAConceptsGet.h"
     15# include "pmFPAWrite.h"
    1516
    16 #include "pmFlatField.h"
    17 #include "pmMaskBadPixels.h"
    18 #include "pmNonLinear.h"
    19 #include "pmSubtractBias.h"
    20 #include "pmChipMosaic.h"
    21 //#include "pmFPAMorph.h"
     17# include "pmReadoutCombine.h"
    2218
    23 #define RECIPE "PHASE2"                // Name of the recipe to use
     19# define RECIPE "MERGE" // Name of the recipe to use
    2420
     21// XXX : same as in ppImage
    2522typedef enum {
    2623    PP_LOAD_NONE,
     
    3027} ppImageLoadDepth;
    3128
     29// XXX : same as in ppImage
    3230typedef struct {
    3331    psMetadata *site;
     
    4846
    4947typedef struct {
    50     psArray *data;
     48    psArray *input;
     49    ppFPA *output;
    5150    ppFPA *process;
    5251    ppFPA *mask;
     
    5554typedef struct {
    5655    ppImageLoadDepth imageLoadDepth;
    57 
    58     psStats *mergeStats;                // Statistics for overscan
    59     void *overscanFit;                  // Overscan fit (polynomial or spline)
    60     pmFit overscanFitType;              // Fit type for overscan
    61     pmOverscanAxis overscanMode;        // Axis for overscan
    62 
    63     bool doNonLin;                      // Non-linearity correction
    64     psDataType nonLinearType;
    65     psMetadataItem *nonLinearData;
    66     void *nonLinearSource;
     56    bool doMask;                        // apply a pixel mask before stacking
     57    pmCombineParams *combineParams;
     58    bool applyZeroScale;
     59    double gain;
     60    double readnoise;
    6761} ppOptions;
    6862
    69 typedef struct {
    70     pmCell *input;
    71     pmCell *mask;
    72     pmCell *bias;
    73     pmCell *dark;
    74     pmCell *flat;
    75 } ppDetrend;
     63bool ppMergeConfig (ppConfig *config, int argc, char **argv);
     64bool ppMergeLoop (ppData *data, ppOptions *options, ppConfig *config);
     65bool ppMergeOptions (ppData *data, ppOptions *options, ppConfig *config);
     66bool ppMergeOutput (ppData *data, ppOptions *options, ppConfig *config);
     67bool ppMergeParseCamera (ppData *data, ppConfig *config);
     68bool ppMergeParseDetrend (ppData *data, ppOptions *options, ppConfig *config);
    7669
    77 bool ppImageConfig (ppConfig *config, int argc, char **argv);
    78 bool ppImageLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell);
    79 bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config);
    80 bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config);
    81 bool ppImageParseCamera (ppData *data, ppConfig *config, char **argv);
    82 bool ppImageParseDetrend (ppData *data, ppOptions *options, ppConfig *config);
     70bool ppMergeCell (pmCell *output, pmCell *mask, psArray *cellList, ppOptions *options, ppConfig *config);
    8371
    84 bool ppReadoutWeights (pmReadout *readout);
    85 
    86 bool ppDetrendCell (ppDetrend *detrend, ppOptions *options, ppConfig *config);
    87 
    88 bool ppDetrendMask (pmCell *cell, pmReadout *input, pmReadout *mask);
    89 bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options);
    90 bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem);
    91 bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem);
    92 bool ppDetrendBias (pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options);
    93 pmReadout* ppDetrendPedestal (pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options);
     72// XXX : these functions are identical to the ppImage equivalents
    9473pmReadout* ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis);
    95 
    9674bool ppFPAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis);
     75bool ppMergeLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell);
  • trunk/ppMerge/src/ppMergeCell.c

    r5860 r5862  
    11# include "ppMerge.h"
    2 
    3 // mask, bias, dark, flat are defined per Cell
    4 // pedestal is constructed for each readout, which may have different exposure times
    52
    63pmReadout *ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis) {
     
    1916}
    2017
    21 bool ppMergeCell (psArray *cellList, pmCell *maskCell, ppOptions *options, ppConfig *config) {
     18bool ppMergeCell (pmCell *outputCell, pmCell *maskCell, psArray *cellList, ppOptions *options, ppConfig *config) {
    2219
    2320    pmCell *sample = cellList->data[0];
    24     pmReadout *mask   = ppDetrendSelectFirst (maskCell, "mask", options->doMask);
     21    // pmReadout *mask = ppDetrendSelectFirst (maskCell, "mask", options->doMask);
     22
     23    // list to carry readouts for processing
     24    psArray *inputs = psArrayAlloc (cellList->n);
     25    inputs->n = 0;
     26
     27    psVector *combineZero = psVectorAlloc (128, PS_TYPE_F32);
     28    combineZero->n = 0;
     29
     30    psVector *combineScale = psVectorAlloc (128, PS_TYPE_F32);
     31    combineScale->n = 0;
     32
     33    int nVal = 0;
    2534
    2635    // push all readouts from each image onto the list
    2736    // not clear that this is the right process -- how to merge readouts?
    2837    // are all readouts from this cell equivalent? (ie, across images?)
    29     // XXX need to set / carry the zero,scale values
    30 
    31     readouts = psListAlloc ();
    32 
     38    // XXX need to set the zero,scale values correctly for each readout
    3339    for (int i = 0; i < cellList->n; i++) {
    3440        pmCell *cell = cellList->data[i];
    3541        for (int j = 0; j < cell->readouts->n; j++) {
    36             psListAdd (cell->readouts->data[j], PS_LIST_TAIL);
     42            psArrayAdd (inputs, 16, cell->readouts->data[j]);
     43
     44            combineZero->data.F32[nVal] = 0.0;
     45            combineScale->data.F32[nVal] = 1.0;
     46            psVectorExtend (combineZero, 100, 1);
     47            psVectorExtend (combineScale, 100, 1);
     48            nVal ++;
    3749        }
    3850    }
    3951
    40     // XXX : need to consider the output
    41    
    42     psImage *output = pmReadoutCombine (NULL, readouts, params,...);
     52    // XXX : need to assign these correctly
     53    float combineGain = 1.0;
     54    float combineNoise = 0.0;
    4355
     56    // XXX somehow need to transfer the input cell concepts to the
     57    //     the output cell.  this is weak: are the concepts fixed
     58    //     or not for a collection of images...
     59    outputCell->concepts = sample->concepts;
     60
     61    // XXX where is the output readouts array allocated?
     62    pmReadout *outputReadout = pmReadoutAlloc (outputCell);
     63    outputReadout->image = pmReadoutCombine (NULL, inputs,
     64                                             combineZero,
     65                                             combineScale,
     66                                             options->combineParams,
     67                                             options->applyZeroScale,
     68                                             combineGain, combineNoise);
    4469    return true;
    4570}
     71
     72
     73// XXX a psList does not make sense here: we are using the fixed length psVectors
     74//     to carry bzero and bscale, a psArray should be used for the images
  • trunk/ppMerge/src/ppMergeConfig.c

    r5860 r5862  
    1 # include "ppImage.h"
     1# include "ppMerge.h"
    22
    33bool ppMergeConfig (ppConfig *config, int argc, char **argv) {
     
    2020    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-zero",  0, "Name of the mask image", 0);
    2121    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-scale", 0, "Chip number to process (if positive)", 1);
     22    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-chip",  0, "Chip number to process (if positive)",-1);
    2223
    2324    if (! psArgumentParse(config->arguments, &argc, argv) || argc != 2) {
    2425        printf("\nPan-STARRS Phase 2 processing\n\n");
    25         printf("Usage: %s INPUT.fits OUTPUT.fits\n\n", argv[0]);
     26        printf("Usage: %s OUTPUT.fits\n\n", argv[0]);
    2627        psArgumentHelp(config->arguments);
    2728        psFree(config->arguments);
  • trunk/ppMerge/src/ppMergeLoop.c

    r5860 r5862  
    33bool ppMergeLoop (ppData *data, ppOptions *options, ppConfig *config) {
    44
    5     ppDetrend detrend;
    6 
    7     ppFPA *sampleFPA = data->input->data[0];
     5    char name[128];
     6    ppFPA *sample = data->input->data[0];
     7    pmFPA *sampleFPA = sample->fpa;
    88
    99    psArray *cellList = psArrayAlloc (data->input->n);
     
    2020    // iterate over all chips, using sampleFPA as reference
    2121    for (int i = 0; i < sampleFPA->chips->n; i++) {
     22        pmChip *maskChip = data->mask->fpa->chips->data[i]; // Chip of interest in input image
     23        pmChip *outputChip = data->output->fpa->chips->data[i]; // Chip of interest in input image
    2224        pmChip *sampleChip = sampleFPA->chips->data[i]; // Chip of interest in input image
    23         pmChip *maskChip = data->mask->fpa->chips->data[i]; // Chip of interest in input image
    2425        if (! sampleChip->valid) { continue; }
    2526
     
    3536        // iterate over all cells, using sampleChip as reference
    3637        for (int j = 0; j < sampleChip->cells->n; j++) {
     38            pmCell *maskCell = maskChip->cells->data[j];
     39            pmCell *outputCell = outputChip->cells->data[j];
    3740            pmCell *sampleCell = sampleChip->cells->data[j];
    38             pmCell *maskCell = maskChip->cells->data[j];
    3941            if (! sampleCell->valid) { continue; }
    4042
     
    5052            // build an array of the cells of interest
    5153            for (int k = 0; k < cellList->n; k++) {
    52                 pmFPA *thisFPA = data->input->data[k];
     54                ppFPA *thisFrame = data->input->data[k];
     55                pmFPA *thisFPA = thisFrame->fpa;
    5356                pmChip *thisChip = thisFPA->chips->data[i];
    5457                cellList->data[k] = thisChip->cells->data[j];
     
    5659
    5760            // run the merge function
    58             ppMergeCell (cellList, maskCell, options, config);
     61            ppMergeCell (outputCell, maskCell, cellList, options, config);
     62
     63            sprintf (name, "test.%d.%d.fits", i, j);
     64            psFits *fits = psFitsOpen (name, "w");
     65            pmReadout *readout = outputCell->readouts->data[0];
     66            psFitsWriteImage (fits, NULL, readout->image, 0);
     67            psFitsClose (fits);
     68
     69# if (0)
     70            if (sampleCell->hdu) {
     71                outputCell->hdu = sampleCell->hdu;
     72                outputCell->hdu->images = psArrayAlloc (1);
     73                outputCell->hdu->images->data[0] = outputCell->readouts->data[0];
     74            }
     75# endif
    5976        }
     77# if (0)       
     78        if (sampleChip->hdu) {
     79            outputChip->hdu = sampleChip->hdu;
     80            outputChip->hdu->images = psArrayAlloc (1);
     81            // outputChip->hdu->images->data[0] = outputChip->readouts->data[0];
     82        }
     83# endif
    6084    }
    6185    return true;
  • trunk/ppMerge/src/ppMergeOptions.c

    r5860 r5862  
    1 # include "ppImage.h"
     1# include "ppMerge.h"
    22
    33// XXX EAM : optionally choose the mask image based on the detrend database
     
    2626    }
    2727
    28     // how do we calculate the merge stack?
    29     options->mergeStats = NULL;
    30     psString stat = psMetadataLookupStr(NULL, config->recipe, "MERGE.STAT");
    31     if (! strcasecmp(stat, "MEAN")) {
    32       options->mergeStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    33     } else if (! strcasecmp(stat, "MEDIAN")) {
    34       options->mergeStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    35     } else {
    36       psErrorStackPrint(stderr, "MERGE.STAT (%s) is not one of MEAN, MEDIAN: assuming MEAN\n", stat);
    37       options->mergeStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    38     }
    39 
    40     // mask - recipe options
     28    // global pixel mask
     29    options->doMask = false;
    4130    if (psMetadataLookupBool(NULL, config->recipe, "MASK")) {
    4231        data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask");
     
    4938    }
    5039
     40    // how do we calculate the merge stack?
     41    psStatsOptions mergeStats = 0;
     42    psString stat = psMetadataLookupStr(NULL, config->recipe, "MERGE.STAT");
     43    if (! strcasecmp(stat, "MEAN")) {
     44        mergeStats = PS_STAT_SAMPLE_MEAN;
     45    } else if (! strcasecmp(stat, "MEDIAN")) {
     46        mergeStats = PS_STAT_SAMPLE_MEDIAN;
     47    } else {
     48        psAbort ("merge", "MERGE.STAT (%s) is not one of MEAN, MEDIAN\n", stat);
     49    }
     50    options->combineParams = pmCombineParamsAlloc (mergeStats);
     51
     52    // other merge stack options
     53    options->applyZeroScale = psMetadataLookupBool(NULL, config->recipe, "MERGE.RESCALE");
     54
     55    int nKeep = psMetadataLookupS32(&status, config->recipe, "MERGE.NKEEP");
     56    if (status && nKeep > 0) {
     57        options->combineParams->nKeep = nKeep;
     58    }
     59
     60    float fracHigh = psMetadataLookupF32(&status, config->recipe, "MERGE.FRAC.HIGH");
     61    if (status) {
     62        options->combineParams->fracHigh = fracHigh;
     63    }
     64
     65    float fracLow = psMetadataLookupF32(&status, config->recipe, "MERGE.FRAC.LOW");
     66    if (status) {
     67        options->combineParams->fracLow = fracLow;
     68    }
     69
     70    // XXX need to set the masking value somehow...
     71
     72    // gain and readnoise come from camera parameters and depend on chip/cell
     73    // XXX drop these from the options structure?
     74    options->gain = 1.0;
     75    options->readnoise = 0.0;
     76
    5177    return true;
    5278}
  • trunk/ppMerge/src/ppMergeParseCamera.c

    r5860 r5862  
    3838            ppFPA *fpa = ppFPA_Alloc ();
    3939            fpa->filename = psStringCopy (globList.gl_pathv[i]);
     40            psArrayAdd (input, 100, fpa);
    4041        }
    41         psArrayAdd (input, 100, fpa);
    4242    }
    4343
     
    5656        }
    5757        while (fgets (line, 1024, f) != NULL) {
    58             nItems = fscanf (f, "%s %lf %lf", filename, &zero, &scale);
    59             fpa = ppFPA_Alloc ();
     58            nItems = sscanf (line, "%s %lf %lf", filename, &zero, &scale);
     59            ppFPA *fpa = ppFPA_Alloc ();
    6060            switch (nItems) {
    6161              case 0:
     
    6565                fpa->zero  = zero;
    6666                fpa->scale = scale;
    67                 // NOTE: continues to case 1 below
     67                fpa->filename = psStringCopy (filename);
     68                psArrayAdd (input, 100, fpa);
     69                break;
    6870              case 1:
    6971                fpa->filename = psStringCopy (filename);
     
    8587
    8688    // Open the input images, test that they are the same camera
    87     psLogMsg("phase2", PS_LOG_INFO, "Opening input images\n");
     89    psLogMsg("merge", PS_LOG_INFO, "Opening input images\n");
    8890    for (int i = 0; i < input->n; i++) {
    8991       
    9092        ppFPA *fpa = input->data[i];
     93
     94        psLogMsg("merge", PS_LOG_INFO, "Trying %s...\n", fpa->filename);
    9195
    9296        fpa->fits = psFitsOpen(fpa->filename, "r"); // File handle for FITS file
     
    130134
    131135    // data->process acts as a process mask for the full FPA
    132     data->process = pmFPAConstruct(config->camera);
     136    data->process = ppFPA_Alloc ();
     137    data->process->fpa = pmFPAConstruct(config->camera);
    133138
    134139    // see if we have selected a specific chip
     
    144149    // data->mask carries a pixel mask for pixels to be ignored
    145150    // the name and contents of the mask are determined in ppMergeOptions
    146     data->mask = pmFPAConstruct(config->camera);
     151    data->mask = ppFPA_Alloc ();
     152    data->mask->fpa = pmFPAConstruct(config->camera);
     153
     154    // data->output will store the output file
     155    // currently, we keep the complete output file and write it at the end
     156    data->output = ppFPA_Alloc ();
     157    data->output->fpa = pmFPAConstruct(config->camera);
     158    data->output->filename = psMetadataLookupPtr (NULL, config->arguments, "-output");
     159    if (! *data->output->filename) {
     160        psAbort ("merge", "output file not specified");
     161    }
    147162
    148163    return true;
  • trunk/ppMerge/src/ppMergeParseDetrend.c

    r5860 r5862  
    1 # include "ppImage.h"
     1# include "ppMerge.h"
    22
    33// open all needed detrend files
Note: See TracChangeset for help on using the changeset viewer.