IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 4, 2005, 5:22:13 PM (21 years ago)
Author:
eugene
Message:

running sources in brightness order, using a mask

File:
1 edited

Legend:

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

    r4114 r4115  
    3636    test->metricStats = NULL;
    3737    test->metric      = psVectorAlloc (sources->n, PS_TYPE_F64);
     38    test->mask        = psVectorAlloc (sources->n, PS_TYPE_U8);
    3839
    3940    for (int i = 0; i < test->modelFLT->n; i++) {
    4041        test->modelFLT->data[i] = NULL;
    4142        test->modelPSF->data[i] = NULL;
     43        test->mask->data.U8[i]  = 0;
    4244    }   
    4345    return (test);
     
    5759        psModel  *model  = pmSourceModelGuess (source, test->modelType);
    5860
    59         // fit model as FLT, not PSF (skip poor fits)
    60         if (!pmSourceFitModel (source, model, false)) continue;
     61        // fit model as FLT, not PSF (mask & skip poor fits)
     62        if (!pmSourceFitModel (source, model, false)) {
     63          test->mask->data.U8[i] = 1;
     64          continue;
     65        }
    6166        test->modelFLT->data[i] = model;
    6267        Nflt ++;
     
    6671
    6772    // stage 2: construct a psf (pmPSF) from this collection of model fits
    68     pmPSFFromModels (test->psf, test->modelFLT);
     73    pmPSFFromModels (test->psf, test->modelFLT, test->mask);
    6974
    7075    // stage 3: refit with fixed shape parameters
     
    7378        psSource *source = test->sources->data[i];
    7479        psModel  *modelFLT = test->modelFLT->data[i];
    75         if (modelFLT == NULL) continue;
     80
     81        // masked for: bad model fit, outlier in parameters
     82        if (test->mask->data.U8[i]) continue;
     83        if (modelFLT == NULL) {
     84          psLogMsg ("psphot.psftest", 2, "programming error: missing model not masked\n");
     85          continue;
     86        }
    7687        psModel  *modelPSF = psModelFromPSF (modelFLT, test->psf); // set shape for this model
    7788
    7889        // fit model as PSF, not FLT (skip poor fits)
    79         if (!pmSourceFitModel (source, modelPSF, true)) continue;
     90        if (!pmSourceFitModel (source, modelPSF, true)) {
     91          test->mask->data.U8[i] = 1;
     92          continue;
     93        }
    8094        test->modelPSF->data[i] = modelPSF;
    8195        Npsf ++;
     
    92106        float fitSum = 0;
    93107     
     108        // is this metricMask redundant with test->mask ?
    94109        metricMask->data.U8[i] = 1;
    95110        test->metric->data.F64[i] = 0;
    96111
     112        if (test->mask->data.U8[i]) continue;
     113
    97114        psModel *model = test->modelPSF->data[i];
    98         if (model == NULL) continue;
     115        if (model == NULL) {
     116          psLogMsg ("psphot.psftest", 2, "programming error: missing model not masked\n");
     117          continue;
     118        }
    99119
    100120        psImage *image = ((psSource *)test->sources->data[i])->pixels;
    101121        psImage *mask  = ((psSource *)test->sources->data[i])->mask;
    102122
     123        // this metric is Ap-Fit
    103124        float sky = model->params->data.F32[0];
    104 
    105125        for (int ix = 0; ix < image->numCols; ix++) {
    106126            for (int iy = 0; iy < image->numRows; iy++) {
     
    110130            }
    111131        }
    112         // this metric is Ap-Fit
    113132        // fprintf (stderr, "%d %f %f  %f\n", i, obsSum, fitSum, test->metric->data.F64[i]);
     133        // keep the good metrics
    114134        if ((fitSum > 0) && (obsSum > 0)) {
    115135            metricMask->data.U8[i] = 0;
    116136            test->metric->data.F64[i] = -2.5*log10(obsSum/fitSum);
    117         }       
     137        } else {
     138          test->mask->data.U8[i] = 1;
     139        }
    118140    }
    119141
     
    128150// input: an array of psModels, pre-allocated psf
    129151// some of the array entries may be NULL, ignore them
    130 bool pmPSFFromModels (pmPSF *psf, psArray *models) {
     152bool pmPSFFromModels (pmPSF *psf, psArray *models, psVector *mask) {
    131153
    132154    int n;
    133155
    134     // construct the x and y vectors from the collection of objects
    135     // count the number of valid model measurements
     156    // construct the fit vectors from the collection of objects
     157    // use the mask to ignore missing fits
    136158    psVector *x = psVectorAlloc (models->n, PS_TYPE_F64);
    137159    psVector *y = psVectorAlloc (models->n, PS_TYPE_F64);
    138     n = 0;
     160    psVector *z = psVectorAlloc (models->n, PS_TYPE_F64);
     161    psVector *dz = psVectorAlloc (models->n, PS_TYPE_F64);
     162
    139163    for (int i = 0; i < models->n; i++) {
    140164        psModel *model = models->data[i];
     
    142166
    143167        // XXX EAM : this is fragile: x and y must be stored consistently at 2,3
    144         x->data.F64[n] = model->params->data.F32[2];
    145         y->data.F64[n] = model->params->data.F32[3];
    146         n++;
    147     }
    148     x->n = y->n = n;
     168        x->data.F64[i] = model->params->data.F32[2];
     169        y->data.F64[i] = model->params->data.F32[3];
     170    }
    149171
    150172    // we are doing a robust fit.  after each pass, we drop points which are
    151     // more deviant than three sigma.
    152     psVector *z = psVectorAlloc (x->n, PS_TYPE_F64);
    153     psVector *dz = psVectorAlloc (x->n, PS_TYPE_F64);
     173    // more deviant than three sigma. 
     174    // mask is currently updated for each pass. this is inconsistent
     175
    154176    for (int i = 0; i < psf->params->n; i++) {
    155         n = 0;
    156177        for (int j = 0; j < models->n; j++) {
    157178            psModel *model = models->data[j];
    158179            if (model == NULL) continue;
    159             z->data.F64[n] = model->params->data.F32[i + 4];
    160             dz->data.F64[n] = 1;
    161             n++;
     180            z->data.F64[j] = model->params->data.F32[i + 4];
     181            dz->data.F64[j] = 1;
    162182            // XXX EAM : need to use actual errors?
    163183            // XXX EAM : this is fragile: psf(Nparams) = model(Nparams) - 4
    164184        }
    165         if (n != x->n) psAbort ("pmPSFFromModels", "programming error: mismatched number of NULL models\n");
    166         z->n = n;
    167         dz->n = n;
    168 
    169         psf->params->data[i] = RobustFit2D (psf->params->data[i], x, y, z, dz);
     185        // if (n != x->n) psAbort ("pmPSFFromModels", "programming error: mismatched number of NULL models\n");
     186
     187        psf->params->data[i] = RobustFit2D (psf->params->data[i], mask, x, y, z, dz);
    170188        // psPolynomial2DDump (psf->params->data[i]);
    171189    }
Note: See TracChangeset for help on using the changeset viewer.