IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 15, 2009, 4:02:42 PM (17 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/ppStack/src/ppStackMatch.c

    r25022 r25406  
    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
     16                     PM_SOURCE_MODE_CR_LIMIT | PM_SOURCE_MODE_EXT_LIMIT) // Mask to apply to input sources
    1717#define FAINT_SOURCE_FRAC 1.0e-4         // Set minimum flux to this fraction of faintest source flux
    1818#define COVAR_FRAC 0.01                 // Truncation fraction for covariance matrix
     
    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)
     
    222256            }
    223257            psFitsClose(fits);
    224 
    225             // Add in variance factor
    226             pmSubtractionKernels *kernels = psMetadataLookupPtr(NULL, conv->analysis,
    227                                                                 PM_SUBTRACTION_ANALYSIS_KERNEL); // Kernels
    228             float vf = pmSubtractionVarianceFactor(kernels, 0.0, 0.0, false); // Variance factor
    229             psMetadataItem *vfItem = psMetadataLookup(readout->parent->concepts, "CELL.VARFACTOR");
    230             if (!isfinite(vf)) {
    231                 vf = 1.0;
    232             }
    233             if (isfinite(vfItem->data.F32)) {
    234                 vfItem->data.F32 *= vf;
    235             } else {
    236                 vfItem->data.F32 = vf;
    237             }
    238258
    239259            if (!readImage(&readout->image, options->imageNames->data[index], config) ||
     
    302322
    303323            if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows,
    304                                           stampSources, NULL, NULL, options->psf, NAN, footprint + size,
    305                                           false, true)) {
     324                                          stampSources, SOURCE_MASK, NULL, NULL, options->psf,
     325                                          NAN, footprint + size, false, true)) {
    306326                psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF.");
    307327                psFree(fake);
     
    413433            }
    414434
    415             // Set the variance factor
    416             psMetadataItem *vfItem = psMetadataLookup(readout->parent->concepts, "CELL.VARFACTOR");
    417             float vf = psMetadataLookupF32(NULL, conv->analysis, PM_SUBTRACTION_ANALYSIS_VARFACTOR_1);
    418             if (!isfinite(vf)) {
    419                 vf = 1.0;
    420             }
    421             if (isfinite(vfItem->data.F32)) {
    422                 vfItem->data.F32 *= vf;
    423             } else {
    424                 vfItem->data.F32 = vf;
    425             }
    426 
    427435            // Replace original images with convolved
    428436            psFree(readout->image);
     
    512520        psBinaryOp(readout->variance, readout->variance, "*", psScalarAlloc(PS_SQR(norm), PS_TYPE_F32));
    513521    }
    514    
     522
    515523    // Ensure the background value is zero
    516524    psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for background
     
    521529    } else {
    522530      if (!psMetadataLookupBool(NULL, config->arguments, "PPSTACK.SKIP.BG.SUB")) {
    523         psLogMsg("ppStack", PS_LOG_INFO, "Correcting convolved image background by %lf (+/- %lf)",
    524                 psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), psStatsGetValue(bg, PS_STAT_ROBUST_STDEV));
    525         (void)psBinaryOp(readout->image, readout->image, "-",
    526                         psScalarAlloc(psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), PS_TYPE_F32));
     531        psLogMsg("ppStack", PS_LOG_INFO, "Correcting convolved image background by %lf (+/- %lf)",
     532                psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), psStatsGetValue(bg, PS_STAT_ROBUST_STDEV));
     533        (void)psBinaryOp(readout->image, readout->image, "-",
     534                        psScalarAlloc(psStatsGetValue(bg, PS_STAT_ROBUST_MEDIAN), PS_TYPE_F32));
    527535      }
    528536    }
    529    
     537
     538    if (!stackRenormaliseReadout(config, readout)) {
     539        psFree(rng);
     540        psFree(bg);
     541        return false;
     542    }
    530543
    531544    // Measure the variance level for the weighting
Note: See TracChangeset for help on using the changeset viewer.