IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 12, 2008, 3:56:42 PM (18 years ago)
Author:
eugene
Message:

move pmGrowthCurveGenerate to own file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmPSF.c

    r20000 r20076  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2008-10-08 21:53:29 $
     8 *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2008-10-13 01:56:42 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    401401    return psf;
    402402}
    403 
    404 // we generate the growth curve for the center of the image with the specified psf model
    405 bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType markVal)
    406 {
    407     PS_ASSERT_PTR_NON_NULL(readout, false);
    408     PS_ASSERT_PTR_NON_NULL(readout->image, false);
    409 
    410     // bool status;
    411     float xc, yc, dx, dy;
    412     float fitMag, apMag;
    413     float radius;
    414 
    415     // create template model
    416     pmModel *modelRef = pmModelAlloc(psf->type);
    417 
    418     // maskVal is used to test for rejected pixels, and must include markVal
    419     maskVal |= markVal;
    420 
    421     // XXXX A Serious hack: the psf might not be determined in the field center.
    422     // for the moment, just try a few locations until it is defined!
    423 
    424     pmModel *model = NULL;
    425     for (int ix = -1; ix <= +1; ix ++) {
    426         for (int iy = -1; iy <= +1; iy ++) {
    427 
    428             // use the center of the center pixel of the image
    429             xc = (0.5 + 0.3*ix)*readout->image->numCols + readout->image->col0 + 0.5;
    430             yc = (0.5 + 0.3*ix)*readout->image->numRows + readout->image->row0 + 0.5;
    431             dx = psf->growth->maxRadius + 1;
    432             dy = psf->growth->maxRadius + 1;
    433 
    434             // assign the x and y coords to the image center
    435             // create an object with center intensity of 1000
    436             modelRef->params->data.F32[PM_PAR_SKY] = 0;
    437             modelRef->params->data.F32[PM_PAR_I0] = 1000;
    438             modelRef->params->data.F32[PM_PAR_XPOS] = xc;
    439             modelRef->params->data.F32[PM_PAR_YPOS] = yc;
    440 
    441             // create modelPSF from this model
    442             model = pmModelFromPSF (modelRef, psf);
    443             if (model) goto got_model;
    444         }
    445     }
    446     psAssert (model, "cannot build growth curve (psf model is invalid everywhere)");
    447 
    448 got_model:
    449     // measure the fitMag for this model
    450     pmSourcePhotometryModel (&fitMag, model);
    451     psf->growth->fitMag = fitMag;
    452 
    453     // generate working image for this source
    454     psRegion region = {xc - dx, xc + dx, yc - dy, yc + dy};
    455 
    456     // force region to stop at dimensions of image
    457     region = psRegionForImage (readout->image, region);
    458 
    459     // the view, image, and mask retain col0,row0
    460     psImage *view = psImageSubset (readout->image, region);
    461     psImage *image = psImageCopy (NULL, view, PS_TYPE_F32);
    462     psImage *mask = psImageCopy (NULL, view, PS_TYPE_U8);
    463 
    464     psImageInit (image, 0.0);
    465     psImageInit (mask, 0);
    466 
    467     // place the reference object in the image center
    468     // no need to mask the source here
    469     // XXX should we measure this for the analytical model only or the full model?
    470     pmModelAdd (image, NULL, model, PM_MODEL_OP_FULL, maskVal);
    471 
    472     // loop over a range of source fluxes
    473     // no need to interpolate since we have forced the object center
    474     // to 0.5, 0.5 above
    475     bool completeGrowthCurve = true;            // do we have a complete curve of growth?
    476     for (int i = 0; i < psf->growth->radius->n; i++) {
    477 
    478         radius = psf->growth->radius->data.F32[i];
    479 
    480         // mask the given aperture and measure the apMag
    481         psImageKeepCircle (mask, xc, yc, radius, "OR", markVal);
    482         if (!pmSourcePhotometryAper (&apMag, model, image, mask, maskVal)) {
    483             psError(PM_ERR_PHOTOM, false, "Measuring apMag for radius == %g", radius);
    484             psErrorStackPrint (stderr, "failure to get growth curve");
    485             psErrorClear();
    486             completeGrowthCurve = false;
    487             break;
    488         }
    489         psImageKeepCircle (mask, xc, yc, radius, "AND", PS_NOT_U8(markVal));
    490 
    491         // the 'ignore' mode is for testing
    492         if (ignore) {
    493             psf->growth->apMag->data.F32[i] = fitMag;
    494         } else {
    495             psf->growth->apMag->data.F32[i] = apMag;
    496         }
    497     }
    498 
    499     if (completeGrowthCurve) {
    500         psf->growth->apRef = psVectorInterpolate (psf->growth->radius, psf->growth->apMag, psf->growth->refRadius);
    501         psf->growth->apLoss = psf->growth->fitMag - psf->growth->apRef;
    502     } else {
    503         psf->growth->apRef = NAN;
    504         psf->growth->apLoss = 0;
    505     }
    506 
    507     psLogMsg ("psphot.growth", 4, "GrowthCurve : apLoss : %f\n", psf->growth->apLoss);
    508 
    509     psFree (view);
    510     psFree (image);
    511     psFree (mask);
    512     psFree (model);
    513     psFree (modelRef);
    514 
    515     return completeGrowthCurve ? true : false;
    516 }
Note: See TracChangeset for help on using the changeset viewer.