IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31926


Ignore:
Timestamp:
Jul 22, 2011, 5:08:37 PM (15 years ago)
Author:
eugene
Message:

allow pcm fitting with a 1d gauss instead of full convolution

Location:
branches/eam_branches/ipp-20110710/psModules/src/objects
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110710/psModules/src/objects/pmPCM_MinimizeChisq.c

    r29012 r31926  
    4545# define USE_FFT 1
    4646# define PRE_CONVOLVE 1
     47# define TESTCOPY 0
    4748
    4849bool pmPCM_MinimizeChisq (
     
    9394        psFree (pcm->psfFFT);
    9495    }
    95     pcm->psfFFT = psImageConvolveKernelInit(pcm->modelFlux, pcm->psf);
     96# if (!TESTCOPY)
     97    if (!pcm->use1Dgauss) {
     98        pcm->psfFFT = psImageConvolveKernelInit(pcm->modelFlux, pcm->psf);
     99    }
     100# endif
    96101# endif   
    97102
     
    309314# if (PRE_CONVOLVE)
    310315    // convolve model image and derivative images with pre-convolved kernel
    311     psImageConvolveKernel (pcm->modelConvFlux, pcm->modelFlux, NULL, 0, pcm->psfFFT);
     316
     317// XXX for a test, just copy, rather than convolve
     318# if (TESTCOPY)
     319    psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type);
     320# else
     321    if (pcm->use1Dgauss) {
     322        // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
     323        // * the model flux is not masked
     324        // * threading takes place above this level
     325        pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type);
     326        psImageSmooth (pcm->modelConvFlux, pcm->sigma, pcm->nsigma);
     327    } else {
     328        psImageConvolveKernel (pcm->modelConvFlux, pcm->modelFlux, NULL, 0, pcm->psfFFT);
     329    }
     330# endif
     331
    312332    for (int n = 0; n < pcm->dmodelsFlux->n; n++) {
    313333        if (pcm->dmodelsFlux->data[n] == NULL) continue;
     
    315335        psImage *dmodel = pcm->dmodelsFlux->data[n];
    316336        psImage *dmodelConv = pcm->dmodelsConvFlux->data[n];
    317         psImageConvolveKernel (dmodelConv, dmodel, NULL, 0, pcm->psfFFT);
     337# if (TESTCOPY)
     338        psImageCopy (dmodelConv, dmodel, dmodel->type.type);
     339# else
     340        if (pcm->use1Dgauss) {
     341            // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
     342            // * the model flux is not masked
     343            // * threading takes place above this level
     344            dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type);
     345            psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma);
     346        } else {
     347            psImageConvolveKernel (dmodelConv, dmodel, NULL, 0, pcm->psfFFT);
     348        }
     349# endif
    318350    }
    319351# else
     
    325357        psImage *dmodel = pcm->dmodelsFlux->data[n];
    326358        psImage *dmodelConv = pcm->dmodelsConvFlux->data[n];
    327         psImageConvolveFFT (dmodelConv, dmodel, NULL, 0, pcm->psf);
     359
     360        if (pcm->use1Dgauss) {
     361            // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
     362            // * the model flux is not masked
     363            // * threading takes place above this level
     364            dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type);
     365            psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma);
     366        } else {
     367            psImageConvolveFFT (dmodelConv, dmodel, NULL, 0, pcm->psf);
     368        }
    328369    }
    329370# endif // PRE-CONVOLVE
  • branches/eam_branches/ipp-20110710/psModules/src/objects/pmPCMdata.c

    r31451 r31926  
    4141#include "pmPCMdata.h"
    4242
     43# define USE_DELTA_PSF 0
     44# define USE_1D_GAUSS 1
     45
    4346static void pmPCMdataFree (pmPCMdata *pcm) {
    4447
     
    8891    pcm->constraint = NULL;
    8992    pcm->nDOF = 0;
     93
     94    // full convolution with the PSF is expensive.  if we have to save time, we can do a 1D
     95    // convolution with a Gaussian approximation to the kernel
     96    pcm->use1Dgauss = false;
     97    pcm->nsigma = 3.0;
     98    pcm->sigma = 1.0; // this should be set to something sensible when the psf is known
    9099
    91100    return pcm;
     
    257266    pcm->nDOF = nPix - nParams;
    258267
     268# if (USE_1D_GAUSS)
     269    pmModel *modelPSF = source->modelPSF;
     270    psAssert (modelPSF, "psf model must be defined");
     271   
     272    psEllipseShape shape;
     273    psEllipseAxes axes;
     274
     275    shape.sx  = modelPSF->params->data.F32[PM_PAR_SXX];
     276    shape.sy  = modelPSF->params->data.F32[PM_PAR_SYY];
     277    shape.sxy = modelPSF->params->data.F32[PM_PAR_SXY];
     278    axes = psEllipseShapeToAxes (shape, 20.0);
     279   
     280    float FWHM_MAJOR = 2*modelPSF->modelRadius (modelPSF->params, 0.5*modelPSF->params->data.F32[PM_PAR_I0]);
     281    float FWHM_MINOR = FWHM_MAJOR * (axes.minor / axes.major);
     282
     283    pcm->use1Dgauss = true;
     284    pcm->sigma = 0.5 * (FWHM_MAJOR + FWHM_MINOR) / 2.35;
     285    pcm->nsigma = 2.0;
     286# endif
     287
    259288    return pcm;
    260289}
  • branches/eam_branches/ipp-20110710/psModules/src/objects/pmPCMdata.h

    r31153 r31926  
    3535    int nPar;
    3636    int nDOF;
     37
     38    bool use1Dgauss;
     39    float sigma;
     40    float nsigma;
    3741} pmPCMdata;
    3842
  • branches/eam_branches/ipp-20110710/psModules/src/objects/pmSourceFitPCM.c

    r31153 r31926  
    5050bool pmSourceFitPCM (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
    5151   
     52    psTimerStart ("pmSourceFitPCM");
     53
    5254    psVector *params  = pcm->modelConv->params;
    5355    psVector *dparams  = pcm->modelConv->dparams;
     
    6466    psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
    6567
     68    float t1 = psTimerMark ("pmSourceFitPCM");
     69
    6670    bool fitStatus = pmPCM_MinimizeChisq (myMin, covar, params, source, pcm);
     71    float t2 = psTimerMark ("pmSourceFitPCM");
     72
    6773    for (int i = 0; i < dparams->n; i++) {
    6874        if ((pcm->constraint->paramMask != NULL) && pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])
     
    7682    }
    7783    psTrace ("psphot", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value);
     84    float t3 = psTimerMark ("pmSourceFitPCM");
    7885
    7986    // renormalize output model image (generated by fitting process)
     
    97104        pmSourceChisqUnsubtracted (source, pcm->modelConv, maskVal);
    98105    }
     106    float t4 = psTimerMark ("pmSourceFitPCM");
    99107
    100108    // set the model success or failure status
     
    114122
    115123    source->mode |= PM_SOURCE_MODE_FITTED; // XXX is this needed?
     124    float t5 = psTimerMark ("pmSourceFitPCM");
     125
     126    if (0) {
     127        fprintf (stderr, "nIter: %2d, npix: %5d, t1: %6.4f, t2: %6.4f, t3: %6.4f, t4: %6.4f, t5: %6.4f\n", myMin->iter, pcm->nPix, t1, t2, t3, t4, t5);
     128    }
    116129
    117130    psFree(myMin);
Note: See TracChangeset for help on using the changeset viewer.