IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28253


Ignore:
Timestamp:
Jun 7, 2010, 4:52:17 PM (16 years ago)
Author:
Paul Price
Message:

Use a common target PSF image. This is to make everything run MUCH faster for stacks of lots of images.

Location:
trunk/ppStack/src
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/Makefile.am

    r27037 r28253  
    4848        ppStackPhotometry.c     \
    4949        ppStackFinish.c         \
     50        ppStackTarget.c         \
    5051        ppStackErrorCodes.c
    5152
  • trunk/ppStack/src/ppStack.h

    r27427 r28253  
    2626typedef enum {
    2727    PPSTACK_FILES_PREPARE,              // Files for preparation
     28    PPSTACK_FILES_TARGET,               // Files for target generation
    2829    PPSTACK_FILES_CONVOLVE,             // Files for convolution
    2930    PPSTACK_FILES_STACK,                // Stack files
     
    115116void ppStackVersionPrint(void);
    116117
     118/// Generate target PSF image
     119psImage *ppStackTarget(ppStackOptions *options, // Options for stacking
     120                       pmConfig *config         // Configuration
     121    );
     122
    117123/// Convolve image to match specified seeing
    118124bool ppStackMatch(pmReadout *readout,   // Readout to be convolved; replaced with output
     125                  const psImage *target,   // Target PSF image
    119126                  ppStackOptions *options, // Options for stacking
    120127                  int index,            // Index of image to match
  • trunk/ppStack/src/ppStackConvolve.c

    r28182 r28253  
    4545    options->convCovars = psArrayAlloc(num); // Covariance matrices
    4646
     47    psImage *target = NULL;             // Target PSF image
     48    if (options->convolve) {
     49        target = ppStackTarget(options, config);
     50        if (!target) {
     51            psError(psErrorCodeLast(), false, "Unable to produce stack target image");
     52            return false;
     53        }
     54    }
     55
    4756    psVector *renorms = psVectorAlloc(num, PS_TYPE_F32); // Renormalisation values for variances
    4857    psVectorInit(renorms, NAN);
     
    7180            psFree(fpaList);
    7281            psFree(cellList);
     82            psFree(target);
    7383            return false;
    7484        }
     
    8797            psFree(fpaList);
    8898            psFree(cellList);
     99            psFree(target);
    89100            return false;
    90101        }
     
    93104        psTimerStart("PPSTACK_MATCH");
    94105        options->origCovars->data[i] = psMemIncrRefCounter(readout->covariance);
    95         if (!ppStackMatch(readout, options, i, config)) {
     106        if (!ppStackMatch(readout, target, options, i, config)) {
    96107            // XXX many things can cause a failure of ppStackMatch -- should some be handled differently?
    97108            psErrorCode error = psErrorCodeLast(); // Error code
     
    102113              case PPSTACK_ERR_IO:
    103114                psError(error, false, "Unable to match image %d due to fatal error.", i);
     115                psFree(rng);
     116                psFree(fpaList);
     117                psFree(cellList);
     118                psFree(target);
    104119                return false;
    105120                // Non-fatal errors
     
    154169            psFree(cellList);
    155170            psFree(rng);
     171            psFree(target);
    156172            return false;
    157173        }
     
    164180            psFree(rng);
    165181            psFree(maskHeader);
     182            psFree(target);
    166183            return false;
    167184        }
     
    172189            psFree(cellList);
    173190            psFree(rng);
     191            psFree(target);
    174192            return false;
    175193        }
     
    222240            psFree(cellList);
    223241            psFree(rng);
     242            psFree(target);
    224243            return false;
    225244        }
     
    229248    }
    230249    psFree(rng);
     250    psFree(target);
    231251
    232252    psFree(options->sourceLists); options->sourceLists = NULL;
  • trunk/ppStack/src/ppStackFiles.c

    r27417 r28253  
    1616static char *filesPrepare[] = { "PPSTACK.INPUT.PSF", "PPSTACK.INPUT.SOURCES", "PPSTACK.TARGET.PSF", NULL };
    1717
     18/// Files required for generating convolution target
     19static char *filesTarget[] = { "PPSTACK.INPUT.VARIANCE", "PPSTACK.INPUT.MASK", NULL };
     20
    1821/// Files required for the convolution
    1922static char *filesConvolve[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.VARIANCE", NULL };
    20 
    21 //                                 "PPSTACK.CONV.KERNEL", NULL };
    2223
    2324/// Regular (convolved) stack files
     
    4142    switch (list) {
    4243      case PPSTACK_FILES_PREPARE:  return filesPrepare;
     44      case PPSTACK_FILES_TARGET:   return filesTarget;
    4345      case PPSTACK_FILES_CONVOLVE: return filesConvolve;
    4446      case PPSTACK_FILES_STACK:    return filesStack;
  • trunk/ppStack/src/ppStackMatch.c

    r27426 r28253  
    1313#define MAG_IGNORE 50                   // Ignore magnitudes fainter than this --- they're not real!
    1414#define FAKE_SIZE 1                     // Size of fake convolution kernel
    15 #define SOURCE_MASK (PM_SOURCE_MODE_FAIL | PM_SOURCE_MODE_DEFECT | PM_SOURCE_MODE_SATURATED | \
    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
    1815#define COVAR_FRAC 0.01                 // Truncation fraction for covariance matrix
    1916
     
    4946#endif
    5047
    51 // Get coordinates from a source
    52 static void coordsFromSource(float *x, float *y, const pmSource *source)
    53 {
    54     assert(x && y);
    55     assert(source);
    56 
    57     if (source->modelPSF) {
    58         *x = source->modelPSF->params->data.F32[PM_PAR_XPOS];
    59         *y = source->modelPSF->params->data.F32[PM_PAR_YPOS];
    60     } else {
    61         *x = source->peak->xf;
    62         *y = source->peak->yf;
    63     }
    64     return;
    65 }
    66 
    67 static psArray *stackSourcesFilter(psArray *sources, // Source list to filter
    68                                    int exclusion // Exclusion zone, pixels
    69     )
    70 {
    71     psAssert(sources && sources->n > 0, "Require array of sources");
    72     if (exclusion <= 0) {
    73         return psMemIncrRefCounter(sources);
    74     }
    75 
    76     int num = sources->n;               // Number of sources
    77     psVector *x = psVectorAlloc(num, PS_TYPE_F32), *y = psVectorAlloc(num, PS_TYPE_F32); // Coordinates
    78     int numGood = 0;                    // Number of good sources
    79     for (int i = 0; i < num; i++) {
    80         pmSource *source = sources->data[i]; // Source of interest
    81         if (!source) {
    82             continue;
    83         }
    84         coordsFromSource(&x->data.F32[numGood], &y->data.F32[numGood], source);
    85         numGood++;
    86     }
    87     x->n = y->n = numGood;
    88 
    89     psTree *tree = psTreePlant(2, 2, PS_TREE_EUCLIDEAN, x, y); // kd tree
    90 
    91     psArray *filtered = psArrayAllocEmpty(numGood); // Filtered list of sources
    92     psVector *coords = psVectorAlloc(2, PS_TYPE_F64); // Coordinates of source
    93     int numFiltered = 0;                // Number of filtered sources
    94     for (int i = 0; i < num; i++) {
    95         pmSource *source = sources->data[i]; // Source of interest
    96         if (!source) {
    97             continue;
    98         }
    99         float xSource, ySource;         // Coordinates of source
    100         coordsFromSource(&xSource, &ySource, source);
    101 
    102         coords->data.F64[0] = xSource;
    103         coords->data.F64[1] = ySource;
    104 
    105         long numWithin = psTreeWithin(tree, coords, exclusion); // Number within exclusion zone
    106         psTrace("ppStack", 9, "Source at %.0lf,%.0lf has %ld sources in exclusion zone",
    107                 coords->data.F64[0], coords->data.F64[1], numWithin);
    108         if (numWithin == 1) {
    109             // Only itself inside the exclusion zone
    110             filtered = psArrayAdd(filtered, filtered->n, source);
    111         } else {
    112             numFiltered++;
    113         }
    114     }
    115     psFree(coords);
    116     psFree(tree);
    117     psFree(x);
    118     psFree(y);
    119 
    120     psLogMsg("ppStack", PS_LOG_INFO, "Filtered out %d of %d sources", numFiltered, numGood);
    121 
    122     return filtered;
    123 }
    12448
    12549// Add background into the fake image
     
    202126
    203127
    204 bool ppStackMatch(pmReadout *readout, ppStackOptions *options, int index, const pmConfig *config)
     128bool ppStackMatch(pmReadout *readout, const psImage *target, ppStackOptions *options,
     129                  int index, const pmConfig *config)
    205130{
    206131    assert(readout);
     
    286211        } else {
    287212#endif
    288 
    289213            // Normal operations here
    290             psAssert(options->psf, "Require target PSF");
    291             psAssert(options->sourceLists && options->sourceLists->data[index], "Require source list");
     214            psAssert(target, "Require target PSF image");
    292215
    293216            int order = psMetadataLookupS32(NULL, ppsub, "SPATIAL.ORDER"); // Spatial polynomial order
     
    341264            }
    342265
    343             pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF
    344 
    345             psStats *bg = psStatsAlloc(PS_STAT_ROBUST_STDEV); // Statistics for background
    346             psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
    347             if (!psImageBackground(bg, NULL, readout->image, readout->mask, maskVal | maskBad, rng)) {
    348                 psError(PPSTACK_ERR_DATA, false, "Can't measure background for image.");
    349                 psFree(fake);
    350                 psFree(optWidths);
    351                 psFree(conv);
    352                 psFree(bg);
    353                 psFree(rng);
    354                 return false;
    355             }
    356             float minFlux = NOISE_FRACTION * bg->robustStdev; // Minimum flux level for fake image
    357             psFree(rng);
    358             psFree(bg);
    359 
    360             // For the sake of stamps, remove nearby sources
    361             psArray *stampSources = stackSourcesFilter(options->sourceLists->data[index],
    362                                                        footprint); // Filtered list of sources
    363 
    364             bool oldThreads = pmReadoutFakeThreads(true); // Old threading state
    365             if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows,
    366                                           stampSources, SOURCE_MASK, NULL, NULL, options->psf,
    367                                           minFlux, footprint + size, false, true)) {
    368                 psError(PPSTACK_ERR_DATA, false, "Unable to generate fake image with target PSF.");
    369                 psFree(fake);
    370                 psFree(optWidths);
    371                 psFree(conv);
    372                 return false;
    373             }
    374             pmReadoutFakeThreads(oldThreads);
    375 
     266            pmReadout *fake = pmReadoutAlloc(NULL);
     267            fake->image = psImageCopy(NULL, target, PS_TYPE_F32);
    376268            fake->mask = psImageCopy(NULL, readout->mask, PS_TYPE_IMAGE_MASK);
    377269
     
    420312                    psFree(fake);
    421313                    psFree(optWidths);
    422                     psFree(stampSources);
    423314                    psFree(conv);
    424315                    if (threads > 0) {
     
    436327                    psFree(fake);
    437328                    psFree(optWidths);
    438                     psFree(stampSources);
    439329                    psFree(conv);
    440330                    psFree(widthsCopy);
     
    446336
    447337                if (!pmSubtractionMatch(NULL, conv, fake, readout, footprint, stride, regionSize, spacing,
    448                                         threshold, stampSources, stampsName, type, size, order, widthsCopy,
     338                                        threshold, options->sources, stampsName, type, size, order, widthsCopy,
    449339                                        orders, inner, ringsOrder, binning, penalty,
    450340                                        optimum, optWidths, optOrder, optThresh, iter, rej, normFrac,
     
    454344                    psFree(fake);
    455345                    psFree(optWidths);
    456                     psFree(stampSources);
    457346                    psFree(conv);
    458347                    psFree(widthsCopy);
     
    492381            psFree(fake);
    493382            psFree(optWidths);
    494             psFree(stampSources);
    495383
    496384            if (threads > 0) {
Note: See TracChangeset for help on using the changeset viewer.