IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14348


Ignore:
Timestamp:
Jul 20, 2007, 2:05:10 PM (19 years ago)
Author:
eugene
Message:

various fixes to get PSFConv model working

Location:
trunk/psphot/src
Files:
2 edited

Legend:

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

    r14338 r14348  
    1515    if (!psMetadataLookupBool (&status, recipe, "TEST_FIT")) return false;
    1616
     17    psTimerStart ("modelTest");
     18
    1719    // find the currently selected readout
    1820    pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");
     
    5456    if (fitModeWord && !strcasecmp (fitModeWord, "DEFAULT")) fitMode = PM_SOURCE_FIT_EXT;
    5557
     58    // construct the source structures
     59    pmSource *source = pmSourceAlloc();
     60    source->peak = pmPeakAlloc (xObj, yObj, 0, 0);
     61    pmSourceDefinePixels (source, readout, xObj, yObj, OUTER);
     62
    5663    // in fitMode, psf sets the model type
    5764    if (fitMode == PM_SOURCE_FIT_PSF) {
     
    5966        if (!psf) psAbort("PSF_INPUT_FILE not supplied");
    6067        modelType = psf->type;
     68        source->type = PM_SOURCE_TYPE_STAR;
    6169    }
    6270    if (fitMode == PM_SOURCE_FIT_EXT) {
     
    8391        modelType = pmModelSetType (modelName);
    8492        if (modelType < 0) psAbort("unknown model %s", modelName);
     93        source->type = PM_SOURCE_TYPE_EXTENDED;
    8594    }
    8695    if (fitMode == PM_SOURCE_FIT_PSF_X_EXT) {
     
    111120        modelType = pmModelSetType (modelName);
    112121        if (modelType < 0) psAbort("unknown model %s", modelName);
    113     }
    114 
    115     // construct the source structures
    116     pmSource *source = pmSourceAlloc();
    117     source->peak = pmPeakAlloc (xObj, yObj, 0, 0);
    118     pmSourceDefinePixels (source, readout, xObj, yObj, OUTER);
     122        source->type = PM_SOURCE_TYPE_EXTENDED;
     123    }
    119124
    120125    // find the local sky
     
    140145    // get the initial model parameter guess
    141146    pmModel *model = pmSourceModelGuess (source, modelType);
     147    source->modelEXT = model;
    142148
    143149    // if any parameters are defined by the user, take those values
     
    162168    // for PSF fitting, set the shape parameters based on the PSF & source position
    163169    if (fitMode == PM_SOURCE_FIT_PSF) {
    164         pmModel *modelPSF = pmModelFromPSF (model, psf);
     170        source->modelPSF = pmModelFromPSF (model, psf);
    165171        psFree (model);
    166         model = modelPSF;
     172        model = source->modelPSF;
    167173        params = model->params->data.F32;
    168174    }
     
    212218
    213219    // subtract object, leave local sky
    214     pmModelSub (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
     220    // pmModelSub (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
     221    pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    215222
    216223    fprintf (stderr, "output parameters: \n");
     
    223230    psphotSaveImage (NULL, source->maskObj, "mask.fits");
    224231
     232    psLogMsg ("psphot", PS_LOG_INFO, "model test : %f sec\n", psTimerMark ("modelTest"));
     233
    225234    exit (0);
    226235}
  • trunk/psphot/src/psphotPSFConvModel.c

    r14338 r14348  
    1212bool psphotPSFConvModel (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
    1313   
     14    bool status;
     15
     16    int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
     17    if (!status) {
     18        psfSize = 2;
     19    }
     20
    1421    // make sure we save a cached copy of the psf flux
    1522    pmSourceCachePSF (source, maskVal);
     
    1724    // convert the cached cached psf model for this source to a psKernel
    1825    // XXX for the moment, hard-wire the kernel to be 5x5 (2 pix radius)
    19     psKernel *psf = psphotKernelFromPSF (source, 2);
     26    // XXX for the moment, hard-wire the kernel to be 9x9 (4 pix radius)
     27    psKernel *psf = psphotKernelFromPSF (source, psfSize);
     28
     29    // psf must be normalized (integral = 1.0)
     30    double sum = 0.0;
     31    for (int i = 0; i < psf->image->numRows; i++) {
     32        for (int j = 0; j < psf->image->numCols; j++) {
     33            sum += psf->image->data.F32[i][j];
     34        }
     35    }
     36    assert (sum > 0.0);
     37    for (int i = 0; i < psf->image->numRows; i++) {
     38        for (int j = 0; j < psf->image->numCols; j++) {
     39            psf->image->data.F32[i][j] /= sum;
     40        }
     41    }
     42
     43# if (0)
     44    // XXX sanity check: convolve with delta function should behave like unconvolved version
     45    for (int i = 0; i < psf->image->numRows; i++) {
     46        for (int j = 0; j < psf->image->numCols; j++) {
     47            psf->image->data.F32[i][j] = 0.0;
     48        }
     49    }
     50    psf->image->data.F32[2][2] = 1.0;
     51# endif
    2052
    2153    // generate copy of the model
     
    69101    psTrace ("psphot", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value);
    70102
     103    // renormalize output model image
     104    float Io = params->data.F32[PM_PAR_I0];
     105    for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
     106        for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
     107            source->modelFlux->data.F32[iy][ix] /= Io;
     108        }
     109    }
     110
    71111    // save the resulting chisq, nDOF, nIter
    72112    modelConv->chisq = myMin->value;
Note: See TracChangeset for help on using the changeset viewer.