IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18865


Ignore:
Timestamp:
Aug 1, 2008, 2:50:07 PM (18 years ago)
Author:
Paul Price
Message:

Adding PSF_FIT_ITER, PSF_FIT_TOL, EXT_FIT_ITER and EXT_FIT_TOL recipe
parameters to control the non-linear source fitting. We want to
separate the PSF fits and the general extended source fits: we can
afford to spend more time on the PSF fits to make sure they're right
(and that they succeed), whereas we're willing to throw away other
sources if they don't fit.

Location:
trunk/psphot/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotChoosePSF.c

    r18582 r18865  
    6464    assert (status);
    6565
    66     // XXX ROBUST seems to be too agressive given the small numbers. 
     66    // XXX ROBUST seems to be too agressive given the small numbers.
    6767    // options->stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    6868    options->stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
     
    7474    options->psfFieldYo = readout->image->row0;
    7575
    76     pmSourceFitModelInit (15, 0.01, PS_SQR(SKY_SIG), options->poissonErrorsPhotLMM);
     76    int fitIter = psMetadataLookupS32(&status, recipe, "PSF_FIT_ITER"); // Maximum number of fit iterations
     77    if (!status || fitIter <= 0) {
     78        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "PSF_FIT_ITER is not positive");
     79        return false;
     80    }
     81    float fitTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance
     82    if (!status || !isfinite(fitTol) || fitTol <= 0) {
     83        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "PSF_FIT_TOL is not positive");
     84        return false;
     85    }
     86    pmSourceFitModelInit(fitIter, fitTol, PS_SQR(SKY_SIG), options->poissonErrorsPhotLMM);
    7787
    7888    psArray *stars = psArrayAllocEmpty (sources->n);
     
    188198        bool mdok;                      // Status of MD lookup
    189199        if (!psMetadataLookupBool(&mdok, recipe, PSPHOT_RECIPE_PSF_FAKE_ALLOW)) {
    190             psFree (modelNames);
    191             psFree(options);
     200            psFree (modelNames);
     201            psFree(options);
    192202            return NULL;
    193203        }
    194204
    195205        // generate a psf model using the first selection
    196         psLogMsg ("psphot.pspsf", PS_LOG_INFO, "Using guess PSF model");
     206        psLogMsg ("psphot.pspsf", PS_LOG_INFO, "Using guess PSF model");
    197207
    198208        // unset the PSFSTAR flags (none are used):
  • trunk/psphot/src/psphotReadout.c

    r18834 r18865  
    6262        return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);
    6363    }
    64  
     64
    6565    // XXX test write out the footprint image
    6666    if (0) {
    67         psImage *footprintImage = pmSetFootprintArrayIDs (detections->footprints, true);
    68         psphotSaveImage (NULL, footprintImage, "footprints.1.fits");
    69         psFree (footprintImage);
     67        psImage *footprintImage = pmSetFootprintArrayIDs (detections->footprints, true);
     68        psphotSaveImage (NULL, footprintImage, "footprints.1.fits");
     69        psFree (footprintImage);
    7070    }
    7171
     
    112112    }
    113113
     114    // Define source fitting parameters for everything that follows PSF fits
     115    // This allows different parameters to be used from the PSF fitting
     116    {
     117        bool status = true;             // Status of MD lookup
     118        int fitIter = psMetadataLookupS32(&status, recipe, "EXT_FIT_ITER"); // Max number of fit iterations
     119        if (!status || fitIter <= 0) {
     120            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "EXT_FIT_ITER is not positive");
     121            return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     122        }
     123        float fitTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_TOL"); // Fit tolerance
     124        if (!status || !isfinite(fitTol) || fitTol <= 0) {
     125            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "EXT_FIT_TOL is not positive");
     126            return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     127        }
     128        bool poisson = psMetadataLookupBool(&status, recipe, "POISSON.ERRORS.PHOT.LMM"); // Poisson errors?
     129        if (!status) {
     130            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "POISSON.ERRORS.PHOT.LMM is not defined");
     131            return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     132        }
     133        float skySig = psMetadataLookupF32(&status, recipe, "SKY_SIG");
     134        if (!status || !isfinite(skySig) || skySig <= 0) {
     135            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "SKY_SIG is not positive");
     136            return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     137        }
     138        pmSourceFitModelInit(fitIter, fitTol, PS_SQR(skySig), poisson);
     139    }
     140
    114141    // include externally-supplied sources
    115142    psphotLoadExtSources (config, view, sources);
     
    124151    psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE);
    125152
    126     if (0) { 
    127         FILE *out = fopen ("out.pass1.dat", "w");
    128        
    129         for (int i = 0; i < sources->n; i++) {
    130             pmSource *source = sources->data[i];
    131             if (!source) continue;
    132             pmPeak *peak = source->peak;
    133             if (!peak) continue;
    134             pmModel *model = source->modelPSF;
    135             if (!model) continue;
    136             if (!model->params) continue;
    137            
    138             fprintf (out, "%d %f %f  %f %f  %f %f\n",
    139                      i, peak->xf, peak->yf, peak->flux, peak->SN,
    140                      model->params->data.F32[PM_PAR_I0],
    141                      model->dparams->data.F32[PM_PAR_I0]);
    142         }
    143         fclose (out);
     153    if (0) {
     154        FILE *out = fopen ("out.pass1.dat", "w");
     155
     156        for (int i = 0; i < sources->n; i++) {
     157            pmSource *source = sources->data[i];
     158            if (!source) continue;
     159            pmPeak *peak = source->peak;
     160            if (!peak) continue;
     161            pmModel *model = source->modelPSF;
     162            if (!model) continue;
     163            if (!model->params) continue;
     164
     165            fprintf (out, "%d %f %f  %f %f  %f %f\n",
     166                     i, peak->xf, peak->yf, peak->flux, peak->SN,
     167                     model->params->data.F32[PM_PAR_I0],
     168                     model->dparams->data.F32[PM_PAR_I0]);
     169        }
     170        fclose (out);
    144171    }
    145172
     
    178205    // XXX test write out the footprint image
    179206    if (0) {
    180         psImage *footprintImage = pmSetFootprintArrayIDs (detections->footprints, true);
    181         psphotSaveImage (NULL, footprintImage, "footprints.2.fits");
    182         psFree (footprintImage);
     207        psImage *footprintImage = pmSetFootprintArrayIDs (detections->footprints, true);
     208        psphotSaveImage (NULL, footprintImage, "footprints.2.fits");
     209        psFree (footprintImage);
    183210    }
    184211
     
    208235    psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE);
    209236
    210     if (0) { 
    211         FILE *out = fopen ("out.pass2.dat", "w");
    212        
    213         for (int i = 0; i < sources->n; i++) {
    214             pmSource *source = sources->data[i];
    215             if (!source) continue;
    216             pmPeak *peak = source->peak;
    217             if (!peak) continue;
    218             pmModel *model = source->modelPSF;
    219             if (!model) continue;
    220             if (!model->params) continue;
    221            
    222             fprintf (out, "%d %f %f  %f %f  %f %f\n",
    223                      i, peak->xf, peak->yf, peak->flux, peak->SN,
    224                      model->params->data.F32[PM_PAR_I0],
    225                      model->dparams->data.F32[PM_PAR_I0]);
    226         }
    227         fclose (out);
     237    if (0) {
     238        FILE *out = fopen ("out.pass2.dat", "w");
     239
     240        for (int i = 0; i < sources->n; i++) {
     241            pmSource *source = sources->data[i];
     242            if (!source) continue;
     243            pmPeak *peak = source->peak;
     244            if (!peak) continue;
     245            pmModel *model = source->modelPSF;
     246            if (!model) continue;
     247            if (!model->params) continue;
     248
     249            fprintf (out, "%d %f %f  %f %f  %f %f\n",
     250                     i, peak->xf, peak->yf, peak->flux, peak->SN,
     251                     model->params->data.F32[PM_PAR_I0],
     252                     model->dparams->data.F32[PM_PAR_I0]);
     253        }
     254        fclose (out);
    228255    }
    229256
     
    234261
    235262    if (0) {
    236         psphotSaveImage (NULL, readout->mask, "mask.fits");
    237     }
    238        
     263        psphotSaveImage (NULL, readout->mask, "mask.fits");
     264    }
     265
    239266    psphotExtendedSourceAnalysis (readout, sources, recipe);
    240267
     
    243270finish:
    244271
    245     // plot positive sources 
    246     // psphotSourcePlots (readout, sources, recipe); 
     272    // plot positive sources
     273    // psphotSourcePlots (readout, sources, recipe);
    247274
    248275    // measure aperture photometry corrections
Note: See TracChangeset for help on using the changeset viewer.