IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18893


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

Location:
trunk/psModules/src
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/Makefile.am

    r16841 r18893  
    1313        pmDetrendDB.c \
    1414        pmShutterCorrection.c \
     15        pmDetrendThreads.c \
    1516        pmShifts.c \
    1617        pmDark.c
     
    2829        pmDetrendDB.h \
    2930        pmShutterCorrection.h \
     31        pmDetrendThreads.h \
    3032        pmShifts.h \
    3133        pmDark.h
  • 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,
  • trunk/psModules/src/detrend/pmBias.h

    r14505 r18893  
    55 * @author Paul Price, IfA
    66 *
    7  * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-08-15 20:21:18 $
     7 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2008-08-05 01:24:47 $
    99 * Copyright 2004--2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    2222bool pmBiasSubtract(pmReadout *in,      ///< Input readout, to be overscan/bias/dark corrected
    2323                    pmOverscanOptions *overscanOpts, ///< Options for overscan subtraction, or NULL
    24                     const pmReadout *bias, ///< Bias to subtract, or NULL
    25                     const pmReadout *dark, ///< Dark to scale and subtract, or NULL
     24                    pmReadout *bias, ///< Bias to subtract, or NULL
     25                    pmReadout *dark, ///< Dark to scale and subtract, or NULL
    2626                    const pmFPAview *view ///< View for readout of interest
    2727                   );
     
    3030// image.  The bias image is subtracted in place from the input image.
    3131bool pmBiasSubtractFrame(pmReadout *in, // Input readout
    32                           const pmReadout *sub, // Readout to be subtracted from input
    33                           float scale   // Scale to apply before subtracting
     32                        pmReadout *sub, // Readout to be subtracted from input
     33                        float scale   // Scale to apply before subtracting
    3434    );
     35
     36bool pmBiasSubtractScan_Threaded (psThreadJob *job);
     37bool pmBiasSubtractScan (pmReadout *in, pmReadout *sub, float scan, int xOffset, int yOffset, int rowStart, int rowStop);
    3538
    3639/// @}
  • trunk/psModules/src/detrend/pmDark.c

    r18859 r18893  
    1111#include "pmFPAWrite.h"
    1212#include "pmReadoutStack.h"
     13#include "pmDetrendThreads.h"
    1314
    1415#include "pmDark.h"
     
    366367}
    367368
    368 bool pmDarkApply(pmReadout *readout, const pmCell *dark, psMaskType bad)
     369bool pmDarkApplyScan_Threaded (psThreadJob *job) {
     370    pmReadout *readout   = job->args->data[0];
     371    pmCell *dark         = job->args->data[1];
     372    psPolynomialMD *poly = job->args->data[2];
     373    psVector *values     = job->args->data[3];
     374
     375    psMaskType bad = PS_SCALAR_VALUE(job->args->data[4],U8);
     376    bool doNorm    = PS_SCALAR_VALUE(job->args->data[5],U8);
     377    float norm     = PS_SCALAR_VALUE(job->args->data[6],F32);
     378    int rowStart   = PS_SCALAR_VALUE(job->args->data[7],S32);
     379    int rowStop    = PS_SCALAR_VALUE(job->args->data[8],S32);
     380    bool status = pmDarkApplyScan (readout, dark, poly, values, bad, doNorm, norm, rowStart, rowStop);
     381    return status;
     382}
     383
     384bool pmDarkApplyScan (pmReadout *readout, const pmCell *dark, psPolynomialMD *poly, psVector *values, psMaskType bad, bool doNorm, float norm, int rowStart, int rowStop) {
     385
     386    int numCols = readout->image->numCols;
     387    int numTerms = dark->readouts->n;   // Number of polynomial terms
     388
     389    // thread here by scan
     390    for (int y = rowStart; y < rowStop; y++) {
     391        for (int x = 0; x < numCols; x++) {
     392            for (int i = 0; i < numTerms; i++) {
     393                pmReadout *ro = dark->readouts->data[i]; // Dark readout
     394                poly->coeff->data.F64[i] = ro->image->data.F32[y][x];
     395            }
     396            float value = psPolynomialMDEval(poly, values); // Value of dark current
     397            if (doNorm) {
     398                value *= norm;
     399            }
     400            readout->image->data.F32[y][x] -= value;
     401            if (readout->mask && !isfinite(value)) {
     402                readout->mask->data.PS_TYPE_MASK_DATA[y][x] = bad;
     403            }
     404        }
     405    }
     406    return true;
     407}
     408
     409bool pmDarkApply(pmReadout *readout, pmCell *dark, psMaskType bad)
    369410{
    370411    PS_ASSERT_PTR_NON_NULL(readout, false);
     
    433474    psFree(orders);
    434475
    435     for (int y = 0; y < numRows; y++) {
    436         for (int x = 0; x < numCols; x++) {
    437             for (int i = 0; i < numTerms; i++) {
    438                 pmReadout *ro = dark->readouts->data[i]; // Dark readout
    439                 poly->coeff->data.F64[i] = ro->image->data.F32[y][x];
    440             }
    441             float value = psPolynomialMDEval(poly, values); // Value of dark current
    442             if (doNorm) {
    443                 value *= norm;
    444             }
    445             readout->image->data.F32[y][x] -= value;
    446             if (readout->mask && !isfinite(value)) {
    447                 readout->mask->data.PS_TYPE_MASK_DATA[y][x] = bad;
    448             }
    449         }
     476    // thread here by scan
     477
     478    bool threaded = true;
     479    int scanRows = pmDetrendGetScanRows();
     480    if (scanRows == 0) {
     481        threaded = false;
     482        scanRows = readout->image->numRows;
     483    }
     484
     485    for (int rowStart = 0; rowStart < readout->image->numRows; rowStart += scanRows) {
     486      int rowStop = PS_MIN (rowStart + scanRows, readout->image->numRows);
     487
     488# define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \
     489      psScalar *scalar = psScalarAlloc(VALUE, TYPE); \
     490      psArrayAdd(ARRAY, 1, scalar); \
     491      psFree (scalar); }
     492     
     493      if (threaded) {
     494          // allocate a job, construct the arguments for this job
     495          psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_DARK");
     496          psArrayAdd (job->args, 1, readout);
     497          psArrayAdd (job->args, 1, dark);
     498          psArrayAdd (job->args, 1, poly);
     499          psArrayAdd (job->args, 1, values);
     500          PS_ARRAY_ADD_SCALAR (job->args, bad, PS_TYPE_MASK);
     501          PS_ARRAY_ADD_SCALAR (job->args, doNorm, PS_TYPE_U8);
     502          PS_ARRAY_ADD_SCALAR (job->args, norm, PS_TYPE_F32);
     503          PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32);
     504          PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32);
     505
     506          // ppImageDetrendReadout(config, options, view)
     507          if (!psThreadJobAddPending (job)) {
     508              return false;
     509          }
     510      } else {
     511          pmDarkApplyScan (readout, dark, poly, values, bad, doNorm, norm, rowStart, rowStop);
     512      }
     513    }
     514
     515    if (threaded) {
     516        // wait here for the threaded jobs to finish
     517        if (!psThreadPoolWait ()) {
     518            psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     519            return false;
     520        }
     521        fprintf (stderr, "success for threaded jobs\n");
     522
     523        // free the done jobs
     524        psThreadJob *job = NULL;
     525        while ((job = psThreadJobGetDone()) != NULL) {
     526            psFree (job);
     527        }
    450528    }
    451529
  • trunk/psModules/src/detrend/pmDark.h

    r18859 r18893  
    4040    );
    4141
     42bool pmDarkApplyScan_Threaded (psThreadJob *job);
     43bool pmDarkApplyScan (pmReadout *readout, const pmCell *dark, psPolynomialMD *poly, psVector *values, psMaskType bad, bool doNorm, float norm, int rowStart, int rowStop);
     44
    4245// Apply dark
    4346bool pmDarkApply(pmReadout *readout,    // Readout to which to apply dark
    44                  const pmCell *dark,    // Dark to apply
     47                 pmCell *dark,    // Dark to apply
    4548                 psMaskType bad         // Mask value to give bad pixels
    4649    );
  • trunk/psModules/src/detrend/pmFlatField.c

    r15673 r18893  
    1111#include "pmFPAMaskWeight.h"
    1212#include "pmFlatField.h"
     13#include "pmDetrendThreads.h"
     14
     15bool pmFlatFieldScan_Threaded (psThreadJob *job) {
     16    psImage *inImage   = job->args->data[0];
     17    psImage *inMask    = job->args->data[1];
     18    psImage *flatImage = job->args->data[2];
     19    psImage *flatMask  = job->args->data[3];
     20
     21    psMaskType badFlat = PS_SCALAR_VALUE(job->args->data[4],U8);
     22    int xOffset        = PS_SCALAR_VALUE(job->args->data[5],S32);
     23    int yOffset        = PS_SCALAR_VALUE(job->args->data[6],S32);
     24    int rowStart       = PS_SCALAR_VALUE(job->args->data[7],S32);
     25    int rowStop        = PS_SCALAR_VALUE(job->args->data[8],S32);
     26    bool status = pmFlatFieldScan (inImage, inMask, flatImage, flatMask, badFlat, xOffset, yOffset, rowStart, rowStop);
     27    return status;
     28}
     29
     30// Macro for all PS types
     31#define FLAT_DIVISION_CASE(TYPE, SPECIAL)       \
     32    case PS_TYPE_##TYPE:                        \
     33    for (int j = rowStart; j < rowStop; j++) { \
     34        for (int i = 0; i < inImage->numCols; i++) { \
     35            ps##TYPE flatValue = flatImage->data.TYPE[j + yOffset][i + xOffset]; \
     36            if (!isfinite(flatValue) || flatValue <= 0.0 || \
     37                (flatMask && flatMask->data.U8[j + yOffset][i + xOffset])) { \
     38                if (inMask) { \
     39                    inMask->data.PS_TYPE_MASK_DATA[j][i] |= badFlat; \
     40                } \
     41                inImage->data.TYPE[j][i] = SPECIAL; \
     42            } else { \
     43                inImage->data.TYPE[j][i] /= flatValue; \
     44            } \
     45        } \
     46    } \
     47    break;
     48
     49bool pmFlatFieldScan (psImage *inImage, psImage *inMask, psImage *flatImage, psImage *flatMask, psMaskType badFlat, int xOffset, int yOffset, int rowStart, int rowStop) {
     50
     51    switch (inImage->type.type) {
     52        FLAT_DIVISION_CASE(U8,  0);
     53        FLAT_DIVISION_CASE(U16, 0);
     54        FLAT_DIVISION_CASE(U32, 0);
     55        FLAT_DIVISION_CASE(U64, 0);
     56        FLAT_DIVISION_CASE(S8,  0);
     57        FLAT_DIVISION_CASE(S16, 0);
     58        FLAT_DIVISION_CASE(S32, 0);
     59        FLAT_DIVISION_CASE(S64, 0);
     60        FLAT_DIVISION_CASE(F32, NAN);
     61        FLAT_DIVISION_CASE(F64, NAN);
     62    default:
     63        psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unsupported type for input image: %x\n",
     64                inImage->type.type);
     65        return false;
     66    }
     67    return true;
     68}
    1369
    1470bool pmFlatField(pmReadout *in, const pmReadout *flat, psMaskType badFlat)
     
    71127    }
    72128
    73     // Macro for all PS types
    74     #define FLAT_DIVISION_CASE(TYPE, SPECIAL) \
    75 case PS_TYPE_##TYPE: \
    76     for (int j = 0; j < inImage->numRows; j++) { \
    77         for (int i = 0; i < inImage->numCols; i++) { \
    78             ps##TYPE flatValue = flatImage->data.TYPE[j + yOffset][i + xOffset]; \
    79             if (!isfinite(flatValue) || flatValue <= 0.0 || \
    80                 (flatMask && flatMask->data.U8[j + yOffset][i + xOffset])) { \
    81                 if (inMask) { \
    82                     inMask->data.PS_TYPE_MASK_DATA[j][i] |= badFlat; \
    83                 } \
    84                 inImage->data.TYPE[j][i] = SPECIAL; \
    85             } else { \
    86                 inImage->data.TYPE[j][i] /= flatValue; \
    87             } \
    88         } \
    89     } \
    90     break;
     129    bool threaded = true;
     130    int scanRows = pmDetrendGetScanRows();
     131    if (scanRows == 0) {
     132        threaded = false;
     133        scanRows = inImage->numRows;
     134    }
    91135
    92     switch (inImage->type.type) {
    93         FLAT_DIVISION_CASE(U8,  0);
    94         FLAT_DIVISION_CASE(U16, 0);
    95         FLAT_DIVISION_CASE(U32, 0);
    96         FLAT_DIVISION_CASE(U64, 0);
    97         FLAT_DIVISION_CASE(S8,  0);
    98         FLAT_DIVISION_CASE(S16, 0);
    99         FLAT_DIVISION_CASE(S32, 0);
    100         FLAT_DIVISION_CASE(S64, 0);
    101         FLAT_DIVISION_CASE(F32, NAN);
    102         FLAT_DIVISION_CASE(F64, NAN);
    103     default:
    104         psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unsupported type for input image: %x\n",
    105                 inImage->type.type);
    106         return false;
     136    for (int rowStart = 0; rowStart < inImage->numRows; rowStart += scanRows) {
     137      int rowStop = PS_MIN (rowStart + scanRows, inImage->numRows);
     138
     139# define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \
     140      psScalar *scalar = psScalarAlloc(VALUE, TYPE); \
     141      psArrayAdd(ARRAY, 1, scalar); \
     142      psFree (scalar); }
     143     
     144      if (threaded) {
     145          // allocate a job, construct the arguments for this job
     146          psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_FLAT");
     147          psArrayAdd (job->args, 1, inImage);
     148          psArrayAdd (job->args, 1, inMask);
     149          psArrayAdd (job->args, 1, flatImage);
     150          psArrayAdd (job->args, 1, flatMask);
     151          PS_ARRAY_ADD_SCALAR (job->args, badFlat, PS_TYPE_U8);
     152          PS_ARRAY_ADD_SCALAR (job->args, xOffset, PS_TYPE_S32);
     153          PS_ARRAY_ADD_SCALAR (job->args, yOffset, PS_TYPE_S32);
     154          PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32);
     155          PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32);
     156
     157          // ppImageDetrendReadout(config, options, view)
     158          if (!psThreadJobAddPending (job)) {
     159              return false;
     160          }
     161      } else {
     162          pmFlatFieldScan (inImage, inMask, flatImage, flatMask, badFlat, xOffset, yOffset, rowStart, rowStop);
     163      }
     164    }
     165
     166    if (threaded) {
     167        // wait here for the threaded jobs to finish
     168        if (!psThreadPoolWait ()) {
     169            psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     170            return false;
     171        }
     172        fprintf (stderr, "success for threaded jobs\n");
     173
     174        // free done jobs
     175        psThreadJob *job = NULL;
     176        while ((job = psThreadJobGetDone()) != NULL) {
     177            psFree (job);
     178        }
    107179    }
    108180
  • trunk/psModules/src/detrend/pmFlatField.h

    r13591 r18893  
    55 * @author Paul Price, IfA
    66 *
    7  * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-06-02 03:51:03 $
     7 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2008-08-05 01:24:47 $
    99 * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    2727                 psMaskType badFlat     ///< Mask value to give bad flat pixels
    2828                );
     29
     30bool pmFlatFieldScan_Threaded (psThreadJob *job);
     31bool pmFlatFieldScan (psImage *inImage, psImage *inMask, psImage *flatImage, psImage *flatMask, psMaskType badFlag, int xOffset, int yOffset, int rowStart, int rowStop);
     32
     33
    2934/// @}
    3035#endif
  • trunk/psModules/src/detrend/pmShutterCorrection.c

    r18860 r18893  
    1414#include "pmConceptsAverage.h"
    1515#include "pmReadoutStack.h"
     16#include "pmDetrendThreads.h"
    1617
    1718#include "pmShutterCorrection.h"
     
    655656
    656657
     658bool pmShutterCorrectionApplyScan_Threaded (psThreadJob *job) {
     659    psImage *image        = job->args->data[0];
     660    psImage *shutterImage = job->args->data[1];
     661    psImage *mask         = job->args->data[2];
     662
     663    float exptime    = PS_SCALAR_VALUE(job->args->data[3],F32);
     664    psMaskType blank = PS_SCALAR_VALUE(job->args->data[4],U8);
     665    int rowStart     = PS_SCALAR_VALUE(job->args->data[5],S32);
     666    int rowStop      = PS_SCALAR_VALUE(job->args->data[6],S32);
     667    bool status = pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop);
     668    return status;
     669}
     670
     671bool pmShutterCorrectionApplyScan(psImage *image, psImage *shutterImage, psImage *mask, float exptime, psMaskType blank, int rowStart, int rowStop)
     672{
     673    for (int y = rowStart; y < rowStop; y++) {
     674        for (int x = 0; x < image->numCols; x++) {
     675            if (mask && !isfinite(shutterImage->data.F32[y][x])) {
     676                mask->data.PS_TYPE_MASK_DATA[y][x] |= blank;
     677                image->data.F32[y][x] = NAN;
     678                continue;
     679            }
     680            image->data.F32[y][x] *= exptime / (exptime + shutterImage->data.F32[y][x]);
     681        }
     682    }
     683    return true;
     684}
     685
    657686bool pmShutterCorrectionApply(pmReadout *readout, const pmReadout *shutter, psMaskType blank)
    658687{
     
    700729    psImage *image = readout->image;    // Image to correct
    701730    psImage *mask = readout->mask;      // Corresponding mask
     731
     732    bool threaded = true;
     733    int scanRows = pmDetrendGetScanRows();
     734    if (scanRows == 0) {
     735        threaded = false;
     736        scanRows = image->numRows;
     737    }
    702738
    703739    if (exptime <= 0.0) {
     
    720756        psFree (line);
    721757    } else {
    722         for (int y = 0; y < image->numRows; y++) {
    723             for (int x = 0; x < image->numCols; x++) {
    724                 if (mask && !isfinite(shutterImage->data.F32[y][x])) {
    725                     mask->data.PS_TYPE_MASK_DATA[y][x] |= blank;
    726                     image->data.F32[y][x] = NAN;
    727                     continue;
    728                 }
    729                 image->data.F32[y][x] *= exptime / (exptime + shutterImage->data.F32[y][x]);
    730             }
    731         }
     758        for (int rowStart = 0; rowStart < image->numRows; rowStart += scanRows) {
     759            int rowStop = PS_MIN (rowStart + scanRows, image->numRows);
     760
     761# define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \
     762      psScalar *scalar = psScalarAlloc(VALUE, TYPE); \
     763      psArrayAdd(ARRAY, 1, scalar); \
     764      psFree (scalar); }
     765     
     766            if (threaded) {
     767                // allocate a job, construct the arguments for this job
     768                psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_SHUTTER");
     769                psArrayAdd (job->args, 1, image);
     770                psArrayAdd (job->args, 1, shutterImage);
     771                psArrayAdd (job->args, 1, mask);
     772                PS_ARRAY_ADD_SCALAR (job->args, exptime, PS_TYPE_F32);
     773                PS_ARRAY_ADD_SCALAR (job->args, blank, PS_TYPE_MASK);
     774                PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32);
     775                PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32);
     776
     777                // ppImageDetrendReadout(config, options, view)
     778                if (!psThreadJobAddPending (job)) {
     779                    return false;
     780                }
     781            } else {
     782                pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop);
     783            }
     784        }
     785        if (threaded) {
     786            // wait here for the threaded jobs to finish
     787            if (!psThreadPoolWait ()) {
     788                psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     789                return false;
     790            }
     791            fprintf (stderr, "success for threaded jobs\n");
     792
     793            // free the done jobs
     794            psThreadJob *job = NULL;
     795            while ((job = psThreadJobGetDone()) != NULL) {
     796                psFree (job);
     797            }
     798        }
    732799    }
    733800    psFree(shutterImage);
  • trunk/psModules/src/detrend/pmShutterCorrection.h

    r18860 r18893  
    55 * @author Paul Price, IfA
    66 *
    7  * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2008-08-01 23:58:37 $
     7 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2008-08-05 01:24:47 $
    99 * Copyright 2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    124124    );
    125125
     126bool pmShutterCorrectionApplyScan_Threaded (psThreadJob *job);
     127bool pmShutterCorrectionApplyScan(psImage *image, psImage *shutterImage, psImage *mask, float exptime, psMaskType blank, int rowStart, int rowStop);
     128
    126129/// Apply a shutter correction
    127130///
  • trunk/psModules/src/psmodules.h

    r18828 r18893  
    1313#include <pmConfig.h>
    1414#include <pmDetrendDB.h>
     15#include <pmDetrendThreads.h>
    1516#include <pmHDU.h>
    1617#include <pmFPA.h>
Note: See TracChangeset for help on using the changeset viewer.