IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 13, 2007, 12:09:35 PM (18 years ago)
Author:
Paul Price
Message:

Checking in version that should allow ppStack to compile.

File:
1 edited

Legend:

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

    r15764 r15814  
    7272    float xOrigSpacing = (float)(numCols - 2 * radius) / (float)(instances - 1); // Spacing between instances
    7373    float yOrigSpacing = (float)(numRows - 2 * radius) / (float)(instances - 1); // Spacing between instances
    74     //    int fakeSpacing = 2 * radius + 1;   // Spacing between instances (x and y) in the fake image
    75     //    int fakeSize = instances * fakeSpacing; // Size of fake image
     74    int fakeSpacing = 2 * radius + 1;   // Spacing between instances (x and y) in the fake image
     75    int fakeSize = instances * fakeSpacing; // Size of fake image
    7676
    7777    // Generate list of fake sources (instances of the PSF)
     
    8282    for (int j = 0, index = 0; j < instances; j++) {
    8383        float yOrig = j * yOrigSpacing + radius; // Source position in original image
    84         //        float yFake = j * fakeSpacing + radius; // Position in fake image
    85         //        int dy = yFake - yOrig;         // Difference between fake and original position
     84        float yFake = j * fakeSpacing + radius; // Position in fake image
     85        int dy = yFake - yOrig;         // Difference between fake and original position
    8686
    8787        for (int i = 0; i < instances; i++, index++) {
    8888            float xOrig = i * xOrigSpacing + radius; // Source position in original image
    89             //            float xFake = i * fakeSpacing + radius; // Position in fake image
    90             //            int dx = xFake - xOrig;     // Difference between fake and original position
     89            float xFake = i * fakeSpacing + radius; // Position in fake image
     90            int dx = xFake - xOrig;     // Difference between fake and original position
    9191
    9292            pmSource *fake = pmSourceAlloc(); // Fake source
    93             //            fake->peak = pmPeakAlloc(xFake - dx, yFake - dy, PEAK_FLUX, PM_PEAK_LONE);
    94             fake->peak = pmPeakAlloc(xOrig, yOrig, PEAK_FLUX, PM_PEAK_LONE);
     93            fake->peak = pmPeakAlloc(xFake - dx, yFake - dy, PEAK_FLUX, PM_PEAK_LONE);
    9594            fake->type = PM_SOURCE_TYPE_STAR;
    9695
     
    104103
    105104            fakes->data[index] = fake;
    106             xOffset->data.S32[index] = 0; // dx;
    107             yOffset->data.S32[index] = 0; // dy;
     105            xOffset->data.S32[index] = dx;
     106            yOffset->data.S32[index] = dy;
    108107        }
    109108    }
    110109
    111110    // Generate fake images with each PSF, and take the envelope
    112     psImage *envelope = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Image with envelope of PSFs
     111    psImage *envelope = psImageAlloc(fakeSize, fakeSize, PS_TYPE_F32); // Image with envelope of PSFs
    113112    psImageInit(envelope, 0.0);
    114113    pmReadout *fakeRO = pmReadoutAlloc(NULL); // Fake readout
    115114    for (int i = 0; i < inputs->n; i++) {
    116115        pmPSF *psf = inputs->data[i];   // PSF of interest
    117         if (!pmReadoutFakeFromSources(fakeRO, numCols, numRows, fakes, xOffset, yOffset, psf,
    118                                       NAN, radius)) {
     116        pmResiduals *resid = psf->residuals;// PSF residuals
     117        psf->residuals = NULL;
     118        if (!pmReadoutFakeFromSources(fakeRO, fakeSize, fakeSize, fakes, xOffset, yOffset, psf,
     119                                      NAN, radius, true)) {
    119120            psError(PS_ERR_UNKNOWN, false, "Unable to generate fake readout.");
    120121            psFree(envelope);
     
    122123            psFree(xOffset);
    123124            psFree(fakes);
     125            psf->residuals = resid;
    124126            return NULL;
    125127        }
     128        psf->residuals = resid;
    126129
    127130        // Need to renormalise sources so they all have the same peak.  You would think they do have the same
     
    159162        }
    160163
     164
     165
    161166#ifdef TESTING
    162167        {
     
    183188#endif
    184189
    185     // Reset the fake source pixels to the envelope pixels
     190    // Put the fake sources onto a full-size image
    186191    pmReadout *readout = pmReadoutAlloc(NULL); // Readout to contain envelope pixels
    187     readout->image = envelope;
    188     readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    189     psImageInit(readout->weight, WEIGHT_VAL);
     192    readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     193    psImageInit(readout->image, 0.0);
     194    for (int i = 0; i < numFakes; i++) {
     195        pmSource *source = fakes->data[i]; // Fake source
     196        // Position of source on fake image
     197        int xFake = source->peak->x + xOffset->data.S32[i];
     198        int yFake = source->peak->y + yOffset->data.S32[i];
     199        psRegion region = psRegionSet(xFake - radius, xFake + radius,
     200                                      yFake - radius, yFake + radius); // PSF region
     201        psImage *subImage = psImageSubset(envelope, region); // Subimage of fake PSF
     202
     203        // Position of source on "real" image
     204        int x0 = source->peak->x - radius;
     205        int y0 = source->peak->y - radius;
     206
     207        if (!psImageOverlaySection(readout->image, subImage, x0, y0, "=")) {
     208            psError(PS_ERR_UNKNOWN, false, "Unable to overlay PSF");
     209            psFree(readout);
     210            psFree(xOffset);
     211            psFree(yOffset);
     212            psFree(fakes);
     213            return NULL;
     214        }
     215    }
     216    readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "+", psScalarAlloc(1.0, PS_TYPE_F32));
    190217    readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
    191218    psImageInit(readout->mask, 0);
    192219
     220#ifdef TESTING
     221    {
     222        // Write out the envelope
     223        psFits *fits = psFitsOpen("psf_field_full.fits", "w");
     224        psFitsWriteImage(fits, NULL, readout->image, 0, NULL);
     225        psFitsClose(fits);
     226    }
     227#endif
     228
    193229    for (int i = 0; i < numFakes; i++) {
    194230        pmSource *source = fakes->data[i]; // Fake source
    195         float x = source->peak->xf + xOffset->data.S32[i]; // x coordinates of source
    196         float y = source->peak->yf + yOffset->data.S32[i]; // y coordinates of 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
     233
     234        psFree(source->pixels);
     235        psFree(source->weight);
     236        psFree(source->maskView);
     237        psFree(source->maskObj);
     238        source->pixels = NULL;
     239        source->weight = NULL;
     240        source->maskView = NULL;
     241        source->maskObj = NULL;
    197242
    198243        if (!pmSourceDefinePixels(source, readout, x, y, (float)radius)) {
     
    205250        }
    206251
     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
     267
    207268        if (!pmSourceMoments(source, radius)) {
    208269            psError(PS_ERR_UNKNOWN, false, "Unable to measure moments for source.");
     
    213274            return NULL;
    214275        }
    215     }
     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
    216289
    217290    pmPSFOptions *options = pmPSFOptionsAlloc(); // Options for fitting a PSF
     
    224297    options->radius = radius;
    225298
    226     options->psfTrendMode = PM_TREND_POLY_ORD;
     299    options->psfTrendMode = PM_TREND_MAP;
    227300    options->psfTrendNx = 1;
    228301    options->psfTrendNy = 1;
     
    261334
    262335        pmReadout *generated = pmReadoutAlloc(NULL); // Generated image
    263         pmReadoutFakeFromSources(generated, numCols, numRows, fakes, xOffset, yOffset, psf, NAN, radius);
     336        pmReadoutFakeFromSources(generated, numCols, numRows, fakes, xOffset, yOffset, psf, NAN, radius,
     337                                 false);
    264338        {
    265339            psFits *fits = psFitsOpen("psf_field_model.fits", "w");
Note: See TracChangeset for help on using the changeset viewer.