IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14514


Ignore:
Timestamp:
Aug 15, 2007, 2:08:27 PM (19 years ago)
Author:
Paul Price
Message:

Reworking APIs to be a bit more practical.

Location:
trunk/psModules/src/imcombine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtractionStamps.c

    r14513 r14514  
    99#include "pmSubtractionStamps.h"
    1010
    11 
    12 #define PM_SUBTRACTION_MASK_BAD_STAMP (PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_FOOTPRINT | \
    13                                        PM_SUBTRACTION_MASK_REJ) // Mask indicates a stamp would be bad
    14 
    15 
    1611//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1712// Private (file-static) functions
     
    2419    psFree(stamp->matrix);
    2520    psFree(stamp->vector);
    26 }
    27 
     21    psFree(stamp->reference);
     22    psFree(stamp->input);
     23    psFree(stamp->weight);
     24}
     25
     26// Is this region OK?
     27static bool checkStampRegion(int x, int y, // Coordinates of stamp
     28                             const psRegion *region // Region of interest
     29    )
     30{
     31    if (!region) {
     32        return true;
     33    }
     34    return (x < region->x0 || x > region->x1 || y < region->y0 || y > region->y1) ?
     35        false : true;
     36}
     37
     38// Is this position unmasked?
     39static bool checkStampMask(int x, int y, // Coordinates of stamp
     40                           const psImage *mask
     41    )
     42{
     43    if (!mask) {
     44        return true;
     45    }
     46    return (mask->data.PS_TYPE_MASK_DATA[y][x] & (PM_SUBTRACTION_MASK_BORDER |
     47                                                  PM_SUBTRACTION_MASK_FOOTPRINT | PM_SUBTRACTION_MASK_REJ)) ?
     48        false : true;
     49}
    2850
    2951//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    3860    stamp->x = NAN;
    3961    stamp->y = NAN;
     62    stamp->flux = NAN;
    4063    stamp->xNorm = NAN;
    4164    stamp->yNorm = NAN;
     
    135158                for (int y = yStart; y <= yStop ; y++) {
    136159                    for (int x = xStart; x <= xStop ; x++) {
    137                         if ((!subMask || !(subMask->data.PS_TYPE_MASK_DATA[y][x] &
    138                                            PM_SUBTRACTION_MASK_BAD_STAMP)) &&
    139                             image->data.F32[y][x] > fluxBest) {
     160                        if (checkStampMask(x, y, subMask) && image->data.F32[y][x] > fluxBest) {
    140161                            fluxBest = image->data.F32[y][x];
    141162                            xBest = x;
     
    147168                stamp->x = xBest;
    148169                stamp->y = yBest;
     170                stamp->flux = fluxBest;
    149171
    150172                // Reset the postage stamps since we're making a new stamp
     
    173195
    174196
    175 psArray *pmSubtractionSetStamps(const psVector *x, const psVector *y,
     197psArray *pmSubtractionSetStamps(const psVector *x, const psVector *y, const psVector *flux,
    176198                                const psImage *subMask, const psRegion *region)
    177199{
     
    181203    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false);
    182204    PS_ASSERT_VECTORS_SIZE_EQUAL(y, x, false);
     205    if (flux) {
     206        PS_ASSERT_VECTOR_NON_NULL(flux, false);
     207        PS_ASSERT_VECTOR_TYPE(flux, PS_TYPE_F32, false);
     208        PS_ASSERT_VECTORS_SIZE_EQUAL(flux, x, false);
     209    }
    183210    if (subMask) {
    184211        PS_ASSERT_IMAGE_NON_NULL(subMask, false);
     
    191218    for (int i = 0; i < num; i++) {
    192219        int xStamp = x->data.F32[i] + 0.5, yStamp = y->data.F32[i] + 0.5; // Pixel coords of stamp
    193         if (region && (xStamp < region->x0 || xStamp > region->x1 ||
    194                        yStamp < region->y0 || yStamp > region->y1)) {
    195             // Not interested at this time
    196             continue;
    197         }
    198 
    199         if (subMask && subMask->data.PS_TYPE_MASK_DATA[yStamp][xStamp] & PM_SUBTRACTION_MASK_BAD_STAMP) {
    200             // It's bad
     220        if (!checkStampRegion(xStamp, yStamp, region)) {
     221            continue;
     222        }
     223        if (!checkStampMask(xStamp, yStamp, subMask)) {
    201224            continue;
    202225        }
     
    205228        stamp->x = x->data.F32[i];
    206229        stamp->y = y->data.F32[i];
     230        if (flux) {
     231            stamp->flux = flux->data.F32[i];
     232        }
    207233        stamps->data[stamps->n++] = stamp;
    208234    }
     
    278304
    279305
    280 psArray *pmSubtractionGenerateStamps(const psVector *x, const psVector *y, const psVector *flux,
    281                                      float sigma, int footprint, const pmSubtractionKernels *kernels)
    282 {
    283     PS_ASSERT_VECTOR_NON_NULL(x, false);
    284     PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, false);
    285     PS_ASSERT_VECTOR_NON_NULL(y, false);
    286     PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false);
    287     PS_ASSERT_VECTORS_SIZE_EQUAL(y, x, false);
    288     PS_ASSERT_VECTOR_NON_NULL(flux, false);
    289     PS_ASSERT_VECTOR_TYPE(flux, PS_TYPE_F32, false);
    290     PS_ASSERT_VECTORS_SIZE_EQUAL(flux, y, false);
     306bool pmSubtractionGenerateStamps(psArray *stamps, float sigma, int footprint,
     307                                 const pmSubtractionKernels *kernels)
     308{
     309    PS_ASSERT_ARRAY_NON_NULL(stamps, false);
    291310    PS_ASSERT_FLOAT_LARGER_THAN(sigma, 0.0, false);
     311    PS_ASSERT_INT_NONNEGATIVE(footprint, false);
    292312
    293313    int size = kernels->size + footprint; // Size of postage stamps
    294     int num = x->n;                     // Number of stamps
    295     psArray *stamps = psArrayAlloc(num); // Stamps, to return
     314    int num = stamps->n;                // Number of stamps
    296315
    297316    for (int i = 0; i < num; i++) {
    298         pmSubtractionStamp *stamp = pmSubtractionStampAlloc(PM_SUBTRACTION_STAMP_CALCULATE); // Stamp
    299         stamps->data[i] = stamp;
    300 
    301         stamp->x = x->data.F32[i];
    302         stamp->y = y->data.F32[i];
    303 
    304         float xStamp = x->data.F32[i] - (int)(stamp->x + 0.5); // x coordinate of star in stamp frame
    305         float yStamp = y->data.F32[i] - (int)(stamp->y + 0.5); // y coordinate of star in stamp frame
    306         float fluxStamp = flux->data.F32[i]; // Flux of star
    307 
     317        pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest
     318        if (!(stamp->status & PM_SUBTRACTION_STAMP_CALCULATE)) {
     319            continue;
     320        }
     321
     322        float x = stamp->x, y = stamp->y; // Coordinates of stamp
     323        float flux = stamp->flux; // Flux of star
     324        if (!isfinite(flux)) {
     325            psWarning("Unable to generate PSF for stamp %d --- bad flux.", i);
     326            continue;
     327        }
     328
     329        float xStamp = x - (int)(x + 0.5); // x coordinate of star in stamp frame
     330        float yStamp = y - (int)(y + 0.5); // y coordinate of star in stamp frame
     331
     332        psFree(stamp->input);
    308333        stamp->input = psKernelAlloc(-size, size, -size, size);
    309334        psKernel *input = stamp->input; // Target stamp
    310335
    311336        // Put in a Gaussian, just for fun!
    312         for (int y = -size; y <= size; y++) {
    313             for (int x = -size; x <= size; x++) {
    314                 input->kernel[y][x] = fluxStamp / sigma * 0.5 * M_2_SQRTPI * M_SQRT1_2 *
    315                     expf(0.5 * (PS_SQR(x + xStamp) + PS_SQR(y + yStamp)) / PS_SQR(sigma));
     337        for (int v = -size; v <= size; v++) {
     338            for (int u = -size; u <= size; u++) {
     339                input->kernel[v][u] = flux / sigma * 0.5 * M_2_SQRTPI * M_SQRT1_2 *
     340                    expf(0.5 * (PS_SQR(u + xStamp) + PS_SQR(v + yStamp)) / PS_SQR(sigma));
    316341            }
    317342        }
  • trunk/psModules/src/imcombine/pmSubtractionStamps.h

    r14513 r14514  
    1818typedef struct {
    1919    float x, y;                         ///< Position
     20    float flux;                         ///< Flux
    2021    float xNorm, yNorm;                 ///< Normalised position
    2122    psKernel *reference;                ///< Reference image postage stamp
     
    3940psArray *pmSubtractionSetStamps(const psVector *x, ///< x coordinates for each stamp
    4041                                const psVector *y, ///< y coordinates for each stamp
     42                                const psVector *flux, ///< Flux for each stamp, or NULL
    4143                                const psImage *mask, ///< Mask, or NULL
    4244                                const psRegion *region ///< Region in which to search for stamps, or NULL
     
    5355
    5456/// Generate target for stamps based on list
    55 psArray *pmSubtractionGenerateStamps(const psVector *x, ///< x coordinates for each stamp
    56                                      const psVector *y, ///< y coordinates for each stamp
    57                                      const psVector *flux, ///< Flux for each stamp
    58                                      float sigma, ///< Gaussian width for each stamp
    59                                      int footprint, ///< Stamp footprint size
    60                                      const pmSubtractionKernels *kernels ///< Kernel basis functions
     57bool pmSubtractionGenerateStamps(psArray *stamps, ///< Stamps
     58                                 float sigma, ///< Gaussian width for each stamp
     59                                 int footprint, ///< Stamp footprint size
     60                                 const pmSubtractionKernels *kernels ///< Kernel basis functions
    6161    );
    6262
Note: See TracChangeset for help on using the changeset viewer.