IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5976


Ignore:
Timestamp:
Jan 13, 2006, 5:14:07 PM (20 years ago)
Author:
Paul Price
Message:

Small hacks from updating psModule code for FPAs and concepts

Location:
trunk/ppImage/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/Makefile.am

    r5910 r5976  
    99        ppDetrendNonLinear.c \
    1010        ppDetrendPedestal.c \
     11        ppFile.c \
    1112        ppImage.c \
    1213        ppImageConfig.c \
  • trunk/ppImage/src/ppImage.c

    r5860 r5976  
    1 # include "ppImage.h"
     1#include "ppImage.h"
    22
    3 int main (int argc, char **argv) {
     3int main(int argc, char **argv)
     4{
    45
    56    ppData data;
     
    78    ppOptions options;
    89
    9     psTimerStart("phase2");
     10    psTimerStart(TIMERNAME);
    1011
    1112    // Parse the configuration and arguments
    12     ppImageConfig (&config, argc, argv);
     13    ppImageConfig(&config, argc, argv);
    1314
    1415    // Open the input image, output image, output mask
    1516    // Get camera configuration from header if not already defined
    1617    // Construct camera in preparation for reading
    17     ppImageParseCamera (&data, &config);
     18    ppImageParseCamera(&data, &config);
    1819
    1920    // Set various tasks (define optional operations)
    20     ppImageOptions (&data, &options, &config);
     21    ppImageOptions(&data, &options, &config);
    2122
    2223    // open detrend images, load headers, optionally load pixels
    23     ppImageParseDetrend (&data, &options, &config);
     24    ppImageParseDetrend(&data, &options, &config);
    2425
    2526    // Image Arithmetic Loop
    26     ppImageLoop (&data, &options, &config);
     27    ppImageLoop(&data, &options, &config);
    2728
    2829    // output options
    29     // ppImageOutput (&data, &options, &config);
     30    // ppImageOutput(&data, &options, &config);
    3031
    31     exit (0);
     32    exit(EXIT_SUCCESS);
    3233}
  • trunk/ppImage/src/ppImage.h

    r5860 r5976  
     1#ifndef PP_IMAGE_H
     2#define PP_IMAGE_H
     3
    14#include <stdio.h>
    25#include <strings.h>
     
    2225
    2326#define RECIPE "PHASE2"                 // Name of the recipe to use
     27#define TIMERNAME "ppImage"             // Name of timer
    2428
     29// How much of the FPA to load at a time
    2530typedef enum {
    26     PP_LOAD_NONE,
    27     PP_LOAD_FPA,
    28     PP_LOAD_CHIP,
    29     PP_LOAD_CELL,
     31    PP_LOAD_NONE,                       // Don't load anything
     32    PP_LOAD_FPA,                        // Load the entire FPA at once
     33    PP_LOAD_CHIP,                       // Load by chip
     34    PP_LOAD_CELL,                       // Load by cell
    3035} ppImageLoadDepth;
    3136
     37// Configuration data
    3238typedef struct {
    33     psMetadata *site;
    34     psMetadata *camera;
    35     psMetadata *recipe;
    36     psMetadata *arguments;
    37     psDB       *database;
     39    psMetadata *site;                   // The site configuration
     40    psMetadata *camera;                 // The camera configuration
     41    psMetadata *recipe;                 // The recipe (i.e., specific setups)
     42    psMetadata *arguments;              // The command-line arguments
     43    psDB       *database;               // Database handle
    3844} ppConfig;
    3945
     46// Options
    4047typedef struct {
    41     bool doMask;                        // Mask bad pixles
    42     bool doBias;                        // Bias subtraction
    43     bool doDark;                        // Dark subtraction
    44     bool doFlat;                        // Flat-field normalisation
    45     bool doFringe;                      // Fringe subtraction
    46     bool doSource;                      // Source identification and photometry
    47     bool doAstrom;                      // Astrometry
     48    bool doMask;                        // Mask bad pixels
     49    bool doBias;                        // Bias subtraction
     50    bool doDark;                        // Dark subtraction
     51    bool doFlat;                        // Flat-field normalisation
     52    bool doFringe;                      // Fringe subtraction
     53    bool doSource;                      // Source identification and photometry
     54    bool doAstrom;                      // Astrometry
    4855
    49     bool doOverscan;                    // Overscan subtraction
    50     int overscanBins;                   // Number of pixels per bin for overscan
    51     psStats *overscanStats;             // Statistics for overscan
    52     void *overscanFit;                  // Overscan fit (polynomial or spline)
    53     pmFit overscanFitType;              // Fit type for overscan
    54     pmOverscanAxis overscanMode;        // Axis for overscan
     56    bool doOverscan;                    // Overscan subtraction
     57    int overscanBins;                   // Number of pixels per bin for overscan
     58    psStats *overscanStats;             // Statistics for overscan
     59    void *overscanFit;                  // Overscan fit (polynomial or spline)
     60    pmFit overscanFitType;              // Fit type for overscan
     61    pmOverscanAxis overscanMode;        // Axis for overscan
    5562
    56     bool doNonLin;                      // Non-linearity correction
     63    bool doNonLin;                      // Non-linearity correction
    5764    psDataType nonLinearType;
    5865    psMetadataItem *nonLinearData;
    5966    void *nonLinearSource;
    6067
    61     ppImageLoadDepth imageLoadDepth;
     68    ppImageLoadDepth imageLoadDepth;    // How much of the FPA to load at once
    6269} ppOptions;
    6370
     71// A file to process
    6472typedef struct {
    65     char *filename;
    66     pmFPA *fpa;
    67     psFits *fits;
    68     psMetadata *header;
    69 } ppFPA;
     73    char *filename;                     // File name
     74    psFits *fits;                       // The FITS file handle
     75    psMetadata *phu;                    // The FITS header
     76    pmFPA *fpa;                         // The FPA, with pixels and extensions
     77} ppFile;
    7078
     79// The data to be processed
    7180typedef struct {
    72     ppFPA *input;
    73     ppFPA *mask;
    74     ppFPA *bias;
    75     ppFPA *dark;
    76     ppFPA *flat;
    77     ppFPA *fringe;
    78     ppFPA *process;
     81    ppFile *input;                      // The input, to be operated upon
     82    ppFile *mask;                       // The bad pixel mask image
     83    ppFile *bias;                       // The bias correction image
     84    ppFile *dark;                       // The dark correction image
     85    ppFile *flat;                       // The flat-field correction image
     86    ppFile *fringe;                     // The fringe correction image
     87#if 0
     88    ppFile *process;                    // A dummy file pointing out what needs to be processed
     89#endif
    7990} ppData;
    8091
     92// Cells to be used in the detrend
    8193typedef struct {
    82     pmCell *input;
    83     pmCell *mask;
    84     pmCell *bias;
    85     pmCell *dark;
    86     pmCell *flat;
     94    pmCell *input;                      // The input cell, to be operated upon
     95    pmCell *mask;                       // The bad pixel mask
     96    pmCell *bias;                       // The bias correction
     97    pmCell *dark;                       // The dark correction
     98    pmCell *flat;                       // The flat-field correction
    8799} ppDetrend;
    88100
    89 bool ppImageConfig (ppConfig *config, int argc, char **argv);
    90 bool ppImageLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell);
    91 bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config);
    92 bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config);
    93 bool ppImageParseCamera (ppData *data, ppConfig *config);
    94 bool ppImageParseDetrend (ppData *data, ppOptions *options, ppConfig *config);
    95101
    96 bool ppReadoutWeights (pmReadout *readout);
     102// Allocators
     103ppFile *ppFileAlloc(void);
    97104
    98 bool ppDetrendCell (ppDetrend *detrend, ppOptions *options, ppConfig *config);
    99105
    100 bool ppDetrendMask (pmCell *cell, pmReadout *input, pmReadout *mask);
    101 bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options);
    102 bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem);
    103 bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem);
    104 bool ppDetrendBias (pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options);
    105 pmReadout* ppDetrendPedestal (pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options);
    106 pmReadout* ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis);
    107106
    108 bool ppFPAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis);
     107// Parse the site configuration (and camera and recipe if specified); read the command-line arguments
     108bool ppImageConfig(ppConfig *config,   // The configuration(output)
     109                   int argc, char **argv // Command-line arguments
     110                   );
     111
     112// Determine what type of camera, and initialise
     113bool ppImageParseCamera(ppData *data,   // The data to be processed
     114                        ppConfig *config // Configuration
     115                        );
     116
     117// Determine the procession options
     118bool ppImageOptions(ppData *data,       // The data to be processed
     119                    ppOptions *options, // Processing options
     120                    ppConfig *config    // Configuration
     121                    );
     122
     123
     124// Loop over the
     125bool ppImageLoop(ppData *data, ppOptions *options, ppConfig *config);
     126
     127// Load the pixels for the given file
     128bool ppImageLoadPixels(ppFile *input,   // File for which to load the pixels
     129                       psDB *db,        // Database handle (for reading concepts)
     130                       int nChip,       // Chip number to load
     131                       int nCell        // Cell number to load
     132                       );
     133
     134bool ppImageParseDetrend(ppData *data, ppOptions *options, ppConfig *config);
     135
     136bool ppReadoutWeights(pmReadout *readout);
     137
     138bool ppDetrendCell(ppDetrend *detrend, ppOptions *options, ppConfig *config);
     139
     140bool ppDetrendMask(pmCell *cell, pmReadout *input, pmReadout *mask);
     141bool ppDetrendNonLinear(pmCell *cell, pmReadout *input, ppOptions *options);
     142bool ppDetrendNonLinearLookup(pmReadout *input, psMetadataItem *dataItem);
     143bool ppDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem);
     144bool ppDetrendBias(pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options);
     145pmReadout* ppDetrendPedestal(pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options);
     146pmReadout* ppDetrendSelectFirst(pmCell *cell, char *name, bool doThis);
     147
     148#if 0
     149bool ppFileOpen(ppFile *fpa, psMetadata *camera, char *name, bool doThis);
     150#endif
     151
     152
     153#endif // Pau.
  • trunk/ppImage/src/ppImageConfig.c

    r5858 r5976  
    1 # include "ppImage.h"
     1#include "ppImage.h"
    22
    3 bool ppImageConfig (ppConfig *config, int argc, char **argv) {
     3bool ppImageConfig(ppConfig *config, int argc, char **argv)
     4{
     5    // Initialise the configuration
     6    config->site = NULL;                // Site configuration
     7    config->camera = NULL;              // Camera configuration
     8    config->recipe = NULL;              // Recipe configuration
     9    config->arguments = NULL;           // The command-line arguments
     10    config->database = NULL;            // Database handle
    411
    5     // Parse the configurations
    6     config->site = NULL;            // Site configuration
    7     config->camera = NULL;          // Camera configuration
    8     config->recipe = NULL;          // Recipe configuration
    9 
    10     // XXX - this should be split into a function to parse argc,argv
    11     //       and a second to read the config files. 
     12    // XXX - this should be split into a function to parse argc,argv
     13    //       and a second to read the config files.
    1214    //       all argc,argv should be interpretted before work is done.
    1315    if (! pmConfigRead(&config->site, &config->camera, &config->recipe, &argc, argv, RECIPE)) {
     
    2325    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-flat", 0, "Name of the flat-field image", "");
    2426    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-mask", 0, "Name of the mask image", "");
     27    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-fringe", 0, "Name of the fringe image", "");
    2528    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)", -1);
    2629
     
    3336    }
    3437
    35     // add the input and output images to the arguments list
    36     psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-input",  0, "Name of the input image",  argv[1]);
    37     psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-output", 0, "Name of the output image", argv[2]);
     38    // Add the input and output images (which remain on the command-line) to the arguments list
     39    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-input",  0, "Name of the input image",  argv[1]);
     40    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-output", 0, "Name of the output image", argv[2]);
    3841
    39     // define Database handle, if used
     42    // Define database handle, if used
     43#if 0
    4044    config->database = pmConfigDB(config->site);
     45#endif
     46
    4147    return true;
    42 } 
     48}
  • trunk/ppImage/src/ppImageDetrendNonLinear.c

    r5858 r5976  
    66    psVector *coeff = dataItem->data.V; // The coefficient vector
    77    if (coeff->type.type != PS_TYPE_F64) {
    8         psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version
    9         psFree (coeff);
    10         coeff = temp;
     8        psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version
     9        psFree (coeff);
     10        coeff = temp;
    1111    }
    1212    psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1, PS_POLYNOMIAL_ORD);
     
    1717    psFree(correction);
    1818    return true;
    19 }   
     19}
    2020
    2121bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem) {
     
    2525    psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0);
    2626    if (psLookupTableRead(table) <= 0) {
    27         psErrorStackPrint(stderr, "Unable to read non-linearity correction file "
    28                           "%s --- ignored\n", name);
    29         return false;
    30     } 
     27        psErrorStackPrint(stderr, "Unable to read non-linearity correction file "
     28                          "%s --- ignored\n", name);
     29        return false;
     30    }
    3131#ifdef PRODUCTION
    3232    pmNonLinearityLookup(input, table);
     
    3838    psFree(table);
    3939    return true;
    40 }   
     40}
    4141
    4242bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options) {
     
    4646    switch (options->nonLinearType) {
    4747      case PS_DATA_VECTOR:
    48         ppDetrendNonLinearPolynomial (input, options->nonLinearData);
    49         return true;
     48        ppDetrendNonLinearPolynomial (input, options->nonLinearData);
     49        return true;
    5050
    5151      case PS_DATA_STRING:
    52         ppDetrendNonLinearLookup (input, options->nonLinearData);
    53         return true;
     52        ppDetrendNonLinearLookup (input, options->nonLinearData);
     53        return true;
    5454
    5555      case PS_DATA_METADATA:
    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);
    61             return false;
    62         }
    63         if (concept->type != PS_DATA_STRING) {
    64             psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as"
    65                      " expected for non-linearity correction --- ignored.\n",
    66                      concept);
    67             return false;
    68         }
     56        // XXX EAM: this is somewhat confusing : let's wrap in a function when i understand it
    6957
    70         // Get the value of the concept
    71         psString conceptValue = concept->data.V;
    72         psMetadata *folder = (psMetadata *)options->nonLinearData->data.V;
    73         psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue);
    74         if (!optionItem) {
    75             psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA"
    76                      " --- ignored.\n", conceptValue);
    77             return false;
    78         }
     58        // Go looking for the value in the hierarchy
     59        concept = psMetadataLookup(cell->concepts, options->nonLinearSource);
     60        if (! concept) {
     61            pmChip *chip = cell->parent;// Parent chip
     62            concept = psMetadataLookup(chip->concepts, options->nonLinearSource);
     63            if (! concept) {
     64                pmFPA *fpa = chip->parent; // Parent FPA
     65                concept = psMetadataLookup(fpa->concepts, options->nonLinearSource);
     66                if (! concept) {
     67                    psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s "
     68                             "for non-linearity correction --- ignored.\n", options->nonLinearSource);
     69                    return false;
     70                }
     71            }
     72        }
    7973
    80         switch (optionItem->type) {
    81           case PS_DATA_VECTOR:
    82             ppDetrendNonLinearPolynomial (input, optionItem);
    83             return true;
    84           case PS_DATA_STRING:
    85             ppDetrendNonLinearLookup (input, optionItem);
    86             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;
    92         }
     74        if (concept->type != PS_DATA_STRING) {
     75            psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as"
     76                     " expected for non-linearity correction --- ignored.\n",
     77                     concept);
     78            return false;
     79        }
     80
     81        // Get the value of the concept
     82        psString conceptValue = concept->data.V;
     83        psMetadata *folder = (psMetadata *)options->nonLinearData->data.V;
     84        psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue);
     85        if (!optionItem) {
     86            psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA"
     87                     " --- ignored.\n", conceptValue);
     88            return false;
     89        }
     90
     91        switch (optionItem->type) {
     92          case PS_DATA_VECTOR:
     93            ppDetrendNonLinearPolynomial (input, optionItem);
     94            return true;
     95          case PS_DATA_STRING:
     96            ppDetrendNonLinearLookup (input, optionItem);
     97            return true;
     98          default:
     99            psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "
     100                     "desired but unable to interpret NONLIN.DATA for %s"
     101                     " --- ignored\n", conceptValue);
     102            return false;
     103        }
    93104      default:
    94         psAbort("phase2", "Invalid options->nonLinearType");
     105        psAbort("phase2", "Invalid options->nonLinearType");
    95106    }
    96107    return true;
  • trunk/ppImage/src/ppImageLoadPixels.c

    r5858 r5976  
    1 # include "ppImage.h"
     1// XXX PAP: Need to look this over some more
    22
    3 bool ppImageLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell) {
     3#include "ppImage.h"
    44
    5     // an input chip is valid if:
    6     // (((nChip == i) || (nChip == -1)) && process.valid)
     5bool ppImageLoadPixels(ppFile *input, psDB *db, int chipNum, int cellNum)
     6{
     7    // an input chip is valid for processing if:
     8    // (((chipNum == i) || (chipNum == -1)) && chip.process)
    79
    8     // if we have not opened the file, skip it
     10    // If we have not opened the file, skip it
    911    if (input->fits == NULL) {
    10         return false;
     12        return false;
    1113    }
    1214
    13     fprintf (stderr, "loading %d,%d for %s\n", nChip, nCell, input->filename);
     15    psTrace(__func__, 1, "Loading %d,%d for %s\n", chipNum, cellNum, input->filename);
    1416
    15     // set input:valid flags according to process and nChip/nCell
     17    // set input:valid flags according to process and chipNum/cellNum
    1618    for (int i = 0; i < input->fpa->chips->n; i++) {
    17         pmChip *pChip = process->fpa->chips->data[i];
    18         pmChip *iChip = input->fpa->chips->data[i];
     19        pmChip *chip = input->fpa->chips->data[i]; // Chip in input image
     20        chip->process = (! chip->exists && ((chipNum == i) || (chipNum == -1)));
    1921
    20         iChip->valid = pChip->valid;
    21         iChip->valid &= (nChip == i) || (nChip == -1);
    22 
    23         for (int j = 0; j < iChip->cells->n; j++) {
    24 
    25             pmCell *pCell = pChip->cells->data[j];
    26             pmCell *iCell = iChip->cells->data[j];
    27 
    28             iCell->valid =  pCell->valid;
    29             iCell->valid &= iChip->valid;
    30             iCell->valid &= (nCell == i) || (nCell == -1);
    31         }
     22        for (int j = 0; j < chip->cells->n; j++) {
     23            pmCell *cell = chip->cells->data[j]; // Cell in input image
     24            cell->process &= chip->process;
     25            cell->process = (! cell->exists && ((cellNum == i) || (cellNum == -1)));
     26        }
    3227    }
    3328
    3429    // Read in the input pixels
    35     if (! pmFPARead(input->fpa, input->fits, input->header, db)) {
     30    if (! pmFPARead(input->fpa, input->fits, input->phu, db)) {
    3631        psErrorStackPrint(stderr, "Unable to populate camera from input FITS file\n");
    3732        exit(EXIT_FAILURE);
    3833    }
    3934
     35#if 0
     36    // XXX PAP: Not sure this is required any more.
     37
    4038    // reset input:valid flags to true
    4139    for (int i = 0; i < input->fpa->chips->n; i++) {
    4240
    43         pmChip *iChip = input->fpa->chips->data[i];
    44         iChip->valid = true;
    45         for (int j = 0; j < iChip->cells->n; j++) {
     41        pmChip *chip = input->fpa->chips->data[i];
     42        chip->process = true;
     43        for (int j = 0; j < chip->cells->n; j++) {
    4644
    47             pmCell *iCell = iChip->cells->data[j];
    48             iCell->valid = true;
    49         }
     45            pmCell *cell = chip->cells->data[j];
     46            cell->process = true;
     47        }
    5048    }
     49#endif
    5150
    5251    return true;
  • trunk/ppImage/src/ppImageLoop.c

    r5858 r5976  
    11# include "ppImage.h"
    22
    3 bool ppImageLoop (ppData *data, ppOptions *options, ppConfig *config) {
    4 
     3bool ppImageLoop(ppData *data, ppOptions *options, ppConfig *config)
     4{
    55    ppDetrend detrend;
    66
    77    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);
     8        psTrace(__func__, 1, "Loading pixels for FPA...\n");
     9        ppImageLoadPixels(data->input, config->database, -1, -1);
     10        ppImageLoadPixels(data->bias,  config->database, -1, -1);
     11        ppImageLoadPixels(data->dark,  config->database, -1, -1);
     12        ppImageLoadPixels(data->mask,  config->database, -1, -1);
     13        ppImageLoadPixels(data->flat,  config->database, -1, -1);
    1314    }
     15
    1416    for (int i = 0; i < data->input->fpa->chips->n; i++) {
    1517        pmChip *inputChip = data->input->fpa->chips->data[i]; // Chip of interest in input image
     
    1921        pmChip *flatChip  = data->flat->fpa->chips->data[i];  // Chip of interest in flat image
    2022
    21         if (! inputChip->valid) { continue; }
     23        printf("Chip %d: %x %x\n", i, inputChip->exists, inputChip->process);
     24        if (! inputChip->process) { continue; }
    2225
    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         }
     26        if (options->imageLoadDepth == PP_LOAD_CHIP) {
     27            psTrace(__func__, 1, "Loading pixels for chip %d...\n", i);
     28            ppImageLoadPixels(data->input, config->database, i, -1);
     29            ppImageLoadPixels(data->bias,  config->database, i, -1);
     30            ppImageLoadPixels(data->dark,  config->database, i, -1);
     31            ppImageLoadPixels(data->mask,  config->database, i, -1);
     32            ppImageLoadPixels(data->flat,  config->database, i, -1);
     33        }
     34
    3035        for (int j = 0; j < inputChip->cells->n; j++) {
    3136            detrend.input = inputChip->cells->data[j]; // Cell of interest in input image
     
    3540            detrend.flat  = flatChip->cells->data[j];  // Cell of interest in flat image
    3641
    37             if (! detrend.input->valid) { continue; }
     42            printf ("\tCell %d: %x %x\n", j, detrend.input->exists, detrend.input->process);
     43            if (! detrend.input->process) { continue; }
    3844
    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);
    47         }
     45            if (options->imageLoadDepth == PP_LOAD_CELL) {
     46                psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j);
     47                ppImageLoadPixels(data->input, config->database, i, j);
     48                ppImageLoadPixels(data->bias,  config->database, i, j);
     49                ppImageLoadPixels(data->dark,  config->database, i, j);
     50                ppImageLoadPixels(data->mask,  config->database, i, j);
     51                ppImageLoadPixels(data->flat,  config->database, i, j);
     52            }
     53
     54            ppDetrendCell (&detrend, options, config);
     55        }
    4856    }
    4957    return true;
  • trunk/ppImage/src/ppImageOptions.c

    r5858 r5976  
    1 # include "ppImage.h"
     1#include "ppImage.h"
    22
    33// XXX EAM : this needs signficant work to choose the detrend images based on the detrend database
    44
    5 bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config) {
     5bool ppImageOptions(ppData *data, ppOptions *options, ppConfig *config)
     6{
    67
    7     bool status;
    8 
    9     // default initial values
    10     options->doMask = false;            // Mask bad pixels
    11     options->doNonLin = false;          // Non-linearity correction
    12     options->doBias = false;            // Bias subtraction
    13     options->doDark = false;            // Dark subtraction
    14     options->doOverscan = false;        // Overscan subtraction
    15     options->doFlat = false;            // Flat-field normalisation
    16     options->doFringe = false;          // Fringe subtraction
    17     options->doSource = false;          // Source identification and photometry
    18     options->doAstrom = false;          // Astrometry
    19     options->overscanBins = 1;          // Number of pixels per bin for overscan
     8    // Flags for various activities
     9    options->doMask = false;            // Mask bad pixels
     10    options->doNonLin = false;          // Non-linearity correction
     11    options->doBias = false;            // Bias subtraction
     12    options->doDark = false;            // Dark subtraction
     13    options->doOverscan = false;        // Overscan subtraction
     14    options->doFlat = false;            // Flat-field normalisation
     15    options->doFringe = false;          // Fringe subtraction
     16    options->doSource = false;          // Source identification and photometry
     17    options->doAstrom = false;          // Astrometry
     18    // Overscan options
     19    options->overscanBins = 1;          // Number of pixels per bin for overscan
    2020    options->overscanStats = NULL;      // Statistics for overscan
    21     options->overscanFit = NULL;        // Overscan fit (polynomial or spline)
     21    options->overscanFit = NULL;        // Overscan fit (polynomial or spline)
    2222    options->overscanFitType = PM_FIT_NONE; // Fit type for overscan
    2323    options->overscanMode = PM_OVERSCAN_NONE; // Axis for overscan
     24    // Non-linearity options
     25    options->nonLinearType = 0;         // Type of non-linearity data (vector, string or metadata)
     26    options->nonLinearData = NULL;      // The non-linearity data
     27    options->nonLinearSource = NULL;    // If the non-linearity data is a menu, this provides the key
     28    // Various others
     29    options->imageLoadDepth = PP_LOAD_NONE; // No load depth specified yet
    2430
    25     options->doNonLin = false;
    26     options->nonLinearType = false;
    27     options->nonLinearData = NULL;
    28     options->nonLinearSource = NULL;
    29 
    30     options->imageLoadDepth = PP_LOAD_NONE;
    31     char *depth = psMetadataLookupPtr(NULL, config->recipe, "LOAD.DEPTH");
    32     if (depth == NULL) {
    33         psAbort ("phase2", "load depth not specified");
     31    bool mdStatus = false;              // Result of MD lookup
     32    const char *depth = psMetadataLookupStr(&mdStatus, config->recipe, "LOAD.DEPTH");
     33    if (! mdStatus || ! depth || strlen(depth) == 0) {
     34        psLogMsg("ppImage", PS_LOG_ERROR, "LOAD.DEPTH not specified in recipe.");
     35        exit(EXIT_FAILURE);
    3436    }
    3537    if (!strcasecmp(depth, "FPA")) {
    36         options->imageLoadDepth = PP_LOAD_FPA;
    37     }
    38     if (!strcasecmp(depth, "CHIP")) {
    39         options->imageLoadDepth = PP_LOAD_CHIP;
    40     }
    41     if (!strcasecmp(depth, "CELL")) {
    42         options->imageLoadDepth = PP_LOAD_CELL;
    43     }
    44     if (options->imageLoadDepth == PP_LOAD_NONE) {
    45         psAbort ("phase2", "load depth not specified");
     38        options->imageLoadDepth = PP_LOAD_FPA;
     39    } else if (!strcasecmp(depth, "CHIP")) {
     40        options->imageLoadDepth = PP_LOAD_CHIP;
     41    } else if (!strcasecmp(depth, "CELL")) {
     42        options->imageLoadDepth = PP_LOAD_CELL;
     43    } else {
     44        psLogMsg(__func__, PS_LOG_ERROR, "LOAD.DEPTH in recipe is not FPA, CHIP or CELL.");
     45        exit(EXIT_FAILURE);
    4646    }
    4747
    48     // mask - recipe options
     48    // Mask recipe options
    4949    if (psMetadataLookupBool(NULL, config->recipe, "MASK")) {
    50         data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask");
    51         if (strlen(data->mask->filename) > 0) {
     50        data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask");
     51        if (data->mask->filename && strlen(data->mask->filename) > 0) {
    5252            options->doMask = true;
    5353        } else {
    54             psLogMsg("phase2", PS_LOG_WARN, "Masking is desired, but no mask was supplied"
    55                      " --- no masking will be performed.\n");
     54            psLogMsg(__func__, PS_LOG_WARN, "Masking is desired, but no mask was supplied"
     55                     " --- no masking will be performed.\n");
    5656        }
    5757    }
    5858
    59     // non-linear - recipe options
     59    // Non-linearity recipe options
    6060    if (psMetadataLookupBool(NULL, config->recipe, "NONLIN")) {
    61         psMetadataItem *dataItem = psMetadataLookup(config->recipe, "NONLIN.DATA");
    62         if (! dataItem) {
    63             psAbort("phase2", "Non-linearity correction desired, but unable to "
    64                      "find NONLIN.DATA in recipe");
    65         }
     61        psMetadataItem *dataItem = psMetadataLookup(config->recipe, "NONLIN.DATA");
     62        if (! dataItem) {
     63            psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but unable to "
     64                     "find NONLIN.DATA in recipe.");
     65            exit(EXIT_FAILURE);
     66        }
    6667
    6768        options->doNonLin = true;
    68         options->nonLinearType = dataItem->type;
    69         options->nonLinearData = dataItem;
     69        options->nonLinearType = dataItem->type;
     70        options->nonLinearData = dataItem;
    7071
    71         switch (dataItem->type) {
    72           case PS_DATA_VECTOR:
    73           case PS_DATA_STRING:
    74             break;
     72        switch (dataItem->type) {
     73            // No immediate action required
     74          case PS_DATA_VECTOR:
     75          case PS_DATA_STRING:
     76            break;
    7577
    76           case PS_DATA_METADATA:
    77             // This is a menu
    78             options->nonLinearSource = psMetadataLookupStr(&status, config->recipe, "NONLIN.SOURCE");
    79             if (! status || ! options->nonLinearSource) {
    80                 psAbort("phase2", "Non-linearity correction desired, but unable to "
    81                          "find NONLIN.SOURCE in recipe");
    82             }
    83             break;
    84 
    85           default:
    86             psAbort("phase2", "Non-linearity correction desired, but "
    87                     "NONLIN.DATA is of invalid type.");
    88         }
    89 
     78            // This is a menu; we need the key
     79          case PS_DATA_METADATA:
     80            {
     81                bool status;
     82                options->nonLinearSource = psMetadataLookupStr(&status, config->recipe, "NONLIN.SOURCE");
     83                if (! status || ! options->nonLinearSource) {
     84                    psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but unable to "
     85                            "find NONLIN.SOURCE in recipe");
     86                    exit(EXIT_FAILURE);
     87                }
     88            }
     89            break;
     90          default:
     91            psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but "
     92                    "NONLIN.DATA is of invalid type.");
     93            exit(EXIT_FAILURE);
     94        }
    9095    }
    9196
    92     // bias - recipe options
     97    // Bias recipe options
    9398    if (psMetadataLookupBool(NULL, config->recipe, "BIAS")) {
    94         data->bias->filename = psMetadataLookupStr(NULL, config->arguments, "-bias");
    95         if (strlen(data->bias->filename) > 0) {
     99        data->bias->filename = psMetadataLookupStr(NULL, config->arguments, "-bias");
     100        if (data->bias->filename && strlen(data->bias->filename) > 0) {
    96101            options->doBias = true;
    97102        } else {
    98             psLogMsg("phase2", PS_LOG_WARN, "Bias subtraction is desired, but no bias was supplied --- "
     103            psLogMsg(__func__, PS_LOG_WARN, "Bias subtraction is desired, but no bias was supplied --- "
    99104                     "no bias subtraction will be performed.\n");
    100105        }
    101106    }
    102107
    103     // dark - recipe options
     108    // Dark recipe options
    104109    if (psMetadataLookupBool(NULL, config->recipe, "DARK")) {
    105         data->dark->filename = psMetadataLookupStr(NULL, config->arguments, "-dark");
    106         if (strlen(data->dark->filename) > 0) {
     110        data->dark->filename = psMetadataLookupStr(NULL, config->arguments, "-dark");
     111        if (data->dark->filename && strlen(data->dark->filename) > 0) {
    107112            options->doDark = true;
    108113        } else {
    109             psLogMsg("phase2", PS_LOG_WARN, "Dark subtraction is desired, but no dark was supplied --- "
     114            psLogMsg(__func__, PS_LOG_WARN, "Dark subtraction is desired, but no dark was supplied --- "
    110115                     "no dark subtraction will be performed.\n");
    111116        }
    112117    }
    113118
    114     // overscan - recipe options
     119    // XXX PAP: The overscan stuff needs to be updated following the reworked API
     120
     121    // Overscan recipe options
    115122    // XXX EAM : we should abort on invalid options. default options?
    116123    if (psMetadataLookupBool(NULL, config->recipe, "OVERSCAN")) {
    117         // XXX EAM : does 'overscanMode = NONE' mean doOverscan = false?
     124        // XXX EAM : does 'overscanMode = NONE' mean doOverscan = false?
    118125        options->doOverscan = true;
    119126        psString mode = psMetadataLookupStr(NULL, config->recipe, "OVERSCAN.MODE");
     
    123130            options->overscanMode = PM_OVERSCAN_ALL;
    124131        } else if (strcasecmp(mode, "NONE")) {
    125             psLogMsg("phase2", PS_LOG_WARN, "OVERSCAN.MODE (%s) is not one of NONE, INDIVIDUAL, or ALL:"
     132            psLogMsg(__func__, PS_LOG_WARN, "OVERSCAN.MODE (%s) is not one of NONE, INDIVIDUAL, or ALL:"
    126133                     " assuming NONE.\n", mode);
    127134        }
     
    135142            options->overscanFitType = PM_FIT_SPLINE;
    136143            // int order = psMetadataLookupS32(NULL, config->recipe, "OVERSCAN.ORDER"); // Order of polynomial fit
    137             // XXX : not in psLib yet : options->overscanFit = psSpline1DAlloc();
     144            // XXX : not in psLib yet : options->overscanFit = psSpline1DAlloc();
    138145        } else if (strcasecmp(fit, "NONE")) {
    139             psLogMsg("phase2", PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:"
     146            psLogMsg(__func__, PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:"
    140147                     " assuming NONE.\n", fit);
    141148        }
     
    158165    // flat-field - recipe options
    159166    if (psMetadataLookupBool(NULL, config->recipe, "FLAT")) {
    160         data->flat->filename = psMetadataLookupStr(NULL, config->arguments, "-flat");
     167        data->flat->filename = psMetadataLookupStr(NULL, config->arguments, "-flat");
    161168        if (strlen(data->flat->filename) > 0) {
    162169            options->doFlat = true;
    163170        } else {
    164             psLogMsg("phase2", PS_LOG_WARN, "Flat-fielding is desired, but no flat was supplied --- "
     171            psLogMsg(__func__, PS_LOG_WARN, "Flat-fielding is desired, but no flat was supplied --- "
    165172                     "no flat-fielding will be performed.\n");
    166173        }
  • trunk/ppImage/src/ppImageParseCamera.c

    r5860 r5976  
    1 # include "ppImage.h"
     1#include "ppImage.h"
    22
    3 static void ppFPA_Free (ppFPA *fpa) {
    4     return;
    5 }
     3bool ppImageParseCamera(ppData *data, ppConfig *config)
     4{
     5    // Initialise the containers where the files will go
     6    data->input   = ppFileAlloc();
     7    data->mask    = ppFileAlloc();
     8    data->bias    = ppFileAlloc();
     9    data->dark    = ppFileAlloc();
     10    data->flat    = ppFileAlloc();
     11    data->fringe  = ppFileAlloc();
     12#if 0
     13    data->process = ppFileAlloc();
     14#endif
    615
    7 ppFPA *ppFPA_Alloc (void) {
    8 
    9     ppFPA *fpa = psAlloc (sizeof(ppFPA));
    10     psMemSetDeallocator(fpa, (psFreeFunc) ppFPA_Free);
    11 
    12     fpa->filename = NULL;
    13     fpa->fpa = NULL;
    14     fpa->fits = NULL;
    15     fpa->header = NULL;
    16 
    17     return fpa;
    18 }
    19 
    20 bool ppImageParseCamera (ppData *data, ppConfig *config) {
    21    
    22     bool status;
    23 
    24     data->input   = ppFPA_Alloc ();
    25     data->mask    = ppFPA_Alloc ();
    26     data->bias    = ppFPA_Alloc ();
    27     data->dark    = ppFPA_Alloc ();
    28     data->flat    = ppFPA_Alloc ();
    29     data->fringe  = ppFPA_Alloc ();
    30     data->process = ppFPA_Alloc ();
    31    
    32     data->input->filename = psMetadataLookupPtr (NULL, config->arguments, "-input");
     16    data->input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, "-input"));
    3317
    3418    // Open the input image
    35     psLogMsg("phase2", PS_LOG_INFO, "Opening input image: %s\n", data->input->filename);
     19    psLogMsg("ppImage", PS_LOG_INFO, "Opening input image: %s\n", data->input->filename);
    3620    data->input->fits = psFitsOpen(data->input->filename, "r"); // File handle for FITS file
    3721    if (! data->input->fits) {
     22        // There's no point in continuing if we can't open the input
    3823        psErrorStackPrint(stderr, "Can't open input image: %s\n", data->input->filename);
    3924        exit(EXIT_FAILURE);
    4025    }
    41     data->input->header = psFitsReadHeader(NULL, data->input->fits); // FITS header
     26    data->input->phu = psFitsReadHeader(NULL, data->input->fits); // FITS header
    4227
    4328    // Get camera configuration from header if not already defined
    4429    if (! config->camera) {
    45         config->camera = pmConfigCameraFromHeader(config->site, data->input->header);
     30        config->camera = pmConfigCameraFromHeader(config->site, data->input->phu);
    4631        if (! config->camera) {
     32             // There's no point in continuing if we can't recognise what we've got
    4733            psErrorStackPrint(stderr, "Can't find camera configuration!\n");
    4834            exit(EXIT_FAILURE);
    4935        }
    50    } else if (! pmConfigValidateCamera(config->camera, data->input->header)) {
    51         psError(PS_ERR_IO, true, "%s does not seem to be from the camera.\n", data->input->filename);
     36   } else if (! pmConfigValidateCamera(config->camera, data->input->phu)) {
     37       // There's no point in continuing if what we've got doesn't match what we've been told
     38        psError(PS_ERR_IO, true, "%s does not seem to be from the specified camera.\n",
     39                data->input->filename);
    5240        exit(EXIT_FAILURE);
    5341    }
    5442
    55     // determine the correct recipe to use
     43    // Determine the correct recipe to use
    5644    if (! config->recipe && !(config->recipe = pmConfigRecipeFromCamera(config->camera, RECIPE))) {
     45        // There's no point in continuing if we can't work out what recipe to use
    5746        psErrorStackPrint(stderr, "Can't find recipe configuration!\n");
    5847        exit(EXIT_FAILURE);
    5948    }
    6049
    61     // Construct camera in preparation for reading
     50    // Construct cameras in preparation for reading
    6251    data->input->fpa   = pmFPAConstruct(config->camera);
    6352    data->mask->fpa    = pmFPAConstruct(config->camera);
     
    6655    data->flat->fpa    = pmFPAConstruct(config->camera);
    6756    data->fringe->fpa  = pmFPAConstruct(config->camera);
     57#if 0
    6858    data->process->fpa = pmFPAConstruct(config->camera);
     59#endif
    6960
    7061    // XXX EAM : extend this to allow an array of selected chips by name
    7162    // Chip selection: if we are using a single chip, select it for each FPA
    72     // data->process acts as a process mask for the full FPA
    73     int chipNum = psMetadataLookupS32(&status, config->arguments, "-chip"); // Chip number to work on
     63    int chipNum = psMetadataLookupS32(NULL, config->arguments, "-chip"); // Chip number to work on
    7464    if (chipNum >= 0) {
    75         if (! pmFPASelectChip(data->process->fpa, chipNum)) {
     65        if (! pmFPASelectChip(data->input->fpa, chipNum)) {
    7666            psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum);
    7767            exit(EXIT_FAILURE);
    7868        }
    79         psLogMsg("phase2", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);
     69        psLogMsg("ppImage", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);
    8070    }
    8171    return true;
     
    8474// XXX EAM : I dropped the pre-open of the output files; replace with a stats test of output permissions
    8575
    86 // XXX : for split data (data spread across multiple files), this step is only operating on a component 
     76// XXX : for split data (data spread across multiple files), this step is only operating on a component
    8777//       of the FPA.  the other components should be set to 'invalid' in this case?
  • trunk/ppImage/src/ppImageParseDetrend.c

    r5858 r5976  
    88// XXX : add fringe frame
    99
    10 bool ppFPAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis) {
     10bool ppFileOpen(ppFile *file, psMetadata *camera, char *name, bool doThis) {
    1111
    1212    if (!doThis) {
    13         return false;
     13        return false;
    1414    }
    1515
    16     psLogMsg("phase2", PS_LOG_INFO, "Opening %s image: %s\n", name, fpa->filename);
    17     fpa->fits = psFitsOpen(fpa->filename, "r"); // File handle
    18     fpa->header = psFitsReadHeader(NULL, fpa->fits); // primary header
    19     if (! pmConfigValidateCamera(camera, fpa->header)) {
    20         psError(PS_ERR_IO, true, "%s (%s) does not seem to be from the correct camera.\n", name, fpa->filename);
    21         exit(EXIT_FAILURE);
     16    psLogMsg("phase2", PS_LOG_INFO, "Opening %s image: %s\n", name, file->filename);
     17    file->fits = psFitsOpen(file->filename, "r"); // File handle
     18    file->phu = psFitsReadHeader(NULL, file->fits); // primary header
     19    if (! pmConfigValidateCamera(camera, file->phu)) {
     20        psError(PS_ERR_IO, true, "%s (%s) does not seem to be from the correct camera.\n", name,
     21                file->filename);
     22        exit(EXIT_FAILURE);
    2223    }
    2324    return true;
     
    2627bool ppImageParseDetrend (ppData *data, ppOptions *options, ppConfig *config) {
    2728
    28     ppFPAOpen (data->mask, config->camera, "mask", options->doMask);
    29     ppFPAOpen (data->bias, config->camera, "bias", options->doBias);
    30     ppFPAOpen (data->dark, config->camera, "dark", options->doDark);
    31     ppFPAOpen (data->flat, config->camera, "flat", options->doFlat);
     29    ppFileOpen(data->mask, config->camera, "mask", options->doMask);
     30    ppFileOpen(data->bias, config->camera, "bias", options->doBias);
     31    ppFileOpen(data->dark, config->camera, "dark", options->doDark);
     32    ppFileOpen(data->flat, config->camera, "flat", options->doFlat);
    3233    return true;
    3334}
Note: See TracChangeset for help on using the changeset viewer.