IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 2, 2009, 5:10:19 PM (17 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/20090820
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090820

  • branches/eam_branches/20090820/ppStack/src/ppStackMatch.c

    r25045 r25766  
    1414#define FAKE_SIZE 1                     // Size of fake convolution kernel
    1515#define SOURCE_MASK (PM_SOURCE_MODE_FAIL | PM_SOURCE_MODE_DEFECT | PM_SOURCE_MODE_SATURATED | \
    16                      PM_SOURCE_MODE_CR_LIMIT) // Mask to apply to input sources
    17 #define FAINT_SOURCE_FRAC 1.0e-4         // Set minimum flux to this fraction of faintest source flux
     16                     PM_SOURCE_MODE_CR_LIMIT | PM_SOURCE_MODE_EXT_LIMIT) // Mask to apply to input sources
     17#define NOISE_FRACTION 0.01             // Set minimum flux to this fraction of noise
    1818#define COVAR_FRAC 0.01                 // Truncation fraction for covariance matrix
    1919
     
    8787    x->n = y->n = numGood;
    8888
    89     psTree *tree = psTreePlant(2, 2, x, y); // kd tree
     89    psTree *tree = psTreePlant(2, 2, PS_TREE_EUCLIDEAN, x, y); // kd tree
    9090
    9191    psArray *filtered = psArrayAllocEmpty(numGood); // Filtered list of sources
     
    162162}
    163163
     164// Renormalise a readout's variance map
     165bool stackRenormaliseReadout(const pmConfig *config, // Configuration
     166                             pmReadout *readout      // Readout to renormalise
     167    )
     168{
     169    bool mdok; // Status of metadata lookups
     170
     171    psMetadata *recipe = psMetadataLookupPtr(NULL, config->recipes, PPSTACK_RECIPE); // Recipe for ppStack
     172    psAssert(recipe, "Need PPSTACK recipe");
     173
     174    if (!psMetadataLookupBool(&mdok, recipe, "RENORM")) return true;
     175
     176    int num = psMetadataLookupS32(&mdok, recipe, "RENORM.NUM");
     177    if (!mdok) {
     178        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.NUM is not set in the recipe");
     179        return false;
     180    }
     181    float minValid = psMetadataLookupF32(&mdok, recipe, "RENORM.MIN");
     182    if (!mdok) {
     183        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.MIN is not set in the recipe");
     184        return false;
     185    }
     186    float maxValid = psMetadataLookupF32(&mdok, recipe, "RENORM.MAX");
     187    if (!mdok) {
     188        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.MAX is not set in the recipe");
     189        return false;
     190    }
     191
     192    psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask
     193
     194    return pmReadoutVarianceRenormalise(readout, maskBad, num, minValid, maxValid);
     195}
     196
     197
    164198
    165199bool ppStackMatch(pmReadout *readout, ppStackOptions *options, int index, const pmConfig *config)
     
    232266            psRegion *region = psMetadataLookupPtr(NULL, conv->analysis,
    233267                                                   PM_SUBTRACTION_ANALYSIS_REGION); // Convolution region
    234 
    235             pmSubtractionAnalysis(readout->analysis, kernels, region,
     268            pmSubtractionKernels *kernels = psMetadataLookupPtr(NULL, conv->analysis,
     269                                                                PM_SUBTRACTION_ANALYSIS_KERNEL);
     270
     271            pmSubtractionAnalysis(readout->analysis, NULL, kernels, region,
    236272                                  readout->image->numCols, readout->image->numRows);
    237273
     
    283319            pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF
    284320
     321            psStats *bg = psStatsAlloc(PS_STAT_ROBUST_STDEV); // Statistics for background
     322            psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
     323            if (!psImageBackground(bg, NULL, readout->image, readout->mask, maskVal | maskBad, rng)) {
     324                psError(PS_ERR_UNKNOWN, false, "Can't measure background for image.");
     325                psFree(fake);
     326                psFree(optWidths);
     327                psFree(conv);
     328                psFree(bg);
     329                psFree(rng);
     330                return false;
     331            }
     332            float minFlux = NOISE_FRACTION * bg->robustStdev; // Minimum flux level for fake image
     333            psFree(rng);
     334            psFree(bg);
     335
    285336            // For the sake of stamps, remove nearby sources
    286337            psArray *stampSources = stackSourcesFilter(options->sourceLists->data[index],
     
    288339
    289340            if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows,
    290                                           stampSources, NULL, NULL, options->psf, NAN, footprint + size,
    291                                           false, true)) {
     341                                          stampSources, SOURCE_MASK, NULL, NULL, options->psf,
     342                                          minFlux, footprint + size, false, true)) {
    292343                psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF.");
    293344                psFree(fake);
     
    335386                                                               PM_SUBTRACTION_ANALYSIS_KERNEL); // Conv kernel
    336387            if (kernel) {
    337                 if (!pmSubtractionMatchPrecalc(conv, NULL, readout, fake, readout->analysis,
     388                if (!pmSubtractionMatchPrecalc(NULL, conv, fake, readout, readout->analysis,
    338389                                               stride, sysError, maskVal, maskBad, maskPoor,
    339390                                               poorFrac, badFrac)) {
     
    349400                }
    350401            } else {
    351                 if (!pmSubtractionMatch(conv, NULL, readout, fake, footprint, stride, regionSize, spacing,
     402                if (!pmSubtractionMatch(NULL, conv, fake, readout, footprint, stride, regionSize, spacing,
    352403                                        threshold, stampSources, stampsName, type, size, order, widths,
    353404                                        orders, inner, ringsOrder, binning, penalty,
    354405                                        optimum, optWidths, optOrder, optThresh, iter, rej, sysError,
    355406                                        maskVal, maskBad, maskPoor, poorFrac, badFrac,
    356                                         PM_SUBTRACTION_MODE_1)) {
     407                                        PM_SUBTRACTION_MODE_2)) {
    357408                    psError(PS_ERR_UNKNOWN, false, "Unable to match images.");
    358409                    psFree(fake);
     
    502553    }
    503554
     555    if (!stackRenormaliseReadout(config, readout)) {
     556        psFree(rng);
     557        psFree(bg);
     558        return false;
     559    }
    504560
    505561    // Measure the variance level for the weighting
Note: See TracChangeset for help on using the changeset viewer.