IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 4, 2008, 3:24:47 PM (18 years ago)
Author:
eugene
Message:

adding threaded and unthreaded versions of the detrend application code; adding pmDetrendThreads functions for management

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmBias.c

    r16841 r18893  
    1414#include "pmFPAview.h"
    1515#include "pmFPACalibration.h"
     16#include "pmDetrendThreads.h"
    1617
    1718#include "pmOverscan.h"
    1819#include "pmBias.h"
     20
     21bool pmBiasSubtractScan_Threaded (psThreadJob *job) {
     22    pmReadout *in = job->args->data[0];
     23    pmReadout *sub = job->args->data[1];
     24    float scale  = PS_SCALAR_VALUE(job->args->data[2],F32);
     25    int xOffset  = PS_SCALAR_VALUE(job->args->data[3],S32);
     26    int yOffset  = PS_SCALAR_VALUE(job->args->data[4],S32);
     27    int rowStart = PS_SCALAR_VALUE(job->args->data[5],S32);
     28    int rowStop  = PS_SCALAR_VALUE(job->args->data[6],S32);
     29    bool status = pmBiasSubtractScan (in, sub, scale, xOffset, yOffset, rowStart, rowStop);
     30    return status;
     31}
     32
     33bool pmBiasSubtractScan (pmReadout *in, pmReadout *sub, float scale, int xOffset, int yOffset, int rowStart, int rowStop) {
     34
     35    psImage *inImage  = in->image;      // The input image
     36    psImage *inMask   = in->mask;       // The input mask
     37    psImage *subImage = sub->image;     // The image to be subtracted
     38    psImage *subMask  = sub->mask;      // The mask for the subtraction image
     39
     40    if (scale == 1.0) {
     41        for (int i = rowStart; i < rowStop; i++) {
     42            for (int j = 0; j < inImage->numCols; j++) {
     43                inImage->data.F32[i][j] -= subImage->data.F32[i+yOffset][j+xOffset];
     44                if (inMask && subMask) {
     45                    inMask->data.U8[i][j] |= subMask->data.U8[i+yOffset][j+xOffset];
     46                }
     47            }
     48        }
     49    } else {
     50        for (int i = rowStart; i < rowStop; i++) {
     51            for (int j = 0; j < inImage->numCols; j++) {
     52                inImage->data.F32[i][j] -= subImage->data.F32[i+yOffset][j+xOffset] * scale;
     53                if (inMask && subMask) {
     54                    inMask->data.U8[i][j] |= subMask->data.U8[i+yOffset][j+xOffset];
     55                }
     56            }
     57        }
     58    }
     59    return true;
     60}
    1961
    2062// pmBiasSubtractFrame(): this routine will take as input a readout for the input image and a readout for the bias
    2163// image.  The bias image is subtracted in place from the input image.
    2264bool pmBiasSubtractFrame(pmReadout *in, // Input readout
    23                           const pmReadout *sub, // Readout to be subtracted from input
    24                           float scale   // Scale to apply before subtracting
    25                          )
     65                        pmReadout *sub, // Readout to be subtracted from input
     66                        float scale   // Scale to apply before subtracting
     67    )
    2668{
    2769    PS_ASSERT_PTR_NON_NULL(in, false);
     
    3678
    3779    psImage *inImage  = in->image;      // The input image
    38     psImage *inMask   = in->mask;       // The input mask
    3980    psImage *subImage = sub->image;     // The image to be subtracted
    40     psImage *subMask  = sub->mask;      // The mask for the subtraction image
    4181
    4282    // Check parities
     
    76116    }
    77117
    78     if (scale == 1.0) {
    79         for (int i = 0; i < inImage->numRows; i++) {
    80             for (int j = 0; j < inImage->numCols; j++) {
    81                 inImage->data.F32[i][j] -= subImage->data.F32[i+y0in-y0sub][j+x0in-x0sub];
    82                 if (inMask && subMask) {
    83                     inMask->data.U8[i][j] |= subMask->data.U8[i+y0in-y0sub][j+x0in-x0sub];
    84                 }
    85             }
    86         }
    87     } else {
    88         for (int i = 0; i < inImage->numRows; i++) {
    89             for (int j = 0; j < inImage->numCols; j++) {
    90                 inImage->data.F32[i][j] -= subImage->data.F32[i+y0in-y0sub][j+x0in-x0sub] * scale;
    91                 if (inMask && subMask) {
    92                     inMask->data.U8[i][j] |= subMask->data.U8[i+y0in-y0sub][j+x0in-x0sub];
    93                 }
    94             }
    95         }
     118    int xOffset = x0in - x0sub;
     119    int yOffset = y0in - y0sub;
     120
     121    bool threaded = true;
     122    int scanRows = pmDetrendGetScanRows();
     123    if (scanRows == 0) {
     124        threaded = false;
     125        scanRows = inImage->numRows;
     126    }
     127
     128    for (int rowStart = 0; rowStart < inImage->numRows; rowStart += scanRows) {
     129      int rowStop = PS_MIN (rowStart + scanRows, inImage->numRows);
     130
     131# define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \
     132      psScalar *scalar = psScalarAlloc(VALUE, TYPE); \
     133      psArrayAdd(ARRAY, 1, scalar); \
     134      psFree (scalar); }
     135     
     136      if (threaded) {
     137          // allocate a job, construct the arguments for this job
     138          psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_BIAS");
     139          psArrayAdd (job->args, 1, in);
     140          psArrayAdd (job->args, 1, sub);
     141          PS_ARRAY_ADD_SCALAR (job->args, scale, PS_TYPE_F32);
     142          PS_ARRAY_ADD_SCALAR (job->args, xOffset, PS_TYPE_S32);
     143          PS_ARRAY_ADD_SCALAR (job->args, yOffset, PS_TYPE_S32);
     144          PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32);
     145          PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32);
     146
     147          // ppImageDetrendReadout(config, options, view)
     148          if (!psThreadJobAddPending (job)) {
     149              return false;
     150          }
     151      } else {
     152          pmBiasSubtractScan (in, sub, scale, xOffset, yOffset, rowStart, rowStop);
     153      }
     154    }
     155
     156    if (threaded) {
     157        // wait here for the threaded jobs to finish
     158        if (!psThreadPoolWait ()) {
     159            psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     160            return false;
     161        }
     162        fprintf (stderr, "success for threaded jobs\n");
     163
     164        // each job records its own goodPixel values; sum them here
     165        // we have only supplied one type of job, so we can assume the types here
     166        psThreadJob *job = NULL;
     167        while ((job = psThreadJobGetDone()) != NULL) {
     168            psFree (job);
     169        }
    96170    }
    97171
     
    100174
    101175bool pmBiasSubtract(pmReadout *in, pmOverscanOptions *overscanOpts,
    102                     const pmReadout *bias, const pmReadout *dark, const pmFPAview *view)
     176                    pmReadout *bias, pmReadout *dark, const pmFPAview *view)
    103177{
    104178    psTrace("psModules.detrend", 4,
Note: See TracChangeset for help on using the changeset viewer.