IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20596


Ignore:
Timestamp:
Nov 8, 2008, 2:30:32 PM (18 years ago)
Author:
eugene
Message:

some values are not found in all cell: average only existing entries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/concepts/pmConceptsAverage.c

    r20576 r20596  
    102102}
    103103
     104float averageWithDropouts (psList *sources, char *name) {
     105
     106    bool status;
     107
     108    float sum = 0;
     109    int nCells = 0;                     // Number of cells;
     110    psListIterator *sourcesIter = psListIteratorAlloc(sources, PS_LIST_HEAD, false); // Iterator for sources
     111    pmCell *cell = NULL;                // Source cell from iteration
     112    while ((cell = psListGetAndIncrement(sourcesIter))) {
     113        if (!cell) {
     114            continue;
     115        }
     116
     117        float value = psMetadataLookupF32(&status, cell->concepts, name);
     118        if (!status) continue;
     119        if (!isfinite(value)) continue;
     120
     121        sum += value;
     122        nCells++;
     123    }
     124    psFree (sourcesIter);
     125
     126    float average = sum / nCells;
     127    return average;
     128}
    104129
    105130// Set a variety of concepts in a cell by averaging over several
     
    111136    PS_ASSERT_INT_POSITIVE(sources->n, false);
    112137
    113     float gain       = 0.0;             // Gain
    114     float readnoise  = 0.0;             // Read noise
    115138    float saturation = INFINITY;        // Saturation level
    116139    float bad        = -INFINITY;       // Bad level
    117     float exposure   = 0.0;             // Exposure time
    118     float darktime   = 0.0;             // Dark time
    119140    double time      = 0.0;             // Time of observation
    120141    psTimeType timeSys = 0;             // Time system
     
    124145    int xParity = 0, yParity = 0;       // Parity
    125146
     147    float gain      = averageWithDropouts (sources, "CELL.GAIN");
     148    float readnoise = averageWithDropouts (sources, "CELL.READNOISE");
     149    float exposure  = averageWithDropouts (sources, "CELL.EXPOSURE");
     150    float darktime  = averageWithDropouts (sources, "CELL.DARKTIME");
     151
     152    // other concepts are a bit more "special"
    126153    int nCells = 0;                     // Number of cells;
    127154    psListIterator *sourcesIter = psListIteratorAlloc(sources, PS_LIST_HEAD, false); // Iterator for sources
     
    133160
    134161        nCells++;
    135         gain       += psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN");
    136         readnoise  += psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE");
    137         exposure   += psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE");
    138         darktime   += psMetadataLookupF32(NULL, cell->concepts, "CELL.DARKTIME");
    139162        psTime *cellTime = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TIME");
    140163        time       += psTimeToMJD(cellTime);
     
    200223    psFree(sourcesIter);
    201224
    202     gain      /= (float)nCells;
    203     readnoise /= (float)nCells;
    204     exposure  /= (float)nCells;
    205     darktime  /= (float)nCells;
    206     time      /= (double)nCells;
     225    time /= nCells;
    207226
    208227    MD_UPDATE(target->concepts, "CELL.GAIN", F32, gain);
Note: See TracChangeset for help on using the changeset viewer.