IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 7, 2005, 2:57:14 PM (21 years ago)
Author:
Paul Price
Message:

Importing from PAP cvs tree again. This will now be the working tree.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/stac/src/stacScales.c

    r3673 r5743  
    1414    assert(image->type.type == PS_TYPE_F32);
    1515
    16 // Will use robust median instead of sampling --- it's supposed to be fast.
    1716#if 1
    1817    int size = image->numCols * image->numRows; // Number of pixels in image
    1918    int numSamples = size / sample;     // Number of samples in image
    2019    psVector *values = psVectorAlloc(numSamples + 1, PS_TYPE_F32); // Vector containing sub-sample
     20    psVector *mask = psVectorAlloc(numSamples + 1, PS_TYPE_U8); // Mask for sample
    2121
    2222    int offset = 0;                     // Offset from start of the row
     
    2727        while (col < image->numCols) {
    2828            values->data.F32[index] = image->data.F32[row][col];
     29            if (isnan(values->data.F32[index])) {
     30                mask->data.U8[index] = 1;
     31            } else {
     32                mask->data.U8[index] = 0;
     33            }
    2934            col += sample;
    3035            index++;
     
    3439
    3540    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    36     stats = psVectorStats(stats, values, NULL, NULL, 0);
     41    stats = psVectorStats(stats, values, NULL, mask, 1);
    3742    float median = stats->sampleMedian;
    3843    psFree(stats);
    3944    psFree(values);
     45    psFree(mask);
    4046#else
     47    // Will use robust median instead of sampling --- it's supposed to be fast.
    4148    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Using a clipped mean because median is SLOW
    4249    stats->clipSigma = 3.0;
     
    162169                        }
    163170                    }
    164                     psTrace("stac.scales", 9, "Star at %f,%f --> %f\n", coords->x, coords->y, sum);
    165171                    // Subtract background, renormalise to account for circular aperture
    166172                    if (numPix > 0 && sum > 0) {
    167173                        sum -= offsets->data.F32[i] * (float)numPix;
    168174                        photometry->data.F32[j] = sum * M_PI * aper2 / (float)numPix;
     175                        if (photometry->data.F32[j] > 0 && finite(photometry->data.F32[j])) {
     176                            mask->data.U8[j] = 1;
     177                            psTrace("stac.scales", 8, "Star at %f,%f --> %f\n", coords->x, coords->y, sum);
     178                        } else {
     179                            mask->data.U8[j] = 0;
     180                        }
     181                    } else {
    169182                        mask->data.U8[j] = 0;
    170                     } else {
    171                         mask->data.U8[j] = 1;
    172183                    }
    173184                }
     
    182193        psVector *ref = stars->data[0]; // The reference photometry
    183194        psVector *refMask = masks->data[0]; // The reference mask
     195#if 0
    184196        psStats *stats = psStatsAlloc(PS_STAT_CLIPPED_MEAN); // Statistics
    185197        stats->clipSigma = 2.5;
    186198        stats->clipIter = 3;
     199#else
     200        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); // Statistics
     201#endif
    187202        for (int i = 1; i < scales->n; i++) {
    188             psVector *compare = stars->data[i]; // The comparison photometry
    189             psVector *compareMask = masks->data[i]; // The comparison mask
    190 
    191             compare = (psVector*)psBinaryOp(compare, compare, "/", ref);
    192             compareMask = (psVector*)psBinaryOp(compareMask, compareMask, "+", refMask);
    193 
    194             stats = psVectorStats(stats, compare, NULL, compareMask, 3); // Use maskVal of 3 to catch 1 and 2
    195 
     203            psVector *input = stars->data[i];   // The comparison photometry
     204            psVector *inputMask = masks->data[i]; // The comparison mask
     205
     206            psVector *compare = (psVector*)psBinaryOp(NULL, input, "/", ref);
     207            psVector *compareMask = (psVector*)psBinaryOp(NULL, inputMask, "*", refMask);
     208            (void)psBinaryOp(compareMask, psScalarAlloc(1, PS_TYPE_U8), "-", compareMask);
     209
     210#if 0
     211            psTrace("stac.scales", 9, "Getting scale for image %d...\n", i);
     212            for (int j = 0; j < compare->n; j++) {
     213                if (compareMask->data.U8[j] & 1) {
     214                    psTrace("stac.scales", 9, "Bad star %d: %f %f --> %f %d\n", j, input->data.F32[j],
     215                            ref->data.F32[j], compare->data.F32[j], compareMask->data.U8[j]);
     216                } else {
     217                    psTrace("stac.scales", 9, "Good star %d: %f %f --> %f %d\n", j, input->data.F32[j],
     218                            ref->data.F32[j], compare->data.F32[j], compareMask->data.U8[j]);
     219                }
     220            }
     221#endif
     222
     223            psVectorStats(stats, compare, NULL, compareMask, 1);
     224
     225#if 0
    196226            scales->data.F32[i] = stats->clippedMean;
     227#else
     228            scales->data.F32[i] = stats->sampleMedian;
     229#endif
    197230            psTrace("stac.scales", 5, "Scale for image %d is %f\n", i, scales->data.F32[i]);
     231            psFree(compare);
     232            psFree(compareMask);
    198233        }
    199234        psFree(stats);
Note: See TracChangeset for help on using the changeset viewer.