IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14652


Ignore:
Timestamp:
Aug 23, 2007, 2:11:02 PM (19 years ago)
Author:
magnier
Message:
  • added function pointers to pmModel to provide class-dependent functions
  • dropped pmModel*_GetFunction functions (use pmModel->func functions instead)
  • added modelParamsFromPSF functions to model classes
  • changed pmModelGroup to pmModelClass
  • added pmSourceFitSet.[ch]
  • updated pmSourceFitSet to allow variable model classes
  • added functions to add/sub and eval models & sources with an offset between image and chip
  • added function to set a pmModel flux
  • added function to instatiate a pmModel from a pmPSF at a coordinate
  • moved pmPSF I/O to chip->analysis from readout->analysis
  • changed pmPSF I/O function names from *ForPSFmodel to pmPSFmodel*
  • changed pmModel.params_NEW back to pmModel.params
  • changed pmFind*Peaks to pmPeaksIn* (* = Image,Vector)
  • dropped pmCullPeaks (deprecated)
  • changed pmModelSetType to pmModelClassGetType
  • changed pmModelGetType to pmModelClassGetName
  • fixed PGAUSS implementation of modelRadius function
Location:
trunk/psModules/src/objects
Files:
7 added
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/Makefile.am

    r14472 r14652  
    77     pmMoments.c \
    88     pmModel.c \
    9      pmModelGroup.c \
     9     pmModelClass.c \
     10     pmModelUtils.c \
    1011     pmSource.c \
     12     pmSourceUtils.c \
    1113     pmSourceSky.c \
    1214     pmSourceContour.c \
    1315     pmSourceFitModel.c \
     16     pmSourceFitSet.c \
    1417     pmSourcePhotometry.c \
    1518     pmSourceIO.c \
     
    3134
    3235EXTRA_DIST = \
    33         models/pmModel_GAUSS.c \
    34         models/pmModel_PGAUSS.c \
    35         models/pmModel_QGAUSS.c \
    36         models/pmModel_SGAUSS.c \
    37         models/pmModel_RGAUSS.c \
    38         models/pmModel_SERSIC.c
     36     models/pmModel_GAUSS.c \
     37     models/pmModel_PGAUSS.c \
     38     models/pmModel_QGAUSS.c \
     39     models/pmModel_SGAUSS.c \
     40     models/pmModel_RGAUSS.c \
     41     models/pmModel_SERSIC.c
    3942
    4043pkginclude_HEADERS = \
     
    4245     pmMoments.h \
    4346     pmModel.h \
    44      pmModelGroup.h \
     47     pmModelClass.h \
     48     pmModelUtils.h \
    4549     pmSource.h \
     50     pmSourceUtils.h \
    4651     pmSourceSky.h \
    4752     pmSourceContour.h \
    4853     pmSourceFitModel.h \
     54     pmSourceFitSet.h \
    4955     pmSourcePhotometry.h \
    5056     pmSourceIO.h \
  • trunk/psModules/src/objects/models/pmModel_GAUSS.c

    r14220 r14652  
    1919 *****************************************************************************/
    2020
    21 # define PM_MODEL_FUNC       pmModelFunc_GAUSS
    22 # define PM_MODEL_FLUX       pmModelFlux_GAUSS
    23 # define PM_MODEL_GUESS      pmModelGuess_GAUSS
    24 # define PM_MODEL_LIMITS     pmModelLimits_GAUSS
    25 # define PM_MODEL_RADIUS     pmModelRadius_GAUSS
    26 # define PM_MODEL_FROM_PSF   pmModelFromPSF_GAUSS
    27 # define PM_MODEL_FIT_STATUS pmModelFitStatus_GAUSS
    28 
     21# define PM_MODEL_FUNC            pmModelFunc_GAUSS
     22# define PM_MODEL_FLUX            pmModelFlux_GAUSS
     23# define PM_MODEL_GUESS           pmModelGuess_GAUSS
     24# define PM_MODEL_LIMITS          pmModelLimits_GAUSS
     25# define PM_MODEL_RADIUS          pmModelRadius_GAUSS
     26# define PM_MODEL_FROM_PSF        pmModelFromPSF_GAUSS
     27# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_GAUSS
     28# define PM_MODEL_FIT_STATUS      pmModelFitStatus_GAUSS
     29
     30// the model is a function of the pixel coordinate (pixcoord[0,1] = x,y)
    2931psF32 PM_MODEL_FUNC(psVector *deriv,
    3032                    const psVector *params,
     
    3840    psF32 py = Y / PAR[PM_PAR_SYY];
    3941    psF32 z  = PS_SQR(px) + PS_SQR(py) + PAR[PM_PAR_SXY]*X*Y;
     42    assert (z >= 0.0);
     43
    4044    psF32 r  = exp(-z);
    4145    psF32 q  = PAR[PM_PAR_I0]*r;
     
    6165# define AR_MAX 20.0
    6266# define AR_RATIO 0.99
     67
    6368bool PM_MODEL_LIMITS (psMinConstraintMode mode, int nParam, float *params, float *beta)
    6469{
     
    9398            break;
    9499        case PM_PAR_SXX:
    95             beta_lim = 0.5;
     100            beta_lim = 2.0;
    96101            break;
    97102        case PM_PAR_SYY:
    98             beta_lim = 0.5;
     103            beta_lim = 2.0;
    99104            break;
    100105        case PM_PAR_SXY:
     
    257262bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, pmPSF *psf)
    258263{
    259 
    260264    psF32 *out = modelPSF->params->data.F32;
    261265    psF32 *in  = modelFLT->params->data.F32;
    262266
    263267    // we require these two parameters to exist
    264     assert (psf->params_NEW->n > PM_PAR_YPOS);
    265     assert (psf->params_NEW->n > PM_PAR_XPOS);
     268    assert (psf->params->n > PM_PAR_YPOS);
     269    assert (psf->params->n > PM_PAR_XPOS);
    266270
    267271    // supply the model-fitted parameters, or copy from the input
    268     for (int i = 0; i < psf->params_NEW->n; i++) {
    269         if (psf->params_NEW->data[i] == NULL) {
     272    for (int i = 0; i < psf->params->n; i++) {
     273        if (psf->params->data[i] == NULL) {
    270274            out[i] = in[i];
    271275        } else {
    272             psPolynomial2D *poly = psf->params_NEW->data[i];
     276            psPolynomial2D *poly = psf->params->data[i];
    273277            out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    274278        }
     
    289293    // apply the model limits here: this truncates excessive extrapolation
    290294    // XXX do we need to do this still?  should we put in asserts to test?
    291     for (int i = 0; i < psf->params_NEW->n; i++) {
     295    for (int i = 0; i < psf->params->n; i++) {
    292296        // apply the limits to all components or just the psf-model parameters?
    293         if (psf->params_NEW->data[i] == NULL)
     297        if (psf->params->data[i] == NULL)
    294298            continue;
    295299
     
    306310}
    307311
     312// construct the PSF model from the FLT model and the psf
     313// XXX is this sufficiently general do be a global function, not a pmModelClass function?
     314bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
     315{
     316    psF32 *PAR = model->params->data.F32;
     317
     318    // we require these two parameters to exist
     319    assert (psf->params->n > PM_PAR_YPOS);
     320    assert (psf->params->n > PM_PAR_XPOS);
     321
     322    PAR[PM_PAR_SKY]  = 0.0;
     323    PAR[PM_PAR_I0]   = Io;
     324    PAR[PM_PAR_XPOS] = Xo;
     325    PAR[PM_PAR_YPOS] = Yo;
     326   
     327    // supply the model-fitted parameters, or copy from the input
     328    for (int i = 0; i < psf->params->n; i++) {
     329        if (i == PM_PAR_SKY) continue;
     330        if (i == PM_PAR_I0) continue;
     331        if (i == PM_PAR_XPOS) continue;
     332        if (i == PM_PAR_YPOS) continue;
     333        psPolynomial2D *poly = psf->params->data[i];
     334        assert (poly);
     335        PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     336    }
     337
     338    // the 2D PSF model fits polarization terms (E0,E1,E2)
     339    // convert to shape terms (SXX,SYY,SXY)
     340    // XXX user-defined value for limit?
     341    if (!pmPSF_FitToModel (PAR, 0.1)) {
     342        psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
     343        return false;
     344    }
     345
     346    // apply the model limits here: this truncates excessive extrapolation
     347    // XXX do we need to do this still?  should we put in asserts to test?
     348    for (int i = 0; i < psf->params->n; i++) {
     349        // apply the limits to all components or just the psf-model parameters?
     350        if (psf->params->data[i] == NULL)
     351            continue;
     352
     353        bool status = true;
     354        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
     355        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
     356        if (!status) {
     357            psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
     358            model->flags |= PM_MODEL_STATUS_LIMITS;
     359        }
     360    }
     361    return(true);
     362}
     363
    308364// check the status of the fitted model
    309365// this test is invalid if the parameters are derived
     
    311367bool PM_MODEL_FIT_STATUS (pmModel *model)
    312368{
    313 
    314369    psF32 dP;
    315370    bool  status;
     
    339394# undef PM_MODEL_RADIUS
    340395# undef PM_MODEL_FROM_PSF
     396# undef PM_MODEL_PARAMS_FROM_PSF
    341397# undef PM_MODEL_FIT_STATUS
  • trunk/psModules/src/objects/models/pmModel_PGAUSS.c

    r14220 r14652  
    1919 *****************************************************************************/
    2020
    21 # define PM_MODEL_FUNC       pmModelFunc_PGAUSS
    22 # define PM_MODEL_FLUX       pmModelFlux_PGAUSS
    23 # define PM_MODEL_GUESS      pmModelGuess_PGAUSS
    24 # define PM_MODEL_LIMITS     pmModelLimits_PGAUSS
    25 # define PM_MODEL_RADIUS     pmModelRadius_PGAUSS
    26 # define PM_MODEL_FROM_PSF   pmModelFromPSF_PGAUSS
    27 # define PM_MODEL_FIT_STATUS pmModelFitStatus_PGAUSS
     21# define PM_MODEL_FUNC            pmModelFunc_PGAUSS
     22# define PM_MODEL_FLUX            pmModelFlux_PGAUSS
     23# define PM_MODEL_GUESS           pmModelGuess_PGAUSS
     24# define PM_MODEL_LIMITS          pmModelLimits_PGAUSS
     25# define PM_MODEL_RADIUS          pmModelRadius_PGAUSS
     26# define PM_MODEL_FROM_PSF        pmModelFromPSF_PGAUSS
     27# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_PGAUSS
     28# define PM_MODEL_FIT_STATUS      pmModelFitStatus_PGAUSS
    2829
    2930// the model is a function of the pixel coordinate (pixcoord[0,1] = x,y)
     
    6667# define AR_RATIO 0.99
    6768
    68 // we constraint limits by the min valid minor axis:
    69 # define MIN_MINOR_AXIS 0.5
    70 
    71 // f3 = (s_b^-2 - s_a^-2); F3_SQ_MAX is MIN_MINOR_AXIS^-4
    72 # define F3_SQ_MAX 16.0
    73 
    74 static float saveParams[8];
    75 
    7669bool PM_MODEL_LIMITS (psMinConstraintMode mode, int nParam, float *params, float *beta)
    7770{
     
    150143            psAbort("invalid parameter %d for param min test", nParam);
    151144        }
    152         saveParams[nParam] = params[nParam];
    153145        if (params[nParam] < params_min) {
    154146            params[nParam] = params_min;
     
    184176            psAbort("invalid parameter %d for param max test", nParam);
    185177        }
    186         saveParams[nParam] = params[nParam];
    187178        if (params[nParam] > params_max) {
    188179            params[nParam] = params_max;
     
    263254psF64 PM_MODEL_RADIUS (const psVector *params, psF64 flux)
    264255{
     256    psF64 z, f;
     257    int Nstep = 0;
    265258    psEllipseShape shape;
    266259
     
    280273    // this estimates the radius assuming f(z) is roughly exp(-z)
    281274    psEllipseAxes axes = psEllipseShapeToAxes (shape, 20.0);
    282     psF64 radius = axes.major * sqrt (2.0 * log(PAR[PM_PAR_I0] / flux));
     275    psF64 sigma = axes.major;
     276
     277    psF64 limit = flux / PAR[PM_PAR_I0];
     278
     279    // use the fact that f is monotonically decreasing
     280    z = 0;
     281    Nstep = 0;
     282
     283    // choose a z value guaranteed to be beyond our limit
     284    float z0 = pow((1.0 / limit), (1.0 / 3.0));
     285    float z1 = (1.0 / limit);
     286    z1 = PS_MAX (z0, z1);
     287    z0 = 0.0;
     288
     289    // perform a type of bisection to find the value
     290    float f0 = 1.0 / (1 + z0 + z0*z0/2.0 + z0*z0*z0/6.0);
     291    float f1 = 1.0 / (1 + z1 + z1*z1/2.0 + z1*z1*z1/6.0);
     292    while ((Nstep < 10) && (fabs(z1 - z0) > 0.5)) {
     293        z = 0.5*(z0 + z1);
     294        f = 1.0 / (1 + z + z*z/2.0 + z*z*z/6.0);
     295        if (f > limit) {
     296            z0 = z;
     297            f0 = f;
     298        } else {
     299            z1 = z;
     300            f1 = f;
     301        }
     302        Nstep ++;
     303    }
     304    psF64 radius = sigma * sqrt (2.0 * z);
     305
     306    // psF64 radius = axes.major * sqrt (2.0 * log(PAR[PM_PAR_I0] / flux));
    283307
    284308    if (isnan(radius))
     
    297321
    298322    // we require these two parameters to exist
    299     assert (psf->params_NEW->n > PM_PAR_YPOS);
    300     assert (psf->params_NEW->n > PM_PAR_XPOS);
    301 
    302     for (int i = 0; i < psf->params_NEW->n; i++) {
    303         if (psf->params_NEW->data[i] == NULL) {
     323    assert (psf->params->n > PM_PAR_YPOS);
     324    assert (psf->params->n > PM_PAR_XPOS);
     325
     326    for (int i = 0; i < psf->params->n; i++) {
     327        if (psf->params->data[i] == NULL) {
    304328            out[i] = in[i];
    305329        } else {
    306             psPolynomial2D *poly = psf->params_NEW->data[i];
     330            psPolynomial2D *poly = psf->params->data[i];
    307331            out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    308332        }
     
    322346    // apply the model limits here: this truncates excessive extrapolation
    323347    // XXX do we need to do this still?  should we put in asserts to test?
    324     for (int i = 0; i < psf->params_NEW->n; i++) {
     348    for (int i = 0; i < psf->params->n; i++) {
    325349        // apply the limits to all components or just the psf-model parameters?
    326         if (psf->params_NEW->data[i] == NULL)
     350        if (psf->params->data[i] == NULL)
    327351            continue;
    328352
     
    339363}
    340364
     365// construct the PSF model from the FLT model and the psf
     366// XXX is this sufficiently general do be a global function, not a pmModelClass function?
     367bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
     368{
     369    psF32 *PAR = model->params->data.F32;
     370
     371    // we require these two parameters to exist
     372    assert (psf->params->n > PM_PAR_YPOS);
     373    assert (psf->params->n > PM_PAR_XPOS);
     374
     375    PAR[PM_PAR_SKY]  = 0.0;
     376    PAR[PM_PAR_I0]   = Io;
     377    PAR[PM_PAR_XPOS] = Xo;
     378    PAR[PM_PAR_YPOS] = Yo;
     379   
     380    // supply the model-fitted parameters, or copy from the input
     381    for (int i = 0; i < psf->params->n; i++) {
     382        if (i == PM_PAR_SKY) continue;
     383        if (i == PM_PAR_I0) continue;
     384        if (i == PM_PAR_XPOS) continue;
     385        if (i == PM_PAR_YPOS) continue;
     386        psPolynomial2D *poly = psf->params->data[i];
     387        assert (poly);
     388        PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     389    }
     390
     391    // the 2D PSF model fits polarization terms (E0,E1,E2)
     392    // convert to shape terms (SXX,SYY,SXY)
     393    // XXX user-defined value for limit?
     394    if (!pmPSF_FitToModel (PAR, 0.1)) {
     395        psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
     396        return false;
     397    }
     398
     399    // apply the model limits here: this truncates excessive extrapolation
     400    // XXX do we need to do this still?  should we put in asserts to test?
     401    for (int i = 0; i < psf->params->n; i++) {
     402        // apply the limits to all components or just the psf-model parameters?
     403        if (psf->params->data[i] == NULL)
     404            continue;
     405
     406        bool status = true;
     407        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
     408        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
     409        if (!status) {
     410            psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
     411            model->flags |= PM_MODEL_STATUS_LIMITS;
     412        }
     413    }
     414    return(true);
     415}
     416
    341417bool PM_MODEL_FIT_STATUS (pmModel *model)
    342418{
     
    367443# undef PM_MODEL_RADIUS
    368444# undef PM_MODEL_FROM_PSF
     445# undef PM_MODEL_PARAMS_FROM_PSF
    369446# undef PM_MODEL_FIT_STATUS
  • trunk/psModules/src/objects/models/pmModel_QGAUSS.c

    r14344 r14652  
    2020   *****************************************************************************/
    2121
    22 # define PM_MODEL_FUNC       pmModelFunc_QGAUSS
    23 # define PM_MODEL_FLUX       pmModelFlux_QGAUSS
    24 # define PM_MODEL_GUESS      pmModelGuess_QGAUSS
    25 # define PM_MODEL_LIMITS     pmModelLimits_QGAUSS
    26 # define PM_MODEL_RADIUS     pmModelRadius_QGAUSS
    27 # define PM_MODEL_FROM_PSF   pmModelFromPSF_QGAUSS
    28 # define PM_MODEL_FIT_STATUS pmModelFitStatus_QGAUSS
     22# define PM_MODEL_FUNC            pmModelFunc_QGAUSS
     23# define PM_MODEL_FLUX            pmModelFlux_QGAUSS
     24# define PM_MODEL_GUESS           pmModelGuess_QGAUSS
     25# define PM_MODEL_LIMITS          pmModelLimits_QGAUSS
     26# define PM_MODEL_RADIUS          pmModelRadius_QGAUSS
     27# define PM_MODEL_FROM_PSF        pmModelFromPSF_QGAUSS
     28# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_QGAUSS
     29# define PM_MODEL_FIT_STATUS      pmModelFitStatus_QGAUSS
    2930
    3031psF32 PM_MODEL_FUNC (psVector *deriv,
     
    350351
    351352    // we require these two parameters to exist
    352     assert (psf->params_NEW->n > PM_PAR_YPOS);
    353     assert (psf->params_NEW->n > PM_PAR_XPOS);
    354 
    355     for (int i = 0; i < psf->params_NEW->n; i++) {
    356         if (psf->params_NEW->data[i] == NULL) {
     353    assert (psf->params->n > PM_PAR_YPOS);
     354    assert (psf->params->n > PM_PAR_XPOS);
     355
     356    for (int i = 0; i < psf->params->n; i++) {
     357        if (psf->params->data[i] == NULL) {
    357358            out[i] = in[i];
    358359        } else {
    359             psPolynomial2D *poly = psf->params_NEW->data[i];
     360            psPolynomial2D *poly = psf->params->data[i];
    360361            out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    361362        }
     
    372373    // apply the model limits here: this truncates excessive extrapolation
    373374    // XXX do we need to do this still?  should we put in asserts to test?
    374     for (int i = 0; i < psf->params_NEW->n; i++) {
     375    for (int i = 0; i < psf->params->n; i++) {
    375376        // apply the limits to all components or just the psf-model parameters?
    376         if (psf->params_NEW->data[i] == NULL)
     377        if (psf->params->data[i] == NULL)
    377378            continue;
    378379
     
    390391}
    391392
     393// construct the PSF model from the FLT model and the psf
     394// XXX is this sufficiently general do be a global function, not a pmModelClass function?
     395bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
     396{
     397    psF32 *PAR = model->params->data.F32;
     398
     399    // we require these two parameters to exist
     400    assert (psf->params->n > PM_PAR_YPOS);
     401    assert (psf->params->n > PM_PAR_XPOS);
     402
     403    PAR[PM_PAR_SKY]  = 0.0;
     404    PAR[PM_PAR_I0]   = Io;
     405    PAR[PM_PAR_XPOS] = Xo;
     406    PAR[PM_PAR_YPOS] = Yo;
     407   
     408    // supply the model-fitted parameters, or copy from the input
     409    for (int i = 0; i < psf->params->n; i++) {
     410        if (i == PM_PAR_SKY) continue;
     411        if (i == PM_PAR_I0) continue;
     412        if (i == PM_PAR_XPOS) continue;
     413        if (i == PM_PAR_YPOS) continue;
     414        psPolynomial2D *poly = psf->params->data[i];
     415        assert (poly);
     416        PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     417    }
     418
     419    // the 2D PSF model fits polarization terms (E0,E1,E2)
     420    // convert to shape terms (SXX,SYY,SXY)
     421    // XXX user-defined value for limit?
     422    if (!pmPSF_FitToModel (PAR, 0.1)) {
     423        psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
     424        return false;
     425    }
     426
     427    // apply the model limits here: this truncates excessive extrapolation
     428    // XXX do we need to do this still?  should we put in asserts to test?
     429    for (int i = 0; i < psf->params->n; i++) {
     430        // apply the limits to all components or just the psf-model parameters?
     431        if (psf->params->data[i] == NULL)
     432            continue;
     433
     434        bool status = true;
     435        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
     436        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
     437        if (!status) {
     438            psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
     439            model->flags |= PM_MODEL_STATUS_LIMITS;
     440        }
     441    }
     442    return(true);
     443}
     444
    392445bool PM_MODEL_FIT_STATUS (pmModel *model)
    393446{
     
    418471# undef PM_MODEL_RADIUS
    419472# undef PM_MODEL_FROM_PSF
     473# undef PM_MODEL_PARAMS_FROM_PSF
    420474# undef PM_MODEL_FIT_STATUS
  • trunk/psModules/src/objects/models/pmModel_RGAUSS.c

    r14323 r14652  
    2020 *****************************************************************************/
    2121
    22 # define PM_MODEL_FUNC       pmModelFunc_RGAUSS
    23 # define PM_MODEL_FLUX       pmModelFlux_RGAUSS
    24 # define PM_MODEL_GUESS      pmModelGuess_RGAUSS
    25 # define PM_MODEL_LIMITS     pmModelLimits_RGAUSS
    26 # define PM_MODEL_RADIUS     pmModelRadius_RGAUSS
    27 # define PM_MODEL_FROM_PSF   pmModelFromPSF_RGAUSS
    28 # define PM_MODEL_FIT_STATUS pmModelFitStatus_RGAUSS
     22# define PM_MODEL_FUNC            pmModelFunc_RGAUSS
     23# define PM_MODEL_FLUX            pmModelFlux_RGAUSS
     24# define PM_MODEL_GUESS           pmModelGuess_RGAUSS
     25# define PM_MODEL_LIMITS          pmModelLimits_RGAUSS
     26# define PM_MODEL_RADIUS          pmModelRadius_RGAUSS
     27# define PM_MODEL_FROM_PSF        pmModelFromPSF_RGAUSS
     28# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_RGAUSS
     29# define PM_MODEL_FIT_STATUS      pmModelFitStatus_RGAUSS
    2930
    3031psF32 PM_MODEL_FUNC (psVector *deriv,
     
    343344
    344345    // we require these two parameters to exist
    345     assert (psf->params_NEW->n > PM_PAR_YPOS);
    346     assert (psf->params_NEW->n > PM_PAR_XPOS);
    347 
    348     for (int i = 0; i < psf->params_NEW->n; i++) {
    349         if (psf->params_NEW->data[i] == NULL) {
     346    assert (psf->params->n > PM_PAR_YPOS);
     347    assert (psf->params->n > PM_PAR_XPOS);
     348
     349    for (int i = 0; i < psf->params->n; i++) {
     350        if (psf->params->data[i] == NULL) {
    350351            out[i] = in[i];
    351352        } else {
    352             psPolynomial2D *poly = psf->params_NEW->data[i];
     353            psPolynomial2D *poly = psf->params->data[i];
    353354            out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    354355        }
     
    365366    // apply the model limits here: this truncates excessive extrapolation
    366367    // XXX do we need to do this still?  should we put in asserts to test?
    367     for (int i = 0; i < psf->params_NEW->n; i++) {
     368    for (int i = 0; i < psf->params->n; i++) {
    368369        // apply the limits to all components or just the psf-model parameters?
    369         if (psf->params_NEW->data[i] == NULL)
     370        if (psf->params->data[i] == NULL)
    370371            continue;
    371372
     
    383384}
    384385
     386// construct the PSF model from the FLT model and the psf
     387// XXX is this sufficiently general do be a global function, not a pmModelClass function?
     388bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
     389{
     390    psF32 *PAR = model->params->data.F32;
     391
     392    // we require these two parameters to exist
     393    assert (psf->params->n > PM_PAR_YPOS);
     394    assert (psf->params->n > PM_PAR_XPOS);
     395
     396    PAR[PM_PAR_SKY]  = 0.0;
     397    PAR[PM_PAR_I0]   = Io;
     398    PAR[PM_PAR_XPOS] = Xo;
     399    PAR[PM_PAR_YPOS] = Yo;
     400   
     401    // supply the model-fitted parameters, or copy from the input
     402    for (int i = 0; i < psf->params->n; i++) {
     403        if (i == PM_PAR_SKY) continue;
     404        if (i == PM_PAR_I0) continue;
     405        if (i == PM_PAR_XPOS) continue;
     406        if (i == PM_PAR_YPOS) continue;
     407        psPolynomial2D *poly = psf->params->data[i];
     408        assert (poly);
     409        PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     410    }
     411
     412    // the 2D PSF model fits polarization terms (E0,E1,E2)
     413    // convert to shape terms (SXX,SYY,SXY)
     414    // XXX user-defined value for limit?
     415    if (!pmPSF_FitToModel (PAR, 0.1)) {
     416        psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
     417        return false;
     418    }
     419
     420    // apply the model limits here: this truncates excessive extrapolation
     421    // XXX do we need to do this still?  should we put in asserts to test?
     422    for (int i = 0; i < psf->params->n; i++) {
     423        // apply the limits to all components or just the psf-model parameters?
     424        if (psf->params->data[i] == NULL)
     425            continue;
     426
     427        bool status = true;
     428        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
     429        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
     430        if (!status) {
     431            psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
     432            model->flags |= PM_MODEL_STATUS_LIMITS;
     433        }
     434    }
     435    return(true);
     436}
     437
    385438bool PM_MODEL_FIT_STATUS (pmModel *model)
    386439{
     
    411464# undef PM_MODEL_RADIUS
    412465# undef PM_MODEL_FROM_PSF
     466# undef PM_MODEL_PARAMS_FROM_PSF
    413467# undef PM_MODEL_FIT_STATUS
  • trunk/psModules/src/objects/models/pmModel_SERSIC.c

    r14345 r14652  
    2323   *****************************************************************************/
    2424
    25 # define PM_MODEL_FUNC       pmModelFunc_SERSIC
    26 # define PM_MODEL_FLUX       pmModelFlux_SERSIC
    27 # define PM_MODEL_GUESS      pmModelGuess_SERSIC
    28 # define PM_MODEL_LIMITS     pmModelLimits_SERSIC
    29 # define PM_MODEL_RADIUS     pmModelRadius_SERSIC
    30 # define PM_MODEL_FROM_PSF   pmModelFromPSF_SERSIC
    31 # define PM_MODEL_FIT_STATUS pmModelFitStatus_SERSIC
     25# define PM_MODEL_FUNC            pmModelFunc_SERSIC
     26# define PM_MODEL_FLUX            pmModelFlux_SERSIC
     27# define PM_MODEL_GUESS           pmModelGuess_SERSIC
     28# define PM_MODEL_LIMITS          pmModelLimits_SERSIC
     29# define PM_MODEL_RADIUS          pmModelRadius_SERSIC
     30# define PM_MODEL_FROM_PSF        pmModelFromPSF_SERSIC
     31# define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_SERSIC
     32# define PM_MODEL_FIT_STATUS      pmModelFitStatus_SERSIC
    3233
    3334psF32 PM_MODEL_FUNC (psVector *deriv,
     
    360361
    361362    // we require these two parameters to exist
    362     assert (psf->params_NEW->n > PM_PAR_YPOS);
    363     assert (psf->params_NEW->n > PM_PAR_XPOS);
    364 
    365     for (int i = 0; i < psf->params_NEW->n; i++) {
    366         if (psf->params_NEW->data[i] == NULL) {
     363    assert (psf->params->n > PM_PAR_YPOS);
     364    assert (psf->params->n > PM_PAR_XPOS);
     365
     366    for (int i = 0; i < psf->params->n; i++) {
     367        if (psf->params->data[i] == NULL) {
    367368            out[i] = in[i];
    368369        } else {
    369             psPolynomial2D *poly = psf->params_NEW->data[i];
     370            psPolynomial2D *poly = psf->params->data[i];
    370371            out[i] = psPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);
    371372        }
     
    382383    // apply the model limits here: this truncates excessive extrapolation
    383384    // XXX do we need to do this still?  should we put in asserts to test?
    384     for (int i = 0; i < psf->params_NEW->n; i++) {
     385    for (int i = 0; i < psf->params->n; i++) {
    385386        // apply the limits to all components or just the psf-model parameters?
    386         if (psf->params_NEW->data[i] == NULL)
     387        if (psf->params->data[i] == NULL)
    387388            continue;
    388389
     
    400401}
    401402
     403// construct the PSF model from the FLT model and the psf
     404// XXX is this sufficiently general do be a global function, not a pmModelClass function?
     405bool PM_MODEL_PARAMS_FROM_PSF (pmModel *model, pmPSF *psf, float Xo, float Yo, float Io)
     406{
     407    psF32 *PAR = model->params->data.F32;
     408
     409    // we require these two parameters to exist
     410    assert (psf->params->n > PM_PAR_YPOS);
     411    assert (psf->params->n > PM_PAR_XPOS);
     412
     413    PAR[PM_PAR_SKY]  = 0.0;
     414    PAR[PM_PAR_I0]   = Io;
     415    PAR[PM_PAR_XPOS] = Xo;
     416    PAR[PM_PAR_YPOS] = Yo;
     417   
     418    // supply the model-fitted parameters, or copy from the input
     419    for (int i = 0; i < psf->params->n; i++) {
     420        if (i == PM_PAR_SKY) continue;
     421        if (i == PM_PAR_I0) continue;
     422        if (i == PM_PAR_XPOS) continue;
     423        if (i == PM_PAR_YPOS) continue;
     424        psPolynomial2D *poly = psf->params->data[i];
     425        assert (poly);
     426        PAR[i] = psPolynomial2DEval(poly, Xo, Yo);
     427    }
     428
     429    // the 2D PSF model fits polarization terms (E0,E1,E2)
     430    // convert to shape terms (SXX,SYY,SXY)
     431    // XXX user-defined value for limit?
     432    if (!pmPSF_FitToModel (PAR, 0.1)) {
     433        psError(PM_ERR_PSF, false, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
     434        return false;
     435    }
     436
     437    // apply the model limits here: this truncates excessive extrapolation
     438    // XXX do we need to do this still?  should we put in asserts to test?
     439    for (int i = 0; i < psf->params->n; i++) {
     440        // apply the limits to all components or just the psf-model parameters?
     441        if (psf->params->data[i] == NULL)
     442            continue;
     443
     444        bool status = true;
     445        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MIN, i, PAR, NULL);
     446        status &= PM_MODEL_LIMITS (PS_MINIMIZE_PARAM_MAX, i, PAR, NULL);
     447        if (!status) {
     448            psTrace ("psModules.objects", 5, "Hitting parameter limits at (r,c) = (%.1f, %.1f)", Xo, Yo);
     449            model->flags |= PM_MODEL_STATUS_LIMITS;
     450        }
     451    }
     452    return(true);
     453}
     454
    402455bool PM_MODEL_FIT_STATUS (pmModel *model)
    403456{
     
    428481# undef PM_MODEL_RADIUS
    429482# undef PM_MODEL_FROM_PSF
     483# undef PM_MODEL_PARAMS_FROM_PSF
    430484# undef PM_MODEL_FIT_STATUS
  • trunk/psModules/src/objects/pmGrowthCurve.c

    r12949 r14652  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-04-21 19:47:14 $
     7 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-08-24 00:11:02 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "pmMoments.h"
    2424#include "pmResiduals.h"
     25#include "pmGrowthCurve.h"
     26#include "pmPSF.h"
    2527#include "pmModel.h"
    2628#include "pmSource.h"
    27 #include "pmGrowthCurve.h"
    28 #include "pmPSF.h"
    2929#include "psVectorBracket.h"
    3030
  • trunk/psModules/src/objects/pmModel.c

    r13898 r14652  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-06-20 02:22:26 $
     8 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2121#include <string.h>
    2222#include <pslib.h>
     23#include "pmHDU.h"
     24#include "pmFPA.h"
    2325#include "pmResiduals.h"
     26#include "pmGrowthCurve.h"
     27#include "pmPSF.h"
    2428#include "pmModel.h"
    25 
    26 /* The following types and functions need to be known by pmModel.c and are defined in
    27    pmModelGroup.h.  The use of pmSource and other types in pmModelGroup.h prevent us from
    28    directly including it here  ***/
    29 
    30 typedef psMinimizeLMChi2Func pmModelFunc;
    31 typedef bool (*pmModelFitStatusFunc)(pmModel *model);
    32 pmModelFunc pmModelFunc_GetFunction (pmModelType type);
    33 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type);
    34 int pmModelParameterCount(pmModelType type);
     29#include "pmModelClass.h"
    3530
    3631static void modelFree(pmModel *tmp)
     
    4540pmModelAlloc(): Allocate the pmModel structure, along with its parameters,
    4641and initialize the type member.  Initialize the params to 0.0.
    47 XXX EAM: simplifying code with pmModelParameterCount
    4842*****************************************************************************/
    4943pmModel *pmModelAlloc(pmModelType type)
     
    5347    pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
    5448    psMemSetDeallocator(tmp, (psFreeFunc) modelFree);
     49
     50    pmModelClass *class = pmModelClassSelect (type);
     51    if (class == NULL) {
     52        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
     53        return(NULL);
     54    }
    5555
    5656    tmp->type = type;
     
    6262    tmp->residuals = NULL;              // XXX should the model own this memory?
    6363
    64     psS32 Nparams = pmModelParameterCount(type);
    65     if (Nparams == 0) {
    66         psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
    67         return(NULL);
    68     }
     64    psS32 Nparams = pmModelClassParameterCount(type);
     65    assert (Nparams);
    6966
    7067    tmp->params  = psVectorAlloc(Nparams, PS_TYPE_F32);
    7168    tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32);
     69    assert (tmp->params);
     70    assert (tmp->dparams);
    7271
    7372    for (psS32 i = 0; i < tmp->params->n; i++) {
     
    7574        tmp->dparams->data.F32[i] = 0.0;
    7675    }
     76
     77    tmp->modelFunc          = class->modelFunc;
     78    tmp->modelFlux          = class->modelFlux;
     79    tmp->modelRadius        = class->modelRadius;
     80    tmp->modelLimits        = class->modelLimits;
     81    tmp->modelGuess         = class->modelGuess;
     82    tmp->modelFromPSF       = class->modelFromPSF;
     83    tmp->modelParamsFromPSF = class->modelParamsFromPSF;
     84    tmp->modelFitStatus     = class->modelFitStatus;
    7785
    7886    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     
    92100    new->radiusFit = model->radiusFit;
    93101
    94     // XXX note that model->residuals is just a reference
    95     new->residuals = model->residuals;
    96 
    97102    for (int i = 0; i < new->params->n; i++) {
    98103        new->params->data.F32[i]  = model->params->data.F32[i];
    99104        new->dparams->data.F32[i] = model->dparams->data.F32[i];
    100105    }
     106
     107    // note that model->residuals is just a reference
     108    new->residuals = model->residuals;
    101109
    102110    return (new);
     
    123131    x->data.F32[1] = (psF32) (row + image->row0);
    124132    psF32 tmpF;
    125     pmModelFunc modelFunc;
    126 
    127     modelFunc = pmModelFunc_GetFunction (model->type);
    128     tmpF = modelFunc (NULL, model->params, x);
     133
     134    tmpF = model->modelFunc (NULL, model->params, x);
     135    psFree(x);
     136    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     137    return(tmpF);
     138}
     139
     140psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, psS32 col, psS32 row, int dx, int dy)
     141{
     142    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     143    PS_ASSERT_PTR_NON_NULL(image, false);
     144    PS_ASSERT_PTR_NON_NULL(model, false);
     145    PS_ASSERT_PTR_NON_NULL(model->params, false);
     146
     147    // Allocate the x coordinate structure and convert row/col to image space.
     148    //
     149    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
     150    x->data.F32[0] = (psF32) (col + image->col0 + dx);
     151    x->data.F32[1] = (psF32) (row + image->row0 + dy);
     152    psF32 tmpF;
     153
     154    tmpF = model->modelFunc (NULL, model->params, x);
    129155    psFree(x);
    130156    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     
    137163                          pmModelOpMode mode,
    138164                          bool add,
    139                           psMaskType maskVal
     165                          psMaskType maskVal,
     166                          int dx,
     167                          int dy
    140168    )
    141169{
     
    148176    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
    149177    psVector *params = model->params;
    150     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
     178
    151179    psS32 imageCol;
    152180    psS32 imageRow;
     
    209237            // Convert i/j to image coord space:
    210238            // XXX should we use using 0.5 pixel offset?
    211             imageCol = ix + image->col0;
    212             imageRow = iy + image->row0;
     239            imageCol = ix + image->col0 + dx;
     240            imageRow = iy + image->row0 + dy;
    213241
    214242            x->data.F32[0] = (float) imageCol;
     
    219247            // add in the desired components for this coordinate
    220248            if (mode & PM_MODEL_OP_FUNC) {
    221                 pixelValue += modelFunc (NULL, params, x);
     249                pixelValue += model->modelFunc (NULL, params, x);
    222250            }
    223251
     
    280308{
    281309    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    282     psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal);
     310    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, 0.0, 0.0);
    283311    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    284312    return(rc);
     
    294322{
    295323    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    296     psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal);
     324    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, 0.0, 0.0);
    297325    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    298326    return(rc);
    299327}
    300328
    301 // check for success of model fit
    302 bool pmModelFitStatus (pmModel *model)
    303 {
    304 
    305     bool status;
    306 
    307     pmModelFitStatusFunc statusFunc = pmModelFitStatusFunc_GetFunction (model->type);
    308     status = statusFunc (model);
    309 
    310     return (status);
    311 }
    312 
     329/******************************************************************************
     330 *****************************************************************************/
     331bool pmModelAddWithOffset(psImage *image,
     332                          psImage *mask,
     333                          pmModel *model,
     334                          pmModelOpMode mode,
     335                          psMaskType maskVal,
     336                          int dx,
     337                          int dy)
     338{
     339    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     340    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, dx, dy);
     341    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     342    return(rc);
     343}
     344
     345/******************************************************************************
     346 *****************************************************************************/
     347bool pmModelSubWithOffset(psImage *image,
     348                          psImage *mask,
     349                          pmModel *model,
     350                          pmModelOpMode mode,
     351                          psMaskType maskVal,
     352                          int dx,
     353                          int dy)
     354{
     355    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     356    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, dx, dy);
     357    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     358    return(rc);
     359}
  • trunk/psModules/src/objects/pmModel.h

    r13898 r14652  
    1 /* @file  pmObjects.h
     1/* @file  pmModel.h
    22 * @brief Functions to define and manipulate object models
    33 *
     
    55 * @author EAM, IfA
    66 *
    7  * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-06-20 02:22:26 $
     7 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-08-24 00:11:02 $
    99 *
    1010 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717/// @{
    1818
    19 // type of model carried by the pmModel structure
    20 typedef int pmModelType;
     19/* pointers for the functions types below are supplied to each pmModel, and can be used by
     20   the programmer without needing to know the model class */
    2121
    2222typedef enum {
     
    4141} pmModelOpMode;
    4242
     43typedef struct pmModel pmModel;
     44typedef struct pmSource pmSource;
     45
     46//  This function is the model chi-square minimization function for this model.
     47typedef psMinimizeLMChi2Func pmModelFunc;
     48
     49//  This function sets the parameter limits for this model.
     50typedef psMinimizeLMLimitFunc pmModelLimits;
     51
     52// This function returns the integrated flux for the given model parameters.
     53typedef psF64 (*pmModelFlux)(const psVector *params);
     54
     55// This function returns the radius at which the given model and parameters
     56// achieves the given flux.
     57typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
     58
     59//  This function provides the model guess parameters based on the details of
     60//  the given source.
     61typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source);
     62
     63//  This function constructs the PSF model for the given source based on the
     64//  supplied psf and the EXT model for the object.
     65typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf);
     66
     67//  This function sets the model parameters based on the PSF for a given coordinate and central
     68//  intensity
     69typedef bool (*pmModelParamsFromPSF)(pmModel *model, pmPSF *psf, float Xo, float Yo, float Io);
     70
     71//  This function returns the success / failure status of the given model fit
     72typedef bool (*pmModelFitStatusFunc)(pmModel *model);
     73
    4374/** pmModel data structure
    4475 *
     
    5081 *
    5182 */
    52 typedef struct
    53 {
     83struct pmModel {
    5484    pmModelType type;                   ///< Model to be used.
    5585    psVector *params;                   ///< Paramater values.
     
    6292    float radiusFit;                    ///< fit radius actually used
    6393    pmResiduals *residuals;             ///< normalized PSF residuals
    64 }
    65 pmModel;
    6694
    67 /* XXX we are currently saving the residuals with the pmModel.  It might be better to save this
    68  * in the pmSource.  we may want an API to Add/Sub a pmModel (analytical model only) or a
    69  * pmSource (analytical + residuals).
    70  */
     95    // functions for this model which depend on the model class
     96    pmModelFunc          modelFunc;
     97    pmModelFlux          modelFlux;
     98    pmModelRadius        modelRadius;
     99    pmModelLimits        modelLimits;
     100    pmModelGuessFunc     modelGuess;
     101    pmModelFromPSFFunc   modelFromPSF;
     102    pmModelParamsFromPSF modelParamsFromPSF;
     103    pmModelFitStatusFunc modelFitStatus;
     104};
    71105
    72106/** Symbolic names for the elements of [d]params
     
    130164);
    131165
     166bool pmModelAddWithOffset(psImage *image,
     167                          psImage *mask,
     168                          pmModel *model,
     169                          pmModelOpMode mode,
     170                          psMaskType maskVal,
     171                          int dx,
     172                          int dy);
     173
     174bool pmModelSubWithOffset(psImage *image,
     175                          psImage *mask,
     176                          pmModel *model,
     177                          pmModelOpMode mode,
     178                          psMaskType maskVal,
     179                          int dx,
     180                          int dy);
     181
    132182/** pmModelFitStatus()
    133183 *
  • trunk/psModules/src/objects/pmModelGroup.c

    r14325 r14652  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-07-20 00:31:43 $
     8 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828#include "pmResiduals.h"
    2929#include "pmModel.h"
    30 #include "pmResiduals.h"
    31 #include "pmPSF.h"
    32 #include "pmSource.h"
    3330#include "pmModelGroup.h"
    3431#include "pmErrorCodes.h"
     
    198195    return (models[type].name);
    199196}
    200 
    201 /******************************************************************************
    202     pmSourceModelGuess(source, model): This function allocates a new
    203     pmModel structure based on the given modelType specified in the argument list.
    204     The corresponding pmModelGuess function is returned, and used to
    205     supply the values of the params array in the pmModel structure.
    206  
    207     XXX: Many parameters are based on the src->moments structure, which is in
    208     image, not subImage coords.  Therefore, the calls to the model evaluation
    209     functions will be in image, not subImage coords.  Remember this.
    210 *****************************************************************************/
    211 pmModel *pmSourceModelGuess(pmSource *source,
    212                             pmModelType modelType)
    213 {
    214     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    215     PS_ASSERT_PTR_NON_NULL(source, NULL);
    216     PS_ASSERT_PTR_NON_NULL(source->moments, NULL);
    217     PS_ASSERT_PTR_NON_NULL(source->peak, NULL);
    218 
    219     pmModel *model = pmModelAlloc(modelType);
    220 
    221     pmModelGuessFunc modelGuessFunc = pmModelGuessFunc_GetFunction(modelType);
    222     if (!modelGuessFunc(model, source)) {
    223         psFree (model);
    224         return NULL;
    225     }
    226 
    227     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
    228     return(model);
    229 }
    230 
  • trunk/psModules/src/objects/pmModelGroup.h

    r11253 r14652  
    11/* @file  pmModelGroup.h
    22 *
    3  * The object model function types are defined to allow for the flexible addition
    4  * of new object models. Every object model, with parameters represented by
    5  * pmModel, has an associated set of functions which provide necessary support
    6  * operations. A set of abstract functions allow the programmer to select the
    7  * approriate function or property for a specific named object model.
     3 * The object model function types are desined to allow for the flexible addition of new object
     4 * models. Every object model, with parameters represented by pmModel, has an associated set of
     5 * functions which provide necessary support operations. A set of abstract functions allow the
     6 * programmer to select the approriate function or property for a specific named object model.
     7 *
     8 * Every model instance belongs to a class of models, defined by the value of
     9 * the pmModelType type entry. Various functions need access to information about
     10 * each of the models. Some of this information varies from model to model, and
     11 * may depend on the current parameter values or other data quantities. In order
     12 * to keep the code from requiring the information about each model to be coded
     13 * into the low-level fitting routines, we define a collection of functions which
     14 * allow us to abstract this type of model-dependent information. These generic
     15 * functions take the model type and return the corresponding function pointer
     16 * for the specified model. Each model is defined by creating this collection of
     17 * specific functions, and placing them in a single file for each model. We
     18 * define the following structure to carry the collection of information about
     19 * the models.
    820 *
    921 * @author EAM, IfA
    1022 *
    11  * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    12  * @date $Date: 2007-01-24 02:54:15 $
     23 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     24 * @date $Date: 2007-08-24 00:11:02 $
    1325 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1426 */
     
    2335typedef psMinimizeLMChi2Func pmModelFunc;
    2436
    25 //  This function is the model chi-square minimization function for this model.
     37//  This function sets the parameter limits for this model.
    2638typedef psMinimizeLMLimitFunc pmModelLimits;
    2739
     
    2941typedef psF64 (*pmModelFlux)(const psVector *params);
    3042
    31 
    3243// This function returns the radius at which the given model and parameters
    3344// achieves the given flux.
    3445typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
    3546
    36 /*  This function sets the model parameter limits vectors for the given model
    37  */
    38 // typedef bool (*pmModelLimits)(psVector **beta_lim, psVector **params_min, psVector **params_max);
    39 
    40 /*  This function provides the model guess parameters based on the details of
    41  *   the given source.
    42  */
     47//  This function provides the model guess parameters based on the details of
     48//  the given source.
    4349typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source);
    4450
    45 
    46 /*  This function constructs the PSF model for the given source based on the
    47  *  supplied psf and the EXT model for the object.
    48  */
     51//  This function constructs the PSF model for the given source based on the
     52//  supplied psf and the EXT model for the object.
    4953typedef bool (*pmModelFromPSFFunc)(pmModel *modelPSF, pmModel *modelEXT, pmPSF *psf);
    5054
    51 /*  This function returns the success / failure status of the given model fit
    52  */
     55//  This function sets the model parameters based on the PSF for a given coordinate and central
     56//  intensity
     57typedef bool (*pmModelParamsFromPSF)(pmModel *model, pmPSF *psf, float Xo, float Yo, float Io);
     58
     59//  This function returns the success / failure status of the given model fit
    5360typedef bool (*pmModelFitStatusFunc)(pmModel *model);
    5461
    55 /* Every model instance belongs to a class of models, defined by the value of
    56  * the pmModelType type entry. Various functions need access to information about
    57  * each of the models. Some of this information varies from model to model, and
    58  * may depend on the current parameter values or other data quantities. In order
    59  * to keep the code from requiring the information about each model to be coded
    60  * into the low-level fitting routines, we define a collection of functions which
    61  * allow us to abstract this type of model-dependent information. These generic
    62  * functions take the model type and return the corresponding function pointer
    63  * for the specified model. Each model is defined by creating this collection of
    64  * specific functions, and placing them in a single file for each model. We
    65  * define the following structure to carry the collection of information about
    66  * the models.
    67  */
    6862typedef struct
    6963{
     
    7670    pmModelGuessFunc     modelGuessFunc;
    7771    pmModelFromPSFFunc   modelFromPSFFunc;
     72    pmModelParamsFromPSF modelParamsFromPSF;
    7873    pmModelFitStatusFunc modelFitStatusFunc;
    7974}
  • trunk/psModules/src/objects/pmModelUtils.c

    r14530 r14652  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-08-16 18:33:37 $
     7 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-08-24 00:11:02 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2020#include <string.h>
    2121#include <pslib.h>
     22#include "pmHDU.h"
     23#include "pmFPA.h"
    2224#include "pmResiduals.h"
     25#include "pmGrowthCurve.h"
     26#include "pmPSF.h"
    2327#include "pmModel.h"
     28#include "pmErrorCodes.h"
     29#include "pmModelUtils.h"
    2430
    25 // instantiate a model for the PSF at this location (normalized or not?)
    26 // NOTE: psf and (x,y) are defined wrt chip coordinates
    27 pmModel *pmModelFromPSFforXY (pmPSF *psf, float x, float y, float flux) {
    28 
    29     assert (psf);
    30 
    31     // allocate a new pmModel to hold the PSF version
    32     pmModel *modelEXT = pmModelAlloc (psf->type);
    33 
    34     modelEXT->params->data.F32[PM_PAR_SKY]  = 0.0;
    35     modelEXT->params->data.F32[PM_PAR_I0]   = 1.0;
    36     modelEXT->params->data.F32[PM_PAR_XPOS] = x;
    37     modelEXT->params->data.F32[PM_PAR_YPOS] = y;
    38 
    39     // find function used to set the model parameters
    40     pmModelFromPSFFunc modelFromPSFFunc = pmModelFromPSFFunc_GetFunction (psf->type);
    41 
     31/*****************************************************************************
     32pmModelFromPSF (*modelEXT, *psf):  use the model position parameters to
     33construct a realization of the PSF model at the object coordinates
     34 *****************************************************************************/
     35pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
     36{
    4237    // allocate a new pmModel to hold the PSF version
    4338    pmModel *modelPSF = pmModelAlloc (psf->type);
    4439
    45     // adjust the normalization:
    46     pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
    47     normFlux = modelFluxFunc (model->params);
    48     assert (isfinite(normFlux));
    49     assert (normFlux > 0);
    50 
    51     // set the correct normalization
    52     modelEXT->params->data.F32[PM_PAR_I0] = flux / normFlux;
    53 
    5440    // set model parameters for this source based on PSF information
    55     if (!modelFromPSFFunc (modelPSF, modelEXT, psf)) {
     41    if (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) {
    5642        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
    5743        psFree(modelPSF);
     
    6046    // XXX note that model->residuals is just a reference
    6147    modelPSF->residuals = psf->residuals;
    62     psFree (modelEXT);
    6348
    6449    return (modelPSF);
    6550}
    6651
    67 pmSource *pmSourceFromModel (pmModel *model, pmReadout *readout, pmSourceType type) {
     52// instantiate a model for the PSF at this location with peak flux
     53// NOTE: psf and (Xo,Yo) are defined wrt chip coordinates
     54pmModel *pmModelFromPSFforXY (pmPSF *psf, float Xo, float Yo, float Io) {
    6855
    69     pmSource *source = pmSourceAlloc ();
     56    assert (psf);
    7057
    71     // use the model centroid for the peak
    72     switch (type) {
    73       case PM_SOURCE_TYPE_STAR:
    74         source->modelPSF = model;
    75         break;
    76       case PM_SOURCE_TYPE_EXTENDED:
    77         source->modelEXT = model;
    78         break;
    79       default:
    80         psAbort ("psphot", "error");
     58    // allocate a new pmModel to hold the PSF version
     59    pmModel *modelPSF = pmModelAlloc (psf->type);
     60
     61    // set model parameters for this source based on PSF information
     62    if (!modelPSF->modelParamsFromPSF (modelPSF, psf, Xo, Yo, Io)) {
     63        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
     64        psFree(modelPSF);
     65        return NULL;
    8166    }
    8267
    83     source->peak = pmPeakAlloc ();
     68    // XXX note that model->residuals is just a reference
     69    modelPSF->residuals = psf->residuals;
    8470
    85     float x = model->params->data.F32[PM_PAR_XPOS];
    86     float y = model->params->data.F32[PM_PAR_YPOS];
     71    return (modelPSF);
     72}
    8773
    88     // XXX need to define the radius in some rational way
    89     // XXX x,y are defined wrt readout->image parent, but the model
    90     // parameters are defined wrt chip coordinates
    91     pmSourceDefinePixels (source, readout, x, y, radius);
     74// set this model to have the requested flux
     75bool pmModelSetFlux (pmModel *model, float flux) {
    9276
    93     return (source);
     77    // set Io to be 1.0
     78    model->params->data.F32[PM_PAR_I0] = 1.0;
     79
     80    // determine the normalized flux
     81    float normFlux = model->modelFlux (model->params);
     82    assert (isfinite(normFlux));
     83    assert (normFlux > 0);
     84
     85    // set the desired normalization
     86    model->params->data.F32[PM_PAR_I0] = flux / normFlux;
     87
     88    return true;
    9489}
  • trunk/psModules/src/objects/pmPSF.c

    r13898 r14652  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-06-20 02:22:26 $
     8 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828#include "pmMoments.h"
    2929#include "pmResiduals.h"
     30#include "pmGrowthCurve.h"
     31#include "pmPSF.h"
    3032#include "pmModel.h"
    3133#include "pmSource.h"
    32 #include "pmGrowthCurve.h"
    33 #include "pmPSF.h"
    34 #include "pmModelGroup.h"
     34#include "pmModelClass.h"
     35#include "pmModelUtils.h"
    3536#include "pmSourcePhotometry.h"
    3637#include "pmFPAMaskWeight.h"
     
    7475    psFree (psf->ApTrend);
    7576    psFree (psf->growth);
    76     psFree (psf->params_NEW);
     77    psFree (psf->params);
    7778    psFree (psf->residuals);
    7879    return;
     
    103104    psf->skyBias  = 0.0;
    104105    psf->skySat   = 0.0;
     106    psf->nPSFstars  = 0;
     107    psf->nApResid   = 0;
    105108    psf->poissonErrors = poissonErrors;
    106109
     
    124127    psf->residuals = NULL;
    125128
    126     Nparams = pmModelParameterCount (type);
     129    Nparams = pmModelClassParameterCount (type);
    127130    if (!Nparams) {
    128131        psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType");
    129132        return(NULL);
    130133    }
    131     psf->params_NEW = psArrayAlloc(Nparams);
     134    psf->params = psArrayAlloc(Nparams);
    132135
    133136    // the order of the PSF parameter (X,Y) fits is determined by the psfTrendMask polynomial
     
    139142
    140143    if (psfTrendMask) {
    141         for (int i = 0; i < psf->params_NEW->n; i++) {
     144        for (int i = 0; i < psf->params->n; i++) {
    142145            if (i == PM_PAR_SKY)
    143146                continue;
     
    155158                }
    156159            }
    157             psf->params_NEW->data[i] = param;
     160            psf->params->data[i] = param;
    158161        }
    159162    }
     
    161164    psMemSetDeallocator(psf, (psFreeFunc) pmPSFFree);
    162165    return(psf);
    163 }
    164 
    165 /*****************************************************************************
    166 pmModelFromPSF (*modelEXT, *psf):  use the model position parameters to
    167 construct a realization of the PSF model at the object coordinates
    168  *****************************************************************************/
    169 pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
    170 {
    171 
    172     // need to define the relationship between the modelEXT and modelPSF ?
    173 
    174     // find function used to set the model parameters
    175     pmModelFromPSFFunc modelFromPSFFunc = pmModelFromPSFFunc_GetFunction (psf->type);
    176 
    177     // allocate a new pmModel to hold the PSF version
    178     pmModel *modelPSF = pmModelAlloc (psf->type);
    179 
    180     // set model parameters for this source based on PSF information
    181     if (!modelFromPSFFunc (modelPSF, modelEXT, psf)) {
    182         psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
    183         psFree(modelPSF);
    184         return NULL;
    185     }
    186     // XXX note that model->residuals is just a reference
    187     modelPSF->residuals = psf->residuals;
    188 
    189     return (modelPSF);
    190166}
    191167
     
    335311    va_start(ap, sxy);
    336312
    337     pmModelType type = pmModelSetType (typeName);
     313    pmModelType type = pmModelClassGetType (typeName);
    338314    psPolynomial2D *psfTrend = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 0, 0);
    339315    pmPSF *psf = pmPSFAlloc (type, true, psfTrend);
    340316
    341     psVector *par = psVectorAlloc (psf->params_NEW->n, PS_TYPE_F32);
     317    psVector *par = psVectorAlloc (psf->params->n, PS_TYPE_F32);
    342318    par->data.F32[PM_PAR_SXX] = sxx;
    343319    par->data.F32[PM_PAR_SYY] = syy;
     
    348324    // set the psf shape parameters
    349325    psPolynomial2D *poly = NULL;
    350     poly = psf->params_NEW->data[PM_PAR_E0];
     326    poly = psf->params->data[PM_PAR_E0];
    351327    poly->coeff[0][0] = pol.e0;
    352328
    353     poly = psf->params_NEW->data[PM_PAR_E1];
     329    poly = psf->params->data[PM_PAR_E1];
    354330    poly->coeff[0][0] = pol.e1;
    355331
    356     poly = psf->params_NEW->data[PM_PAR_E2];
     332    poly = psf->params->data[PM_PAR_E2];
    357333    poly->coeff[0][0] = pol.e2;
    358334
    359     for (int i = PM_PAR_SXY + 1; i < psf->params_NEW->n; i++) {
    360         poly = psf->params_NEW->data[i];
     335    for (int i = PM_PAR_SXY + 1; i < psf->params->n; i++) {
     336        poly = psf->params->data[i];
    361337        poly->coeff[0][0] = (psF32)va_arg(ap, psF64);
    362338    }
  • trunk/psModules/src/objects/pmPSF.h

    r13898 r14652  
    66 * @author EAM, IfA
    77 *
    8  * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2007-06-20 02:22:26 $
     8 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2007-08-24 00:11:02 $
    1010 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1111 */
     
    1616/// @addtogroup Objects Object Detection / Analysis Functions
    1717/// @{
     18
     19// type of model carried by the pmModel structure
     20typedef int pmModelType;
    1821
    1922typedef enum {
     
    4447typedef struct
    4548{
    46     pmModelType type;   ///< PSF Model in use
    47     psArray *params_NEW;   ///< Model parameters (psPolynomial2D)
    48     // XXXXX I am changing params: we will allocate elements for the
    49     // unfitted elements (So, Io, Xo, Yo) and leave them as NULL
    50     // I am using a new name to catch all refs to params with gcc
     49    pmModelType type;                   ///< PSF Model in use
     50    psArray *params;                    ///< Model parameters (psPolynomial2D)
    5151    psPolynomial1D *ChiTrend;         ///< Chisq vs flux fit (correction for systematic errors)
    5252    psPolynomial4D *ApTrend;            ///< ApResid vs (x,y,rflux) (rflux = ten(0.4*mInst))
     
    7979);
    8080
    81 /**
    82  *
    83  * This function constructs a pmModel instance based on the pmPSF description
    84  * of the PSF. The input is a pmModel with at least the values of the centroid
    85  * coordinates (possibly normalization if this is needed) defined. The values of
    86  * the PSF-dependent parameters are specified for the specific realization based
    87  * on the coordinates of the object.
    88  *
    89  */
    90 pmModel *pmModelFromPSF(
    91     pmModel *model,                     ///< Add comment
    92     pmPSF *psf                          ///< Add comment
    93 );
    94 
    9581bool pmPSFMaskApTrend (psPolynomial4D *trend, pmPSFApTrendOptions option);
    9682
  • trunk/psModules/src/objects/pmPSF_IO.c

    r14207 r14652  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-07-14 03:20:22 $
     8 *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4040#include "pmGrowthCurve.h"
    4141#include "pmResiduals.h"
     42#include "pmPSF.h"
    4243#include "pmModel.h"
    43 #include "pmPSF.h"
    4444#include "pmPSF_IO.h"
    4545#include "pmSource.h"
    46 #include "pmModelGroup.h"
     46#include "pmModelClass.h"
    4747#include "pmSourceIO.h"
    4848
    49 bool pmFPAviewCheckDataStatusForPSFmodel (const pmFPAview *view, const pmFPAfile *file)
     49bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file)
    5050{
    5151    pmFPA *fpa = file->fpa;
    5252
    5353    if (view->chip == -1) {
    54         bool exists = pmFPACheckDataStatusForPSFmodel (fpa);
     54        bool exists = pmPSFmodelCheckDataStatusForFPA (fpa);
    5555        return exists;
    5656    }
     
    6262
    6363    if (view->cell == -1) {
    64         bool exists = pmChipCheckDataStatusForPSFmodel (chip);
     64        bool exists = pmPSFmodelCheckDataStatusForChip (chip);
    6565        return exists;
    6666    }
     
    6969        return false;
    7070    }
    71     pmCell *cell = chip->cells->data[view->cell];
    72 
    73     if (view->readout == -1) {
    74         bool exists = pmCellCheckDataStatusForPSFmodel (cell);
    75         return exists;
    76     }
    77 
    78     if (view->readout >= cell->readouts->n) {
    79         psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
    80         return false;
    81     }
    82     pmReadout *readout = cell->readouts->data[view->readout];
    83 
    84     return pmReadoutCheckDataStatusForPSFmodel (readout);
    85 }
    86 
    87 bool pmFPACheckDataStatusForPSFmodel (const pmFPA *fpa) {
     71    psError(PS_ERR_IO, false, "PSF only valid at the chip level");
     72    return false;
     73}
     74
     75bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa) {
    8876
    8977    for (int i = 0; i < fpa->chips->n; i++) {
    9078        pmChip *chip = fpa->chips->data[i];
    9179        if (!chip) continue;
    92         if (pmChipCheckDataStatusForPSFmodel (chip)) return true;
     80        if (pmPSFmodelCheckDataStatusForChip (chip)) return true;
    9381    }
    9482    return false;
    9583}
    9684
    97 bool pmChipCheckDataStatusForPSFmodel (const pmChip *chip) {
    98 
    99     for (int i = 0; i < chip->cells->n; i++) {
    100         pmCell *cell = chip->cells->data[i];
    101         if (!cell) continue;
    102         if (pmCellCheckDataStatusForPSFmodel (cell)) return true;
    103     }
    104     return false;
    105 }
    106 
    107 bool pmCellCheckDataStatusForPSFmodel (const pmCell *cell) {
    108 
    109     for (int i = 0; i < cell->readouts->n; i++) {
    110         pmReadout *readout = cell->readouts->data[i];
    111         if (!readout) continue;
    112         if (pmReadoutCheckDataStatusForPSFmodel (readout)) return true;
    113     }
    114     return false;
    115 }
    116 
    117 bool pmReadoutCheckDataStatusForPSFmodel (const pmReadout *readout) {
     85bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip) {
    11886
    11987    bool status;
    12088
    12189    // select the psf of interest
    122     pmPSF *psf = psMetadataLookupPtr(&status, readout->analysis, "PSPHOT.PSF");
     90    pmPSF *psf = psMetadataLookupPtr(&status, chip->analysis, "PSPHOT.PSF");
    12391    return psf ? true : false;
    12492}
    12593
    126 bool pmFPAviewWritePSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     94bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    12795{
    12896
     
    13098
    13199    if (view->chip == -1) {
    132         if (!pmFPAWritePSFmodel(fpa, view, file, config)) {
     100        if (!pmPSFmodelWriteFPA(fpa, view, file, config)) {
    133101            psError(PS_ERR_IO, false, "Failed to write PSF for fpa");
    134102            return false;
     
    143111
    144112    if (view->cell == -1) {
    145         if (!pmChipWritePSFmodel (chip, view, file, config)) {
     113        if (!pmPSFmodelWriteChip (chip, view, file, config)) {
    146114            psError(PS_ERR_IO, false, "Failed to write PSF for chip");
    147115            return false;
     
    150118    }
    151119
    152     if (view->cell >= chip->cells->n) {
    153         return false;
    154     }
    155     pmCell *cell = chip->cells->data[view->cell];
    156 
    157     if (view->readout == -1) {
    158         if (!pmCellWritePSFmodel (cell, view, file, config)) {
    159             psError(PS_ERR_IO, false, "Failed to write PSF for cell");
    160             return false;
    161         }
    162         return true;
    163     }
    164 
    165     if (view->readout >= cell->readouts->n) {
    166         return false;
    167     }
    168     pmReadout *readout = cell->readouts->data[view->readout];
    169 
    170     if (!pmReadoutWritePSFmodel (readout, view, file, config)) {
    171         psError(PS_ERR_IO, false, "Failed to write PSF for readout");
    172         return false;
    173     }
    174     return true;
     120    psError(PS_ERR_IO, false, "PSF must be written at the chip level");
     121    return false;
    175122}
    176123
    177124// read in all chip-level PSFmodel files for this FPA
    178 bool pmFPAWritePSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     125bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    179126{
    180127
    181128    for (int i = 0; i < fpa->chips->n; i++) {
    182129        pmChip *chip = fpa->chips->data[i];
    183         if (!pmChipWritePSFmodel (chip, view, file, config)) {
     130        if (!pmPSFmodelWriteChip (chip, view, file, config)) {
    184131            psError(PS_ERR_IO, false, "Failed to write PSF for %dth chip", i);
    185132            return false;
     
    190137
    191138// read in all cell-level PSFmodel files for this chip
    192 bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    193 {
    194     for (int i = 0; i < chip->cells->n; i++) {
    195         pmCell *cell = chip->cells->data[i];
    196         if (!pmCellWritePSFmodel (cell, view, file, config)) {
    197             psError(PS_ERR_IO, false, "Failed to write PSF for %dth cell", i);
    198             return false;
    199         }
     139bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     140{
     141    if (!pmPSFmodelWrite (chip->analysis, view, file, config)) {
     142        psError(PS_ERR_IO, false, "Failed to write PSF for chip");
     143        return false;
    200144    }
    201145    return true;
    202146}
    203147
    204 // read in all readout-level PSFmodel files for this cell
    205 bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    206 {
    207     for (int i = 0; i < cell->readouts->n; i++) {
    208         pmReadout *readout = cell->readouts->data[i];
    209         if (!pmReadoutWritePSFmodel (readout, view, file, config)) {
    210             psError(PS_ERR_IO, false, "Failed to write PSF for %dth readout", i);
    211             return false;
    212         }
    213     }
    214     return true;
    215 }
    216 
    217 // for each Readout (ie, analysed image), we write out
     148// for a pmPSF supplied on the analysis metadata, we write out
    218149// - image header        : FITS Image NAXIS = 0
    219150// - psf table (+header) : FITS Table
    220151// - psf resid (+header) : FITS Image
    221152// if needed, we also write out a PHU blank header
    222 bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     153bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    223154{
    224155    bool status;
    225156    pmHDU *hdu;
    226157    char *headName, *tableName, *residName;
     158
     159    if (!analysis) return false;
    227160
    228161    // write a PHU? (only if input image is MEF)
     
    300233
    301234    // select the psf of interest
    302     pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     235    pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF");
    303236    if (!psf) {
    304         psError(PS_ERR_UNKNOWN, true, "missing PSF for this readout");
     237        psError(PS_ERR_UNKNOWN, true, "missing PSF for this analysis metadata");
    305238        psFree (tableName);
    306239        psFree (residName);
     
    313246        psMetadata *header = psMetadataAlloc();
    314247
    315         char *modelName = pmModelGetType (psf->type);
     248        char *modelName = pmModelClassGetName (psf->type);
    316249        psMetadataAddStr (header, PS_LIST_TAIL, "PSF_NAME", 0, "PSF model name", modelName);
    317250
    318251        psMetadataAddBool (header, PS_LIST_TAIL, "POISSON",  0, "Use Poisson errors in fits?", psf->poissonErrors);
    319252
    320         int nPar = pmModelParameterCount (psf->type)    ;
     253        int nPar = pmModelClassParameterCount (psf->type)    ;
    321254        psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
    322255
     
    324257        for (int i = 0; i < nPar; i++) {
    325258            char name[9];
    326             psPolynomial2D *poly = psf->params_NEW->data[i];
     259            psPolynomial2D *poly = psf->params->data[i];
    327260            if (poly == NULL) continue;
    328261            snprintf (name, 9, "PAR%02d_NX", i);
     
    344277        psArray *psfTable = psArrayAllocEmpty (100);
    345278        for (int i = 0; i < nPar; i++) {
    346             psPolynomial2D *poly = psf->params_NEW->data[i];
     279            psPolynomial2D *poly = psf->params->data[i];
    347280            if (poly == NULL) continue; // skip unset parameters (eg, XPOS)
    348281            for (int ix = 0; ix <= poly->nX; ix++) {
     
    445378
    446379// if this file needs to have a PHU written out, write one
    447 bool pmPSF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
     380bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) {
    448381
    449382    // not needed if already written
     
    487420}
    488421
    489 bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     422bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    490423{
    491424
     
    493426
    494427    if (view->chip == -1) {
    495         return pmFPAReadPSFmodel(fpa, view, file, config);
     428        return pmPSFmodelReadFPA(fpa, view, file, config);
    496429    }
    497430
     
    502435
    503436    if (view->cell == -1) {
    504         return pmChipReadPSFmodel(chip, view, file, config);
    505     }
    506 
    507     if (view->cell >= chip->cells->n) {
    508         psAbort("Programming error: view does not apply to FPA.");
    509     }
    510     pmCell *cell = chip->cells->data[view->cell];
    511 
    512     if (view->readout == -1) {
    513         return pmCellReadPSFmodel(cell, view, file, config);
    514     }
    515 
    516     if (view->readout >= cell->readouts->n) {
    517         psAbort("Programming error: view does not apply to FPA.");
    518     }
    519     pmReadout *readout = cell->readouts->data[view->readout];
    520 
    521     return pmReadoutReadPSFmodel(readout, view, file, config);
     437        return pmPSFmodelReadChip(chip, view, file, config);
     438    }
     439
     440    psError(PS_ERR_IO, false, "PSF must be read at the chip level");
     441    return false;
    522442}
    523443
    524444// read in all chip-level PSFmodel files for this FPA
    525 bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     445bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    526446{
    527447    bool success = true;                // Was everything successful?
    528448    for (int i = 0; i < fpa->chips->n; i++) {
    529449        pmChip *chip = fpa->chips->data[i];
    530         success &= pmChipReadPSFmodel(chip, view, file, config);
     450        success &= pmPSFmodelReadChip(chip, view, file, config);
    531451    }
    532452    return success;
     
    534454
    535455// read in all cell-level PSFmodel files for this chip
    536 bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    537 {
    538     bool success = true;                // Was everything successful?
    539     for (int i = 0; i < chip->cells->n; i++) {
    540         pmCell *cell = chip->cells->data[i];
    541         success &= pmCellReadPSFmodel (cell, view, file, config);
    542     }
    543     return success;
    544 }
    545 
    546 // read in all readout-level PSFmodel files for this cell
    547 bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    548 {
    549     bool success = true;                // Was everything successful?
    550     for (int i = 0; i < cell->readouts->n; i++) {
    551         pmReadout *readout = cell->readouts->data[i];
    552         success &= pmReadoutReadPSFmodel(readout, view, file, config);
    553     }
    554     return success;
     456bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     457{
     458    if (!pmPSFmodelRead (chip->analysis, view, file, config)) {
     459        psError(PS_ERR_IO, false, "Failed to write PSF for chip");
     460        return false;
     461    }
     462    return true;
    555463}
    556464
    557465// for each Readout (ie, analysed image), we write out: header + table with PSF model parameters,
    558466// and header + image for the PSF residual images
    559 bool pmReadoutReadPSFmodel(pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     467bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    560468{
    561469    bool status;
     
    599507    // load the PSF model parameters from the FITS table
    600508    char *modelName = psMetadataLookupStr (&status, header, "PSF_NAME");
    601     pmModelType type = pmModelSetType (modelName);
     509    pmModelType type = pmModelClassGetType (modelName);
    602510    if (type == -1) {
    603511        psError(PS_ERR_UNKNOWN, true, "invalid model name %s in psf file %s", modelName, file->filename);
     
    612520    // check the number of expected parameters
    613521    int nPar = psMetadataLookupS32 (&status, header, "PSF_NPAR");
    614     if (nPar != pmModelParameterCount (psf->type))
     522    if (nPar != pmModelClassParameterCount (psf->type))
    615523        psAbort("mismatch model par count");
    616524
     
    627535            return false;
    628536        }
    629         psf->params_NEW->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);
     537        psf->params->data[i] = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder);
    630538    }
    631539
     
    650558        // XXX sanity check here
    651559
    652         psPolynomial2D *poly = psf->params_NEW->data[iPar];
     560        psPolynomial2D *poly = psf->params->data[iPar];
    653561        if (poly == NULL) {
    654562            psError(PS_ERR_UNKNOWN, true, "values for parameter %d, but missing NX", iPar);
     
    698606    }
    699607
    700     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
     608    psMetadataAdd (analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
    701609    psFree (psf);
    702610
     
    708616}
    709617
    710 /************ old support functions, deprecate? **************/
    711 
     618// create a psMetadata representation (human-readable) of a psf model
    712619psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf)
    713620{
     
    717624    }
    718625
    719     char *modelName = pmModelGetType (psf->type);
     626    char *modelName = pmModelClassGetName (psf->type);
    720627    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName);
    721628
    722     int nPar = pmModelParameterCount (psf->type)    ;
     629    int nPar = pmModelClassParameterCount (psf->type)    ;
    723630    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
    724631
    725632    for (int i = 0; i < nPar; i++) {
    726         psPolynomial2D *poly = psf->params_NEW->data[i];
     633        psPolynomial2D *poly = psf->params->data[i];
    727634        if (poly == NULL)
    728635            continue;
     
    742649}
    743650
     651// parse a psMetadata representation (human-readable) of a psf model
    744652pmPSF *pmPSFfromMetadata (psMetadata *metadata)
    745653{
     
    749657
    750658    char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME");
    751     pmModelType type = pmModelSetType (modelName);
     659    pmModelType type = pmModelClassGetType (modelName);
    752660
    753661    bool poissonErrors = psMetadataLookupPtr (&status, metadata, "PSF_POISSON_ERRORS");
     
    759667
    760668    int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR");
    761     if (nPar != pmModelParameterCount (psf->type))
     669    if (nPar != pmModelClassParameterCount (psf->type))
    762670        psAbort("mismatch model par count");
    763671
     
    770678            continue;
    771679        psPolynomial2D *poly = psPolynomial2DfromMetadata (folder);
    772         psFree (psf->params_NEW->data[i]);
    773         psf->params_NEW->data[i] = poly;
     680        psFree (psf->params->data[i]);
     681        psf->params->data[i] = poly;
    774682    }
    775683    sprintf (keyword, "APTREND");
     
    789697    return (psf);
    790698}
    791 
    792 // read in all readout-level Objects files for this cell
    793 bool pmReadoutWritePSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    794 {
    795     bool status;
    796     char *filename;
    797     char *realname;
    798 
    799     pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    800 
    801     switch (file->type) {
    802       case PM_FPA_FILE_PSF:
    803         filename = pmFPAfileNameFromRule (file->filerule, file, view);
    804         bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;
    805         realname = pmConfigConvertFilename (filename, config, create);
    806 
    807         psMetadata *psfData = pmPSFtoMetadata (NULL, psf);
    808         psMetadataConfigWrite (psfData, realname);
    809         psFree (psfData);
    810         psFree (realname);
    811         psFree (filename);
    812         return true;
    813 
    814       default:
    815         fprintf (stderr, "warning: type mismatch\n");
    816         break;
    817     }
    818     return false;
    819 }
    820 
    821 // read in all readout-level Objects files for this cell
    822 bool pmReadoutReadPSFmodel_Config (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
    823 {
    824 
    825     unsigned int Nfail;
    826     char *filename;
    827     char *realname;
    828 
    829     switch (file->type) {
    830       case PM_FPA_FILE_PSF:
    831         filename = pmFPAfileNameFromRule (file->filerule, file, view);
    832         bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;
    833         realname = pmConfigConvertFilename (filename, config, create);
    834 
    835         psMetadata *psfData = psMetadataConfigRead(NULL, &Nfail, realname, FALSE);
    836         pmPSF *psf = pmPSFfromMetadata (psfData);
    837         psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf);
    838 
    839         psFree (psf);
    840         psFree (psfData);
    841         psFree (realname);
    842         psFree (filename);
    843 
    844         return true;
    845 
    846       default:
    847         fprintf (stderr, "warning: type mismatch\n");
    848         break;
    849     }
    850     return false;
    851 }
    852 
  • trunk/psModules/src/objects/pmPSF_IO.h

    r14207 r14652  
    66 * @author EAM, IfA
    77 *
    8  * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2007-07-14 03:20:22 $
     8 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2007-08-24 00:11:02 $
    1010 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1111 */
     
    1717/// @{
    1818
     19bool pmPSFmodelWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     20bool pmPSFmodelWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     21bool pmPSFmodelWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     22bool pmPSFmodelWrite (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     23
     24bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     25
     26bool pmPSFmodelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     27bool pmPSFmodelReadFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     28bool pmPSFmodelReadChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     29bool pmPSFmodelRead (psMetadata *analysis, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
     30
     31bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file);
     32bool pmPSFmodelCheckDataStatusForFPA (const pmFPA *fpa);
     33bool pmPSFmodelCheckDataStatusForChip (const pmChip *chip);
     34
    1935psMetadata *pmPSFtoMetadata (psMetadata *metadata, pmPSF *psf);
    2036pmPSF *pmPSFfromMetadata (psMetadata *metadata);
    21 bool pmFPAviewWritePSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    22 bool pmFPAWritePSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    23 bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    24 bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    25 bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    26 
    27 bool pmPSF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    28 
    29 bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    30 bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    31 bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    32 bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    33 bool pmReadoutReadPSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
    34 
    35 bool pmFPAviewCheckDataStatusForPSFmodel (const pmFPAview *view, const pmFPAfile *file);
    36 bool pmFPACheckDataStatusForPSFmodel (const pmFPA *fpa);
    37 bool pmChipCheckDataStatusForPSFmodel (const pmChip *chip);
    38 bool pmCellCheckDataStatusForPSFmodel (const pmCell *cell);
    39 bool pmReadoutCheckDataStatusForPSFmodel (const pmReadout *readout);
    4037
    4138/// @}
  • trunk/psModules/src/objects/pmPSFtry.c

    r13898 r14652  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-06-20 02:22:26 $
     7 *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-08-24 00:11:02 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "pmMoments.h"
    2424#include "pmResiduals.h"
     25#include "pmGrowthCurve.h"
     26#include "pmPSF.h"
    2527#include "pmModel.h"
    2628#include "pmSource.h"
    27 #include "pmGrowthCurve.h"
    28 #include "pmPSF.h"
     29#include "pmSourceUtils.h"
    2930#include "pmPSFtry.h"
    30 #include "pmModelGroup.h"
     31#include "pmModelClass.h"
     32#include "pmModelUtils.h"
    3133#include "pmSourceFitModel.h"
    3234#include "pmSourcePhotometry.h"
     
    5961
    6062    // validate the requested model name
    61     pmModelType type = pmModelSetType (modelName);
     63    pmModelType type = pmModelClassGetType (modelName);
    6264    if (type == -1) {
    6365        psError (PS_ERR_UNKNOWN, true, "invalid model name %s", modelName);
     
    412414    // This way, the parameters masked by one of the fits will be applied to the others
    413415    for (int i = 0; i < stats->clipIter; i++) {
    414         psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E0], stats, psfTry->mask, 0xff, e0, dz, x, y);
     416        psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E0], stats, psfTry->mask, 0xff, e0, dz, x, y);
    415417        psTrace ("psModules.pmPSFtry", 4, "clipped E0 : keeping %ld of %ld\n", stats->clippedNvalues, e0->n);
    416         psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E1], stats, psfTry->mask, 0xff, e1, dz, x, y);
     418        psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E1], stats, psfTry->mask, 0xff, e1, dz, x, y);
    417419        psTrace ("psModules.pmPSFtry", 4, "clipped E1 : keeping %ld of %ld\n", stats->clippedNvalues, e1->n);
    418         psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E2], stats, psfTry->mask, 0xff, e2, dz, x, y);
     420        psVectorClipFitPolynomial2D (psf->params->data[PM_PAR_E2], stats, psfTry->mask, 0xff, e2, dz, x, y);
    419421        psTrace ("psModules.pmPSFtry", 4, "clipped E2 : keeping %ld of %ld\n", stats->clippedNvalues, e2->n);
    420422    }
     
    436438
    437439    // skip the unfitted parameters (X, Y, Io, Sky) and the shape parameters (SXX, SYY, SXY)
    438     for (int i = 0; i < psf->params_NEW->n; i++) {
     440    for (int i = 0; i < psf->params->n; i++) {
    439441        switch (i) {
    440442          case PM_PAR_SKY:
     
    461463        // the mask is carried from previous steps and updated with this operation
    462464        // the weight is either the flux error or NULL, depending on 'applyWeights'
    463         if (!psVectorClipFitPolynomial2D(psf->params_NEW->data[i], stats, psfTry->mask, 0xff, z, NULL, x, y)) {
     465        if (!psVectorClipFitPolynomial2D(psf->params->data[i], stats, psfTry->mask, 0xff, z, NULL, x, y)) {
    464466            psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i);
    465467            psFree(stats);
     
    489491            fprintf (f, "%f %f : ", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
    490492
    491             for (int i = 0; i < psf->params_NEW->n; i++) {
    492                 if (psf->params_NEW->data[i] == NULL)
     493            for (int i = 0; i < psf->params->n; i++) {
     494                if (psf->params->data[i] == NULL)
    493495                    continue;
    494496                fprintf (f, "%f %f : ", model->params->data.F32[i], modelPSF->params->data.F32[i]);
  • trunk/psModules/src/objects/pmPeaks.c

    r13034 r14652  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-04-26 01:20:29 $
     8 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535                        pmPeakType type)
    3636{
    37     psTrace(__func__, 5, "---- begin ----\n");
     37    psTrace("psModules.objects", 5, "---- begin ----\n");
    3838
    3939    if (peaks == NULL) {
     
    6767    psFree (peak);
    6868
    69     psTrace(__func__, 5, "---- end ----\n");
     69    psTrace("psModules.objects", 5, "---- end ----\n");
    7070    return(peaks);
    7171}
     
    118118*****************************************************************************/
    119119static void peakFree(pmPeak *tmp)
    120 {} // used by pmIsPeak()
     120{} // used by pmPeakTest()
    121121
    122122pmPeak *pmPeakAlloc(psS32 x,
     
    145145}
    146146
    147 bool pmIsPeak(const psPtr ptr)
     147bool pmPeakTest(const psPtr ptr)
    148148{
    149149    return (psMemGetDeallocator(ptr) == (psFreeFunc)peakFree);
     
    193193
    194194/******************************************************************************
    195 pmFindVectorPeaks(vector, threshold): Find all local peaks in the given vector
     195pmPeaksInVector(vector, threshold): Find all local peaks in the given vector
    196196above the given threshold.  Returns a vector of type PS_TYPE_U32 containing
    197197the location (x value) of all peaks.
     
    203203Depending upon actual use, this may need to be optimized.
    204204*****************************************************************************/
    205 psVector *pmFindVectorPeaks(const psVector *vector,
    206                             psF32 threshold)
     205psVector *pmPeaksInVector(const psVector *vector,
     206                        psF32 threshold)
    207207{
    208208    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     
    295295
    296296/******************************************************************************
    297 pmFindImagePeaks(image, threshold): Find all local peaks in the given psImage
     297pmPeaksInImage(image, threshold): Find all local peaks in the given psImage
    298298above the given threshold.  Returns a psArray containing location (x/y value)
    299299of all peaks.
     
    309309
    310310*****************************************************************************/
    311 psArray *pmFindImagePeaks(const psImage *image, psF32 threshold)
     311psArray *pmPeaksInImage(const psImage *image, psF32 threshold)
    312312{
    313313    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     
    327327    row = 0;
    328328    tmpRow = getRowVectorFromImage((psImage *) image, row);
    329     psVector *row1 = pmFindVectorPeaks(tmpRow, threshold);
    330     // pmFindVectorPeaks returns coords in the vector, not corrected for col0
     329    psVector *row1 = pmPeaksInVector(tmpRow, threshold);
     330    // pmPeaksInVector returns coords in the vector, not corrected for col0
    331331
    332332    for (psU32 i = 0 ; i < row1->n ; i++ ) {
     
    382382    for (row = 1 ; row < (image->numRows - 1) ; row++) {
    383383        tmpRow = getRowVectorFromImage((psImage *) image, row);
    384         row1 = pmFindVectorPeaks(tmpRow, threshold);
     384        row1 = pmPeaksInVector(tmpRow, threshold);
    385385
    386386        // Step through all local peaks in this row.
     
    461461    row = image->numRows - 1;
    462462    tmpRow = getRowVectorFromImage((psImage *) image, row);
    463     row1 = pmFindVectorPeaks(tmpRow, threshold);
     463    row1 = pmPeaksInVector(tmpRow, threshold);
    464464    for (psU32 i = 0 ; i < row1->n ; i++ ) {
    465465        col = row1->data.U32[i];
     
    501501}
    502502
    503 
    504 /******************************************************************************
    505 psCullPeaks(peaks, maxValue, valid): eliminate peaks from the psArray that have
    506 a peak value above the given maximum, or fall outside the valid region.
    507  
    508 XXX: Should the sky value be used when comparing the maximum?
    509  
    510 XXX: warning message if valid is NULL?
    511  
    512 XXX: changed API to create a NEW output psArray (should change name as well)
    513  
    514 XXX: Do we free the psList elements of those culled peaks?
    515  
    516 XXX EAM : do we still need pmCullPeaks, or only pmPeaksSubset?
    517 *****************************************************************************/
    518 psList *pmCullPeaks(psList *peaks,
    519                     psF32 maxValue,
    520                     const psRegion valid)
    521 {
    522     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
    523     PS_ASSERT_PTR_NON_NULL(peaks, NULL);
    524 
    525     psListElem *tmpListElem = (psListElem *) peaks->head;
    526     psS32 indexNum = 0;
    527 
    528     //    printf("pmCullPeaks(): list size is %d\n", peaks->size);
    529     while (tmpListElem != NULL) {
    530         pmPeak *tmpPeak = (pmPeak *) tmpListElem->data;
    531         if ((tmpPeak->value > maxValue) ||
    532                 (true == isItInThisRegion(valid, tmpPeak->x, tmpPeak->y))) {
    533             psListRemoveData(peaks, (psPtr) tmpPeak);
    534         }
    535 
    536         indexNum++;
    537         tmpListElem = tmpListElem->next;
    538     }
    539 
    540     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
    541     return(peaks);
    542 }
    543 
    544 // XXX EAM: I changed this to return a new, subset array
    545 //          rather than alter the existing one
    546 // XXX: Fix the *valid pointer.
     503// return a new array of peaks which are in the valid region and below threshold
     504// XXX this function is unused and probably could be dropped
    547505psArray *pmPeaksSubset(
    548506    psArray *peaks,
     
    555513    psArray *output = psArrayAllocEmpty (200);
    556514
    557     psTrace (".pmObjects.pmCullPeaks", 3, "list size is %ld\n", peaks->n);
     515    psTrace ("psModules.objects", 3, "list size is %ld\n", peaks->n);
    558516
    559517    for (int i = 0; i < peaks->n; i++) {
  • trunk/psModules/src/objects/pmPeaks.h

    r11253 r14652  
    1010 * @author GLG, MHPCC
    1111 *
    12  * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    13  * @date $Date: 2007-01-24 02:54:15 $
     12 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     13 * @date $Date: 2007-08-24 00:11:02 $
    1414 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1515 */
     
    7272);
    7373
    74 bool pmIsPeak(const psPtr ptr);
     74bool pmPeakTest(const psPtr ptr);
    7575
    76 /** pmFindVectorPeaks()
     76/** pmPeaksInVector()
    7777 *
    7878 * Find all local peaks in the given vector above the given threshold. A peak
     
    9191 *
    9292 */
    93 psVector *pmFindVectorPeaks(
     93psVector *pmPeaksInVector(
    9494    const psVector *vector,  ///< The input vector (float)
    9595    float threshold   ///< Threshold above which to find a peak
     
    9797
    9898
    99 /** pmFindImagePeaks()
     99/** pmPeaksInImage()
    100100 *
    101101 * Find all local peaks in the given image above the given threshold. This
     
    111111 *
    112112 */
    113 psArray *pmFindImagePeaks(
     113psArray *pmPeaksInImage(
    114114    const psImage *image,  ///< The input image where peaks will be found (float)
    115115    float threshold   ///< Threshold above which to find a peak
  • trunk/psModules/src/objects/pmSource.c

    r14529 r14652  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-08-16 18:33:00 $
     8 *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "pmMoments.h"
    2828#include "pmResiduals.h"
     29#include "pmGrowthCurve.h"
     30#include "pmPSF.h"
    2931#include "pmModel.h"
    3032#include "pmSource.h"
     
    113115}
    114116
    115 bool pmIsSource(const psPtr ptr)
     117bool pmSourceTest(const psPtr ptr)
    116118{
    117119    return (psMemGetDeallocator(ptr) == (psFreeFunc)sourceFree);
     
    337339            return emptyClump;
    338340        }
    339         peaks = pmFindImagePeaks (splane, stats[0].max / 2);
     341        peaks = pmPeaksInImage (splane, stats[0].max / 2);
    340342        psTrace ("psModules.objects", 2, "clump threshold is %f\n", stats[0].max/2);
    341343
     
    797799
    798800// should we call pmSourceCacheModel if it does not exist?
    799 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal) {
     801bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy) {
    800802
    801803    bool status;
     
    856858        target = source->weight;
    857859    }
     860
    858861    if (add) {
    859         status = pmModelAdd (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
     862        status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
    860863    } else {
    861         status = pmModelSub (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
     864        status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
    862865    }
    863866
     
    866869
    867870bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal) {
    868     return pmSourceOp (source, mode, true, maskVal);
     871    return pmSourceOp (source, mode, true, maskVal, 0, 0);
    869872}
    870873
    871874bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal) {
    872     return pmSourceOp (source, mode, false, maskVal);
     875    return pmSourceOp (source, mode, false, maskVal, 0, 0);
     876}
     877
     878bool pmSourceAddWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy) {
     879    return pmSourceOp (source, mode, true, maskVal, dx, dy);
     880}
     881
     882bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy) {
     883    return pmSourceOp (source, mode, false, maskVal, dx, dy);
    873884}
    874885
  • trunk/psModules/src/objects/pmSource.h

    r14505 r14652  
    33 * @author EAM, IfA; GLG, MHPCC
    44 *
    5  * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    6  * @date $Date: 2007-08-15 20:21:18 $
     5 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     6 * @date $Date: 2007-08-24 00:11:02 $
    77 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    88 */
     
    5757 *
    5858 */
    59 typedef struct
    60 {
     59struct pmSource {
    6160    const int id;                       ///< Unique ID for object
    6261    pmPeak *peak;                       ///< Description of peak pixel.
     
    8180    psRegion region;                    ///< area on image covered by selected pixels
    8281    float sky, skyErr;                  ///< The sky and its error at the center of the object
    83 }
    84 pmSource;
     82};
    8583
    8684/** pmPSFClump data structure
     
    114112void pmSourceFreePixels(pmSource *source);
    115113
    116 bool pmIsSource(const psPtr ptr);
     114bool pmSourceTest(const psPtr ptr);
    117115
    118116/** pmSourceDefinePixels()
     
    218216bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal);
    219217bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal);
    220 
    221 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal);
     218bool pmSourceAddWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy);
     219bool pmSourceSubWithOffset (pmSource *source, pmModelOpMode mode, psMaskType maskVal, int dx, int dy);
     220
     221bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy);
    222222bool pmSourceCacheModel (pmSource *source, psMaskType maskVal);
    223223bool pmSourceCachePSF (pmSource *source, psMaskType maskVal);
  • trunk/psModules/src/objects/pmSourceContour.c

    r12949 r14652  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-04-21 19:47:14 $
     8 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2626#include "pmMoments.h"
    2727#include "pmResiduals.h"
     28#include "pmGrowthCurve.h"
     29#include "pmPSF.h"
    2830#include "pmModel.h"
    2931#include "pmSource.h"
  • trunk/psModules/src/objects/pmSourceFitModel.c

    r13932 r14652  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-06-21 22:58:11 $
     8 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "pmGrowthCurve.h"
    2828#include "pmResiduals.h"
     29#include "pmPSF.h"
    2930#include "pmModel.h"
    30 #include "pmPSF.h"
    3131#include "pmSource.h"
    32 #include "pmModelGroup.h"
     32#include "pmModelClass.h"
    3333#include "pmSourceFitModel.h"
    3434
     
    116116    psVector *dparams = model->dparams;
    117117
    118     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
    119     if (!modelFunc)
    120         psAbort("invalid model function");
    121     pmModelLimits checkLimits = pmModelLimits_GetFunction (model->type);
    122     if (!checkLimits)
    123         psAbort("invalid model limits function");
    124 
    125118    // create the minimization constraints
    126119    psMinConstraint *constraint = psMinConstraintAlloc();
    127120    constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_U8);
    128     constraint->checkLimits = checkLimits;
     121    constraint->checkLimits = model->modelLimits;
    129122
    130123    // set parameter mask based on fitting mode
     
    156149    // force the floating parameters to fall within the contraint ranges
    157150    for (int i = 0; i < params->n; i++) {
    158         checkLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
    159         checkLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
     151        model->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
     152        model->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
    160153    }
    161154
     
    174167    psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
    175168
    176     fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, modelFunc);
     169    fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, model->modelFunc);
    177170    for (int i = 0; i < dparams->n; i++) {
    178171        if (psTraceGetLevel("psModules.objects") >= 4) {
     
    201194            altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;
    202195        }
    203         psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, modelFunc);
     196        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, model->modelFunc);
    204197        for (int i = 0; i < dparams->n; i++) {
    205198            if (!constraint->paramMask->data.U8[i])
     
    237230}
    238231
    239 /********************* Source Model Set Functions ***************************/
    240 
    241 // these static variables are used by one pass of pmSourceFitSet to store
    242 // data for a model set.  If we are going to make psphot thread-safe, these
    243 // will have to go in a structure of their own or be allocated once per thread
    244 // sky, p1.1, p1.2, p1.3,... p1.n, p2.1, p2.2,
    245 // nPar = nSrc*(nOnePar - 1) + 1
    246 static pmModelFunc oneModelFunc;
    247 static pmModelLimits oneCheckLimits;
    248 static psVector *onePar;
    249 static psVector *oneDeriv;
    250 static int nOnePar;
    251 
    252 bool pmSourceFitSetInit (pmModelType type)
    253 {
    254 
    255     oneModelFunc = pmModelFunc_GetFunction (type);
    256     oneCheckLimits = pmModelLimits_GetFunction (type);
    257     nOnePar = pmModelParameterCount (type);
    258 
    259     onePar = psVectorAlloc (nOnePar, PS_DATA_F32);
    260     oneDeriv = psVectorAlloc (nOnePar, PS_DATA_F32);
    261 
    262     return true;
    263 }
    264 
    265 void pmSourceFitSetClear (void)
    266 {
    267 
    268     psFree (onePar);
    269     psFree (oneDeriv);
    270     return;
    271 }
    272 
    273 bool pmSourceFitSet_CheckLimits (psMinConstraintMode mode, int nParam, float *params, float *betas)
    274 {
    275     // convert the value of nParam into corresponding single model parameter entry
    276     // convert params into corresponding single model parameter pointer
    277 
    278     int nParamSingle = (nParam - 1) % (nOnePar - 1) + 1;
    279     float *paramSingle = params + nParam - nParamSingle;
    280     float *betaSingle = betas + nParam - nParamSingle;
    281     bool status = oneCheckLimits (mode, nParamSingle, paramSingle, betaSingle);
    282     return status;
    283 }
    284 
    285 psF32 pmSourceFitSet_Function(psVector *deriv,
    286                               const psVector *params,
    287                               const psVector *x)
    288 {
    289 
    290     psF32 value;
    291     psF32 model;
    292 
    293     psF32 *PAR = onePar->data.F32;
    294     psF32 *dPAR = oneDeriv->data.F32;
    295 
    296     psF32 *pars = params->data.F32;
    297     psF32 *dpars = (deriv == NULL) ? NULL : deriv->data.F32;
    298 
    299     int nSrc = (params->n - 1) / (nOnePar - 1);
    300 
    301     PAR[0] = model = pars[0];
    302     for (int i = 0; i < nSrc; i++) {
    303         int nOff = i*nOnePar - i;
    304         for (int n = 1; n < nOnePar; n++) {
    305             PAR[n] = pars[nOff + n];
    306         }
    307         if (deriv == NULL) {
    308             value = oneModelFunc (NULL, onePar, x);
    309         } else {
    310             value = oneModelFunc (oneDeriv, onePar, x);
    311             for (int n = 1; n < nOnePar; n++) {
    312                 dpars[nOff + n] = dPAR[n];
    313             }
    314         }
    315         model += value;
    316     }
    317     if (deriv != NULL) {
    318         dpars[0] = dPAR[0]*2.0;
    319     }
    320     return (model);
    321 }
    322 
    323 /*
    324 i:       0                   1                 2
    325 n:         1  2  3  4  5  6  1  2  3  4  5  6  1  2  3  4  5  6
    326 i*6 + n: 0 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18
    327 */
    328 
    329 bool pmSourceFitSet (pmSource *source,
    330                      psArray *modelSet,
    331                      pmSourceFitMode mode,
    332                      psMaskType maskVal)
    333 {
    334     psTrace("psModules.objects", 3, "---- %s begin ----\n", __func__);
    335     PS_ASSERT_PTR_NON_NULL(source, false);
    336     PS_ASSERT_PTR_NON_NULL(source->pixels, false);
    337     PS_ASSERT_PTR_NON_NULL(source->maskObj, false);
    338     PS_ASSERT_PTR_NON_NULL(source->weight, false);
    339 
    340     psBool fitStatus = true;
    341     psBool onPic     = true;
    342     psBool rc        = true;
    343 
    344     // maximum number of valid pixels
    345     psS32 nPix = source->pixels->numRows * source->pixels->numCols;
    346 
    347     // construct the coordinate and value entries
    348     psArray *x = psArrayAllocEmpty(nPix);
    349     psVector *y = psVectorAllocEmpty(nPix, PS_TYPE_F32);
    350     psVector *yErr = psVectorAllocEmpty(nPix, PS_TYPE_F32);
    351 
    352     // fill in the coordinate and value entries
    353     nPix = 0;
    354     for (psS32 i = 0; i < source->pixels->numRows; i++) {
    355         for (psS32 j = 0; j < source->pixels->numCols; j++) {
    356             // skip masked points
    357             if (source->maskObj->data.U8[i][j] & maskVal) {
    358                 continue;
    359             }
    360             // skip zero-weight points
    361             if (source->weight->data.F32[i][j] == 0) {
    362                 continue;
    363             }
    364             // skip nan values in image
    365             if (!isfinite(source->pixels->data.F32[i][j])) {
    366                 continue;
    367             }
    368 
    369             psVector *coord = psVectorAlloc(2, PS_TYPE_F32);
    370 
    371             // Convert i/j to image space:
    372             coord->data.F32[0] = (psF32) (j + source->pixels->col0);
    373             coord->data.F32[1] = (psF32) (i + source->pixels->row0);
    374             x->data[nPix] = (psPtr *) coord;
    375             y->data.F32[nPix] = source->pixels->data.F32[i][j];
    376 
    377             // psMinimizeLMChi2 takes wt = 1/dY^2.  suggestion from RHL is to use the local sky
    378             // as weight to avoid the bias from systematic errors here we would just use the
    379             // source sky variance
    380             if (PM_SOURCE_FIT_MODEL_PIX_WEIGHTS) {
    381                 yErr->data.F32[nPix] = 1.0 / source->weight->data.F32[i][j];
    382             } else {
    383                 yErr->data.F32[nPix] = 1.0 / PM_SOURCE_FIT_MODEL_WEIGHT;
    384             }
    385             nPix++;
    386         }
    387     }
    388     x->n = nPix;
    389     y->n = nPix;
    390     yErr->n = nPix;
    391 
    392     // base values on first model (all models must be identical)
    393     pmModel *model = modelSet->data[0];
    394 
    395     // determine number of model parameters
    396     int nSrc = modelSet->n;
    397     int nPar = model->params->n - 1;  // number of object parameters (excluding sky)
    398 
    399     // define parameter vectors for source set
    400     psVector *params = psVectorAlloc (nSrc*nPar + 1, PS_TYPE_F32);
    401     psVector *dparams = psVectorAlloc (nSrc*nPar + 1, PS_TYPE_F32);
    402 
    403     // set the static variables
    404     pmSourceFitSetInit (model->type);
    405 
    406     // create the minimization constraints
    407     psMinConstraint *constraint = psMinConstraintAlloc();
    408     constraint->paramMask = psVectorAlloc (nSrc*nPar + 1, PS_TYPE_U8);
    409     constraint->checkLimits = pmSourceFitSet_CheckLimits;
    410 
    411     // set the parameter guesses for the multiple models
    412     // first the value for the single sky parameter
    413     params->data.F32[0] = model->params->data.F32[0];
    414 
    415     // next, the values for the source parameters
    416     for (int i = 0; i < nSrc; i++) {
    417         model = modelSet->data[i];
    418         for (int n = 1; n < nPar + 1; n++) {
    419             params->data.F32[i*nPar + n] = model->params->data.F32[n];
    420         }
    421     }
    422 
    423     if (psTraceGetLevel("psModules.objects") >= 5) {
    424         for (int i = 0; i < params->n; i++) {
    425             fprintf (stderr, "%d %f %d\n", i, params->data.F32[i], constraint->paramMask->data.U8[i]);
    426         }
    427     }
    428 
    429     // set the parameter masks based on the fitting mode
    430     int nParams = 0;
    431     switch (mode) {
    432     case PM_SOURCE_FIT_NORM:
    433         // NORM-only model fits only source normalization (Io)
    434         nParams = nSrc;
    435         psVectorInit (constraint->paramMask, 1);
    436         for (int i = 0; i < nSrc; i++) {
    437             constraint->paramMask->data.U8[1 + i*nPar] = 0;
    438         }
    439         break;
    440     case PM_SOURCE_FIT_PSF:
    441         // PSF model only fits x,y,Io
    442         nParams = 3*nSrc;
    443         psVectorInit (constraint->paramMask, 1);
    444         for (int i = 0; i < nSrc; i++) {
    445             constraint->paramMask->data.U8[1 + i*nPar] = 0;
    446             constraint->paramMask->data.U8[2 + i*nPar] = 0;
    447             constraint->paramMask->data.U8[3 + i*nPar] = 0;
    448         }
    449         break;
    450     case PM_SOURCE_FIT_EXT:
    451         // EXT model fits all params (except sky)
    452         nParams = nPar*nSrc;
    453         psVectorInit (constraint->paramMask, 0);
    454         constraint->paramMask->data.U8[0] = 1;
    455         break;
    456     default:
    457         psAbort("invalid fitting mode");
    458     }
    459 
    460     // force the floating parameters to fall within the contraint ranges
    461     for (int i = 0; i < params->n; i++) {
    462         pmSourceFitSet_CheckLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
    463         pmSourceFitSet_CheckLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
    464     }
    465 
    466     if (nPix <  nParams + 1) {
    467         psTrace (__func__, 4, "insufficient valid pixels\n");
    468         psTrace("psModules.objects", 3, "---- %s() end : fail pixels ----\n", __func__);
    469         model->flags |= PM_MODEL_STATUS_BADARGS;
    470         psFree (x);
    471         psFree (y);
    472         psFree (yErr);
    473         psFree (params);
    474         psFree (dparams);
    475         psFree(constraint);
    476         pmSourceFitSetClear ();
    477         return(false);
    478     }
    479 
    480     psMinimization *myMin = psMinimizationAlloc (PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_TOLERANCE);
    481 
    482     psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
    483 
    484     fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, pmSourceFitSet_Function);
    485     if (!fitStatus) {
    486         psTrace("psModules.objects", 4, "Failed to fit model (%d)\n", nSrc);
    487     }
    488 
    489     // parameter errors from the covariance matrix
    490     for (int i = 0; i < dparams->n; i++) {
    491         if ((constraint->paramMask != NULL) && constraint->paramMask->data.U8[i])
    492             continue;
    493         dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);
    494     }
    495 
    496     // get the Gauss-Newton distance for fixed model parameters
    497     if (constraint->paramMask != NULL) {
    498         psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32);
    499         psVector *altmask = psVectorAlloc (params->n, PS_TYPE_U8);
    500         altmask->data.U8[0] = 1;
    501         for (int i = 1; i < dparams->n; i++) {
    502             altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;
    503         }
    504         psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSet_Function);
    505         for (int i = 0; i < dparams->n; i++) {
    506             if (!constraint->paramMask->data.U8[i])
    507                 continue;
    508             // note that delta is the value *subtracted* from the parameter
    509             // to get the new guess.  for dparams to represent the direction
    510             // of motion, we need to take -delta
    511             dparams->data.F32[i] = -delta->data.F32[i];
    512         }
    513         psFree (delta);
    514         psFree (altmask);
    515     }
    516 
    517     // assign back the parameters to the models
    518     for (int i = 0; i < nSrc; i++) {
    519         model = modelSet->data[i];
    520         model->params->data.F32[0] = params->data.F32[0];
    521         for (int n = 1; n < nPar + 1; n++) {
    522             if (psTraceGetLevel("psModules.objects") >= 4) {
    523                 fprintf (stderr, "%f ", params->data.F32[i*nPar + n]);
    524             }
    525             model->params->data.F32[n] = params->data.F32[i*nPar + n];
    526             model->dparams->data.F32[n] = dparams->data.F32[i*nPar + n];
    527         }
    528         psTrace ("psModules.objects", 4, " src %d", i);
    529 
    530         // save the resulting chisq, nDOF, nIter
    531         // these are not unique for any one source
    532         model->chisq = myMin->value;
    533         model->nIter = myMin->iter;
    534         model->nDOF  = y->n - nParams;
    535 
    536         // set the model success or failure status
    537         model->flags |= PM_MODEL_STATUS_FITTED;
    538         if (!fitStatus) model->flags |= PM_MODEL_STATUS_NONCONVERGE;
    539 
    540         // models can go insane: reject these
    541         onPic &= (model->params->data.F32[PM_PAR_XPOS] >= source->pixels->col0);
    542         onPic &= (model->params->data.F32[PM_PAR_XPOS] <  source->pixels->col0 + source->pixels->numCols);
    543         onPic &= (model->params->data.F32[PM_PAR_XPOS] >= source->pixels->row0);
    544         onPic &= (model->params->data.F32[PM_PAR_XPOS] <  source->pixels->row0 + source->pixels->numRows);
    545         if (!onPic) model->flags |= PM_MODEL_STATUS_OFFIMAGE;
    546     }
    547     psTrace ("psModules.objects", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value);
    548 
    549     source->mode |= PM_SOURCE_MODE_FITTED;
    550 
    551     psFree(x);
    552     psFree(y);
    553     psFree(yErr);
    554     psFree(myMin);
    555     psFree(covar);
    556     psFree(constraint);
    557     psFree(params);
    558     psFree(dparams);
    559 
    560     // free static memory used by pmSourceFitSet
    561     pmSourceFitSetClear ();
    562 
    563     rc = (onPic && fitStatus);
    564     psTrace (__func__, 5, "onPic: %d, fitStatus: %d, nIter: %d, chisq: %f, nDof: %d\n", onPic, fitStatus, model->nIter, model->chisq, model->nDOF);
    565     psTrace("psModules.objects", 5, "---- %s end (%d) ----\n", __func__, rc);
    566     return(rc);
    567 }
    568 
  • trunk/psModules/src/objects/pmSourceIO.c

    r14208 r14652  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-07-14 03:20:44 $
     5 *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-24 00:11:02 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434#include "pmGrowthCurve.h"
    3535#include "pmResiduals.h"
     36#include "pmPSF.h"
    3637#include "pmModel.h"
    37 #include "pmPSF.h"
    3838#include "pmSource.h"
    39 #include "pmModelGroup.h"
     39#include "pmModelClass.h"
    4040#include "pmSourceIO.h"
    4141
  • trunk/psModules/src/objects/pmSourceIO_CMP.c

    r13137 r14652  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-05-03 00:13:03 $
     5 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-24 00:11:02 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232#include "pmGrowthCurve.h"
    3333#include "pmResiduals.h"
     34#include "pmPSF.h"
    3435#include "pmModel.h"
    35 #include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
     
    154154
    155155    // define PSF model type
    156     int modelType = pmModelSetType ("PS_MODEL_GAUSS");
     156    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
    157157
    158158    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
    159159    if (PSF_NAME != NULL) {
    160         modelType = pmModelSetType (PSF_NAME);
     160        modelType = pmModelClassGetType (PSF_NAME);
    161161    }
    162162
  • trunk/psModules/src/objects/pmSourceIO_OBJ.c

    r13137 r14652  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-05-03 00:13:03 $
     5 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-24 00:11:02 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232#include "pmGrowthCurve.h"
    3333#include "pmResiduals.h"
     34#include "pmPSF.h"
    3435#include "pmModel.h"
    35 #include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
  • trunk/psModules/src/objects/pmSourceIO_PS1_DEV_0.c

    r13139 r14652  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-05-03 00:13:42 $
     5 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-24 00:11:02 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232#include "pmGrowthCurve.h"
    3333#include "pmResiduals.h"
     34#include "pmPSF.h"
    3435#include "pmModel.h"
    35 #include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
     
    152152
    153153    // define PSF model type
    154     int modelType = pmModelSetType ("PS_MODEL_GAUSS");
     154    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
    155155
    156156    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
    157157    if (PSF_NAME != NULL) {
    158         modelType = pmModelSetType (PSF_NAME);
     158        modelType = pmModelClassGetType (PSF_NAME);
    159159    }
    160160
  • trunk/psModules/src/objects/pmSourceIO_RAW.c

    r12949 r14652  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-04-21 19:47:14 $
     5 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-24 00:11:02 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232#include "pmGrowthCurve.h"
    3333#include "pmResiduals.h"
     34#include "pmPSF.h"
    3435#include "pmModel.h"
    35 #include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourcePhotometry.h"
    3939#include "pmSourceIO.h"
  • trunk/psModules/src/objects/pmSourceIO_SMPDATA.c

    r13139 r14652  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-05-03 00:13:42 $
     5 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-24 00:11:02 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3030#include "pmPeaks.h"
    3131#include "pmMoments.h"
     32#include "pmResiduals.h"
    3233#include "pmGrowthCurve.h"
    33 #include "pmResiduals.h"
     34#include "pmPSF.h"
    3435#include "pmModel.h"
    35 #include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
     
    132132
    133133    // define PSF model type
    134     int modelType = pmModelSetType ("PS_MODEL_GAUSS");
     134    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
    135135
    136136    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
    137137    if (PSF_NAME != NULL) {
    138         modelType = pmModelSetType (PSF_NAME);
     138        modelType = pmModelClassGetType (PSF_NAME);
    139139    }
    140140
  • trunk/psModules/src/objects/pmSourceIO_SX.c

    r13064 r14652  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-04-27 22:14:08 $
     5 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-24 00:11:02 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232#include "pmGrowthCurve.h"
    3333#include "pmResiduals.h"
     34#include "pmPSF.h"
    3435#include "pmModel.h"
    35 #include "pmPSF.h"
    3636#include "pmSource.h"
    37 #include "pmModelGroup.h"
     37#include "pmModelClass.h"
    3838#include "pmSourceIO.h"
    3939
  • trunk/psModules/src/objects/pmSourcePhotometry.c

    r13898 r14652  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-06-20 02:22:26 $
     5 *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-08-24 00:11:02 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2626#include "pmGrowthCurve.h"
    2727#include "pmResiduals.h"
     28#include "pmPSF.h"
    2829#include "pmModel.h"
    29 #include "pmPSF.h"
    3030#include "pmSource.h"
    31 #include "pmModelGroup.h"
     31#include "pmModelClass.h"
    3232#include "pmSourcePhotometry.h"
    3333
     
    250250
    251251    // measure fitMag
    252     pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
    253     fitSum = modelFluxFunc (model->params);
     252    fitSum = model->modelFlux (model->params);
    254253    if (fitSum <= 0)
    255254        return false;
     
    324323
    325324    // the model function returns the source flux at a position
    326     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
    327325    psVector *coord = psVectorAlloc(2, PS_TYPE_F32);
    328326
     
    354352
    355353            // for the full model, add all points
    356             value = modelFunc (NULL, params, coord) - sky;
     354            value = model->modelFunc (NULL, params, coord) - sky;
    357355            modelSum += value;
    358356
  • trunk/psModules/src/objects/pmSourcePlotApResid.c

    r13473 r14652  
    44 *  @author EAM, IfA
    55 *
    6  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-05-22 21:45:48 $
     6 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-08-24 00:11:02 $
    88 *  Copyright 2006 IfA, University of Hawaii
    99 */
     
    2727#include "pmPeaks.h"
    2828#include "pmMoments.h"
     29#include "pmResiduals.h"
    2930#include "pmGrowthCurve.h"
    30 #include "pmResiduals.h"
     31#include "pmPSF.h"
    3132#include "pmModel.h"
    32 #include "pmPSF.h"
    3333#include "pmSource.h"
    3434#include "pmSourcePlots.h"
  • trunk/psModules/src/objects/pmSourcePlotMoments.c

    r13473 r14652  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-05-22 21:45:48 $
     7 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-08-24 00:11:02 $
    99 *
    1010 *  Copyright 2006 IfA, University of Hawaii
     
    3232#include "pmGrowthCurve.h"
    3333#include "pmResiduals.h"
     34#include "pmPSF.h"
    3435#include "pmModel.h"
    35 #include "pmPSF.h"
    3636#include "pmSource.h"
    3737#include "pmSourcePlots.h"
  • trunk/psModules/src/objects/pmSourcePlotPSFModel.c

    r13473 r14652  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-05-22 21:45:48 $
     7 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-08-24 00:11:02 $
    99 *
    1010 *  Copyright 2006 IfA, University of Hawaii
     
    3232#include "pmGrowthCurve.h"
    3333#include "pmResiduals.h"
     34#include "pmPSF.h"
    3435#include "pmModel.h"
    35 #include "pmPSF.h"
    3636#include "pmSource.h"
    3737#include "pmSourcePlots.h"
  • trunk/psModules/src/objects/pmSourceSky.c

    r13898 r14652  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-06-20 02:22:26 $
     8 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-08-24 00:11:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "pmMoments.h"
    2828#include "pmResiduals.h"
     29#include "pmGrowthCurve.h"
     30#include "pmPSF.h"
    2931#include "pmModel.h"
    3032#include "pmSource.h"
Note: See TracChangeset for help on using the changeset viewer.