IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5858


Ignore:
Timestamp:
Dec 30, 2005, 7:05:28 AM (21 years ago)
Author:
eugene
Message:

cleanups, segfault fixes, etc

Location:
trunk/ppImage/src
Files:
7 added
5 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImage.c

    r5857 r5858  
    55    ppData data;
    66    ppConfig config;
    7     ppRecipe options;
     7    ppOptions options;
    88
    99    psTimerStart("phase2");
    1010
    1111    // Parse the configuration and arguments
    12     ppConfigLoad (&config, argc, argv);
     12    ppImageConfig (&config, argc, argv);
    1313
    1414    // Open the input image, output image, output mask
    1515    // Get camera configuration from header if not already defined
    1616    // Construct camera in preparation for reading
    17     ppDataLoadMeta (&data, &config, argv);
     17    ppImageParseCamera (&data, &config, argv);
    1818
    1919    // Set various tasks (define optional operations)
    20     ppRecipeInit (&options, &config)
     20    ppImageOptions (&data, &options, &config);
    2121
    22     // Read in the input pixels
    23     // Generate mask and weight frame
    24     // Read in detrend pixels
    25     ppDataLoadPixels (&data, &options, &config);
     22    // open detrend images, load headers, optionally load pixels
     23    ppImageParseDetrend (&data, &options, &config);
    2624
    2725    // Image Arithmetic Loop
     
    2927
    3028    // output options
    31     ppImageOutput (&data, &options, &config);
     29    // ppImageOutput (&data, &options, &config);
    3230
    3331    exit (0);
  • trunk/ppImage/src/ppImage.h

    r5857 r5858  
    2323#define RECIPE "PHASE2"                 // Name of the recipe to use
    2424
     25typedef enum {
     26    PP_LOAD_NONE,
     27    PP_LOAD_FPA,
     28    PP_LOAD_CHIP,
     29    PP_LOAD_CELL,
     30} ppImageLoadDepth;
     31
    2532typedef struct {
    2633    psMetadata *site;
     
    3340typedef struct {
    3441    bool doMask;                        // Mask bad pixles
    35     bool doNonLin;                      // Non-linearity correction
    3642    bool doBias;                        // Bias subtraction
    3743    bool doDark;                        // Dark subtraction
    38     bool doOverscan;                    // Overscan subtraction
    3944    bool doFlat;                        // Flat-field normalisation
    4045    bool doFringe;                      // Fringe subtraction
    4146    bool doSource;                      // Source identification and photometry
    4247    bool doAstrom;                      // Astrometry
     48    bool preLoad;
     49
     50    bool doOverscan;                    // Overscan subtraction
    4351    int overscanBins;                   // Number of pixels per bin for overscan
    4452    psStats *overscanStats;             // Statistics for overscan
     
    4755    pmOverscanAxis overscanMode;        // Axis for overscan
    4856
    49     char *maskName;
    50     char *biasName;
    51     char *darkName;
    52     char *flatName;
    53 } ppRecipe;
     57    bool doNonLin;                      // Non-linearity correction
     58    psDataType nonLinearType;
     59    psMetadataItem *nonLinearData;
     60    void *nonLinearSource;
     61
     62    ppImageLoadDepth imageLoadDepth;
     63
     64} ppOptions;
    5465
    5566typedef struct {
     67    char *filename;
     68    pmFPA *fpa;
     69    psFits *fits;
    5670    psMetadata *header;
     71} ppFPA;
    5772
    58     pmFPA *input;
    59     pmFPA *weight;
    60     pmFPA *mask;
    61     pmFPA *bias;
    62     pmFPA *dark;
    63     pmFPA *flat;
    64     pmFPA *fringe;
     73typedef struct {
     74    ppFPA *input;
     75    ppFPA *mask;
     76    ppFPA *bias;
     77    ppFPA *dark;
     78    ppFPA *flat;
     79    ppFPA *fringe;
     80    ppFPA *process;
     81} ppData;
    6582
    66     psFits *inputFile;
    67     psFits *weightFile;
    68     psFits *maskFile;
    69     psFits *biasFile;
    70     psFits *darkFile;
    71     psFits *flatFile;
    72     psFits *fringeFile;
    73 } ppData;
     83typedef struct {
     84    pmCell *input;
     85    pmCell *mask;
     86    pmCell *bias;
     87    pmCell *dark;
     88    pmCell *flat;
     89} ppDetrend;
     90
     91bool ppImageConfig (ppConfig *config, int argc, char **argv);
     92bool ppImageLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell);
     93bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config);
     94bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config);
     95bool ppImageParseCamera (ppData *data, ppConfig *config, char **argv);
     96bool ppImageParseDetrend (ppData *data, ppOptions *options, ppConfig *config);
     97
     98bool ppReadoutWeights (pmReadout *readout);
     99
     100bool ppDetrendCell (ppDetrend *detrend, ppOptions *options, ppConfig *config);
     101
     102bool ppDetrendMask (pmCell *cell, pmReadout *input, pmReadout *mask);
     103bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options);
     104bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem);
     105bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem);
     106bool ppDetrendBias (pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options);
     107pmReadout* ppDetrendPedestal (pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options);
     108pmReadout* ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis);
     109
     110bool ppFPAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis);
  • trunk/ppImage/src/ppImageDetrendBias.c

    r5857 r5858  
    11# include "ppImage.h"
    22
    3 bool ppDetrendBias (pmCell *input, psImage *bias, psImage *dark, ppRecipe *options) {
     3bool ppDetrendBias (pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options) {
    44
    55    psPolynomial1D *poly;
    66    psSpline1D *spline;
     7    psString coeffs;
    78
    8     // XXX EAM : this is an odd trigger for this
    9     if (options->overscanMode == PM_OVERSCAN_ROWS || options->overscanMode == PM_OVERSCAN_COLUMNS) {
     9    // XXX EAM : renamed the general edge overscan concept
     10    if (options->overscanMode == PM_OVERSCAN_EDGE) {
    1011        // Need to get the read direction
    1112        int readdir = psMetadataLookupS32(NULL, inputCell->concepts, "CELL.READDIR");
    1213        if (readdir == 1) {
    13 // psmodule-0.8.0 has confused PM_OVERSCAN_ROWS and PM_OVERSCAN_COLUMNS; bug 608.
    14 #ifdef PRODUCTION
    1514            options->overscanMode = PM_OVERSCAN_ROWS;
    16 #else
     15        } else if (readdir == 2) {
    1716            options->overscanMode = PM_OVERSCAN_COLUMNS;
    18 #endif
    19         } else if (readdir == 2) {
    20 #ifdef PRODUCTION
    21             options->overscanMode = PM_OVERSCAN_COLUMNS;
    22 #else
    23             options->overscanMode = PM_OVERSCAN_ROWS;
    24 #endif
    2517        } else {
    26             psErrorStackPrint(stderr, "CELL.READDIR (%d) is not 1 or 2 --- assuming 1.\n",
    27                               readdir);
    28             options->overscanMode = PM_OVERSCAN_ROWS;
     18            psAbort("phase2", "CELL.READDIR (%d) is not 1 or 2", readdir);
    2919        }
    3020    }
    3121
    32     psList *inputOverscans = pmReadoutGetBias(inputReadout); // List of overscan bias regions
    33 #ifdef PRODUCTION
    34     (void)pmSubtractBias(inputReadout, overscanFit, inputOverscans, overscanMode,
    35                          overscanStats, overscanBins, overscanFitType, pedestal);
    36 #else
    37     (void)pmSubtractBias(inputReadout, overscanFit, inputOverscans, overscanMode,
    38                          overscanStats, overscanBins, overscanFitType, biasReadout);
    39 #endif
     22    // XXX : should this be a psArray?
     23    psList *inputOverscans = NULL;
     24    if (options->doOverscan) {
     25        inputOverscans = pmReadoutGetBias(inputReadout); // List of overscan bias regions
     26    }
     27
     28    // supplies the fit result in 'overscanFit'
     29    pmSubtractBias(inputReadout,
     30                   options->overscanFit,
     31                   inputOverscans,
     32                   options->overscanMode,
     33                   options->overscanStats,
     34                   options->overscanBins,
     35                   options->overscanFitType,
     36                   pedestal);
    4037    psFree(inputOverscans);
    41 
     38   
    4239    // Output overscan fit results, if required
    43     if (!doOverscan) {
     40    if (! options->doOverscan) {
    4441        return true;
    4542    }
    4643
    47     if (! overscanFit) {
     44    if (! options->overscanFit) {
    4845        psLogMsg("phase2", PS_LOG_WARN, "No fit generated!\n");
    4946        return true;
    5047    }
    5148
    52     switch (overscanFitType) {
     49    switch (options->overscanFitType) {
    5350      case PM_FIT_POLYNOMIAL:
    54         poly = (psPolynomial1D*)overscanFit; // The polynomial
    55         psString coeffs = NULL;     // String containing the coefficients
     51        poly = (psPolynomial1D *) options->overscanFit; // The polynomial
     52        coeffs = NULL;     // String containing the coefficients
    5653        for (int i = 0; i < poly->nX; i++) {
    5754            psStringAppend(&coeffs, "%e ", poly->coeff[i]);
     
    6360
    6461      case PM_FIT_SPLINE:
    65         spline = (psSpline1D*)overscanFit; // The spline
    66         psString coeffs = NULL;     // String containing the coefficients
     62        spline = (psSpline1D *) options->overscanFit; // The spline
     63        coeffs = NULL;     // String containing the coefficients
    6764        for (int i = 0; i < spline->n; i++) {
    6865            psPolynomial1D *poly = spline->spline[i]; // i-th polynomial
  • trunk/ppImage/src/ppImageDetrendFlat.c

    r5857 r5858  
    11# include "ppImage.h"
    22
    3 bool ppDetrendFlat () {
     3// why does this use the flat pmReadout?
     4
     5bool ppDetrendFlat (pmReadout *inputReadout, pmReadout *flat, ppOptions *options) {
    46
    57    psLogMsg("phase2", PS_LOG_INFO, "Performing flat field.\n");
     8
     9   
     10
    611#ifndef PRODUCTION
    712    psImage *dummyImage = psImageAlloc(inputReadout->image->numCols,
  • trunk/ppImage/src/ppImageDetrendMask.c

    r5857 r5858  
    11# include "ppImage.h"
    22
    3 bool ppDetrendMask (pmCell *cell, pmReadout *readout, pmImage *mask) {
     3# define MASK_MODE (PM_MASK_TRAP | PM_MASK_BADCOL | PM_MASK_SAT)
     4
     5// XXX pass 'concepts' not 'cell' to this function?
     6
     7bool ppDetrendMask (pmCell *cell, pmReadout *input, pmReadout *mask) {
    48
    59    float saturation = psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION");
    610
    711    // Need to change this later to grow the mask by the size of the convolution kernel
    8     (void)pmMaskBadPixels(readout, mask,
    9                           PM_MASK_TRAP | PM_MASK_BADCOL | PM_MASK_SAT, saturation,
    10                           PM_MASK_TRAP, 0);
     12    // XXX does this function respect the mask / image cell region information?
     13    // XXX should probably take pmRegion *mask
     14    pmMaskBadPixels(input, mask->image, MASK_MODE, saturation, PM_MASK_TRAP, 0);
    1115
    1216    return true;
    1317}
    14 
  • trunk/ppImage/src/ppImageDetrendNonLinear.c

    r5857 r5858  
    11# include "ppImage.h"
    22
    3 bool ppDetrendNonLinear (pmCell *cell, pmReadout *readout, psMetadata *recipe) {
     3bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem) {
    44
    5     psString name;
    6     psVector *coeff;
    7     psMetadata *options;
     5    // These are the polynomial coefficients
     6    psVector *coeff = dataItem->data.V; // The coefficient vector
     7    if (coeff->type.type != PS_TYPE_F64) {
     8        psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version
     9        psFree (coeff);
     10        coeff = temp;
     11    }
     12    psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1, PS_POLYNOMIAL_ORD);
     13    psFree(correction->coeff);
     14    correction->coeff = psMemIncrRefCounter(coeff->data.F64);
     15    pmNonLinearityPolynomial(input, correction);
     16    psFree(coeff);
     17    psFree(correction);
     18    return true;
     19}   
    820
    9     psMetadataItem *dataItem = psMetadataLookup(recipe, "NONLIN.DATA");
    10     if (! dataItem) {
    11         psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but unable to "
    12                  "find NONLIN.DATA in recipe --- ignored.\n");
     21bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem) {
     22
     23    // This is a filename: lookup table
     24    char *name = dataItem->data.V;       // Filename
     25    psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0);
     26    if (psLookupTableRead(table) <= 0) {
     27        psErrorStackPrint(stderr, "Unable to read non-linearity correction file "
     28                          "%s --- ignored\n", name);
    1329        return false;
    1430    }
     31#ifdef PRODUCTION
     32    pmNonLinearityLookup(input, table);
     33#else
     34    psVector *influx = table->values->data[0];
     35    psVector *outflux = table->values->data[1];
     36    pmNonLinearityLookup(input, influx, outflux);
     37#endif
     38    psFree(table);
     39    return true;
     40}   
    1541
    16     switch (dataItem->type) {
     42bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options) {
     43
     44    psMetadataItem *concept;
     45
     46    switch (options->nonLinearType) {
    1747      case PS_DATA_VECTOR:
    18         // These are the polynomial coefficients
    19         coeff = dataItem->data.V; // The coefficient vector
    20         if (coeff->type.type != PS_TYPE_F64) {
    21             psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version
    22             coeff = temp;
    23         }
    24         psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1,
    25                                                          PS_POLYNOMIAL_ORD);
    26         psFree(correction->coeff);
    27         correction->coeff = psMemIncrRefCounter(coeff->data.F64);
    28         (void)pmNonLinearityPolynomial(inputReadout, correction);
    29         psFree(coeff);
    30         psFree(correction);
     48        ppDetrendNonLinearPolynomial (input, options->nonLinearData);
    3149        return true;
    3250
    3351      case PS_DATA_STRING:
    34         // This is a filename
    35         name = dataItem->data.V;       // Filename
    36         psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0);
    37         if (psLookupTableRead(table) <= 0) {
    38             psErrorStackPrint(stderr, "Unable to read non-linearity correction file "
    39                               "%s --- ignored\n", name);
    40             return false;
    41         }
    42 #ifdef PRODUCTION
    43         (void)pmNonLinearityLookup(inputReadout, table);
    44 #else
    45         psVector *influx = table->values->data[0];
    46         psVector *outflux = table->values->data[1];
    47         (void)pmNonLinearityLookup(inputReadout, table->values->data[0],
    48                                    table->values->data[1]);
    49 #endif
    50         psFree(table);
     52        ppDetrendNonLinearLookup (input, options->nonLinearData);
    5153        return true;
    5254
    5355      case PS_DATA_METADATA:
    54         // This is a menu
    55         options = dataItem->data.V; // Options with concept values as keys
    56         bool mdok = false; // Success of MD lookup
    57         psString concept = psMetadataLookupStr(&mdok, recipe, "NONLIN.SOURCE");
    58         if (! mdok || ! concept) {
    59             psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but "
    60                      "unable to find NONLIN.SOURCE in recipe --- ignored.\n");
     56        // XXX this is somewhat confusing : let's wrap in a function when i understand it
     57        concept = pmCellGetConcept(cell, options->nonLinearSource);
     58        if (! concept) {
     59            psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s "
     60                     "for non-linearity correction --- ignored.\n", options->nonLinearSource);
    6161            return false;
    6262        }
    63         psMetadataItem *conceptValueItem = pmCellGetConcept(inputCell, concept);
    64         if (! conceptValueItem) {
    65             psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s "
    66                      "for non-linearity correction --- ignored.\n", concept);
    67             return false;
    68         }
    69         if (conceptValueItem->type != PS_DATA_STRING) {
     63        if (concept->type != PS_DATA_STRING) {
    7064            psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as"
    7165                     " expected for non-linearity correction --- ignored.\n",
     
    7468        }
    7569
    76         psString conceptValue = conceptValueItem->data.V;
    7770        // Get the value of the concept
    78         psMetadataItem *optionItem = psMetadataLookup(options, conceptValue);
     71        psString conceptValue = concept->data.V;
     72        psMetadata *folder = (psMetadata *)options->nonLinearData->data.V;
     73        psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue);
    7974        if (!optionItem) {
    8075            psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA"
     
    8277            return false;
    8378        }
    84         if (optionItem->type == PS_DATA_VECTOR) {
    85             // These are the polynomial coefficients
    86             coeff = optionItem->data.V; // The coefficient vector
    87             if (coeff->type.type != PS_TYPE_F64) {
    88                 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64);
    89                 coeff = temp;
    90             }
    91             // Polynomial correction
    92             psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1,
    93                                                              PS_POLYNOMIAL_ORD);
    94             psFree(correction->coeff);
    95             correction->coeff = psMemIncrRefCounter(coeff->data.F64);
    96             (void)pmNonLinearityPolynomial(inputReadout, correction);
    97             psFree(coeff);
    98             psFree(correction);
     79
     80        switch (optionItem->type) {
     81          case PS_DATA_VECTOR:
     82            ppDetrendNonLinearPolynomial (input, optionItem);
    9983            return true;
    100         }
    101         if (optionItem->type == PS_DATA_STRING) {
    102             // This is a filename
    103             psString tableName = optionItem->data.V; // The filename
    104             psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0);
    105             int numLines = 0; // Number of lines read from table
    106             if ((numLines = psLookupTableRead(table)) <= 0) {
    107                 psErrorStackPrint(stderr, "Unable to read non-linearity "
    108                                   "correction file %s --- ignored\n",
    109                                   tableName);
    110                 return false;
    111             }
    112 #ifdef PRODUCTION
    113             (void)pmNonLinearityLookup(inputReadout, table);
    114 #else
    115             printf("XXX: Non-linearity correction from lookup table not "
    116                    "yet implemented.\n");
    117 #endif
    118             psFree(table);
     84          case PS_DATA_STRING:
     85            ppDetrendNonLinearLookup (input, optionItem);
    11986            return true;
     87          default:
     88            psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "
     89                     "desired but unable to interpret NONLIN.DATA for %s"
     90                     " --- ignored\n", conceptValue);
     91            return false;
    12092        }
    121 
    122         psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "
    123                  "desired but unable to interpret NONLIN.DATA for %s"
    124                  " --- ignored\n", conceptValue);
    125         return false;
    126  
    12793      default:
    128         psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but "
    129                  "NONLIN.DATA is of invalid type --- ignored.\n");
     94        psAbort("phase2", "Invalid options->nonLinearType");
    13095    }
    131     return false;
     96    return true;
    13297}
    13398
  • trunk/ppImage/src/ppImageDetrendPedestal.c

    r5857 r5858  
    11# include "ppImage.h"
    22
    3 psImage *ppDetrendPedestal (pmCell *input, psImage *bias, psImage *dark, ppRecipe *options) {
     3// XXX check on image overlaps, as well as image sizes
     4// XXX what constraints do we put on the detrend images?
     5// XXX this function is much easier if we can assume all detrend images
     6//     should have the same size and represent the same pixels...
    47
    5     psImage *pedestal = NULL;       // Pedestal image (bias + scaled dark)
     8pmReadout *ppDetrendPedestal (pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options) {
    69
    710#ifdef PRODUCTION
     11    static float lastExptime = 0.0;
     12    bool reusePedestal = true;
     13
    814    if (options->doDark) {
    915        // Dark time for input image
     
    1420            exit(EXIT_FAILURE);
    1521        }
    16         pedestal = (psImage*)psBinaryOp(NULL, dark, "*", psScalarAlloc(inputTime * darkTime, PS_TYPE_F32));
     22
     23        if (inputTime != lastExptime) {
     24            // this will create a new pedestal if the input one is NULL
     25            // XXX EAM : this function had darkTime * inputTime, which is wrong, yes?
     26            if (pedestal == NULL) {
     27                pedestal = pmReadoutAlloc (NULL);
     28            }
     29            pedestal->col0    = dark->col0;
     30            pedestal->row0    = dark->row0;
     31            pedestal->colBins = dark->colBins;
     32            pedestal->rowBins = dark->rowBins;
     33
     34            pedestal->image   = (psImage *) psBinaryOp(pedestal->image, dark->image, "*", psScalarAlloc(inputTime / darkTime, PS_TYPE_F32));
     35            reusePedestal = false;
     36            lastExptime = inputTime
     37        }
    1738    }
    18     if (options->doBias) {
    19         if (pedestal) {
    20             if (bias->numRows != dark->numRows ||
    21                 bias->numCols != dark->numCols) {
    22                 psError(PS_ERR_IO, true, "Bias and dark images have different dimensions: "
    23                         "%dx%d vs %dx%d\n", bias->numCols, bias->numRows,
    24                         dark->numCols, dark->numRows);
    25                 exit(EXIT_FAILURE);
    26             }
    27             (void)psBinaryOp(pedestal, pedestal, "+", bias);
    28         } else {
     39
     40    // no bias image, return dark pedestal or NULL
     41    if (!options->doBias) {
     42        return pedestal;
     43    }
     44
     45    // no dark image, return bias pedestal, or reuse
     46    if (!options->doDark) {
     47        if (!pedestal) {
    2948            pedestal = psMemIncrRefCounter(bias);
    3049        }
     50        return pedestal;
    3151    }
     52
     53    if (reusePedestal) {
     54        return pedestal;
     55    }
     56
     57    if (bias->image->numRows != dark->image->numRows ||
     58        bias->image->numCols != dark->image->numCols) {
     59        psError(PS_ERR_IO, true, "Bias and dark images have different dimensions: %dx%d vs %dx%d\n",
     60                bias->image->numCols, bias->image->numRows,
     61                dark->image->numCols, dark->image->numRows);
     62        exit(EXIT_FAILURE);
     63    }
     64
     65    psBinaryOp(pedestal->image, pedestal->image, "+", bias->image);
     66    return pedestal;
     67#else
     68    return NULL;
    3269#endif
    33 
    34     return pedestal;
    3570}
    3671
     72// creates a new pedestal image for this readout
     73// if the current exptime is the same as the last exptime,
     74// reuses the supplied pedestal
  • trunk/ppImage/src/ppImageLoop.c

    r5857 r5858  
    11# include "ppImage.h"
    22
    3 bool ppImageLoop (ppData *data, ppRecipe *options, ppConfig *config) {
     3bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config) {
    44
    5     psArray *inputChips = data->input->chips; // Array of chips in input image
    6     psArray *biasChips  = data->bias->chips;  // Array of chips in bias image
    7     psArray *darkChips  = data->dark->chips;  // Array of chips in dark image
    8     psArray *maskChips  = data->mask->chips;  // Array of chips in mask image
    9     psArray *flatChips  = data->flat->chips;  // Array of chips in flat image
     5    ppDetrend detrend;
    106
    11     for (int i = 0; i < inputChips->n; i++) {
    12         pmChip *inputChip = inputChips->data[i]; // Chip of interest in input image
    13         pmChip *biasChip  = biasChips->data[i];  // Chip of interest in bias image
    14         pmChip *darkChip  = darkChips->data[i];  // Chip of interest in dark image
    15         pmChip *maskChip  = maskChips->data[i];  // Chip of interest in mask image
    16         pmChip *flatChip  = flatChips->data[i];  // Chip of interest in flat image
     7    if (options->imageLoadDepth == PP_LOAD_FPA) {
     8        ppImageLoadPixels (data->input, data->process, config->database, -1, -1);
     9        ppImageLoadPixels (data->bias,  data->process, config->database, -1, -1);
     10        ppImageLoadPixels (data->dark,  data->process, config->database, -1, -1);
     11        ppImageLoadPixels (data->mask,  data->process, config->database, -1, -1);
     12        ppImageLoadPixels (data->flat,  data->process, config->database, -1, -1);
     13    }
     14    for (int i = 0; i < data->input->fpa->chips->n; i++) {
     15        pmChip *inputChip = data->input->fpa->chips->data[i]; // Chip of interest in input image
     16        pmChip *biasChip  = data->bias->fpa->chips->data[i];  // Chip of interest in bias image
     17        pmChip *darkChip  = data->dark->fpa->chips->data[i];  // Chip of interest in dark image
     18        pmChip *maskChip  = data->mask->fpa->chips->data[i];  // Chip of interest in mask image
     19        pmChip *flatChip  = data->flat->fpa->chips->data[i];  // Chip of interest in flat image
    1720
    1821        if (! inputChip->valid) { continue; }
    1922
    20         psArray *inputCells = inputChip->cells; // Array of cells in input image
    21         psArray *biasCells  = biasChip->cells;  // Array of cells in bias image
    22         psArray *darkCells  = darkChip->cells;  // Array of cells in dark image
    23         psArray *maskCells  = maskChip->cells;  // Array of cells in mask image
    24         psArray *flatCells  = flatChip->cells;  // Array of cells in flat image
     23        if (options->imageLoadDepth == PP_LOAD_CHIP) {
     24            ppImageLoadPixels (data->input, data->process, config->database, i, -1);
     25            ppImageLoadPixels (data->bias,  data->process, config->database, i, -1);
     26            ppImageLoadPixels (data->dark,  data->process, config->database, i, -1);
     27            ppImageLoadPixels (data->mask,  data->process, config->database, i, -1);
     28            ppImageLoadPixels (data->flat,  data->process, config->database, i, -1);
     29        }
     30        for (int j = 0; j < inputChip->cells->n; j++) {
     31            detrend.input = inputChip->cells->data[j]; // Cell of interest in input image
     32            detrend.bias  = biasChip->cells->data[j];  // Cell of interest in bias image
     33            detrend.dark  = darkChip->cells->data[j];  // Cell of interest in dark imag
     34            detrend.mask  = maskChip->cells->data[j];  // Cell of interest in mask image
     35            detrend.flat  = flatChip->cells->data[j];  // Cell of interest in flat image
    2536
    26         for (int j = 0; j < inputCells->n; j++) {
    27             pmCell *inputCell = inputCells->data[j]; // Cell of interest in input image
    28             pmCell *biasCell  = biasCells->data[j];  // Cell of interest in bias image
    29             pmCell *darkCell  = darkCells->data[j];  // Cell of interest in dark imag
    30             pmCell *maskCell  = maskCells->data[j];  // Cell of interest in mask image
    31             pmCell *flatCell  = flatCells->data[j];  // Cell of interest in flat image
     37            if (! detrend.input->valid) { continue; }
    3238
    33             if (! inputCell->valid) { continue; }
    34 
    35             ppReadoutDetrend (inputCell, maskCell, biasCell, darkCell, flatCell);
     39            if (options->imageLoadDepth == PP_LOAD_CELL) {
     40                ppImageLoadPixels (data->input, data->process, config->database, i, j);
     41                ppImageLoadPixels (data->bias,  data->process, config->database, i, j);
     42                ppImageLoadPixels (data->dark,  data->process, config->database, i, j);
     43                ppImageLoadPixels (data->mask,  data->process, config->database, i, j);
     44                ppImageLoadPixels (data->flat,  data->process, config->database, i, j);
     45            }
     46            ppDetrendCell (&detrend, options, config);
    3647        }
    3748    }
    3849    return true;
    3950}
     51
     52/* if we allow per-readout loads, we need to load detrend images here */
Note: See TracChangeset for help on using the changeset viewer.