IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 22, 2007, 2:55:49 PM (19 years ago)
Author:
magnier
Message:

adjusted pmModel.h to allow pmModel to use functions which use pmModel
as an argument.

adjusted the order of the pmPSF.h entries to allow that as an argument
as well

changed pmPSF I/O functions to load/save the psf on the
chip->analysis, not the readout->analysis

fixed the modelRadius function for PGAUSS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070817/psModules/src/objects/models/pmModel_PGAUSS.c

    r14220 r14612  
    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
Note: See TracChangeset for help on using the changeset viewer.