IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

add mark & mask to model guess code; add -moments-radius and -psf to psphotModelTest; pass the fit tolerance info to the extended source fits; allow psphotModelTest to do trails and psf-convolved fits

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130307/psphot/src/psphotModelTestReadout.c

    r32348 r35322  
    55
    66    bool status;
     7
     8    psTimerStart ("modelTest");
    79
    810    pmModelClassSetLimits(PM_MODEL_LIMITS_LAX);
     
    4143    }
    4244
     45    // load the psf model, if suppled.  FWHM_MAJ,FWHM_MIN,etc are determined and saved on
     46    // readout->analysis. NOTE: this function currently only loads from PSPHOT.PSF.LOAD
     47    if (!psphotLoadPSF (config, view, filerule)) { // ??? need to supply 2 ?
     48        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
     49        return psphotReadoutCleanup (config, view, filerule);
     50    }
     51
    4352    float MIN_KRON_RADIUS = 5.0;
    4453
     
    5362    // maskVal is used to test for rejected pixels, and must include markVal
    5463    maskVal |= markVal;
     64
     65    // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box)
     66    int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
     67    assert (status);
    5568
    5669    // find the currently selected readout
     
    8497
    8598    // define the source of interest
    86    float xObj     = psMetadataLookupF32 (&status, recipe, "TEST_FIT_X");
     99    float xObj     = psMetadataLookupF32 (&status, recipe, "TEST_FIT_X");
    87100    float yObj     = psMetadataLookupF32 (&status, recipe, "TEST_FIT_Y");
    88101    if (!isfinite(xObj) || !isfinite(yObj)) psAbort ("object position is not defined");
     
    99112    source->type = PM_SOURCE_TYPE_EXTENDED;
    100113
     114    bool TEST_FIT_CONVOLVED = psMetadataLookupBool (&status, recipe, "TEST_FIT_CONVOLVED");
     115
    101116    // find the local sky
    102117    status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal);
    103118    if (!status) psAbort("pmSourceLocalSky error");
    104119
    105     {
     120    bool testMomentsRadius = psMetadataLookupBool (&status, config->arguments, "TEST_MOMENTS_RADIUS");
     121    if (testMomentsRadius) {
    106122        // XXX I want to test an iterative aperture for brighter sources
    107123        float radius = mRADIUS;
     
    109125
    110126            // get the source moments
    111             status = pmSourceMoments (source, radius, 0.0, 0.0, MIN_KRON_RADIUS, maskVal);
     127            status = pmSourceMoments (source, radius, 0.25*radius, 0.0, MIN_KRON_RADIUS, maskVal);
    112128            if (!status) psAbort("psSourceMoments error");
    113129
     
    121137
    122138    // get the source moments
    123     status = pmSourceMoments (source, mRADIUS, 0.0, 0.0, MIN_KRON_RADIUS, maskVal);
     139    status = pmSourceMoments (source, mRADIUS, 0.25*mRADIUS, 0.0, MIN_KRON_RADIUS, maskVal);
    124140    if (!status) psAbort("psSourceMoments error");
    125141
     
    135151    fprintf (stderr, "axes: %f @ (%f, %f)\n", axes.theta*180/M_PI, axes.major, axes.minor);
    136152
     153    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     154    if (psf) {
     155      // set PSF parameters for this model (apply 2D shape model to coordinates Xo, Yo)
     156      source->peak->rawFlux = source->moments->Peak;
     157      float Io = source->moments->Peak;
     158      source->modelPSF = pmModelFromPSFforXY(psf, xObj, yObj, Io);
     159    }
     160
    137161    // get the initial model parameter guess
    138     pmModel *model = pmSourceModelGuess (source, modelType);
     162    pmModel *model = pmSourceModelGuess (source, modelType, maskVal, markVal);
    139163    source->modelEXT = model;
    140164
     
    159183    fprintf (stderr, "peak: %f @ (%f, %f)\n", source->moments->Sum*area, (double)source->peak->x, (double)source->peak->y);
    160184
    161     // list model input shape
    162     psEllipseShape shape;
    163     shape.sx  = 1.4 / model->params->data.F32[4];
    164     shape.sy  = 1.4 / model->params->data.F32[5];
    165     shape.sxy = model->params->data.F32[6];
    166     axes = psEllipseShapeToAxes (shape, 20.0);
    167 
    168     fprintf (stderr, "guess: %f @ (%f, %f)\n", axes.theta*180/M_PI, axes.major, axes.minor);
     185    if (modelType == pmModelClassGetType("PS_MODEL_TRAIL")) {
     186        fprintf (stderr, "guess: %f @ (%f, %f)\n", params[6]*180/M_PI, params[4], params[5]);
     187    } else {
     188        // list model input shape
     189        psEllipseShape shape;
     190        shape.sx  = 1.4 / model->params->data.F32[4];
     191        shape.sy  = 1.4 / model->params->data.F32[5];
     192        shape.sxy = model->params->data.F32[6];
     193        axes = psEllipseShapeToAxes (shape, 20.0);
     194        fprintf (stderr, "guess: %f @ (%f, %f)\n", axes.theta*180/M_PI, axes.major, axes.minor);
     195    }
    169196
    170197    fprintf (stderr, "input parameters: \n");
     
    190217    fitOptions->covarFactor   = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix
    191218
    192     status = pmSourceFitModel (source, model, fitOptions, maskVal);
     219    if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
     220        fitOptions->mode = PM_SOURCE_FIT_NO_INDEX;
     221    }
     222    if (modelType == pmModelClassGetType("PS_MODEL_TRAIL")) {
     223        fitOptions->mode = PM_SOURCE_FIT_TRAIL;
     224    }
     225
     226    if (TEST_FIT_CONVOLVED) {
     227      pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize);
     228      if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
     229        psphotSersicModelClassGuessPCM (pcm, source);
     230      } else {
     231        pmSourceModelGuessPCM (pcm, source, maskVal, markVal);
     232      }
     233      pmPCMupdate(pcm, source, fitOptions, model);
     234      pmSourceFitPCM (pcm, source, fitOptions, maskVal, markVal, psfSize);
     235      psFree (pcm);
     236    } else {
     237      status = pmSourceFitModel (source, model, fitOptions, maskVal);
     238    }
    193239
    194240    // measure the source mags
Note: See TracChangeset for help on using the changeset viewer.