IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35559


Ignore:
Timestamp:
May 9, 2013, 12:15:43 PM (13 years ago)
Author:
eugene
Message:

all EXT_FIT_ITER and EXT_FIT_MIN_TOL to be set independent of the PSF versions; make psphotModelTest more useful for EXT; include mask and mark in modelGuess functions (needed for trail angle guess); allow psphot to work even if variance is missing

Location:
trunk/psphot
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/src

  • trunk/psphot/src/models/pmModel_STRAIL.c

    r31154 r35559  
    475475
    476476//fixed I think...no good way of guessing as far as I can tell
    477 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     477bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    478478{
    479479    pmMoments *Smoments = source->moments;
  • trunk/psphot/src/models/pmModel_TEST1.c

    r31154 r35559  
    123123
    124124// make an initial guess for parameters
    125 bool PM_MODEL_GUESS (pmModel *model, pmSource *source)
     125bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    126126{
    127127    pmMoments *moments = source->moments;
  • trunk/psphot/src/psphotExtendedSourceFits.c

    r34404 r35559  
    9090    assert (markVal);
    9191
     92    // source fitting parameters for extended source fits
     93    int fitIter = psMetadataLookupS32(&status, recipe, "EXT_FIT_ITER"); // Max number of fit iterations
     94    assert (status && fitIter > 0);
     95
     96    float fitMinTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MIN_TOL"); // Fit tolerance
     97    if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) {
     98        fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance
     99        if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) {
     100            psAbort("PSF_FIT_MIN_TOL (and PSF_FIT_TOL) not defined or positive");
     101        }
     102    }
     103
     104    float fitMaxTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_TOL"); // Fit tolerance
     105    if (!status || !isfinite(fitMaxTol) || fitMaxTol <= 0) {
     106        fitMaxTol = 1.0;
     107    }
     108
    92109    // maskVal is used to test for rejected pixels, and must include markVal
    93110    maskVal |= markVal;
     
    181198
    182199            PS_ARRAY_ADD_SCALAR(job->args, psfSize, PS_TYPE_S32);
     200            PS_ARRAY_ADD_SCALAR(job->args, fitIter, PS_TYPE_S32);
     201            PS_ARRAY_ADD_SCALAR(job->args, fitMinTol, PS_TYPE_F32);
     202            PS_ARRAY_ADD_SCALAR(job->args, fitMaxTol, PS_TYPE_F32);
     203
    183204            PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK);
    184205            PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK);
     
    293314    psRegion *region        = job->args->data[4];
    294315    int psfSize             = PS_SCALAR_VALUE(job->args->data[5],S32);
    295     psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA);
    296     psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[7],PS_TYPE_IMAGE_MASK_DATA);
     316    int fitIter             = PS_SCALAR_VALUE(job->args->data[6],S32);
     317    float fitMinTol         = PS_SCALAR_VALUE(job->args->data[7],F32);
     318    float fitMaxTol         = PS_SCALAR_VALUE(job->args->data[8],F32);
     319    psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[9],PS_TYPE_IMAGE_MASK_DATA);
     320    psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[10],PS_TYPE_IMAGE_MASK_DATA);
    297321
    298322    // Define source fitting parameters for extended source fits
     
    301325    fitOptions->saveCovariance = true;  // XXX make this a user option?
    302326    fitOptions->covarFactor    = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix
    303 
    304     // XXX for now, use the defaults for the rest:
    305     // fitOptions->nIter         = fitIter;
    306     // fitOptions->tol           = fitTol;
    307     // fitOptions->poissonErrors = poisson;
    308     // fitOptions->weight        = PS_SQR(skySig);
     327    fitOptions->nIter          = fitIter;
     328    fitOptions->minTol         = fitMinTol;
     329    fitOptions->maxTol         = fitMaxTol;
    309330
    310331    // choose the sources of interest
     
    335356        // set the fit radius based on the first radial moment (also sets the mask pixels)
    336357        psphotSetRadiusMomentsExact(&fitRadius, &windowRadius, readout, source, markVal); // NOTE : 6 allocs
     358
     359        // XXX WATCH OUT HERE!!
     360        // fitRadius = 30;
    337361
    338362        // UPDATE : we have changed the moments calculation.  There is now an iteration within
     
    498522
    499523    // change the value of a scalar on the array (wrap this and put it in psArray.h)
    500     scalar = job->args->data[8];
     524    scalar = job->args->data[11];
    501525    scalar->data.S32 = Next;
    502526
    503     scalar = job->args->data[9];
     527    scalar = job->args->data[12];
    504528    scalar->data.S32 = Nconvolve;
    505529
    506     scalar = job->args->data[10];
     530    scalar = job->args->data[13];
    507531    scalar->data.S32 = NconvolvePass;
    508532
    509     scalar = job->args->data[11];
     533    scalar = job->args->data[14];
    510534    scalar->data.S32 = Nplain;
    511535
    512     scalar = job->args->data[12];
     536    scalar = job->args->data[15];
    513537    scalar->data.S32 = NplainPass;
    514538
    515     scalar = job->args->data[13];
     539    scalar = job->args->data[16];
    516540    scalar->data.S32 = Nfaint;
    517541
    518     scalar = job->args->data[14];
     542    scalar = job->args->data[17];
    519543    scalar->data.S32 = Nfail;
    520544
  • trunk/psphot/src/psphotFakeSources.c

    r19881 r35559  
    2424
    2525        pmModelType modelType = pmModelClassGetType ("PS_MODEL_QGAUSS");
    26         source->modelPSF = pmSourceModelGuess (source, modelType);
     26        source->modelPSF = pmSourceModelGuess (source, modelType, 0, 0);
    2727        sources->data[i] = source;
    2828    }
  • trunk/psphot/src/psphotMakeResiduals.c

    r34086 r35559  
    105105        if (model == NULL) continue;  // model must be defined
    106106
    107         psImage *image  = psImageCopy (NULL, source->pixels,   PS_TYPE_F32);
    108         psImage *variance = psImageCopy (NULL, source->variance,   PS_TYPE_F32);
    109         psImage *mask   = psImageCopy (NULL, source->maskView, PS_TYPE_IMAGE_MASK);
     107        psImage *image    = psImageCopy (NULL, source->pixels,     PS_TYPE_F32);
     108        psImage *mask     = psImageCopy (NULL, source->maskView ? source->maskView : source->maskObj,  PS_TYPE_IMAGE_MASK);
     109        psImage *variance = psImageCopy (NULL, source->variance ? source->variance : source->pixels,   PS_TYPE_F32);
    110110        pmModelSub (image, mask, model, PM_MODEL_OP_FUNC, maskVal);
    111111
  • trunk/psphot/src/psphotModelTestArguments.c

    r32348 r35559  
    151151    }
    152152
     153    // chip selection is used to limit chips to be processed
     154    if ((N = psArgumentGet (argc, argv, "-moments-radius"))) {
     155        psArgumentRemove (N, &argc, argv);
     156        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "TEST_MOMENTS_RADIUS", PS_DATA_BOOL, "", true);
     157    }
     158
    153159    // if these command-line options are supplied, load the file name lists into config->arguments
    154160    // override any configuration-specified source for these files
     
    160166    pmConfigFileSetsMD (config->arguments, &argc, argv, "SRC", "-src", "-srclist");
    161167    pmConfigFileSetsMD (config->arguments, &argc, argv, "SRCTEXT", "-srctext", "-srctextlist");
     168
     169    pmConfigFileSetsMD (config->arguments, &argc, argv, "PSPHOT.PSF", "-psf",      "-psflist");
    162170
    163171    if (argc == 1) {
  • trunk/psphot/src/psphotModelTestReadout.c

    r32348 r35559  
    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
  • trunk/psphot/src/psphotSetThreads.c

    r34559 r35559  
    4040    psFree(task);
    4141
    42     task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 15);
     42    task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 18);
    4343    task->function = &psphotExtendedSourceFits_Threaded;
    4444    psThreadTaskAdd(task);
  • trunk/psphot/src/psphotSourceFits.c

    r34258 r35559  
    457457
    458458    // use the source moments, etc to guess basic model parameters
    459     pmModel *model = pmSourceModelGuess (source, modelType);
     459    pmModel *model = pmSourceModelGuess (source, modelType, maskVal, markVal);
    460460    if (!model) {
    461461        psTrace ("psphot", 5, "failed to generate a model for source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy);
     
    625625        model->params->data.F32[PM_PAR_7] = 0.5/indexGuess[i];
    626626
    627         if (!model->modelGuess(model, source)) {
     627        if (!model->modelGuess(model, source, maskVal, markVal)) {
    628628            model->flags |= PM_MODEL_STATUS_BADARGS;
    629629            return false;
     
    648648    model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it
    649649    model->params->data.F32[PM_PAR_7] = 0.5/indexGuess[iMin];
    650     model->modelGuess(model, source);
     650    model->modelGuess(model, source, maskVal, markVal);
    651651
    652652    return true;
     
    677677        model->params->data.F32[PM_PAR_7] = indexGuess[i];
    678678       
    679         if (!model->modelGuess(model, source)) {
     679        if (!model->modelGuess(model, source, maskVal, markVal)) {
    680680            model->flags |= PM_MODEL_STATUS_BADARGS;
    681681            return false;
  • trunk/psphot/src/psphotStackImageLoop.c

Note: See TracChangeset for help on using the changeset viewer.