IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 9, 2010, 8:18:37 PM (16 years ago)
Author:
Paul Price
Message:

Adding I/O for pattern correction (both row and cell, in the same parts).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psModules/src/detrend/pmPattern.c

    r26819 r26836  
    11#include <stdio.h>
     2#include <string.h>
    23#include <pslib.h>
    34
     
    910// Mask a row as bad
    1011static void patternMaskRow(pmReadout *ro, // Readout to mask
    11                            int y,         // Row to mask
     12                           int y,       // Row to mask
    1213                           psImageMaskType bad // Mask value to give
    1314                           )
     
    1718    psAssert(y < image->numRows, "Row not in image");
    1819
    19     int numCols = image->numCols;       // Size of image
     20    int numCols = image->numCols;       // Number of columns
    2021    for (int x = 0; x < numCols; x++) {
    2122        image->data.F32[y][x] = NAN;
     
    2930    return;
    3031}
     32
     33//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     34// Measurement and application
     35//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3136
    3237bool pmPatternRow(pmReadout *ro, int order, int iter, float rej, float thresh,
     
    8085    psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, order); // Polynomial to fit
    8186    psVector *data = psVectorAlloc(numCols, PS_TYPE_F32); // Data to fit
     87    psArray *corrs = psArrayAlloc(numRows); // Correction parameters
     88
     89    psImage *corr = psImageAlloc(order + 1, numRows, PS_TYPE_F64); // Corrections applied
    8290
    8391    for (int y = 0; y < numRows; y++) {
     
    105113            continue;
    106114        }
     115
     116        memcpy(corr->data.F64[y], poly->coeff, (order + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
     117        corr->data.F64[y][0] -= background;
     118
    107119        psVector *solution = psPolynomial1DEvalVector(poly, indices); // Solution vector
    108120        if (!solution) {
     
    118130        psFree(solution);
    119131    }
     132
     133    psMetadataAddImage(ro->analysis, PS_LIST_TAIL, PM_PATTERN_ROW_CORRECTION, PS_META_REPLACE,
     134                       "Pattern row correction", corr);
     135    psFree(corrs);
    120136
    121137    psFree(indices);
     
    128144}
    129145
    130 
     146bool pmPatternRowApply(pmReadout *ro, psImageMaskType maskBad)
     147{
     148    PM_ASSERT_READOUT_NON_NULL(ro, false);
     149    PM_ASSERT_READOUT_IMAGE(ro, false);
     150
     151    bool mdok;                          // Status of MD lookup
     152    psImage *corr = psMetadataLookupPtr(&mdok, ro->analysis, PM_PATTERN_ROW_CORRECTION); // Correction
     153    if (!mdok) {
     154        // No correction to apply
     155        return true;
     156    }
     157
     158    psImage *image = ro->image; // Image of interest
     159    int numCols = image->numCols, numRows = image->numRows; // Size of image
     160
     161    psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, numCols - 1); // Polynomial to apply
     162    psVector *indices = psVectorAlloc(numCols, PS_TYPE_F32); // Indices for polynomial
     163    float norm = 2.0 / (float)numCols;  // Normalisation for indices
     164    for (int x = 0; x < numCols; x++) {
     165        indices->data.F32[x] = x * norm - 1.0;
     166    }
     167
     168    for (int y = 0; y < numRows; y++) {
     169        memcpy(poly->coeff, corr->data.F64[y], numCols * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
     170        psVector *solution = psPolynomial1DEvalVector(poly, indices); // Solution vector
     171        if (!solution) {
     172            psWarning("Unable to evaluate polynomial for row %d", y);
     173            psErrorClear();
     174            patternMaskRow(ro, y, maskBad);
     175            continue;
     176        }
     177
     178        for (int x = 0; x < numCols; x++) {
     179            image->data.F32[y][x] -= solution->data.F32[x];
     180        }
     181        psFree(solution);
     182    }
     183
     184    psFree(poly);
     185    psFree(indices);
     186
     187    return true;
     188}
    131189
    132190
     
    255313            psImageInit(ro->image, NAN);
    256314            psBinaryOp(ro->mask, ro->mask, "|", psScalarAlloc(maskBad, PS_TYPE_IMAGE_MASK));
     315            psMetadataAddF32(ro->analysis, PS_LIST_TAIL, PM_PATTERN_CELL_CORRECTION, PS_META_REPLACE,
     316                             "Pattern cell correction solution", NAN);
    257317            continue;
    258318        }
     
    262322                 cellName, correction);
    263323        psBinaryOp(ro->image, ro->image, "+", psScalarAlloc(correction, PS_TYPE_F32));
     324        psMetadataAddF32(ro->analysis, PS_LIST_TAIL, PM_PATTERN_CELL_CORRECTION, PS_META_REPLACE,
     325                         "Pattern cell correction solution", correction);
    264326    }
    265327
     
    269331    return true;
    270332}
     333
     334bool pmPatternCellApply(pmReadout *ro, psImageMaskType maskBad)
     335{
     336    PM_ASSERT_READOUT_NON_NULL(ro, false);
     337    PM_ASSERT_READOUT_IMAGE(ro, false);
     338
     339    bool mdok;                          // Status of MD lookup
     340    float corr = psMetadataLookupF32(&mdok, ro->analysis, PM_PATTERN_CELL_CORRECTION); // Correction to apply
     341    if (!mdok) {
     342        // No correction to apply
     343        return true;
     344    }
     345
     346    psImage *image = ro->image, *mask = ro->mask; // Image and mask of interest
     347    int numCols = image->numCols, numRows = image->numRows; // Size of image
     348
     349    if (!isfinite(corr)) {
     350        for (int y = 0; y < numRows; y++) {
     351            for (int x = 0; x < numCols; x++) {
     352                image->data.F32[y][x] = NAN;
     353            }
     354        }
     355        if (mask) {
     356            for (int y = 0; y < numRows; y++) {
     357                for (int x = 0; x < numCols; x++) {
     358                    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskBad;
     359                }
     360            }
     361        }
     362    } else {
     363        for (int y = 0; y < numRows; y++) {
     364            for (int x = 0; x < numCols; x++) {
     365                image->data.F32[y][x] += corr;
     366            }
     367        }
     368    }
     369
     370    return true;
     371}
     372
     373
Note: See TracChangeset for help on using the changeset viewer.