IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2010, 7:42:02 PM (16 years ago)
Author:
eugene
Message:

updates from eam_branches/20091201

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSubReadoutJpeg.c

    r23740 r26899  
    4949    return true;
    5050}
     51
     52bool ppSubResidualSampleJpeg(pmConfig *config)
     53{
     54    return true;
     55
     56    pmFPAview *view = ppSubViewReadout(); // View to readout
     57
     58    // we save sample difference stamps on the convolved image readout->analysis metadata
     59    pmReadout *inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input convolved
     60
     61    psArray *samples = psArrayAllocEmpty(16); // Array of sample stamp images
     62
     63    // we may have multiple entries with the same name; pull them off into a separate array:
     64    psString regex = NULL;          // Regular expression
     65    psStringAppend(&regex, "^%s$", "SUBTRACTION.SAMPLE.STAMP.SET");
     66    psMetadataIterator *iter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD, regex); // Iterator
     67    psFree(regex);
     68
     69    psMetadataItem *item = NULL;// Item from iteration
     70    while ((item = psMetadataGetAndIncrement(iter))) {
     71        assert(item->type == PS_DATA_ARRAY);
     72        psArray *sampleStamps = item->data.V;
     73        samples = psArrayAdd(samples, 16, sampleStamps);
     74    }
     75    psFree(iter);
     76    psAssert (samples, "no sample stamps?");
     77    psAssert (samples->n, "no sample stamps?");
     78
     79    // get the kernel sizes
     80    psArray *kernels = samples->data[0];
     81    psAssert (kernels, "no valid kernel?");
     82    psAssert (kernels->n, "no valid kernel?");
     83
     84    psImage *kernel = kernels->data[0];
     85    psAssert (kernel, "missing valid kernel?");
     86
     87    int DX = kernel->numCols;
     88    int DY = kernel->numRows;
     89
     90    // each array contains up to 9 sample stamps.  generate an image mosaicking these together in 3x3 blocks.
     91    int innerBorder = 1;
     92    int outerBorder = 2;
     93    int NXblock = sqrt(samples->n);
     94    int NYblock = samples->n / NXblock;
     95    if (samples->n % NXblock) NYblock ++;
     96
     97    int NXpix = NXblock * (3 * (DX + innerBorder) + outerBorder);
     98    int NYpix = NYblock * (3 * (DY + innerBorder) + outerBorder);
     99
     100    // output cell
     101    pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.RESID.JPEG");
     102    pmReadout *readout = pmReadoutAlloc(cell);
     103    readout->image = psImageAlloc(NXpix, NYpix, PS_TYPE_F32);
     104
     105    cell->data_exists = true;
     106    cell->parent->data_exists = true;
     107
     108    psImageInit (readout->image, 0.0);
     109
     110    for (int i = 0; i < samples->n; i++) {
     111
     112        int xBlock = i % NXblock;
     113        int yBlock = i / NYblock;
     114
     115        psArray *kernels = samples->data[i];
     116
     117        for (int j = 0; j < kernels->n; j++) {
     118
     119            psImage *kernel = kernels->data[j];
     120
     121            int xSub = j % 3;
     122            int ySub = j / 3;
     123
     124            int xPix = xBlock * (3 * (DX + innerBorder) + outerBorder) + xSub * (DX + innerBorder);
     125            int yPix = yBlock * (3 * (DX + innerBorder) + outerBorder) + ySub * (DY + innerBorder);
     126
     127            for (int y = 0; y < kernel->numRows; y++) {
     128                for (int x = 0; x < kernel->numCols; x++) {
     129                    readout->image->data.F32[y + yPix][x + xPix] = kernel->data.F32[y][x];
     130                }
     131            }
     132        }
     133    }
     134
     135    {
     136        psFits *fits = psFitsOpen ("resid.stamps.fits", "w");
     137        psFitsWriteImage (fits, NULL, readout->image, 0, NULL);
     138        psFitsClose (fits);
     139    }
     140
     141    return true;
     142}
Note: See TracChangeset for help on using the changeset viewer.