IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6817


Ignore:
Timestamp:
Apr 7, 2006, 5:57:23 PM (20 years ago)
Author:
eugene
Message:

substantial upgrade to work with the pmFPAfile paradigm

Location:
trunk/ppImage/src
Files:
10 deleted
12 edited

Legend:

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

    r6747 r6817  
    1212ppImage_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS)
    1313ppImage_SOURCES = \
    14         ppFile.c \
    1514        ppImage.c \
    1615        ppImageConfig.c \
    17         ppImageData.c \
    18         ppImageDetrendBias.c \
     16        ppImageOptions.c \
     17        ppImageParseDetrend.c \
     18        ppImageLoop.c \
    1919        ppImageDetrendCell.c \
    2020        ppImageDetrendMask.c \
     21        ppImageDetrendBias.c \
    2122        ppImageDetrendNonLinear.c \
    22         ppImageLoop.c \
    23         ppImageOptions.c \
    24         ppImageParseCamera.c \
    25         ppImageWeights.c \
    2623        ppMem.c
     24#       ppImageParseCamera.c \
     25#       ppDetrendFlat.c \
     26#       ppImageWeights.c \
    2727#       ppImageLoadPixels.c
    28 #       ppDetrendFlat.c
    2928#       ppImageOutput.c
    3029#       ppImageDetrendPedestal.c
  • trunk/ppImage/src/ppImage.c

    r6775 r6817  
    1 #include <stdio.h>
    2 #include "pslib.h"
    3 #include "psmodules.h"
    41#include "ppImage.h"
    5 #include "ppMem.h"
    62
    7 int main(int argc, char **argv)
    8 {
    9 //    psErrorRegister(NULL, -1);
    10 
    11     ppImageData *data = ppImageDataAlloc();
    12     ppImageOptions *options = ppImageOptionsAlloc();
     3int main(int argc, char **argv) {
    134
    145    psTimerStart(TIMERNAME);
    156
    167    // Parse the configuration and arguments
     8    // Open the input image(s)
     9    // Determine camera, format from header if not already defined
     10    // Construct camera in preparation for reading
    1711    pmConfig *config = ppImageConfig(argc, argv);
    1812
    19     // Open the input image, output image, output mask
    20     // Get camera configuration from header if not already defined
    21     // Construct camera in preparation for reading
    22     ppImageParseCamera(data, config);
     13    // Set various tasks (define optional operations)
     14    ppImageOptions *options = ppImageOptionsParse(config);
    2315
    24     // Set various tasks (define optional operations)
    25     ppImageOptionsParse(data, options, config);
    26 
    27 #if 0
    28     // XXX I think we do this in ppImageParseCamera
    29 
    30     // open detrend images, load headers, optionally load pixels
    31     ppImageParseDetrend(data, options, config);
    32 #endif
     16    // define the active I/O files
     17    ppImageParseDetrend(options, config);
    3318
    3419    // Image Arithmetic Loop
    35     ppImageLoop(data, options, config);
     20    ppImageLoop(options, config);
    3621
    3722    // Cleaning up
    38     psFree(data);
    3923    psFree(options);
    4024    psFree(config);
     
    4327    pmConceptsDone();
    4428    pmConfigDone();
    45     ppMemCheck();
    46 
     29    // ppMemCheck();
     30    fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "ppImage");
    4731    return EXIT_SUCCESS;
    4832}
  • trunk/ppImage/src/ppImage.h

    r6747 r6817  
    22#define PP_IMAGE_H
    33
     4#include <stdio.h>
    45#include "pslib.h"
    56#include "psmodules.h"
    6 
    7 #include "ppImageData.h"
    87#include "ppImageOptions.h"
     8#include "ppMem.h"
    99
    1010#define RECIPE_NAME "PHASE2"            // Name of the recipe to use
     
    1515
    1616// Determine what type of camera, and initialise
    17 bool ppImageParseCamera(ppImageData *data,   // The data to be processed
    18                         pmConfig *config // Configuration
    19                         );
    20 
     17bool ppImageParseDetrend(ppImageOptions *options, pmConfig *config);
    2118
    2219// Loop over the input
    23 bool ppImageLoop(ppImageData *data, ppImageOptions *options, pmConfig *config);
     20bool ppImageLoop(ppImageOptions *options, pmConfig *config);
    2421
    25 // Load the pixels for the given file
    26 bool ppImageLoadPixels(ppFile *input,   // File for which to load the pixels
    27                        psDB *db,        // Database handle (for reading concepts)
    28                        int nChip,       // Chip number to load
    29                        int nCell        // Cell number to load
    30                        );
     22// perform the detrend analysis on the current readout
     23bool ppImageDetrendReadout (ppImageOptions *options, pmConfig *config, pmFPAview *view);
    3124
    32 bool ppImageParseDetrend(ppImageData *data, ppImageOptions *options, pmConfig *config);
     25bool ppImageDetrendBias(pmReadout *inputReadout, pmReadout *bias, pmReadout *dark, ppImageOptions *options);
     26bool ppImageDetrendMask(pmReadout *input, pmReadout *mask);
    3327
    34 bool ppReadoutWeights(pmReadout *readout);
    35 
    36 #if 0
    37 // These functions are not implemented, or not needed
    38 pmReadout* ppDetrendPedestal(pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppImageOptions *options);
    39 bool ppImageOutput(ppImageData *data, pmConfig *config);
    40 bool ppImagePhot(ppImageData *data, ppImageOptions *options, pmConfig *config);
    41 bool ppFileOpen(ppFile *fpa, char *name, bool doThis);
    42 #endif
     28bool ppImageDetrendNonLinear(pmReadout *input, ppImageOptions *options);
     29bool ppImageDetrendNonLinearLookup(pmReadout *input, psMetadataItem *dataItem);
     30bool ppImageDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem);
    4331
    4432#endif // Pau.
  • trunk/ppImage/src/ppImageConfig.c

    r6747 r6817  
    1 #include <stdio.h>
    2 #include "pslib.h"
    3 #include "psmodules.h"
    41#include "ppImage.h"
     2
     3static void usage (void) {
     4    fprintf (stderr, "USAGE: ppImage [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n");
     5    exit (2);
     6}
    57
    68pmConfig *ppImageConfig(int argc, char **argv)
    79{
     10
     11    bool status;
     12
     13    if (argc == 1) usage ();
     14
     15    // load the site-wide configuration information
    816    pmConfig *config = pmConfigRead(&argc, argv);
    917    if (! config) {
     
    1220    }
    1321
    14     // Parse other command-line arguments
     22    // Parse other command-line arguments, save for future use
    1523    config->arguments = psMetadataAlloc(); // The arguments, with default values
    16     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-key", 0, "exposure ID", "");
    17     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-bias", 0, "Name of the bias image", "");
    18     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-dark", 0, "Name of the dark image", "");
    19     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-flat", 0, "Name of the flat-field image", "");
    20     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-mask", 0, "Name of the mask image", "");
    21     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-fringe", 0, "Name of the fringe image", "");
    22     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)", -1);
    2324
    24     if (! psArgumentParse(config->arguments, &argc, argv) || argc != 3) {
    25         printf("\nPan-STARRS Phase 2 processing\n\n");
    26         printf("Usage: %s INPUT.fits OUTPUT.fits\n\n", argv[0]);
    27         psArgumentHelp(config->arguments);
    28         psFree(config->arguments);
    29         exit(EXIT_FAILURE);
     25    // if these command-line options are supplied, load the file name lists into config->arguments
     26    // override any configuration-specified source for these files
     27    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "BIAS", "-bias", "-biaslist");
     28    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "DARK", "-dark", "-darklist");
     29    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "FLAT", "-flat", "-flatlist");
     30    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist");
     31    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "FRINGE", "-fringe", "-fringelist");
     32
     33    // other command-line options
     34    // XXX not sure how these are to be used at the moment
     35    // psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-key", 0, "exposure ID", "");
     36    // psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)", -1);
     37
     38    // the input file is a required argument; if not found, we will exit
     39    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
     40    if (!status) { usage ();}
     41
     42    if (! psArgumentParse(config->arguments, &argc, argv) || argc != 2) {
     43        usage ();
    3044    }
    3145
    3246    // Add the input and output images (which remain on the command-line) to the arguments list
    33     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-input",  0, "Name of the input image",  argv[1]);
    34     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-output", 0, "Name of the output image", argv[2]);
     47    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]);
     48
     49    // the input image(s) are required arguments
     50    // the first one defines the camera
     51    status = false;
     52    pmFPAfileFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT");
     53    if (!status) {
     54        psAbort (__func__, "missing INPUT entry");
     55    }
    3556
    3657    // Define database handle, if used
  • trunk/ppImage/src/ppImageDetrendBias.c

    r6747 r6817  
    1 #include <stdio.h>
    2 #include "pslib.h"
    3 #include "psmodules.h"
    4 #include "ppImageOptions.h"
    5 #include "ppImageDetrend.h"
     1#include "ppImage.h"
    62
    73bool ppImageDetrendBias(pmReadout *inputReadout, pmReadout *bias, pmReadout *dark, ppImageOptions *options)
  • trunk/ppImage/src/ppImageDetrendCell.c

    r6747 r6817  
    1 #include <stdio.h>
    2 #include "pslib.h"
    3 #include "psmodules.h"
    4 #include "ppImageDetrend.h"
    5 #include "ppImageOptions.h"
     1#include "ppImage.h"
    62
    7 // mask, bias, dark, flat are defined per Cell
     3bool ppImageDetrendReadout (ppImageOptions *options, pmConfig *config, pmFPAview *view) {
    84
    9 pmReadout *ppImageDetrendSelectFirst(pmCell *cell, char *name, bool doThis)
    10 {
    11     if (!doThis) {
    12         return NULL;
     5    bool status;
     6    pmFPAfile *file;
     7
     8    // construct a view for the detrend images (which have only one readout)
     9    pmFPAview *detview = pmFPAviewAlloc (0);
     10    *detview = *view;
     11    detview->readout = 0;
     12
     13    // find the currently selected readout
     14    file = psMetadataLookupPtr (&status, config->files, "PPIMAGE.INPUT");
     15    pmReadout *input = pmFPAviewThisReadout (view, file->fpa);
     16
     17    pmReadoutSetWeights (input);
     18
     19    // Mask bad pixels
     20    if (options->doMask) {
     21        file = psMetadataLookupPtr (&status, config->files, "PPIMAGE.MASK");
     22        pmReadout *mask = pmFPAviewThisReadout (detview, file->fpa);
     23        ppImageDetrendMask(input, mask);
    1324    }
    1425
    15     if (cell->readouts->n > 1) {
    16         psLogMsg("phase2", PS_LOG_WARN, "%s contains multiple readouts: only the first will be used.", name);
     26# if 0
     27    // Non-linearity correction
     28    if (options->doNonLin) {
     29        ppImageDetrendNonLinear(detrend->input, input, options);
     30    }
     31# endif
     32
     33    // set up the readouts for dark and bias
     34    pmReadout  *dark = NULL;
     35    pmReadout  *bias = NULL;
     36    if (options->doBias) {
     37        file   = psMetadataLookupPtr (&status, config->files, "PPIMAGE.BIAS");
     38        bias = pmFPAviewThisReadout (detview, file->fpa);
     39    }
     40    if (options->doDark) {
     41        file   = psMetadataLookupPtr (&status, config->files, "PPIMAGE.DARK");
     42        dark = pmFPAviewThisReadout (detview, file->fpa);
    1743    }
    1844
    19     pmReadout *readout = cell->readouts->data[0]; // Readout of interest in this cell
     45    // Bias, dark and overscan subtraction are all merged.
     46    ppImageDetrendBias(input, bias, dark, options);
    2047
    21     return readout;
     48    // Flat-field correction (no options used?)
     49    if (options->doFlat) {
     50        file = psMetadataLookupPtr (&status, config->files, "PPIMAGE.FLAT");
     51        pmReadout *flat = pmFPAviewThisReadout (detview, file->fpa);
     52        pmFlatField(input, flat);
     53    }
     54
     55    psFree (detview);
     56    return true;
    2257}
    2358
    24 bool ppImageDetrendCell(ppImageDetrend *detrend, ppImageOptions *options, pmConfig *config)
    25 {
    26 #if 0
    27     pmCellSetWeights(detrend->input);
    28 #endif
     59    // XXX in psphot, the recipe options are parsed at this depth
     60    // XXX consider if we move ppImageOptions in here
     61    // psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PSPHOT");
    2962
    30     pmReadout *mask = ppImageDetrendSelectFirst(detrend->mask, "mask", options->doMask);
    31     pmReadout *bias = ppImageDetrendSelectFirst(detrend->bias, "bias", options->doBias);
    32     pmReadout *dark = ppImageDetrendSelectFirst(detrend->dark, "dark", options->doDark);
    33     pmReadout *flat = ppImageDetrendSelectFirst(detrend->flat, "flat", options->doFlat);
    34 
    35 #if 0
    36     printf("Flat type: %x\n", flat->image->type.type);
    37     printf("Flat value: %f\n", flat->image->data.F32[flat->image->numRows/2][flat->image->numCols/2]);
    38 #endif
    39 
    40     for (int k = 0; k < detrend->input->readouts->n; k++) {
    41 
    42         pmReadout *input = detrend->input->readouts->data[k]; // Readout of interest in input image
    43 
    44         // Mask bad pixels
    45         if (options->doMask) {
    46             ppImageDetrendMask(detrend->input, input, mask);
    47         }
    48 
    49         // Non-linearity correction
    50         if (options->doNonLin) {
    51             ppImageDetrendNonLinear(detrend->input, input, options);
    52         }
    53 
    54         // Bias, dark and overscan subtraction are all merged.
    55         ppImageDetrendBias(input, bias, dark, options);
    56 
    57         // Flat-field correction (no options used?)
    58         if (options->doFlat) {
    59             pmFlatField(input, flat);
    60         }
    61     }
    62     return true;
    63 }
  • trunk/ppImage/src/ppImageDetrendMask.c

    r6747 r6817  
    1 #include <stdio.h>
    2 #include "psmodules.h"
    3 #include "ppImageDetrend.h"
     1#include "ppImage.h"
    42
    53# define MASK_MODE (PM_MASK_TRAP | PM_MASK_BADCOL | PM_MASK_SAT)
     
    75// XXX pass 'concepts' not 'cell' to this function?
    86
    9 bool ppImageDetrendMask(pmCell *cell, pmReadout *input, pmReadout *mask) {
     7bool ppImageDetrendMask(pmReadout *input, pmReadout *mask) {
    108
    11     float saturation = psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION");
     9    psImage *image = NULL;
     10
     11    float saturation = psMetadataLookupF32(NULL, input->parent->concepts, "CELL.SATURATION");
    1212
    1313    // Need to change this later to grow the mask by the size of the convolution kernel
    1414    // XXX does this function respect the mask / image cell region information?
    1515    // XXX should probably take pmRegion *mask
    16     pmMaskBadPixels(input, mask->image, MASK_MODE, saturation, PM_MASK_TRAP, 0);
     16
     17    if (mask->image->type.type != PS_TYPE_MASK) {
     18        image = psImageCopy (NULL, mask->image, PS_TYPE_MASK);
     19    } else {
     20        image = psMemIncrRefCounter (mask->image);
     21    }
     22
     23    pmMaskBadPixels(input, image, MASK_MODE, saturation, PM_MASK_TRAP, 0);
     24    psFree (image);
    1725
    1826    return true;
    1927}
     28
     29
     30// XXX the translation here should not be needed
     31// the mask should (but is not) be read in using the mask read functions
     32// by identifying the image type as a mask (in pmFPAfile).
     33// currently, pmFPAfileReadImage converts the image to F32
  • trunk/ppImage/src/ppImageDetrendNonLinear.c

    r6747 r6817  
    1 #include <stdio.h>
    2 #include "pslib.h"
    3 #include "psmodules.h"
    4 #include "ppImageDetrend.h"
     1#include "ppImage.h"
    52
    63bool ppImageDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem) {
     
    4340}
    4441
    45 bool ppImageDetrendNonLinear(pmCell *cell, pmReadout *input, ppImageOptions *options) {
     42bool ppImageDetrendNonLinear(pmReadout *input, ppImageOptions *options) {
    4643
    4744    psMetadataItem *concept;
     45    pmCell *cell = input->parent;
    4846
    4947    switch (options->nonLinearType) {
  • trunk/ppImage/src/ppImageLoop.c

    r6775 r6817  
    1 #include <stdio.h>
    2 #include "pslib.h"
    3 #include "psmodules.h"
    4 #include "ppImageDetrend.h"
    5 #include "ppImage.h"
    6 #include "ppMem.h"
     1# include "ppImage.h"
    72
    8 #define MEM_LEAKS 1
     3bool ppImageLoop (ppImageOptions *options, pmConfig *config) {
    94
    10 // Read the entire FPA
    11 void readFPA(ppFile *file,              // File to read
    12              pmConfig *config           // Configuration, containing the DB handle
    13     )
    14 {
    15     if (file->fpa && file->fits) {
    16         pmFPARead(file->fpa, file->fits, config->database);
     5    bool status;
     6    pmChip *chip;
     7    pmCell *cell;
     8    pmReadout *readout;
     9
     10    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPIMAGE.INPUT");
     11    if (!status) {
     12        psErrorStackPrint(stderr, "Can't find input data!\n");
     13        exit(EXIT_FAILURE);
    1714    }
     15
     16    pmFPAview *view = pmFPAviewAlloc (0);
     17
     18    // files associated with the science image
     19    pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE);
     20
     21    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
     22        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     23        if (!chip->process || !chip->file_exists) { continue; }
     24        pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE);
     25
     26        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
     27            psLogMsg ("psphot", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     28            if (!cell->process || !cell->file_exists) { continue; }
     29            pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE);
     30
     31            // process each of the readouts
     32            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
     33                pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE);
     34                if (! readout->data_exists) { continue; }
     35
     36                // perform the detrend analysis
     37                ppImageDetrendReadout (options, config, view);
     38
     39                pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER);
     40            }
     41            pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER);
     42        }
     43
     44        // ppImageChipMosaic (config, view);
     45        // ppImagePSPhot (config, view);
     46        // ppImagePSAstro (config, view);
     47
     48        pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER);
     49
     50        // XXX paul added these frees: make sure the same is happening in the pmFileIOChecks
     51        // Now I can blow away the mosaic so I can then read more.
     52        // psFree(inputChip);
     53        // psFree(biasChip);
     54        // psFree(darkChip);
     55        // psFree(maskChip);
     56        // psFree(flatChip);
     57        // ppMemUsed();
     58    }
     59
     60    // ppImageFPAMosaic (config, view);
     61    // ppImageJpegFPA (config, view);
     62
     63    pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER);
     64
     65    psFree (view);
     66    return true;
    1867}
    1968
    20 // Read a specified chip only
    21 void readChip(ppFile *file,             // File to read
    22               pmConfig *config,         // Configuration
    23               int chipNum               // Chip number to read
    24     )
    25 {
    26     pmFPA *fpa = file->fpa;             // The FPA
    27     if (fpa && file->fits) {
    28         pmChip *chip = fpa->chips->data[chipNum]; // The chip
    29         pmChipRead(chip, file->fits, config->database);
    30     }
    31 }
    32 
    33 
    34 void readCell(ppFile *file, pmConfig *config, int chipNum, int cellNum)
    35 {
    36     pmFPA *fpa = file->fpa;             // The FPA
    37     if (fpa && file->fits) {
    38         pmChip *chip = fpa->chips->data[chipNum]; // The chip
    39         if (chip) {
    40             pmCell *cell = chip->cells->data[cellNum]; // The cell
    41             pmCellRead(cell, file->fits, config->database);
    42         }
    43     }
    44 }
    45 
    46 
    47 bool ppImageLoop(ppImageData *data, ppImageOptions *options, pmConfig *config)
    48 {
    49     ppImageDetrend detrend;
    50 
    51     int processChip = psMetadataLookupS32(NULL, config->arguments, "-chip"); // Chip number to process or -1
    52 
    53     // Load at FPA level if requested
    54     if (processChip < 0 && options->imageLoadDepth == PP_LOAD_FPA) {
    55         psTrace(__func__, 1, "Loading pixels for FPA...\n");
    56         readFPA(data->input, config);
    57         readFPA(data->bias,  config);
    58         readFPA(data->dark,  config);
    59         readFPA(data->mask,  config);
    60         readFPA(data->flat,  config);
    61     }
    62 
    63     psArray *chips = data->input->fpa->chips; // Component chips
    64     for (int i = 0; i < chips->n; i++) {
    65 
    66         if (processChip >= 0 && i != processChip) {
    67             continue;
    68         }
    69         if (options->imageLoadDepth == PP_LOAD_CHIP) {
    70             psTrace(__func__, 1, "Loading pixels for chip %d...\n", i);
    71             readChip(data->input, config, i);
    72             readChip(data->bias,  config, i);
    73             readChip(data->dark,  config, i);
    74             readChip(data->mask,  config, i);
    75             readChip(data->flat,  config, i);
    76         }
    77 
    78         pmChip *inputChip = chips->data[i];
    79         pmChip *biasChip  = data->bias->fpa->chips->data[i];
    80         pmChip *darkChip  = data->dark->fpa->chips->data[i];
    81         pmChip *maskChip  = data->mask->fpa->chips->data[i];
    82         pmChip *flatChip  = data->flat->fpa->chips->data[i];
    83 
    84         psArray *cells = inputChip->cells;
    85         for (int j = 0; j < cells->n; j++) {
    86             detrend.input = inputChip->cells->data[j]; // Cell of interest in input image
    87             detrend.bias  = biasChip->cells->data[j];  // Cell of interest in bias image
    88             detrend.dark  = darkChip->cells->data[j];  // Cell of interest in dark imag
    89             detrend.mask  = maskChip->cells->data[j];  // Cell of interest in mask image
    90             detrend.flat  = flatChip->cells->data[j];  // Cell of interest in flat image
    91 
    92             if (! detrend.input->process) { continue; }
    93 
    94             if (options->imageLoadDepth == PP_LOAD_CELL) {
    95                 psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j);
    96                 readCell(data->input, config, i, j);
    97                 readCell(data->bias,  config, i, j);
    98                 readCell(data->dark,  config, i, j);
    99                 readCell(data->mask,  config, i, j);
    100                 readCell(data->flat,  config, i, j);
    101             }
    102 
    103             ppImageDetrendCell(&detrend, options, config);
    104 
    105             // Need to free detrend cells here so we have enough memory to do other stuff
    106             psFree(detrend.bias);
    107             psFree(detrend.dark);
    108             psFree(detrend.mask);
    109             psFree(detrend.flat);
    110         }
    111 
    112 #if 0
    113         int numMosaicked = pmChipMosaic(inputChip, 1, 1); // Number of cells mosaicked together
    114         psLogMsg(__func__, PS_LOG_INFO, "%d cells mosaicked.\n", numMosaicked);
    115 
    116         // XXX A kludge to get the write to behave w.r.t. the concepts --- we've changed the camera format, so
    117         // the concepts don't know what on earth to do.
    118         const psMetadata *camera = data->input->fpa->camera;
    119         data->input->fpa->camera = NULL;
    120 #endif
    121 
    122         // XXX Photometry goes here!
    123 
    124         pmChipWrite(inputChip, data->output, config->database);
    125 
    126 #if 0
    127         data->input->fpa->camera = camera;
    128 #endif
    129 
    130         // Now I can blow away the mosaic so I can then read more.
    131         psFree(inputChip);
    132         psFree(biasChip);
    133         psFree(darkChip);
    134         psFree(maskChip);
    135         psFree(flatChip);
    136 
    137         ppMemUsed();
    138     }
    139 
    140     return true;
    141 }
  • trunk/ppImage/src/ppImageOptions.c

    r6747 r6817  
    1 #include <stdio.h>
    2 #include "pslib.h"
    31#include "ppImage.h"
    4 #include "ppImageData.h"
    5 #include "ppImageOptions.h"
    62
    73static void imageOptionsFree(ppImageOptions *options)
     
    2521}
    2622
    27 
    28 // XXX EAM : this needs signficant work to choose the detrend images based on the detrend database
    29 
    30 bool ppImageOptionsParse(ppImageData *data, ppImageOptions *options, pmConfig *config)
     23ppImageOptions *ppImageOptionsParse(pmConfig *config)
    3124{
    3225
    33     // Flags for various activities
    34     options->doMask = false;            // Mask bad pixels
    35     options->doNonLin = false;          // Non-linearity correction
    36     options->doBias = false;            // Bias subtraction
    37     options->doDark = false;            // Dark subtraction
     26    ppImageOptions *options = ppImageOptionsAlloc ();
     27
     28    // default flags for various activities
     29    options->doMask     = false;        // Mask bad pixels
     30    options->doNonLin   = false;        // Non-linearity correction
     31    options->doBias     = false;        // Bias subtraction
     32    options->doDark     = false;        // Dark subtraction
    3833    options->doOverscan = false;        // Overscan subtraction
    39     options->doFlat = false;            // Flat-field normalisation
    40     options->doFringe = false;          // Fringe subtraction
    41     options->doSource = false;          // Source identification and photometry
    42     options->doAstrom = false;          // Astrometry
    43     // Overscan options
    44     options->overscan = NULL;           // Overscan options
    45     bool overscanSingle = false;        // A single value for entire overscan?
    46     pmFit overscanFit = PM_FIT_NONE;    // Fit type for overscan
    47     int overscanOrder = 0;              // Order for overscan fit
     34    options->doFlat     = false;        // Flat-field normalisation
     35    options->doFringe   = false;        // Fringe subtraction
     36    options->doSource   = false;        // Source identification and photometry
     37    options->doAstrom   = false;        // Astrometry
     38
     39    // Overscan defaults
     40    options->overscan      = NULL;      // Overscan options
     41    bool overscanSingle    = false;     // A single value for entire overscan?
     42    pmFit overscanFit      = PM_FIT_NONE; // Fit type for overscan
     43    int overscanOrder      = 0;         // Order for overscan fit
    4844    psStats *overscanStats = NULL;      // Statistics for overscan
    49     // Non-linearity options
    50     options->nonLinearType = 0;         // Type of non-linearity data (vector, string or metadata)
    51     options->nonLinearData = NULL;      // The non-linearity data
     45
     46    // Non-linearity default options
     47    options->nonLinearType   = 0;       // Type of non-linearity data (vector, string or metadata)
     48    options->nonLinearData   = NULL;    // The non-linearity data
    5249    options->nonLinearSource = NULL;    // If the non-linearity data is a menu, this provides the key
    53     // Various others
    54     options->imageLoadDepth = PP_LOAD_NONE; // No load depth specified yet
    5550
    56 
     51    // select the recipe for this analysis
    5752    bool mdStatus = false;              // Result of MD lookup
    5853    psMetadata *recipe = psMetadataLookupMD(&mdStatus, config->recipes, RECIPE_NAME);
     
    6055        psLogMsg("ppImage", PS_LOG_ERROR, "Can't find recipe %s in the RECIPES.\n", RECIPE_NAME);
    6156        exit(EXIT_FAILURE);
    62     }
    63 
    64     const char *depth = psMetadataLookupStr(&mdStatus, recipe, "LOAD.DEPTH");
    65     if (! mdStatus || ! depth || strlen(depth) == 0) {
    66         psLogMsg("ppImage", PS_LOG_ERROR, "LOAD.DEPTH not specified in recipe.");
    67         exit(EXIT_FAILURE);
    68     }
    69     if (!strcasecmp(depth, "FPA")) {
    70         options->imageLoadDepth = PP_LOAD_FPA;
    71     } else if (!strcasecmp(depth, "CHIP")) {
    72         options->imageLoadDepth = PP_LOAD_CHIP;
    73     } else if (!strcasecmp(depth, "CELL")) {
    74         options->imageLoadDepth = PP_LOAD_CELL;
    75     } else {
    76         psLogMsg(__func__, PS_LOG_ERROR, "LOAD.DEPTH in recipe %s is not FPA, CHIP or CELL.", RECIPE_NAME);
    77         exit(EXIT_FAILURE);
    78     }
    79 
    80     // Mask recipe options
    81     if (psMetadataLookupBool(NULL, recipe, "MASK")) {
    82         data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask");
    83         if (data->mask->filename && strlen(data->mask->filename) > 0) {
    84             options->doMask = true;
    85         } else {
    86             psLogMsg(__func__, PS_LOG_WARN, "Masking is desired, but no mask was supplied"
    87                      " --- no masking will be performed.\n");
    88         }
    8957    }
    9058
     
    12492                    "NONLIN.DATA is of invalid type in recipe %s.", RECIPE_NAME);
    12593            exit(EXIT_FAILURE);
    126         }
    127     }
    128 
    129     // Bias recipe options
    130     if (psMetadataLookupBool(NULL, recipe, "BIAS")) {
    131         data->bias->filename = psMetadataLookupStr(NULL, config->arguments, "-bias");
    132         if (data->bias->filename && strlen(data->bias->filename) > 0) {
    133             options->doBias = true;
    134         } else {
    135             psLogMsg(__func__, PS_LOG_WARN, "Bias subtraction is desired in recipe %s, but no bias was "
    136                      "supplied --- no bias subtraction will be performed.\n", RECIPE_NAME);
    137         }
    138     }
    139 
    140     // Dark recipe options
    141     if (psMetadataLookupBool(NULL, recipe, "DARK")) {
    142         data->dark->filename = psMetadataLookupStr(NULL, config->arguments, "-dark");
    143         if (data->dark->filename && strlen(data->dark->filename) > 0) {
    144             options->doDark = true;
    145         } else {
    146             psLogMsg(__func__, PS_LOG_WARN, "Dark subtraction is desired in recipe %s, but no dark was "
    147                      "supplied --- no dark subtraction will be performed.\n", RECIPE_NAME);
    14894        }
    14995    }
     
    190136    }
    191137
    192     // flat-field - recipe options
    193     if (psMetadataLookupBool(NULL, recipe, "FLAT")) {
    194         data->flat->filename = psMetadataLookupStr(NULL, config->arguments, "-flat");
    195         if (strlen(data->flat->filename) > 0) {
    196             options->doFlat = true;
    197         } else {
    198             psLogMsg(__func__, PS_LOG_WARN, "Flat-fielding is desired in recipe %s, but no flat was "
    199                      "supplied --- no flat-fielding will be performed.\n", RECIPE_NAME);
    200         }
     138    // Mask recipe options
     139    if (psMetadataLookupBool(NULL, recipe, "MASK")) {
     140        options->doMask = true;
    201141    }
    202142
    203     // XXX need to add the following:
     143    // Bias recipe options
     144    if (psMetadataLookupBool(NULL, recipe, "BIAS")) {
     145        options->doBias = true;
     146    }
    204147
    205     // fringe - recipe options
     148    // Dark recipe options
     149    if (psMetadataLookupBool(NULL, recipe, "DARK")) {
     150        options->doDark = true;
     151    }
    206152
    207     // photom - recipe options
     153    // Flat recipe options
     154    if (psMetadataLookupBool(NULL, recipe, "FLAT")) {
     155        options->doFlat = true;
     156    }
    208157
    209     // astrom - recipe options
    210 
    211     return true;
     158    return options;
    212159}
  • trunk/ppImage/src/ppImageOptions.h

    r6747 r6817  
    11#ifndef PP_IMAGE_OPTIONS_H
    22#define PP_IMAGE_OPTIONS_H
    3 
    4 #include "pslib.h"
    5 #include "psmodules.h"
    6 #include "ppImageData.h"
    7 #include "ppConfig.h"
    8 
    9 // How much of the FPA to load at a time
    10 typedef enum {
    11     PP_LOAD_NONE,                       // Don't load anything
    12     PP_LOAD_FPA,                        // Load the entire FPA at once
    13     PP_LOAD_CHIP,                       // Load by chip
    14     PP_LOAD_CELL,                       // Load by cell
    15 } ppImageLoadDepth;
    163
    174// Options for ppImage processing
     
    3017    psMetadataItem *nonLinearData;
    3118    void *nonLinearSource;
    32     ppImageLoadDepth imageLoadDepth;    // How much of the FPA to load at once
    3319} ppImageOptions;
    3420
     
    3622
    3723// Determine the processing options
    38 bool ppImageOptionsParse(ppImageData *data, // The data to be processed
    39                          ppImageOptions *options, // Processing options
    40                          pmConfig *config    // Configuration
    41     );
     24ppImageOptions *ppImageOptionsParse(pmConfig *config);
    4225
    4326#endif
  • trunk/ppImage/src/ppImageParseDetrend.c

    r6747 r6817  
    1 #include <stdio.h>
    2 #include "pslib.h"
    3 #include "psmodules.h"
    4 #include "ppFile.h"
    5 #include "ppImageData.h"
    6 #include "ppImageOptions.h"
    71#include "ppImage.h"
    82
    9 // open all needed detrend files
    10 // read in primary headers
    11 // validate camera for each detrend image
     3// identify all needed detrend and other I/O files
     4// create the pmFPAfiles for the active I/O files
    125
    13 // XXX : keep the primary headers in data?
    14 // XXX : add fringe frame
     6bool ppImageParseDetrend(ppImageOptions *options, pmConfig *config)
     7{
    158
    16 bool ppImageParseDetrend(ppImageData *data, ppImageOptions *options, pmConfig *config)
    17 {
    18     ppFileOpen(data->mask, "mask", options->doMask);
    19     ppFileOpen(data->bias, "bias", options->doBias);
    20     ppFileOpen(data->dark, "dark", options->doDark);
    21     ppFileOpen(data->flat, "flat", options->doFlat);
     9    bool status;
     10
     11    // some of the output files are associated with the input fpa
     12    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPIMAGE.INPUT");
     13
     14    // the following are defined from the argument list, if given,
     15    // otherwise they revert to the config information
     16
     17    if (options->doBias) {
     18        bool status = false;
     19        pmFPAfileFromArgs (&status, config, "PPIMAGE.BIAS", "BIAS");
     20        pmFPAfileFromConf (&status, config, "PPIMAGE.BIAS", input->fpa);
     21        if (!status) psAbort ("ppImageParseDetrend", "can't find a bias image source");
     22    }
     23
     24    if (options->doDark) {
     25        bool status = false;
     26        pmFPAfileFromArgs (&status, config, "PPIMAGE.DARK", "DARK");
     27        pmFPAfileFromConf (&status, config, "PPIMAGE.DARK", input->fpa);
     28        if (!status) psAbort ("ppImageParseDetrend", "can't find a dark image source");
     29    }
     30
     31    if (options->doMask) {
     32        bool status = false;
     33        pmFPAfileFromArgs (&status, config, "PPIMAGE.MASK", "MASK");
     34        pmFPAfileFromConf (&status, config, "PPIMAGE.MASK", input->fpa);
     35        if (!status) psAbort ("ppImageParseDetrend", "can't find a mask image source");
     36    }
     37
     38    if (options->doFlat) {
     39        bool status = false;
     40        pmFPAfileFromArgs (&status, config, "PPIMAGE.FLAT", "FLAT");
     41        pmFPAfileFromConf (&status, config, "PPIMAGE.FLAT", input->fpa);
     42        if (!status) psAbort ("ppImageParseDetrend", "can't find a flat image source");
     43    }
     44
     45    // the following files are output targets
     46    // XXX which of these are required?
     47    pmFPAfileDefine (config->files, config->camera, input->fpa, "PPIMAGE.OUTPUT");
     48
     49    // XXX do these need to construct a new fpa?
     50    // pmFPAfileDefine (config->files, config->camera, input->input, "PPIMAGE.BIN1");
     51    // pmFPAfileDefine (config->files, config->camera, input->input, "PPIMAGE.BIN2");
     52    // pmFPAfileDefine (config->files, config->camera, input->input, "PPIMAGE.JPG1");
     53    // pmFPAfileDefine (config->files, config->camera, input->input, "PPIMAGE.JPG2");
     54
     55    // ppImage is supplied with an output name, which may be used by multiple
     56    // output files to construct the output names.  supply this value to the
     57    // files which are write types.
     58    char *output = psMetadataLookupPtr(&status, config->arguments, "OUTPUT");
     59    pmFPAfileAddFileNames (config->files, "OUTPUT", output, PM_FPA_MODE_WRITE);
     60
    2261    return true;
    2362}
Note: See TracChangeset for help on using the changeset viewer.