IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30037


Ignore:
Timestamp:
Dec 14, 2010, 4:02:26 PM (15 years ago)
Author:
bills
Message:

Fix nan values in jpeg images by using sample median for cell saturation values instead
of the minimum value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-20101206/psModules/src/concepts/pmConceptsAverage.c

    r29603 r30037  
    136136    return average;
    137137}
     138float medianWithDropouts (psList *sources, char *name) {
     139
     140    bool status;
     141
     142    psListIterator *sourcesIter = psListIteratorAlloc(sources, PS_LIST_HEAD, false); // Iterator for sources
     143    pmCell *cell = NULL;                // Source cell from iteration
     144
     145    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
     146    psVector *values = psVectorAlloc(sources->n, PS_TYPE_F32);
     147    int nvalues = 0;
     148    while ((cell = psListGetAndIncrement(sourcesIter))) {
     149        if (!cell) {
     150            continue;
     151        }
     152
     153        float value = psMetadataLookupF32(&status, cell->concepts, name);
     154        if (!status) continue;
     155        if (!isfinite(value)) continue;
     156
     157        values->data.F32[nvalues++] = value;
     158    }
     159    psFree (sourcesIter);
     160    if (!nvalues) {
     161        psWarning("no valid values found for %s\n", name);
     162        psFree(values);
     163        psFree(stats);
     164        return INFINITY;
     165    }
     166    if (!(values = psVectorRealloc(values, nvalues))) {
     167        psWarning("failed to reallocate values vector for %s\n", name);
     168        psFree(stats);
     169        return INFINITY;
     170    }
     171    if (!psVectorStats(stats, values, NULL, NULL, 0)) {
     172        psWarning("psVectorStats failed for %s\n", name);
     173        psFree(values);
     174        psFree(stats);
     175        return INFINITY;
     176    }
     177
     178    psF32 median = psStatsGetValue(stats, PS_STAT_SAMPLE_MEDIAN);
     179
     180    psFree(values);
     181    psFree(stats);
     182
     183    return median;
     184}
    138185
    139186// Set a variety of concepts in a cell by averaging over several
     
    145192    PS_ASSERT_INT_POSITIVE(sources->n, false);
    146193
    147     float saturation = INFINITY;        // Saturation level
    148194    float bad        = -INFINITY;       // Bad level
    149195    double time      = 0.0;             // Time of observation
     
    158204    float exposure  = averageWithDropouts (sources, "CELL.EXPOSURE");
    159205    float darktime  = averageWithDropouts (sources, "CELL.DARKTIME");
     206    float saturation = medianWithDropouts(sources, "CELL.SATURATION");
    160207
    161208    // other concepts are a bit more "special"
     
    221268        }
    222269
    223         float cellSaturation = psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION");
    224         if (cellSaturation > 10000) {
    225             // do not allow invalid values to polute this calculation
    226             // XXX really need to do this on the basis of the fraction of the cell that contributes..
    227             // if a cell is completely masked, it should not be included.
    228             if (cellSaturation < saturation) {
    229                 saturation = cellSaturation;
    230             }
    231         }
    232270        float cellBad = psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD");
    233271        if (cellBad > bad) {
Note: See TracChangeset for help on using the changeset viewer.