IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15836


Ignore:
Timestamp:
Dec 14, 2007, 3:09:53 PM (18 years ago)
Author:
Paul Price
Message:

It works! Getting rid of old code.

File:
1 edited

Legend:

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

    r15814 r15836  
    3232
    3333#define TESTING                         // Enable test output
    34 #define PEAK_FLUX 1.0e3                 // peak flux for each source
     34#define PEAK_FLUX 1.0e3                 // Peak flux for each source
     35#define SKY_VALUE 0.0e0                 // Sky value for fake image
    3536#define WEIGHT_VAL 1.0e0                // Weighting for image
    36 #define PSF_STATS PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV // Statistics options for measuring PSF
     37#define PSF_STATS PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV // Statistics options for measuring PSF
    3738
    3839
    3940
    4041// XXX To do:
    41 //
    42 // * PSF representation doesn't normalise (x,y) positions in polynomials: need to find out how I can have a
    43 // star at (x1,y1) in the image that is "really" supposed to be at (x2,y2).
    4442//
    4543// * PSF variation when only a portion of the image is present (e.g., the edge of an FPA overlapping a
     
    6058                     int instances, // Number of instances per dimension
    6159                     int radius,        // Radius of each PSF
    62                      const char *modelName // Name of PSF model to use
     60                     const char *modelName,// Name of PSF model to use
     61                     int xOrder, int yOrder // Order for PSF variation fit
    6362                     )
    6463{
     
    6968    PS_ASSERT_INT_POSITIVE(radius, NULL);
    7069    PS_ASSERT_STRING_NON_EMPTY(modelName, NULL);
     70    PS_ASSERT_INT_NONNEGATIVE(xOrder, NULL);
     71    PS_ASSERT_INT_NONNEGATIVE(yOrder, NULL);
    7172
    7273    float xOrigSpacing = (float)(numCols - 2 * radius) / (float)(instances - 1); // Spacing between instances
     
    110111    // Generate fake images with each PSF, and take the envelope
    111112    psImage *envelope = psImageAlloc(fakeSize, fakeSize, PS_TYPE_F32); // Image with envelope of PSFs
    112     psImageInit(envelope, 0.0);
     113    psImageInit(envelope, SKY_VALUE);
    113114    pmReadout *fakeRO = pmReadoutAlloc(NULL); // Fake readout
    114115    for (int i = 0; i < inputs->n; i++) {
     
    135136            float y = source->peak->yf + yOffset->data.S32[j]; // y coordinate of source
    136137
    137 #if 0
    138             psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR,
    139                                                                                fakeRO->image, NULL, NULL, 0,
    140                                                                                0.0, 0.0, 1, 0, 0.0);
    141             double flux;                 // Flux of peak
    142             if (!psImageInterpolate(&flux, NULL, NULL, x, y, interp)) {
    143                 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate source image.");
    144                 psFree(envelope);
    145                 psFree(yOffset);
    146                 psFree(xOffset);
    147                 psFree(fakes);
    148                 return NULL;
    149             }
    150 #else
    151138            double flux = fakeRO->image->data.F32[(int)y][(int)x];
    152 #endif
    153 
    154139            float norm = PEAK_FLUX / flux; // Normalisation for source
    155140            psRegion region = psRegionSet(x - radius, x + radius, y - radius, y + radius); // PSF region
     
    161146            psFree(subEnv);
    162147        }
    163 
    164 
    165148
    166149#ifdef TESTING
     
    214197        }
    215198    }
     199    psFree(xOffset);
     200    psFree(yOffset);
     201
    216202    readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "+", psScalarAlloc(1.0, PS_TYPE_F32));
    217203    readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     
    227213#endif
    228214
     215    // Reset the sources to point to the new pixels, and measure the moments in preparation for PSF fitting
    229216    for (int i = 0; i < numFakes; i++) {
    230217        pmSource *source = fakes->data[i]; // Fake source
    231         float x = source->peak->xf;// + xOffset->data.S32[i]; // x coordinates of source
    232         float y = source->peak->yf;// + yOffset->data.S32[i]; // y coordinates of source
     218        float x = source->peak->xf;    // x coordinates of source
     219        float y = source->peak->yf;    // y coordinates of source
    233220
    234221        psFree(source->pixels);
     
    244231            psError(PS_ERR_UNKNOWN, false, "Unable to define pixels for source.");
    245232            psFree(readout);
    246             psFree(yOffset);
    247             psFree(xOffset);
    248233            psFree(fakes);
    249234            return NULL;
    250235        }
    251 
    252 #if 0
    253         // Need to do some magic so that pmSourceMoments behaves --- the only offsets it understands are the
    254         // col0,row0 in the psImage.
    255         int oldCol0 = source->pixels->col0;
    256         int oldRow0 = source->pixels->row0;
    257         int col0 = oldCol0 - xOffset->data.S32[i];
    258         int row0 = oldRow0 - yOffset->data.S32[i];
    259 
    260         P_PSIMAGE_SET_COL0(source->pixels, col0);
    261         P_PSIMAGE_SET_ROW0(source->pixels, row0);
    262         P_PSIMAGE_SET_COL0(source->weight, col0);
    263         P_PSIMAGE_SET_ROW0(source->weight, row0);
    264         P_PSIMAGE_SET_COL0(source->maskObj, col0);
    265         P_PSIMAGE_SET_ROW0(source->maskObj, row0);
    266 #endif
    267236
    268237        if (!pmSourceMoments(source, radius)) {
    269238            psError(PS_ERR_UNKNOWN, false, "Unable to measure moments for source.");
    270239            psFree(readout);
    271             psFree(yOffset);
    272             psFree(xOffset);
    273240            psFree(fakes);
    274241            return NULL;
    275242        }
    276 
    277 #if 0
    278         P_PSIMAGE_SET_COL0(source->pixels, oldCol0);
    279         P_PSIMAGE_SET_ROW0(source->pixels, oldRow0);
    280         P_PSIMAGE_SET_COL0(source->weight, oldCol0);
    281         P_PSIMAGE_SET_ROW0(source->weight, oldRow0);
    282         P_PSIMAGE_SET_COL0(source->maskObj, oldCol0);
    283         P_PSIMAGE_SET_ROW0(source->maskObj, oldRow0);
    284 #endif
    285     }
    286 
    287     psMemCheckCorruption(stderr, true);
    288 
    289 
     243    }
     244
     245    // Don't assume Poisson errors
    290246    pmPSFOptions *options = pmPSFOptionsAlloc(); // Options for fitting a PSF
    291     // Don't assume Poisson errors --- our fake system isn't Poisson.
    292247    options->poissonErrorsPhotLMM = false;
    293248    options->poissonErrorsPhotLin = false;
    294249    options->poissonErrorsParams = false;
    295250    options->stats = psStatsAlloc(PSF_STATS);
    296 
    297251    options->radius = radius;
    298 
    299252    options->psfTrendMode = PM_TREND_MAP;
    300     options->psfTrendNx = 1;
    301     options->psfTrendNy = 1;
    302 
     253    options->psfTrendNx = xOrder;
     254    options->psfTrendNy = yOrder;
    303255    options->psfFieldNx = numCols;
    304256    options->psfFieldNy = numRows;
     
    313265        psError(PS_ERR_UNKNOWN, false, "Unable to fit PSF model to PSF envelope.");
    314266        psFree(readout);
    315         psFree(yOffset);
    316         psFree(xOffset);
    317267        psFree(fakes);
    318268        return NULL;
     
    334284
    335285        pmReadout *generated = pmReadoutAlloc(NULL); // Generated image
    336         pmReadoutFakeFromSources(generated, numCols, numRows, fakes, xOffset, yOffset, psf, NAN, radius,
     286        pmReadoutFakeFromSources(generated, numCols, numRows, fakes, NULL, NULL, psf, NAN, radius,
    337287                                 false);
    338288        {
     
    341291            psFitsClose(fits);
    342292        }
    343         psBinaryOp(generated->image, generated->image, "-", envelope);
     293        psBinaryOp(generated->image, generated->image, "-", readout->image);
    344294        {
    345295            psFits *fits = psFitsOpen("psf_field_resid.fits", "w");
     
    352302
    353303    psFree(yOffset);
    354     psFree(xOffset);
    355     psFree(fakes);
    356304    psFree(readout);
     305
    357306    return psf;
    358307}
Note: See TracChangeset for help on using the changeset viewer.