IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35321


Ignore:
Timestamp:
Mar 19, 2013, 2:45:32 PM (13 years ago)
Author:
eugene
Message:

add mask and mark values to model guess code; add new angle guess code

Location:
branches/eam_branches/ipp-20130307/psModules/src/objects
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_DEV.c

    r34403 r35321  
    295295// make an initial guess for parameters
    296296// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    297 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     297bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    298298{
    299299    psF32 *PAR  = model->params->data.F32;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_DEV.h

    r29004 r35321  
    55psF32 pmModelFunc_DEV(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_DEV(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_DEV(pmModel *model, pmSource *source);
     7bool pmModelGuess_DEV(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_DEV(const psVector *params);
    99psF64 pmModelRadius_DEV(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_EXP.c

    r34403 r35321  
    287287// make an initial guess for parameters
    288288// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    289 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     289bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    290290{
    291291    psF32 *PAR  = model->params->data.F32;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_EXP.h

    r29004 r35321  
    55psF32 pmModelFunc_EXP(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_EXP(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_EXP(pmModel *model, pmSource *source);
     7bool pmModelGuess_EXP(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_EXP(const psVector *params);
    99psF64 pmModelRadius_EXP(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_GAUSS.c

    r34403 r35321  
    192192// make an initial guess for parameters
    193193// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    194 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     194bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    195195{
    196196    psF32 *PAR  = model->params->data.F32;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_GAUSS.h

    r25738 r35321  
    55psF32 pmModelFunc_GAUSS(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_GAUSS(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_GAUSS(pmModel *model, pmSource *source);
     7bool pmModelGuess_GAUSS(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_GAUSS(const psVector *params);
    99psF64 pmModelRadius_GAUSS(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_PGAUSS.c

    r34403 r35321  
    193193// make an initial guess for parameters
    194194// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    195 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     195bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    196196{
    197197    psF32 *PAR  = model->params->data.F32;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_PGAUSS.h

    r25738 r35321  
    55psF32 pmModelFunc_PGAUSS(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_PGAUSS(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_PGAUSS(pmModel *model, pmSource *source);
     7bool pmModelGuess_PGAUSS(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_PGAUSS(const psVector *params);
    99psF64 pmModelRadius_PGAUSS(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_PS1_V1.c

    r34403 r35321  
    212212// make an initial guess for parameters
    213213// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    214 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     214bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    215215{
    216216    psF32 *PAR  = model->params->data.F32;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_PS1_V1.h

    r25738 r35321  
    55psF32 pmModelFunc_PS1_V1(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_PS1_V1(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_PS1_V1(pmModel *model, pmSource *source);
     7bool pmModelGuess_PS1_V1(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_PS1_V1(const psVector *params);
    99psF64 pmModelRadius_PS1_V1(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_QGAUSS.c

    r34403 r35321  
    213213// make an initial guess for parameters
    214214// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    215 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     215bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    216216{
    217217    psF32 *PAR  = model->params->data.F32;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_QGAUSS.h

    r25738 r35321  
    55psF32 pmModelFunc_QGAUSS(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_QGAUSS(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_QGAUSS(pmModel *model, pmSource *source);
     7bool pmModelGuess_QGAUSS(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_QGAUSS(const psVector *params);
    99psF64 pmModelRadius_QGAUSS(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_RGAUSS.c

    r34403 r35321  
    202202// make an initial guess for parameters
    203203// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    204 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     204bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    205205{
    206206    psF32 *PAR  = model->params->data.F32;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_RGAUSS.h

    r25738 r35321  
    55psF32 pmModelFunc_RGAUSS(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_RGAUSS(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_RGAUSS(pmModel *model, pmSource *source);
     7bool pmModelGuess_RGAUSS(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_RGAUSS(const psVector *params);
    99psF64 pmModelRadius_RGAUSS(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_SERSIC.c

    r34403 r35321  
    307307// make an initial guess for parameters
    308308// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    309 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     309bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    310310{
    311311    pmMoments *moments = source->moments;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_SERSIC.h

    r25738 r35321  
    55psF32 pmModelFunc_SERSIC(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_SERSIC(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_SERSIC(pmModel *model, pmSource *source);
     7bool pmModelGuess_SERSIC(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_SERSIC(const psVector *params);
    99psF64 pmModelRadius_SERSIC(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_TRAIL.c

    r35215 r35321  
    168168        dPAR[PM_PAR_THETA]  = PAR[PM_PAR_I0] * dPdT;
    169169        dPAR[PM_PAR_SIGMA]  = 0;        // we don't actually allow this to vary, so we do not need to calculate it
     170
     171        for (int i = 0; i < 7; i++) {
     172          if (isnan(dPAR[i])) {
     173            fprintf (stderr, "*");
     174          }
     175        }
     176    }
     177    if (isnan(f)) {
     178      fprintf (stderr, "!");
    170179    }
    171180    return(f);
     
    228237}
    229238
     239# define NA 21
     240# define NR 21
     241static float flux[NA][NR];
     242static float npix[NA][NR];
     243
     244bool pmTrailGetAngle (float *To, float *Io, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal, float sigma) {
     245
     246  float Xo, Yo;
     247  if (!pmModelSetPosition(&Xo, &Yo, source)) return false;
     248
     249  psImage *image = source->pixels;
     250  psImage *mask = source->maskObj;
     251  psF32 **imData = image->data.F32;
     252  psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA;
     253
     254  // do a loop over the pixels, generating (dX,dY) dot (cos(theta),sin(theta))
     255  int dP;
     256  int dX = Xo - mask->col0;
     257  dP = mask->numCols - dX;
     258  int DX = PS_MAX(dP, dX);
     259  int NX = mask->numCols;
     260
     261  int dY = Yo - mask->row0;
     262  dP = mask->numRows - dY;
     263  int DY = PS_MAX(dP, dY);
     264  int NY = mask->numRows;
     265
     266  // just hard wire this for now...
     267  float radius = 10.0;
     268  float radius2 = PS_SQR(radius);
     269
     270  // we have an array of Angles x Radii
     271  float dT = M_PI / NA;
     272  for (int na = 0; na < NA; na++) {
     273    memset (flux[na], 0, NR*sizeof(float));
     274    memset (npix[na], 0, NR*sizeof(float));
     275  }
     276
     277  // we skip any pixels [real or virtual] outside of the specified radius (nominally the aperture radius)
     278  // ix and iy track pixels relative to the centroid
     279  for (int ix = -DX; ix < DX + 1; ix++) {
     280    if (ix > radius) continue;
     281    int mx = ix + dX;
     282    for (int iy = -DY; iy < DY + 1; iy++) {
     283      if (iy > radius) continue;
     284      if (ix*ix + iy*iy > radius2) continue;
     285      int my = iy + dY;
     286     
     287      // include count only the unmasked pixels within the image area
     288      if (mx < 0) continue;
     289      if (my < 0) continue;
     290      if (mx >= NX) continue;
     291      if (my >= NY) continue;
     292     
     293      // count pixels which are masked only with bad pixels
     294      if (mkData[my][mx] & maskVal)continue;
     295
     296      // we have defined NA to be 21
     297      int na = 0;
     298      for (float angle = 0.0; na < NA; angle += dT, na ++) {
     299
     300        // XXX optimization : pre-compute the angle sines and cosines
     301        float Rad = (ix * cos(angle)) + (iy * sin(angle));
     302        int nr = PS_MAX (PS_MIN (NR, Rad + 0.5*NR), 0);
     303
     304        flux[na][nr] += imData[my][mx];
     305        npix[na][nr] ++;
     306      }
     307    }
     308  }
     309
     310  // generate a psf model (with integral of 1.0)
     311  float Ao = 1.0 / sqrt(2*M_PI) / sigma;
     312  float psf[NR];
     313  for (int nr = 0; nr < NR; nr++) {
     314    psf[nr] = Ao*exp(-0.5*PS_SQR((nr - 0.5*NR)/sigma));
     315  }
     316
     317  float fangle[NA];
     318  for (int na = 0; na < NA; na++) {
     319    float fpsf = 0.0;
     320    for (int nr = 0; nr < NR; nr++) {
     321      fpsf += psf[nr]*flux[na][nr];
     322    }
     323    fangle[na] = fpsf;
     324    // fprintf (stderr, "fpsf: %f, theta = %f\n", fpsf, PS_DEG_RAD*dT*na);
     325  }
     326
     327  float peak = fangle[0];
     328  int pbin = 0;
     329  for (int na = 0; na < NA; na++) {
     330    if (fangle[na] > peak) {
     331      peak = fangle[na];
     332      pbin = na;
     333    }
     334  }
     335
     336  // result is peak, pbin -> angle
     337  *To = dT * pbin;
     338  *Io = peak * Ao;
     339 
     340  return true;
     341}
     342
    230343// make an initial guess for parameters
    231344// 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters
    232 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     345bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    233346{
    234347    psF32 *PAR  = model->params->data.F32;
     
    260373    //else { size = psfAxes.major; }
    261374
     375    float theta, peak;
     376    pmTrailGetAngle (&theta, &peak, source, maskVal, markVal, psfAxes.major);
     377
    262378    // axes.major is a sigma in the major direction; scale to
    263379    PAR[PM_PAR_LENGTH] = 1.5*2.35*size; // a tophat of length L has L = 1.5 * 2.35 * sigma
     
    266382
    267383    // set the model normalization
    268     if (!pmModelSetNorm(&PAR[PM_PAR_I0], source)) {
    269       return false;
    270     }
     384    // if (!pmModelSetNorm(&PAR[PM_PAR_I0], source)) {
     385    //   return false;
     386    // }
     387    PAR[PM_PAR_I0] = peak;
    271388
    272389    // set the model position
  • branches/eam_branches/ipp-20130307/psModules/src/objects/models/pmModel_TRAIL.h

    r34259 r35321  
    55psF32 pmModelFunc_TRAIL(psVector *deriv, const psVector *params, const psVector *pixcoord);
    66bool pmModelLimits_TRAIL(psMinConstraintMode mode, int nParam, float *params, float *beta);
    7 bool pmModelGuess_TRAIL(pmModel *model, pmSource *source);
     7bool pmModelGuess_TRAIL(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    88psF64 pmModelFlux_TRAIL(const psVector *params);
    99psF64 pmModelRadius_TRAIL(const psVector *params, psF64 flux);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/pmModelFuncs.h

    r34259 r35321  
    107107//  This function provides the model guess parameters based on the details of
    108108//  the given source.
    109 typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source);
     109typedef bool (*pmModelGuessFunc)(pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
    110110
    111111//  This function constructs the PSF model for the given source based on the
  • branches/eam_branches/ipp-20130307/psModules/src/objects/pmPSFtryFitEXT.c

    r34403 r35321  
    8383        }
    8484
    85         source->modelEXT = pmSourceModelGuess (source, options->type);
     85        source->modelEXT = pmSourceModelGuess (source, options->type, maskVal, markVal);
    8686        if (source->modelEXT == NULL) {
    8787            psTrace ("psModules.objects", 4, "masking %d (%d,%d) : failed to generate model guess\n", i, source->peak->x, source->peak->y);
  • branches/eam_branches/ipp-20130307/psModules/src/objects/pmSourceFitPCM.c

    r34403 r35321  
    145145bool pmSourceModelGuessPCM (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) {
    146146
    147     if (!pcm->modelConv->modelGuess(pcm->modelConv, source)) {
     147  if (!pcm->modelConv->modelGuess(pcm->modelConv, source, maskVal, markVal)) {
    148148        return false;
    149149    }
  • branches/eam_branches/ipp-20130307/psModules/src/objects/pmSourceUtils.c

    r34403 r35321  
    4646
    4747/******************************************************************************
    48     pmSourceModelGuess(source, model): This function allocates a new
    49     pmModel structure based on the given modelType specified in the argument list.
    50     The corresponding pmModelGuess function is returned, and used to
    51     supply the values of the params array in the pmModel structure.
     48    pmSourceModelGuess(source, model, maskVal, markVal): This function allocates a new
     49    pmModel structure based on the given modelType specified in the argument list.  The
     50    corresponding pmModelGuess function is returned, and used to supply the values of the
     51    params array in the pmModel structure.
    5252 
    5353    XXX: Many parameters are based on the src->moments structure, which is in
     
    5555    functions will be in image, not subImage coords.  Remember this.
    5656*****************************************************************************/
    57 pmModel *pmSourceModelGuess(pmSource *source,
    58                             pmModelType modelType)
     57pmModel *pmSourceModelGuess(pmSource *source, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal)
    5958{
    6059    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
     
    6564    pmModel *model = pmModelAlloc(modelType);
    6665
    67     if (!model->modelGuess(model, source)) {
     66    if (!model->modelGuess(model, source, maskVal, markVal)) {
    6867        psFree (model);
    6968        return NULL;
  • branches/eam_branches/ipp-20130307/psModules/src/objects/pmSourceUtils.h

    r31451 r35321  
    2727pmModel *pmSourceModelGuess(
    2828    pmSource *source,   ///< The input pmSource
    29     pmModelType model   ///< The type of model to be created.
     29    pmModelType model,   ///< The type of model to be created.
     30    psImageMaskType maskVal,
     31    psImageMaskType markVal
    3032);
    3133
Note: See TracChangeset for help on using the changeset viewer.