IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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/models
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.