IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23268 for trunk/ppImage/src


Ignore:
Timestamp:
Mar 11, 2009, 10:54:22 AM (17 years ago)
Author:
Paul Price
Message:

Adding functionality of reading input files from the configuration dump. This is principally used for ensuring we apply the same detrend images with ppImage that we used originally. Applying this framework to ppImage. Will soon apply to other products. Reworked the pmFPAfileDefineFrom* functions to use common code; I think it still works.

Location:
trunk/ppImage/src
Files:
3 edited

Legend:

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

    r23242 r23268  
    108108
    109109    // the input file is a required argument; if not found, we will exit
    110     bool status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
    111     if (!status) {
    112         usage ();
    113     }
     110    pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
    114111
    115112    // if these command-line options are supplied, load the file name lists into config->arguments
     
    142139        psArgumentRemove(argnum, &argc, argv);
    143140
    144         unsigned int nFail = 0;
    145         psMetadata *normlist = psMetadataConfigRead (NULL, &nFail, argv[argnum], false);
    146         // XXX allow this file to be in nebulous?
     141        unsigned int nFail = 0;
     142        psMetadata *normlist = psMetadataConfigRead (NULL, &nFail, argv[argnum], false);
     143        // XXX allow this file to be in nebulous?
    147144
    148145        psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "NORMALIZATION.TABLE", 0, "Normalization to apply", normlist);
    149         psFree (normlist);
     146        psFree (normlist);
    150147        psArgumentRemove(argnum, &argc, argv);
    151148    }
  • trunk/ppImage/src/ppImageDefineFile.c

    r13562 r23268  
    55# include "ppImage.h"
    66
    7 bool ppImageDefineFile (pmConfig *config, pmFPA *input, char *filerule, char *argname, pmFPAfileType fileType, pmDetrendType detrendType) {
     7bool ppImageDefineFile(pmConfig *config, pmFPA *input, char *filerule, char *argname,
     8                       pmFPAfileType fileType, pmDetrendType detrendType)
     9{
     10    bool status;
     11    pmFPAfile *file = NULL;             // File to be defined
    812
    9     bool status;
    10     pmFPAfile *file;
    11 
    12     // look for the file on the argument list
    13     file = pmFPAfileDefineFromArgs  (&status, config, filerule, argname);
    14     if (!status) {
    15         psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
    16         return false;
     13    if (!file) {
     14        // look for the file on the RUN metadata
     15        file = pmFPAfileDefineFromRun(&status, config, filerule);
     16        if (!status) {
     17            psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
     18            return false;
     19        }
    1720    }
    18     if (file) {
    19         if (file->type != fileType) {
    20             psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
    21             return false;
    22         }
    23         return true;
     21    if (!file) {
     22        // look for the file on the argument list
     23        file = pmFPAfileDefineFromArgs(&status, config, filerule, argname);
     24        if (!status) {
     25            psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
     26            return false;
     27        }
     28    }
     29    if (!file) {
     30        // look for the file in the camera config table
     31        file = pmFPAfileDefineFromConf(&status, config, filerule);
     32        if (!status) {
     33            psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
     34            return false;
     35        }
     36    }
     37    if (!file) {
     38        // look for the file to be loaded from the detrend database
     39        file = pmFPAfileDefineFromDetDB(&status, config, filerule, input, detrendType);
     40        if (!status) {
     41            psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
     42            return false;
     43        }
    2444    }
    2545
    26     // look for the file in the camera config table
    27     file = pmFPAfileDefineFromConf  (&status, config, filerule);
    28     if (!status) {
    29         psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
    30         return false;
    31     }
    32     if (file) {
    33         if (file->type != fileType) {
    34             psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
    35             return false;
    36         }
    37         return true;
     46    if (!file) {
     47        return false;
    3848    }
    3949
    40     // look for the file to be loaded from the detrend database
    41     file = pmFPAfileDefineFromDetDB (&status, config, filerule, input, detrendType);
    42     if (!status) {
    43         psError (PS_ERR_UNKNOWN, false, "failed to load file definition");
    44         return false;
     50    if (file->type != fileType) {
     51        psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
     52        return false;
    4553    }
    46     if (file) {
    47         if (file->type != fileType) {
    48             psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
    49             return false;
    50         }
    51         return true;
    52     }
    53     return false;
     54    return true;
    5455}
    5556
  • trunk/ppImage/src/ppImageParseCamera.c

    r21364 r23268  
    99    bool status = false;
    1010
    11     // the input image defines the camera, and all recipes and options the follow
    12     pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT");
    13     if (!status || !input) {
    14         psError(PS_ERR_IO, false, "Failed to build FPA from PPIMAGE.INPUT");
    15         return NULL;
    16     }
    17     if (input->type != PM_FPA_FILE_IMAGE) {
    18         psError(PS_ERR_IO, true, "PPIMAGE.INPUT is not of type IMAGE");
    19         return NULL;
    20     }
    21 
    22     // if MASK or VARIANCE was supplied on command line, bind files to 'input'.
    23     // the mask and variance will be mosaicked with the image
    24     pmFPAfile *inputMask = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.MASK", "PPIMAGE.INPUT.MASK");
    25     if (!status) {
    26         psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
    27         return NULL;
    28     }
    29     if (inputMask) {
    30       if (inputMask->type != PM_FPA_FILE_MASK) {
    31         psError(PS_ERR_IO, true, "PPIMAGE.INPUT.MASK is not of type MASK");
    32         return NULL;
    33       }
    34     }
    35 
    36     pmFPAfile *inputVariance = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.VARIANCE", "PPIMAGE.INPUT.VARIANCE");
    37     if (!status) {
    38         psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
    39         return NULL;
    40     }
    41     if (inputVariance && inputVariance->type != PM_FPA_FILE_VARIANCE) {
    42         psError(PS_ERR_IO, true, "PPIMAGE.INPUT.VARIANCE is not of type VARIANCE");
    43         return NULL;
    44     }
     11    if (!ppImageDefineFile(config, NULL, "PPIMAGE.INPUT", "INPUT", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_NONE)) {
     12        psError(PS_ERR_IO, false, "Can't find an input image source");
     13        return NULL;
     14    }
     15    pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.INPUT"); // Input file
     16    psAssert(input, "We just put it there!");
    4517
    4618    // add recipe options supplied on command line
    47     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, RECIPE_NAME);
     19    psMetadata *recipe  = psMetadataLookupPtr(&status, config->recipes, RECIPE_NAME);
    4820
    4921    // parse the options from the metadata format to the ppImageOptions structure
    50     ppImageOptions *options = ppImageOptionsParse (config);
     22    ppImageOptions *options = ppImageOptionsParse(config);
    5123
    5224    // the following are defined from the argument list, if given,
     
    5426    // not all input or output images are used in a given recipe
    5527    if (options->doBias) {
    56         if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.BIAS", "BIAS", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_BIAS)) {
    57             psError (PS_ERR_IO, false, "Can't find a bias image source");
    58             psFree (options);
     28        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.BIAS", "BIAS",
     29                               PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_BIAS)) {
     30            psError(PS_ERR_IO, false, "Can't find a bias image source");
     31            psFree(options);
    5932            return NULL;
    6033        }
    6134    }
    6235    if (options->doDark) {
    63         if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.DARK", "DARK", PM_FPA_FILE_DARK, PM_DETREND_TYPE_DARK)) {
    64             psError (PS_ERR_IO, false, "Can't find a dark image source");
    65             psFree (options);
     36        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.DARK", "DARK",
     37                               PM_FPA_FILE_DARK, PM_DETREND_TYPE_DARK)) {
     38            psError(PS_ERR_IO, false, "Can't find a dark image source");
     39            psFree(options);
    6640            return NULL;
    6741        }
    6842    }
    6943    if (options->doMask) {
    70 
    71         if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.MASK", "MASK", PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
    72             psError (PS_ERR_IO, false, "Can't find a mask image source");
    73             psFree (options);
    74             return NULL;
    75         }
     44        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.MASK", "MASK",
     45                               PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
     46            psError(PS_ERR_IO, false, "Can't find a mask image source");
     47            psFree(options);
     48            return NULL;
     49        }
     50
     51#if 0
     52        // I think this is now done automatically in the pmFPAfileDefine and pmFPAfileIOChecks -- PAP.
     53
    7654        // XXX have ppImageDefineFile return the pmFPAfile?
    7755        pmFPAfile *mask = psMetadataLookupPtr(&status, config->files, "PPIMAGE.MASK");
    78         psAssert (mask, "mask not defined?  not possible!");
     56        psAssert(mask, "Just defined the mask!");
    7957
    8058        // Need to read the names of bit masks from the mask header and set them in the
     
    8462            // XXX need to load the mask bit names from one of the headers
    8563            // this grabs the first available hdu : no guarantee that it will be valid, though
    86             pmHDU *hdu = pmHDUGetFirst (mask->fpa);
     64            pmHDU *hdu = pmHDUGetFirst(mask->fpa);
    8765            if (!hdu) {
    8866                psError(PS_ERR_IO, true, "no valid HDU for PPIMAGE.INPUT.MASK");
     
    9068            }
    9169            // XXX is this consistent with the pmConfigMaskReadHeader call above?
    92             if (!pmConfigMaskReadHeader (config, hdu->header)) {
     70            if (!pmConfigMaskReadHeader(config, hdu->header)) {
    9371                psError(PS_ERR_IO, false, "error in mask bits");
    9472                return NULL;
    9573            }
    9674        }
     75#endif
    9776    }
    9877    if (options->doShutter) {
    99         if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.SHUTTER", "SHUTTER", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_SHUTTER)) {
    100             psError (PS_ERR_IO, false, "Can't find a shutter image source");
    101             psFree (options);
     78        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.SHUTTER", "SHUTTER",
     79                               PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_SHUTTER)) {
     80            psError(PS_ERR_IO, false, "Can't find a shutter image source");
     81            psFree(options);
    10282            return NULL;
    10383        }
     
    10585
    10686    if (options->doFlat) {
    107         if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.FLAT", "FLAT", PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_FLAT)) {
    108             psError (PS_ERR_IO, false, "Can't find a flat image source");
    109             psFree (options);
    110             return NULL;
    111         }
    112     }
    113 
    114     int nThreads = psMetadataLookupS32 (&status, config->arguments, "NTHREADS");
     87        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.FLAT", "FLAT",
     88                               PM_FPA_FILE_IMAGE, PM_DETREND_TYPE_FLAT)) {
     89            psError(PS_ERR_IO, false, "Can't find a flat image source");
     90            psFree(options);
     91            return NULL;
     92        }
     93    }
     94
     95    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS");
    11596    if (nThreads > 0) {
    116         int nScanRows = psMetadataLookupS32 (&status, recipe, "SCAN.ROWS");
    117         pmDetrendSetThreadTasks (nScanRows);
     97        int nScanRows = psMetadataLookupS32(&status, recipe, "SCAN.ROWS");
     98        pmDetrendSetThreadTasks(nScanRows);
    11899    }
    119100
     
    166147skip_fringe:
    167148    if (options->doFringe) {
    168         if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.FRINGE", "FRINGE", PM_FPA_FILE_FRINGE, PM_DETREND_TYPE_FRINGE)) {
     149        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.FRINGE", "FRINGE",
     150                               PM_FPA_FILE_FRINGE, PM_DETREND_TYPE_FRINGE)) {
    169151            psError (PS_ERR_IO, false, "Can't find a fringe image source");
    170152            return NULL;
     
    283265        // define associated psphot input/output files
    284266        if (!psphotDefineFiles (config, psphotInput)) {
    285             psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
     267            psError(PSPHOT_ERR_CONFIG, false,
     268                    "Trouble defining the additional input/output files for psphot");
    286269            return false;
    287270        }
     
    291274    if (options->doAstromChip || options->doAstromMosaic) {
    292275        if (!options->doPhotom) {
    293             psError (PSASTRO_ERR_CONFIG, false, "photometry mode is not selected; it is required for astrometry");
     276            psError(PSASTRO_ERR_CONFIG, false,
     277                    "Photometry mode is not selected; it is required for astrometry");
    294278            return false;
    295279        }
    296280
    297         pmFPAfile *psphotOutput = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
    298         PS_ASSERT (psphotOutput, false);
    299 
    300         pmFPAfile *psastroInput = pmFPAfileDefineInput (config, psphotOutput->fpa, NULL, "PSASTRO.INPUT");
    301         PS_ASSERT (psastroInput, false);
     281        pmFPAfile *psphotOutput = psMetadataLookupPtr(&status, config->files, "PSPHOT.OUTPUT");
     282        PS_ASSERT(psphotOutput, false);
     283
     284        pmFPAfile *psastroInput = pmFPAfileDefineInput(config, psphotOutput->fpa, NULL, "PSASTRO.INPUT");
     285        PS_ASSERT(psastroInput, false);
    302286        psastroInput->mode = PM_FPA_MODE_REFERENCE;
    303287
    304288        // define associated psphot input/output files
    305         if (!psastroDefineFiles (config, psastroInput)) {
    306             psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psastro");
     289        if (!psastroDefineFiles(config, psastroInput)) {
     290            psError(PSPHOT_ERR_CONFIG, false,
     291                    "Trouble defining the additional input/output files for psastro");
    307292            return false;
    308293        }
    309294
    310295        // deactivate the psastro files, reactive when needed
    311         pmFPAfileActivate (config->files, false, "PSASTRO.OUTPUT");
     296        pmFPAfileActivate(config->files, false, "PSASTRO.OUTPUT");
    312297    }
    313298
     
    325310
    326311    // outImage is used as a carrier: input to chipImage -> require the data to remain at the CHIP level
    327     outImage->freeLevel = PS_MIN (outImage->freeLevel, PM_FPA_LEVEL_CHIP);
     312    outImage->freeLevel = PS_MIN(outImage->freeLevel, PM_FPA_LEVEL_CHIP);
    328313    outImage->dataLevel = outImage->freeLevel;
    329     outImage->fileLevel = PS_MIN (outImage->fileLevel, outImage->dataLevel);
     314    outImage->fileLevel = PS_MIN(outImage->fileLevel, outImage->dataLevel);
    330315
    331316    // outMask and outVariance must be freed at the same level as outImage (all freed by pmFPAFreeData)
     
    342327
    343328    // the input data is the same as the outImage data : force the free levels to match
    344     input->freeLevel = PS_MIN (outImage->freeLevel, input->freeLevel);
     329    input->freeLevel = PS_MIN(outImage->freeLevel, input->freeLevel);
    345330
    346331    // define the binned target files (which may just be carriers for some camera configurations)
    347     pmFPAfile *bin1 = pmFPAfileDefineFromFPA (config, chipImage->fpa, options->xBin1, options->yBin1, "PPIMAGE.BIN1");
     332    pmFPAfile *bin1 = pmFPAfileDefineFromFPA(config, chipImage->fpa, options->xBin1, options->yBin1,
     333                                             "PPIMAGE.BIN1");
    348334    if (!bin1) {
    349335        psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.BIN1"));
     
    357343    }
    358344
    359     pmFPAfile *bin2 = pmFPAfileDefineFromFPA (config, chipImage->fpa, options->xBin2, options->yBin2, "PPIMAGE.BIN2");
     345    pmFPAfile *bin2 = pmFPAfileDefineFromFPA(config, chipImage->fpa, options->xBin2, options->yBin2,
     346                                             "PPIMAGE.BIN2");
    360347    if (!bin2) {
    361348        psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.BIN2"));
     
    373360    bin2->freeLevel = PM_FPA_LEVEL_FPA;
    374361
    375     pmFPAfile *jpg1 = pmFPAfileDefineOutput (config, byFPA1->fpa, "PPIMAGE.JPEG1");
     362    pmFPAfile *jpg1 = pmFPAfileDefineOutput(config, byFPA1->fpa, "PPIMAGE.JPEG1");
    376363    if (!jpg1) {
    377364        psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.JPEG1"));
     
    384371        return NULL;
    385372    }
    386     pmFPAfile *jpg2 = pmFPAfileDefineOutput (config, byFPA2->fpa, "PPIMAGE.JPEG2");
     373    pmFPAfile *jpg2 = pmFPAfileDefineOutput(config, byFPA2->fpa, "PPIMAGE.JPEG2");
    387374    if (!jpg2) {
    388375        psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.JPEG2"));
     
    404391    // Chip selection: turn on only the chips specified (pass status to suppress missing-key log msg)
    405392    char *chipLine = psMetadataLookupStr(&status, config->arguments, "CHIP_SELECTIONS");
    406     psArray *chips = psStringSplitArray (chipLine, ",", false);
     393    psArray *chips = psStringSplitArray(chipLine, ",", false);
    407394    if (chips->n > 0) {
    408395        pmFPASelectChip (input->fpa, -1, true); // deselect all chips
     
    454441    if (psTraceGetLevel("ppImage.config") > 0) {
    455442        // Get a look inside all the files.
    456         psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL); // Iterator
     443        psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL);
    457444        psMetadataItem *item;               // Item from iteration
    458445        fprintf(stderr, "Files:\n");
Note: See TracChangeset for help on using the changeset viewer.