IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 15, 2006, 8:30:16 AM (21 years ago)
Author:
eugene
Message:

API cleanup, removed old test files, some re-organization, changed FLT/GAL to EXT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotApResid.c

    r5980 r5993  
    11# include "psphot.h"
    2 
    3 psPolynomial4D *psVectorChiClipFitPolynomial4D(
    4     psPolynomial4D *poly,
    5     psStats *stats,
    6     const psVector *mask,
    7     psMaskType maskValue,
    8     const psVector *f,
    9     const psVector *fErr,
    10     const psVector *x,
    11     const psVector *y,
    12     const psVector *z,
    13     const psVector *t)
    14 {
    15     PS_ASSERT_POLY_NON_NULL(poly, NULL);
    16     PS_ASSERT_POLY_TYPE(poly, PS_POLYNOMIAL_ORD, NULL);
    17     PS_ASSERT_PTR_NON_NULL(stats, NULL);
    18     PS_ASSERT_VECTOR_NON_NULL(f, NULL);
    19     PS_ASSERT_VECTOR_TYPE_F32_OR_F64(f, NULL);
    20     if (mask != NULL) {
    21         PS_ASSERT_VECTORS_SIZE_EQUAL(f, mask, NULL);
    22         PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, NULL);
    23     }
    24     PS_ASSERT_VECTOR_NON_NULL(x, NULL);
    25     PS_ASSERT_VECTORS_SIZE_EQUAL(f, x, NULL);
    26     PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, NULL);
    27     PS_ASSERT_VECTOR_NON_NULL(y, NULL);
    28     PS_ASSERT_VECTORS_SIZE_EQUAL(f, y, NULL);
    29     PS_ASSERT_VECTOR_TYPE_F32_OR_F64(y, NULL);
    30     PS_ASSERT_VECTOR_NON_NULL(z, NULL);
    31     PS_ASSERT_VECTORS_SIZE_EQUAL(f, z, NULL);
    32     PS_ASSERT_VECTOR_TYPE_F32_OR_F64(z, NULL);
    33     PS_ASSERT_VECTOR_NON_NULL(t, NULL);
    34     PS_ASSERT_VECTORS_SIZE_EQUAL(f, t, NULL);
    35     PS_ASSERT_VECTOR_TYPE_F32_OR_F64(t, NULL);
    36     PS_ASSERT_VECTOR_NON_NULL(fErr, NULL);
    37     PS_ASSERT_VECTORS_SIZE_EQUAL(fErr, mask, NULL);
    38     PS_ASSERT_VECTOR_TYPE_F32_OR_F64(fErr, NULL);
    39 
    40     // clipping range defined by min and max and/or clipSigma
    41     float minClipSigma;
    42     float maxClipSigma;
    43     if (isfinite(stats->max)) {
    44         maxClipSigma = +fabs(stats->max);
    45     } else {
    46         maxClipSigma = +fabs(stats->clipSigma);
    47     }
    48     if (isfinite(stats->min)) {
    49         minClipSigma = -fabs(stats->min);
    50     } else {
    51         minClipSigma = -fabs(stats->clipSigma);
    52     }
    53     psVector *fit   = NULL;
    54     psVector *resid = psVectorAlloc (x->n, PS_TYPE_F64);
    55 
    56     // eventual expansion: user supplies one of various stats option pairs,
    57     // eg (SAMPLE_MEAN | SAMPLE_STDEV) and the correct pair is used to
    58     // evaluate the clipping sigma
    59     // for now, for the SAMPLE_MEDIAN and SAMPLE_STDEV to be used
    60     stats->options |= (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
    61 
    62     for (int N = 0; N < stats->clipIter; N++) {
    63         int Nkeep = 0;
    64 
    65         poly = psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t);
    66         fit = psPolynomial4DEvalVector (poly, x, y, z, t);
    67         resid = (psVector *) psBinaryOp (resid, (void *) f, "-", (void *) fit);
    68 
    69         stats  = psVectorStats (stats, resid, NULL, mask, maskValue);
    70         psTrace (".psphot.VectorClipFit", 5, "resid stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
    71 
    72         // set mask if pts are not valid
    73         // we are masking out any point which is out of range
    74         // recovery is not allowed with this scheme
    75         for (int i = 0; i < resid->n; i++) {
    76             if ((mask != NULL) && (mask->data.U8[i] & maskValue)) {
    77                 continue;
    78             }
    79             float sigma = hypot (psVectorGet (fErr, i), stats->sampleStdev);
    80             if (resid->data.F64[i] - stats->sampleMedian > sigma*maxClipSigma) {
    81                 if (mask != NULL) {
    82                     mask->data.U8[i] |= 0x01;
    83                 }
    84                 continue;
    85             }
    86             if (resid->data.F64[i] - stats->sampleMedian < sigma*minClipSigma) {
    87                 if (mask != NULL) {
    88                     mask->data.U8[i] |= 0x01;
    89                 }
    90                 continue;
    91             }
    92             Nkeep ++;
    93         }
    94 
    95         psTrace (".psphot.VectorClipFit", 4, "keeping %d of %d pts for fit\n",
    96                  Nkeep, x->n);
    97 
    98         stats->clippedNvalues = Nkeep;
    99         psFree (fit);
    100     }
    101     // Free local temporary variables
    102     psFree (resid);
    103 
    104     if (poly == NULL) {
    105         psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data.  Returning NULL.\n");
    106         return(NULL);
    107     }
    108     return(poly);
    109 }
    1102
    1113// measure the aperture residual statistics
     
    347239    psf->nApResid = residStats->clippedNvalues;
    348240
    349     /*
    350       (aprMag' - fitMag) = rflux*skyBias + ApTrend(x,y)
    351       (aprMag - rflux*skyBias) - fitMag = ApTrend(x,y)
    352       (aprMag - rflux*skyBias) = fitMag + ApTrend(x,y)
    353     */
     241    // save results for later output
     242    psMetadataAdd (config, PS_LIST_TAIL, "SKYBIAS",  PS_DATA_F32 | PS_META_REPLACE, "aperture sky bias",   psf->skyBias);
     243    psMetadataAdd (config, PS_LIST_TAIL, "SKYSAT",   PS_DATA_F32 | PS_META_REPLACE, "aperture sky bias",   psf->skySat);
     244    psMetadataAdd (config, PS_LIST_TAIL, "APMIFIT",  PS_DATA_F32 | PS_META_REPLACE, "aperture residual",   psf->ApResid);
     245    psMetadataAdd (config, PS_LIST_TAIL, "DAPMIFIT", PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", psf->dApResid);
     246    psMetadataAdd (config, PS_LIST_TAIL, "APLOSS",   PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", psf->growth->apLoss);
     247    psMetadataAdd (config, PS_LIST_TAIL, "NAPMIFIT", PS_DATA_S32 | PS_META_REPLACE, "ap residual scatter", psf->nApResid);
    354248
    355249    psLogMsg ("psphot.apresid", 3, "measure full-frame aperture residual: %f sec\n", psTimerMark ("psphot"));
     
    370264}
    371265
     266/*
     267  (aprMag' - fitMag) = rflux*skyBias + ApTrend(x,y)
     268  (aprMag - rflux*skyBias) - fitMag = ApTrend(x,y)
     269  (aprMag - rflux*skyBias) = fitMag + ApTrend(x,y)
     270*/
     271
Note: See TracChangeset for help on using the changeset viewer.