IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 29, 2010, 2:35:46 PM (16 years ago)
Author:
eugene
Message:

attempting to get a better starting guess; attempting to downweight neighbor detections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/psModules/src/objects/pmPCMdata.c

    r28702 r28781  
    256256    return pcm;
    257257}
     258
     259// has the set of fitted terms changed?  has the fitting radius changed?
     260bool pmPCMupdate(pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, pmModel *model) {
     261
     262    bool newWindow = (source->pixels->numRows != pcm->modelFlux->numRows) || (source->pixels->numCols != pcm->modelFlux->numCols);
     263
     264    // re-count the number of unmasked pixels:
     265    if (newWindow) {
     266        for (psS32 i = 0; i < source->pixels->numRows; i++) {
     267            for (psS32 j = 0; j < source->pixels->numCols; j++) {
     268                // XXX are we doing the right thing with the mask?
     269                // skip masked points
     270                if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) {
     271                    continue;
     272                }
     273                // skip zero-variance points
     274                if (source->variance->data.F32[i][j] == 0) {
     275                    continue;
     276                }
     277                // skip nan value points
     278                if (!isfinite(source->pixels->data.F32[i][j])) {
     279                    continue;
     280                }
     281                pcm->nPix ++;
     282            }
     283        }   
     284    }
     285
     286    // if we changed the fit mode, we need to update nDOF
     287    int nParams = 0;
     288    // set parameter mask based on fitting mode
     289    switch (fitOptions->mode) {
     290      case PM_SOURCE_FIT_NORM:
     291        // NORM-only model fits only source normalization (Io)
     292        nParams = 1;
     293        psVectorInit (pcm->constraint->paramMask, 1);
     294        pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
     295        break;
     296      case PM_SOURCE_FIT_PSF:
     297        // PSF model only fits x,y,Io
     298        nParams = 3;
     299        psVectorInit (pcm->constraint->paramMask, 1);
     300        pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
     301        pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_XPOS] = 0;
     302        pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_YPOS] = 0;
     303        break;
     304      case PM_SOURCE_FIT_EXT:
     305        // EXT model fits all params (except sky)
     306        nParams = model->params->n - 1;
     307        psVectorInit (pcm->constraint->paramMask, 0);
     308        pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
     309        break;
     310      case PM_SOURCE_FIT_INDEX:
     311        // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params
     312        psVectorInit (pcm->constraint->paramMask, 1);
     313        pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
     314        if (model->params->n == 7) {
     315            nParams = 1;
     316        } else {
     317            nParams = 2;
     318            pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 0;
     319        }
     320        break;
     321      case PM_SOURCE_FIT_NO_INDEX:
     322        // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params
     323        psVectorInit (pcm->constraint->paramMask, 0);
     324        pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
     325        if (model->params->n == 7) {
     326            nParams = model->params->n - 1;
     327        } else {
     328            nParams = model->params->n - 2;
     329            pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 1;
     330        }
     331        break;
     332      default:
     333        psAbort("invalid fitting mode");
     334    }
     335
     336    if (pcm->nPix <  nParams + 1) {
     337        psTrace ("psModules.objects", 4, "insufficient valid pixels\n");
     338        model->flags |= PM_MODEL_STATUS_BADARGS;
     339        return false;
     340    }
     341    pcm->nDOF = pcm->nPix - nParams - 1;
     342
     343    // has the source pixel window changed?
     344    if (newWindow) {
     345
     346        // adjust all supporting images:
     347        pcm->modelFlux = psImageCopy (pcm->modelFlux, source->pixels, PS_TYPE_F32);
     348        for (psS32 n = 0; n < pcm->dmodelsFlux->n; n++) {
     349            if ((pcm->constraint->paramMask != NULL) && (pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; }
     350            pcm->dmodelsFlux->data[n] = psImageCopy (pcm->dmodelsFlux->data[n], source->pixels, PS_TYPE_F32);
     351        }
     352
     353        // adjust images for convolved model and derivative images
     354        pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, source->pixels, PS_TYPE_F32);
     355        for (psS32 n = 0; n < pcm->dmodelsConvFlux->n; n++) {
     356            if ((pcm->constraint->paramMask != NULL) && (pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; }
     357            pcm->dmodelsConvFlux->data[n] = psImageCopy (pcm->dmodelsConvFlux->data[n], source->pixels, PS_TYPE_F32);
     358        }
     359    }
     360
     361    return true;
     362}
Note: See TracChangeset for help on using the changeset viewer.