IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25309


Ignore:
Timestamp:
Sep 9, 2009, 2:30:43 PM (17 years ago)
Author:
Paul Price
Message:

Instrumenting with debugging information.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap/psphot/src/psphotFake.c

    r25302 r25309  
    33#define MODEL_MASK (PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE | \
    44                    PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_LIMITS) // Mask to apply to models
     5
     6#define TESTING
    57
    68
     
    180182
    181183    float smoothSigma = 0.5*(fwhmMajor + fwhmMinor) / (2.0*sqrtf(2.0*log(2.0))); // Gaussian smoothing sigma
     184    int numCols = readout->image->numCols, numRows = readout->image->numRows; // Size of image
    182185
    183186    psImageMaskType maskVal = psMetadataLookupImageMask(NULL, recipe, "MASK.PSPHOT"); // Value to mask
     
    186189    psphotRemoveAllSources(realSources, recipe);
    187190    //    psphotAddNoise(readout, realSources, recipe);
     191
     192
     193
     194    {
     195        psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
     196        for (int y = 0; y < numRows; y++) {
     197            for (int x = 0; x < numCols; x++) {
     198                readout->image->data.F32[y][x] = psRandomGaussian(rng);
     199                readout->variance->data.F32[y][x] = 1.0;
     200                readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = 0;
     201            }
     202        }
     203        psFree(readout->covariance);
     204        readout->covariance = NULL;
     205        psFree(rng);
     206    }
     207
     208
     209
    188210
    189211    float magLim;                       // Guess at limiting magnitude
     
    193215        return false;
    194216    }
     217
     218#ifdef TESTING
     219    psphotSaveImage(NULL, readout->image, "orig_image.fits");
     220    psphotSaveImage(NULL, readout->variance, "orig_variance.fits");
     221    psphotSaveImage(NULL, readout->mask, "orig_mask.fits");
     222#endif
    195223
    196224    psImage *xFake = NULL, *yFake = NULL; // Coordinates of sources, each bin in a row
     
    201229        return false;
    202230    }
     231
     232#ifdef TESTING
     233    psphotSaveImage(NULL, readout->image, "fake_image.fits");
     234    psphotSaveImage(NULL, readout->variance, "fake_variance.fits");
     235    psphotSaveImage(NULL, readout->mask, "fake_mask.fits");
     236#endif
    203237
    204238    // XXX Could speed this up significantly by only convolving the central pixels of each fake source
     
    211245    }
    212246
     247#ifdef TESTING
     248    psphotSaveImage(NULL, readout->mask, "fake_sig.fits");
     249#endif
     250
    213251    thresh *= thresh;                   // Significance image is actually significance-squared
    214252
    215253    int numBins = magOffsets->n;                          // Number of bins
    216     int numCols = readout->image->numCols, numRows = readout->image->numRows; // Size of image
    217254    psVector *count = psVectorAlloc(numBins, PS_TYPE_S32); // Number of sources found in each bin
    218255    psArray *fakeSources = psArrayAllocEmpty(numSources * numBins); // Fake sources
     
    221258    for (int i = 0; i < numBins; i++) {
    222259        int num = 0;               // Number found
     260
    223261        for (int j = 0; j < numSources; j++) {
    224262            // Coordinates of interest
     
    269307    psVector *magErrMean = psVectorAlloc(numBins, PS_TYPE_F32); // Mean error in magnitude for each bin
    270308    psVector *magErrStdev = psVectorAlloc(numBins, PS_TYPE_F32); // Stdev of error in magnitude for each bin
     309    psVector *magErrErrMean = psVectorAlloc(numBins, PS_TYPE_F32); // Mean error in magnitude for each bin
    271310    psVector *magErr = psVectorAlloc(numSources, PS_TYPE_F32);   // Magnitude errors
     311    psVector *magErrErr = psVectorAlloc(numSources, PS_TYPE_F32); // Error in magnitude error
    272312    psVector *magMask = psVectorAlloc(numSources, PS_TYPE_VECTOR_MASK); // Mask for magnitude errors
    273     psStats *magStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); // Statistics
     313    psStats *magStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV | PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics
     314    psVector *robustMedian = psVectorAlloc(numBins, PS_TYPE_F32);
     315    psVector *robustStdev = psVectorAlloc(numBins, PS_TYPE_F32);
    274316    for (int i = 0, index = 0; i < numBins; i++) {
    275317        psStatsInit(magStats);
    276318        psVectorInit(magMask, 0);
    277319
     320        psString name = NULL;
     321        psStringAppend(&name, "fake_%d.dat", i);
     322        FILE *file = fopen(name, "w");
     323
    278324        float magRef = magLim + magOffsets->data.F32[i]; // Reference magnitude
    279         for (int j = 0; index < fakeEnd->data.S32[i]; j++, index++) {
     325        int j;                          // Index
     326        for (j = 0; index < fakeEnd->data.S32[i]; j++, index++) {
    280327            pmSource *source = fakeSources->data[index]; // Source of interest
    281328            if (!source || !isfinite(source->psfMag)) {
     
    283330                continue;
    284331            }
     332
     333            fprintf(file, "%f %f %f %f %f\n", source->peak->xf, source->peak->yf,
     334                    magRef, source->psfMag, source->errMag);
    285335            magErr->data.F32[j] = source->psfMag - magRef;
    286         }
     336            magErrErr->data.F32[j] = source->errMag;
     337        }
     338        magErr->n = j;
     339        magMask->n = j;
    287340        if (!psVectorStats(magStats, magErr, NULL, magMask, 0xFF)) {
    288341            // Probably because we don't have enough sources
     
    291344        magErrMean->data.F32[i] = magStats->sampleMean;
    292345        magErrStdev->data.F32[i] = magStats->sampleStdev;
    293     }
     346        robustMedian->data.F32[i] = magStats->robustMedian;
     347        robustStdev->data.F32[i] = magStats->robustStdev;
     348        if (!psVectorStats(magStats, magErrErr, NULL, magMask, 0xFF)) {
     349            // Probably because we don't have enough sources
     350            psErrorClear();
     351        }
     352        magErrErrMean->data.F32[i] = magStats->sampleMean;
     353        fclose(file);
     354    }
     355
     356
    294357    psFree(magStats);
    295358    psFree(magMask);
     
    313376    psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.RMS", PS_META_REPLACE,
    314377                        "Stdev in magnitude differences", magErrStdev);
     378    psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.RM", PS_META_REPLACE,
     379                        "Robust median magnitude differences", robustMedian);
     380    psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.RS", PS_META_REPLACE,
     381                        "Robust stdev in magnitude differences", robustStdev);
     382    psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.MEANERR", PS_META_REPLACE,
     383                        "Mean error in magnitude differences", magErrErrMean);
    315384    psMetadataConfigWrite(stats, "fake.stats");
    316385    psFree(stats);
     
    320389    psFree(magErrStdev);
    321390
     391    psFree(robustMedian);
     392    psFree(robustStdev);
     393
    322394    return true;
    323395}
Note: See TracChangeset for help on using the changeset viewer.