IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14655 for trunk/psphot/src


Ignore:
Timestamp:
Aug 23, 2007, 2:40:16 PM (19 years ago)
Author:
eugene
Message:

* updates from branch eam_branch_20070817

  • changed pmIsFoo to pmFooTest
  • changed pmModelGroup to pmModelClass
  • added offsets to pmSourceOp
  • changed pmModel.params_NEW to pmModel.params
  • use new APIs to define a pmModel from a pmPSF at X,Y (pmModelFromPSFforXY)
  • use pmModel member functions instead of _GetFunction functions
  • added modelParamsFromPSF for STRAIL and TEST1
  • move output psf model from readout->analysis to chip->analysis
Location:
trunk/psphot/src
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/models/pmModel_STRAIL.c

    r11702 r14655  
    1212*****************************************************************************/
    1313 
    14 # define PM_MODEL_FUNC       pmModelFunc_STRAIL
    15 # define PM_MODEL_FLUX       pmModelFlux_STRAIL
    16 # define PM_MODEL_GUESS      pmModelGuess_STRAIL
    17 # define PM_MODEL_LIMITS     pmModelLimits_STRAIL
    18 # define PM_MODEL_RADIUS     pmModelRadius_STRAIL
    19 # define PM_MODEL_FROM_PSF   pmModelFromPSF_STRAIL
    20 # define PM_MODEL_FIT_STATUS pmModelFitStatus_STRAIL
     14# define PM_MODEL_FUNC            pmModelFunc_STRAIL
     15# define PM_MODEL_FLUX            pmModelFlux_STRAIL
     16# define PM_MODEL_GUESS           pmModelGuess_STRAIL
     17# define PM_MODEL_LIMITS          pmModelLimits_STRAIL
     18# define PM_MODEL_RADIUS          pmModelRadius_STRAIL
     19# define PM_MODEL_FROM_PSF        pmModelFromPSF_STRAIL
     20# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_STRAIL
     21# define PM_MODEL_FIT_STATUS      pmModelFitStatus_STRAIL
    2122
    2223psF32 PM_MODEL_FUNC(psVector *deriv,
     
    474475 
    475476//fixed I think...no good way of guessing as far as I can tell
    476 bool PM_MODEL_GUESS (pmModel *model, pmSource *source) {
    477 
     477bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     478{
    478479    pmMoments *Smoments = source->moments;
    479480    psF32     *params  = model->params->data.F32;
     
    516517 
    517518//fixed
    518 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf) {
    519  
     519bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf)
     520{
    520521    psF32 *out = modelPSF->params->data.F32;
    521522    psF32 *in  = modelFLT->params->data.F32;
     
    529530 
    530531    for (int i = 4; i < 7; i++) {
    531       psPolynomial2D *poly = psf->params_NEW->data[i-4];
     532      psPolynomial2D *poly = psf->params->data[i-4];
    532533        out[i] = psPolynomial2DEval (poly, out[2], out[3]);
    533534    }
     
    535536}
    536537 
     538// construct the PSF model from the FLT model and the psf
     539// XXX is this sufficiently general do be a global function, not a pmModelClass function?
     540bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
     541{
     542    psF32 *PAR = model->params->data.F32;
     543
     544    // we require these two parameters to exist
     545    assert (psf->params->n > PM_PAR_YPOS);
     546    assert (psf->params->n > PM_PAR_XPOS);
     547
     548    PAR[PM_PAR_SKY]  = 0.0;
     549    PAR[PM_PAR_I0]   = Io;
     550    PAR[PM_PAR_XPOS] = Xo;
     551    PAR[PM_PAR_YPOS] = Yo;
     552   
     553    // supply the model-fitted parameters, or copy from the input
     554    for (int i = 0; i < psf->params->n; i++) {
     555        if (i == PM_PAR_SKY) continue;
     556        psPolynomial2D *poly = psf->params->data[i];
     557        assert (poly);
     558        PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     559    }
     560
     561    // the 2D PSF model fits polarization terms (E0,E1,E2)
     562    // convert to shape terms (SXX,SYY,SXY)
     563    // XXX user-defined value for limit?
     564    if (!pmPSF_FitToModel (PAR, 0.1)) {
     565        psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
     566        return false;
     567    }
     568
     569    // apply the model limits here: this truncates excessive extrapolation
     570    // XXX do we need to do this still?  should we put in asserts to test?
     571    for (int i = 0; i < psf->params->n; i++) {
     572        // apply the limits to all components or just the psf-model parameters?
     573        if (psf->params->data[i] == NULL)
     574            continue;
     575
     576        bool status = true;
     577        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
     578        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
     579        if (!status) {
     580            psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
     581            model->flags |= PM_MODEL_STATUS_LIMITS;
     582        }
     583    }
     584    return(true);
     585}
     586
    537587//done I think
    538 bool PM_MODEL_FIT_STATUS (pmModel *model) {
    539  
     588bool PM_MODEL_FIT_STATUS (pmModel *model)
     589{
    540590    psF32 dP;
    541591    bool  status;
     
    566616# undef PM_MODEL_RADIUS
    567617# undef PM_MODEL_FROM_PSF
     618# undef PM_MODEL_PARAMS_FROM_PSF
    568619# undef PM_MODEL_FIT_STATUS
  • trunk/psphot/src/models/pmModel_TEST1.c

    r11702 r14655  
    1616 *****************************************************************************/
    1717
    18 # define PM_MODEL_FUNC       pmModelFunc_TEST1
    19 # define PM_MODEL_FLUX       pmModelFlux_TEST1
    20 # define PM_MODEL_GUESS      pmModelGuess_TEST1
    21 # define PM_MODEL_LIMITS     pmModelLimits_TEST1
    22 # define PM_MODEL_RADIUS     pmModelRadius_TEST1
    23 # define PM_MODEL_FROM_PSF   pmModelFromPSF_TEST1
    24 # define PM_MODEL_FIT_STATUS pmModelFitStatus_TEST1
    25 
    26 // XXX consider changing to form PAR[SXY]*(1/PAR[SXX]^2 + 1/PAR[SYY]^2)*X*Y
    27 // this would provide natural limits on PAR[SXY] of -0.25 : +0.25
     18# define PM_MODEL_FUNC            pmModelFunc_TEST1
     19# define PM_MODEL_FLUX            pmModelFlux_TEST1
     20# define PM_MODEL_GUESS           pmModelGuess_TEST1
     21# define PM_MODEL_LIMITS          pmModelLimits_TEST1
     22# define PM_MODEL_RADIUS          pmModelRadius_TEST1
     23# define PM_MODEL_FROM_PSF        pmModelFromPSF_TEST1
     24# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_TEST1
     25# define PM_MODEL_FIT_STATUS      pmModelFitStatus_TEST1
    2826
    2927// the model is a function of the pixel coordinate (pixcoord[0,1] = x,y)
    3028psF32 PM_MODEL_FUNC(psVector *deriv,
    31                          const psVector *params,
    32                          const psVector *pixcoord)
     29                    const psVector *params,
     30                    const psVector *pixcoord)
    3331{
    3432    psF32 *PAR = params->data.F32;
     
    127125bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
    128126{
    129 
    130127    pmMoments *moments = source->moments;
    131128    psF32     *PAR  = model->params->data.F32;
     
    160157    norm = 0.0;
    161158
    162     # define DZ 0.25
     159# define DZ 0.25
    163160
    164161    float f0 = 1.0;
     
    209206bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf)
    210207{
    211 
    212208    psF32 *out = modelPSF->params->data.F32;
    213209    psF32 *in  = modelFLT->params->data.F32;
    214210
    215211    // we require these two parameters to exist
    216     assert (psf->params_NEW->n > PM_PAR_YPOS);
    217     assert (psf->params_NEW->n > PM_PAR_XPOS);
    218 
    219     for (int i = 0; i < psf->params_NEW->n; i++) {
    220         if (psf->params_NEW->data[i] == NULL) {
     212    assert (psf->params->n > PM_PAR_YPOS);
     213    assert (psf->params->n > PM_PAR_XPOS);
     214
     215    for (int i = 0; i < psf->params->n; i++) {
     216        if (psf->params->data[i] == NULL) {
    221217            out[i] = in[i];
    222218        } else {           
    223             psPolynomial2D *poly = psf->params_NEW->data[i];
     219            psPolynomial2D *poly = psf->params->data[i];
    224220            out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    225221        }
     
    229225    out[PM_PAR_SXY] = pmPSF_SXYtoModel (out);
    230226
     227    return(true);
     228}
     229
     230// construct the PSF model from the FLT model and the psf
     231// XXX is this sufficiently general do be a global function, not a pmModelClass function?
     232bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
     233{
     234    psF32 *PAR = model->params->data.F32;
     235
     236    // we require these two parameters to exist
     237    assert (psf->params->n > PM_PAR_YPOS);
     238    assert (psf->params->n > PM_PAR_XPOS);
     239
     240    PAR[PM_PAR_SKY]  = 0.0;
     241    PAR[PM_PAR_I0]   = Io;
     242    PAR[PM_PAR_XPOS] = Xo;
     243    PAR[PM_PAR_YPOS] = Yo;
     244   
     245    // supply the model-fitted parameters, or copy from the input
     246    for (int i = 0; i < psf->params->n; i++) {
     247        if (i == PM_PAR_SKY) continue;
     248        psPolynomial2D *poly = psf->params->data[i];
     249        assert (poly);
     250        PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     251    }
     252
     253    // the 2D PSF model fits polarization terms (E0,E1,E2)
     254    // convert to shape terms (SXX,SYY,SXY)
     255    // XXX user-defined value for limit?
     256    if (!pmPSF_FitToModel (PAR, 0.1)) {
     257        psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
     258        return false;
     259    }
     260
     261    // apply the model limits here: this truncates excessive extrapolation
     262    // XXX do we need to do this still?  should we put in asserts to test?
     263    for (int i = 0; i < psf->params->n; i++) {
     264        // apply the limits to all components or just the psf-model parameters?
     265        if (psf->params->data[i] == NULL)
     266            continue;
     267
     268        bool status = true;
     269        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
     270        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
     271        if (!status) {
     272            psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
     273            model->flags |= PM_MODEL_STATUS_LIMITS;
     274        }
     275    }
    231276    return(true);
    232277}
     
    237282bool PM_MODEL_FIT_STATUS (pmModel *model)
    238283{
    239 
    240284    psF32 dP;
    241285    bool  status;
     
    265309# undef PM_MODEL_RADIUS
    266310# undef PM_MODEL_FROM_PSF
     311# undef PM_MODEL_PARAMS_FROM_PSF
    267312# undef PM_MODEL_FIT_STATUS
  • trunk/psphot/src/pmFootprint.c

    r14335 r14655  
    2929}
    3030
    31 bool pmIsSpan(const psPtr ptr)
     31bool pmSpanTest(const psPtr ptr)
    3232{
    3333    return (psMemGetDeallocator(ptr) == (psFreeFunc)spanFree);
     
    115115}
    116116
    117 bool pmIsFootprint(const psPtr ptr) {
     117bool pmFootprintTest(const psPtr ptr) {
    118118    return (psMemGetDeallocator(ptr) == (psFreeFunc)footprintFree);
    119119}
     
    762762   // Set stop bits from peaks list
    763763   //
    764    assert (peaks == NULL || peaks->n == 0 || pmIsPeak(peaks->data[0]));
     764   assert (peaks == NULL || peaks->n == 0 || pmPeakTest(peaks->data[0]));
    765765   if (peaks != NULL) {
    766766       for (int i = 0; i < peaks->n; i++) {
     
    859859   }
    860860   const pmFootprint *fp = footprints->data[0];
    861    assert(pmIsFootprint((const psPtr)fp));
     861   assert(pmFootprintTest((const psPtr)fp));
    862862   const int numCols = fp->region.x1 - fp->region.x0 + 1;
    863863   const int numRows = fp->region.y1 - fp->region.y0 + 1;
     
    884884psImage *pmSetFootprintID(const pmFootprint *fp, // the footprint to insert
    885885                          const int id) {       // the desired ID
    886    assert(fp != NULL && pmIsFootprint((const psPtr)fp));
     886   assert(fp != NULL && pmFootprintTest((const psPtr)fp));
    887887   const int numCols = fp->region.x1 - fp->region.x0 + 1;
    888888   const int numRows = fp->region.y1 - fp->region.y0 + 1;
     
    910910psArray *pmGrowFootprintArray(const psArray *footprints, // footprints to grow
    911911                              int r) {  // how much to grow each footprint
    912     assert (footprints->n == 0 || pmIsFootprint(footprints->data[0]));
     912    assert (footprints->n == 0 || pmFootprintTest(footprints->data[0]));
    913913
    914914    if (footprints->n == 0) {           // we don't know the size of the footprint's region
     
    964964                                const psArray *footprints2, // the other set
    965965                                const int includePeaks) { // which peaks to set? 0x1 => footprints1, 0x2 => 2
    966     assert (footprints1->n == 0 || pmIsFootprint(footprints1->data[0]));
    967     assert (footprints2->n == 0 || pmIsFootprint(footprints2->data[0]));
     966    assert (footprints1->n == 0 || pmFootprintTest(footprints1->data[0]));
     967    assert (footprints2->n == 0 || pmFootprintTest(footprints2->data[0]));
    968968
    969969    if (footprints1->n == 0 || footprints2->n == 0) {           // nothing to do but put copies on merged
     
    10321032                          const psArray *peaks) { // the pmPeaks
    10331033    assert (footprints != NULL);
    1034     assert (footprints->n == 0 || pmIsFootprint(footprints->data[0]));
     1034    assert (footprints->n == 0 || pmFootprintTest(footprints->data[0]));
    10351035    assert (peaks != NULL);
    1036     assert (peaks->n == 0 || pmIsPeak(peaks->data[0]));
     1036    assert (peaks->n == 0 || pmPeakTest(peaks->data[0]));
    10371037   
    10381038    if (footprints->n == 0) {
     
    12221222psArray *pmFootprintArrayToPeaks(const psArray *footprints) {
    12231223   assert(footprints != NULL);
    1224    assert(footprints->n == 0 || pmIsFootprint(footprints->data[0]));
     1224   assert(footprints->n == 0 || pmFootprintTest(footprints->data[0]));
    12251225
    12261226   int npeak = 0;
  • trunk/psphot/src/pmFootprint.h

    r13442 r14655  
    1111
    1212pmSpan *pmSpanAlloc(int y, int x1, int x2);
    13 bool pmIsSpan(const psPtr ptr);
     13bool pmSpanTest(const psPtr ptr);
    1414int pmSpanSortByYX (const void **a, const void **b);
    1515
     
    2525
    2626pmFootprint *pmFootprintAlloc(int nspan, const psImage *img);
    27 bool pmIsFootprint(const psPtr ptr);
     27bool pmFootprintTest(const psPtr ptr);
    2828
    2929pmFootprint *pmFootprintNormalize(pmFootprint *fp);
  • trunk/psphot/src/psphot.c

    r14005 r14655  
    1111    pmErrorRegister();                  // register psModule's error codes/messages
    1212    psphotErrorRegister();              // register our error codes/messages
    13     psphotModelGroupInit ();            // load implementation-specific models
     13    psphotModelClassInit ();            // load implementation-specific models
    1414
    1515    // load command-line arguments, options, and system config data
  • trunk/psphot/src/psphot.h

    r14338 r14655  
    5151
    5252// basic support functions
    53 void            psphotModelGroupInit (void);
     53void            psphotModelClassInit (void);
    5454int             pmPeakSortBySN (const void **a, const void **b);
    5555int             pmPeakSortByY (const void **a, const void **b);
  • trunk/psphot/src/psphotAddNoise.c

    r13900 r14655  
    6868
    6969        // XXX if we use pmSourceOp, the size (and possibly Io) will not be respected
    70         pmSourceOp (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, add, maskVal);
     70        pmSourceOp (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, add, maskVal, 0, 0);
    7171
    7272        // restore original values
  • trunk/psphot/src/psphotChoosePSF.c

    r13900 r14655  
    127127    // print/dump psf parameters
    128128    if (psTraceGetLevel("psphot") >= 5) {
    129         for (int i = PM_PAR_SXX; i < try->psf->params_NEW->n; i++) {
    130             psPolynomial2D *poly = try->psf->params_NEW->data[i];
     129        for (int i = PM_PAR_SXX; i < try->psf->params->n; i++) {
     130            psPolynomial2D *poly = try->psf->params->data[i];
    131131            for (int nx = 0; nx <= poly->nX; nx++) {
    132132                for (int ny = 0; ny <= poly->nY; ny++) {
     
    295295    }
    296296
    297     char *modelName = pmModelGetType (psf->type);
     297    char *modelName = pmModelClassGetName (psf->type);
    298298    psLogMsg ("psphot.pspsf", PS_LOG_INFO, "select psf model: %f sec\n", psTimerMark ("psphot"));
    299299    psLogMsg ("psphot.pspsf", PS_LOG_INFO, "psf model %s, ApResid: %f +/- %f\n", modelName, psf->ApResid, psf->dApResid);
     
    315315    PS_ASSERT_PTR_NON_NULL(image, false);
    316316
    317     pmModel *modelEXT = pmModelAlloc (psf->type);
    318     PS_ASSERT_PTR_NON_NULL(modelEXT, false);
    319 
    320     // make a model with unit central intensity at the image center
    321     modelEXT->params->data.F32[PM_PAR_SKY] = 0;
    322     modelEXT->params->data.F32[PM_PAR_I0] = 1;
    323     modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*image->numCols;
    324     modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*image->numRows;
    325 
    326     // construct a PSF model at this coordinate
    327     pmModel *modelPSF = pmModelFromPSF (modelEXT, psf);
     317    // construct a normalized PSF model at this coordinate (Io = 1.0)
     318    pmModel *modelPSF = pmModelFromPSFforXY (psf, 0.5*image->numCols, 0.5*image->numRows, 1.0);
    328319    if (modelPSF == NULL) {
    329320        psError(PSPHOT_ERR_PSF, false, "Failed to estimate PSF model at image centre");
    330         psFree(modelEXT);
    331321        return false;
    332322    }
    333323
    334     // get the correct model-radius function
    335     pmModelRadius modelRadiusFunc = pmModelRadius_GetFunction (psf->type);
    336 
    337324    // get the model full-width at half-max
    338     psF64 FWHM_X = 2*modelRadiusFunc (modelPSF->params, 0.5);
     325    psF64 FWHM_X = 2*modelPSF->modelRadius (modelPSF->params, 0.5);
    339326
    340327    // XXX make sure this is consistent with the re-definition of PM_PAR_SXX
     
    351338    psMetadataAddS32 (recipe, PS_LIST_TAIL, "NPSFSTAR", PS_META_REPLACE, "Number of stars used to make PSF", psf->nPSFstars);
    352339    psMetadataAddBool(recipe, PS_LIST_TAIL, "PSFMODEL", PS_META_REPLACE, "Valid PSF Model?", true);
    353 
    354     psFree (modelEXT);
    355340    psFree (modelPSF);
    356341
  • trunk/psphot/src/psphotCleanup.c

    r12805 r14655  
    77    psTimerStop ();
    88    psMemCheckCorruption (stderr, true);
    9     pmModelGroupCleanup ();
     9    pmModelClassCleanup ();
    1010    psTimeFinalize ();
    1111    pmConceptsDone ();
  • trunk/psphot/src/psphotEvalFLT.c

    r13804 r14655  
    3737    }
    3838
    39     keep = pmModelFitStatus (model);
     39    keep = model->modelFitStatus(model);
    4040    if (keep) return true;
    4141
  • trunk/psphot/src/psphotFakeSources.c

    r12792 r14655  
    2323        source->type = PM_SOURCE_TYPE_STAR;
    2424
    25         pmModelType modelType = pmModelSetType ("PS_MODEL_QGAUSS");
     25        pmModelType modelType = pmModelClassGetType ("PS_MODEL_QGAUSS");
    2626        source->modelPSF = pmSourceModelGuess (source, modelType);
    2727        sources->data[i] = source;
  • trunk/psphot/src/psphotFindPeaks.c

    r13900 r14655  
    9595
    9696    // find the peaks in the smoothed image
    97     psArray *peaks = pmFindImagePeaks (smooth_im, threshold);
     97    psArray *peaks = pmPeaksInImage (smooth_im, threshold);
    9898    if (peaks == NULL) {
    9999        // XXX this may also be due to a programming or config error
  • trunk/psphot/src/psphotGrowthCurve.c

    r13900 r14655  
    1414    float radius;
    1515
    16     // create template model
    17     pmModel *modelRef = pmModelAlloc(psf->type);
    18 
    1916    // use the center of the center pixel of the image
    2017    xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5;
     
    2320    dy = psf->growth->maxRadius + 1;
    2421
    25     // assign the x and y coords to the image center
    26     // create an object with center intensity of 1000
    27     modelRef->params->data.F32[PM_PAR_SKY] = 0;
    28     modelRef->params->data.F32[PM_PAR_I0] = 1000;
    29     modelRef->params->data.F32[PM_PAR_XPOS] = xc;
    30     modelRef->params->data.F32[PM_PAR_YPOS] = yc;
    31 
    32     // create modelPSF from this model
    33     pmModel *model = pmModelFromPSF (modelRef, psf);
     22    // create normalized model object at xc,yc
     23    pmModel *model = pmModelFromPSFforXY (psf, xc, yc, 1.0);
    3424
    3525    // measure the fitMag for this model
     
    7666    psFree (mask);
    7767    psFree (model);
    78     psFree (modelRef);
    7968
    8069    return true;
  • trunk/psphot/src/psphotModelGroupInit.c

    r12792 r14655  
    77# include "models/pmModel_STRAIL.c"
    88
    9 static pmModelGroup userModels[] = {
    10     {"PS_MODEL_TEST1", 7, pmModelFunc_TEST1,  pmModelFlux_TEST1,  pmModelRadius_TEST1,  pmModelLimits_TEST1,  pmModelGuess_TEST1, pmModelFromPSF_TEST1, pmModelFitStatus_TEST1},
    11     {"PS_MODEL_STRAIL", 9, pmModelFunc_STRAIL,  pmModelFlux_STRAIL,  pmModelRadius_STRAIL,  pmModelLimits_STRAIL,  pmModelGuess_STRAIL, pmModelFromPSF_STRAIL, pmModelFitStatus_STRAIL},
     9static pmModelClass userModels[] = {
     10    {"PS_MODEL_TEST1", 7, pmModelFunc_TEST1,  pmModelFlux_TEST1,  pmModelRadius_TEST1,  pmModelLimits_TEST1,  pmModelGuess_TEST1, pmModelFromPSF_TEST1, pmModelParamsFromPSF_TEST1, pmModelFitStatus_TEST1},
     11    {"PS_MODEL_STRAIL", 9, pmModelFunc_STRAIL,  pmModelFlux_STRAIL,  pmModelRadius_STRAIL,  pmModelLimits_STRAIL,  pmModelGuess_STRAIL, pmModelFromPSF_STRAIL, pmModelParamsFromPSF_STRAIL, pmModelFitStatus_STRAIL},
    1212};
    1313
    14 void psphotModelGroupInit (void)
     14void psphotModelClassInit (void)
    1515{
    1616
    17     // if pmModelGroupInit returns false, we have already init'ed
    18     if (!pmModelGroupInit ()) return;
     17    // if pmModelClassInit returns false, we have already init'ed
     18    if (!pmModelClassInit ()) return;
    1919
    20     int Nmodels = sizeof (userModels) / sizeof (pmModelGroup);
     20    int Nmodels = sizeof (userModels) / sizeof (pmModelClass);
    2121    for (int i = 0; i < Nmodels; i++) {
    22         pmModelGroupAdd (&userModels[i]);
     22        pmModelClassAdd (&userModels[i]);
    2323    }
    2424    return;
  • trunk/psphot/src/psphotModelTest.c

    r14348 r14655  
    8989            modelName = item->data.V;
    9090        }
    91         modelType = pmModelSetType (modelName);
     91        modelType = pmModelClassGetType (modelName);
    9292        if (modelType < 0) psAbort("unknown model %s", modelName);
    9393        source->type = PM_SOURCE_TYPE_EXTENDED;
     
    118118            modelName = item->data.V;
    119119        }
    120         modelType = pmModelSetType (modelName);
     120        modelType = pmModelClassGetType (modelName);
    121121        if (modelType < 0) psAbort("unknown model %s", modelName);
    122122        source->type = PM_SOURCE_TYPE_EXTENDED;
     
    148148
    149149    // if any parameters are defined by the user, take those values
    150     int nParams = pmModelParameterCount (modelType);
     150    int nParams = pmModelClassParameterCount (modelType);
    151151    psF32 *params = model->params->data.F32;
    152152    params[PM_PAR_XPOS] = xObj; // XXX use the user-supplied value,
  • trunk/psphot/src/psphotPSFConvModel.c

    r14348 r14655  
    5858    psVector *dparams = modelConv->dparams;
    5959
    60     // get the model function for this model
    61     pmModelFunc modelFunc = pmModelFunc_GetFunction (modelConv->type);
    62     if (!modelFunc)
    63         psAbort("invalid model function");
    64 
    65     // get the limits function for this model
    66     pmModelLimits checkLimits = pmModelLimits_GetFunction (modelConv->type);
    67     if (!checkLimits)
    68         psAbort("invalid model limits function");
    69 
    7060    // create the minimization constraints
    7161    psMinConstraint *constraint = psMinConstraintAlloc();
    7262    constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_U8);
    73     constraint->checkLimits = checkLimits;
     63    constraint->checkLimits = modelConv->modelLimits;
    7464
    7565    // set parameter mask based on fitting mode
     
    8171    // force the floating parameters to fall within the contraint ranges
    8272    for (int i = 0; i < params->n; i++) {
    83         checkLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
    84         checkLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
     73        modelConv->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
     74        modelConv->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
    8575    }
    8676
     
    9080    psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
    9181
    92     bool fitStatus = psphotModelWithPSF_LMM (myMin, covar, params, constraint, source, psf, modelFunc);
     82    bool fitStatus = psphotModelWithPSF_LMM (myMin, covar, params, constraint, source, psf, modelConv->modelFunc);
    9383    for (int i = 0; i < dparams->n; i++) {
    9484        if (psTraceGetLevel("psphot") >= 4) {
  • trunk/psphot/src/psphotPSFResiduals.c

    r12792 r14655  
    1212    if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
    1313
    14     // XXX if a source is faint, it will not have moments measured.
    15     // it must be modelled as a PSF.  In this case, we need to use
    16     // the peak centroid to get the coordinates and get the peak flux
    17     // from the image?
    18 
    19     // use the source moments, etc to guess basic model parameters
    20     pmModel *modelEXT = pmSourceModelGuess (source, psf->type);
    21    
    22     // XXX put this in a function of its own..
    23     if (modelEXT == NULL) {
    24         psErrorClear (); // XXX need to clear the error from failing the model
    25         modelEXT = pmModelAlloc(psf->type);
    26         psF32 *PAR = modelEXT->params->data.F32;
    27         PAR[PM_PAR_SKY]  = 0;
    28         // XXX get this from the image pixels
    29         PAR[PM_PAR_I0]   = source->peak->flux;
    30         PAR[PM_PAR_XPOS] = source->peak->xf;
    31         PAR[PM_PAR_YPOS] = source->peak->yf;
     14    if (source->mode & PM_SOURCE_MODE_SATSTAR) {
     15        Xo = source->moments->x;
     16        Yo = source->moments->y;
     17        Io = source->peak->flux;
    3218    } else {
    33         // these valuse are set in pmSourceModelGuess, should this rule be in there as well?
    34         if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
    35             modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->x;
    36             modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->y;
    37         } else {
    38             modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf;
    39             modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf;
    40         }
     19        Xo = source->peak->xf;
     20        Yo = source->peak->yf;
     21        Io = source->peak->flux;
    4122    }
    4223
    4324    // set PSF parameters for this model (apply 2D shape model)
    44     pmModel *modelPSF = pmModelFromPSF (modelEXT, psf);
    45     psFree (modelEXT);
     25    pmModel *modelPSF = pmModelFromPSFforXY (psf, Xo, Yo, Io);
    4626
    4727    // XXX need to define the guess flux?
  • trunk/psphot/src/psphotRadiusChecks.c

    r13035 r14655  
    66static float PSF_FIT_RADIUS = 0;        // radius to use in fitting (ignored if <= 0,
    77                                        // and a per-object radius is calculated)
    8 static pmModelRadius modelRadiusPSF;
    98
    109bool psphotInitRadiusPSF(const psMetadata *recipe,
     
    1716    PSF_FIT_RADIUS =  psMetadataLookupF32(&status, recipe, "PSF_FIT_RADIUS");
    1817
    19     // this function specifies the radius at this the model hits the given flux
    20     modelRadiusPSF       = pmModelRadius_GetFunction (type);
    2118    return true;
    2219}
     
    3431    if (radiusFit <= 0) {               // use fixed radius
    3532        if (moments == NULL) {
    36             radiusFit = modelRadiusPSF(model->params, PSF_FIT_NSIGMA*moments->dSky);
     33            radiusFit = model->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
    3734        } else {
    38             radiusFit = modelRadiusPSF(model->params, 1.0);
     35            radiusFit = model->modelRadius(model->params, 1.0);
    3936        }
    4037    }
     
    6259
    6360    // set the fit radius based on the object flux limit and the model
    64     model->radiusFit = (RADIUS_TYPE) (modelRadiusPSF (model->params, PSF_FIT_NSIGMA*moments->dSky) + dR + PSF_FIT_PADDING);
     61    model->radiusFit = (RADIUS_TYPE) (model->modelRadius (model->params, PSF_FIT_NSIGMA*moments->dSky) + dR + PSF_FIT_PADDING);
    6562    if (isnan(model->radiusFit)) psAbort("error in radius");
    6663       
     
    7875static float EXT_FIT_NSIGMA;
    7976static float EXT_FIT_PADDING;
    80 static pmModelRadius modelRadiusEXT;
    8177
    8278bool psphotInitRadiusEXT (psMetadata *recipe, pmModelType type) {
     
    8783    EXT_FIT_PADDING  = psMetadataLookupF32 (&status, recipe, "EXT_FIT_PADDING");
    8884
    89     // this function specifies the radius at this the model hits the given flux
    90     modelRadiusEXT       = pmModelRadius_GetFunction (type);
    9185    return true;
    9286}
     
    10195
    10296    // set the fit radius based on the object flux limit and the model
    103     model->radiusFit = (RADIUS_TYPE) (modelRadiusEXT (model->params, EXT_FIT_NSIGMA*moments->dSky) + EXT_FIT_PADDING);
     97    model->radiusFit = (RADIUS_TYPE) (model->modelRadius (model->params, EXT_FIT_NSIGMA*moments->dSky) + EXT_FIT_PADDING);
    10498    if (isnan(model->radiusFit)) psAbort("error in radius");
    10599
  • trunk/psphot/src/psphotReadout.c

    r14346 r14655  
    251251
    252252    // plot positive sources
    253     // psphotSourcePlots (readout, sources, recipe);
     253    psphotSourcePlots (readout, sources, recipe, maskVal);
    254254
    255255    // measure aperture photometry corrections
  • trunk/psphot/src/psphotReadoutCleanup.c

    r13835 r14655  
    5757    if (psf) {
    5858        // save the psf for possible output.  if there was already an entry, it was loaded from external sources
    59         // the new one may have been updated or modified, so replace the existing entry
    60         psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE,  "psphot psf", psf);
     59        // the new one may have been updated or modified, so replace the existing entry.  We
     60        // are required to save it on the chip, but this will cause problems if we ever want to
     61        // run psphot on an unmosaiced image
     62        pmCell *cell = readout->parent;
     63        pmChip *chip = cell->parent;
     64        psMetadataAdd (chip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE,  "psphot psf", psf);
    6165    }
    6266
  • trunk/psphot/src/psphotSourceFits.c

    r13900 r14655  
    195195    // extended source model descriptions
    196196    char *modelNameEXT = psMetadataLookupStr (&status, recipe, "EXT_MODEL");
    197     modelTypeEXT = pmModelSetType (modelNameEXT);
     197    modelTypeEXT = pmModelClassGetType (modelNameEXT);
    198198    psphotInitRadiusEXT (recipe, modelTypeEXT);
    199199
  • trunk/psphot/src/psphotTestSourceOutput.c

    r12950 r14655  
    2121    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
    2222    psVector *params = model->params;
    23     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
    2423    psS32 imageCol;
    2524    psS32 imageRow;
     
    6867            // set the appropriate pixel value for this coordinate
    6968            if (mode & PSPHOT_ADD_MODEL) {
    70                 pixelValue = modelFunc (NULL, params, x) - skyValue;
     69                pixelValue = model->modelFunc (NULL, params, x) - skyValue;
    7170            } else {
    7271                pixelValue = 0.0;
Note: See TracChangeset for help on using the changeset viewer.