IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 5, 2010, 9:22:59 AM (16 years ago)
Author:
eugene
Message:

do not free nonlinear options (is a double free); add linearity input option from command line; free linearity table after application; move old version of correction to it own function (not currently used, but perhaps someday)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100817/ppImage/src/ppImageDetrendNonLinear.c

    r29486 r29679  
    44
    55#include "ppImage.h"
    6 
    76
    87bool ppImageDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem) {
     
    4746
    4847bool ppImageDetrendNonLinear(pmReadout *input, pmFPAview *detview, pmConfig  *config) {
    49   bool status;
     48    bool status;
    5049
    51   pmFPAfile *linearity_file = psMetadataLookupPtr(&status,config->files,"PPIMAGE.LINEARITY");
    52   psFits *linearity_fits = linearity_file->fits;
     50    pmFPAfile *linearity_file = psMetadataLookupPtr(&status,config->files,"PPIMAGE.LINEARITY");
     51    psFits *linearity_fits = linearity_file->fits;
    5352
    54   if (!psFitsMoveExtName(linearity_fits,psMetadataLookupStr(&status,input->parent->concepts,"CELL.NAME"))) {
    55     psError(PS_ERR_IO, false, "Unable to move to non-linearity table %s",psMetadataLookupStr(&status,input->parent->concepts,"CELL.NAME"));
    56     return(false);
    57   }
     53    char *extname = psMetadataLookupStr(&status,input->parent->concepts,"CELL.NAME");
     54    if (!extname) {
     55        psError(PS_ERR_IO, false, "missing CELL.NAME in concepts");
     56        return(false);
     57    }
     58
     59    if (!psFitsMoveExtName(linearity_fits,extname)) {
     60        psError(PS_ERR_IO, false, "Unable to move to non-linearity table %s", extname);
     61        return(false);
     62    }
    5863 
    59   psArray *table = psFitsReadTable(linearity_fits);
    60   if (!table) {
    61     psError(PS_ERR_IO, false, "Unable to read non-linearity table.\n");
    62     return(false);
    63   }
     64    psArray *table = psFitsReadTable(linearity_fits);
     65    if (!table) {
     66        psError(PS_ERR_IO, false, "Unable to read non-linearity table.\n");
     67        return(false);
     68    }
    6469
    65   // It might be better to pack lookup table here...
    66   // Why? I only use that lookup table once for the single cell it matches.
     70    // It might be better to pack lookup table here...
     71    // Why? I only use that lookup table once for the single cell it matches.
    6772 
    68   if (!pmNonLinearityApply(input,table)) {
    69     psError(PS_ERR_UNKNOWN, false, "Unable to apply non-linearity corrections.\n");
    70     return(false);
    71   }         
     73    if (!pmNonLinearityApply(input,table)) {
     74        psError(PS_ERR_UNKNOWN, false, "Unable to apply non-linearity corrections.\n");
     75        psFree (table);
     76        return(false);
     77    }       
     78    psFree (table);
    7279
     80    return true;
     81}
    7382
    74   return(true);
     83bool ppImageDetrendNonLinear_Original(pmReadout *input, ppImageOptions *options) {
     84
     85    psMetadataItem *concept;
     86    pmCell *cell = input->parent;
     87
     88    switch (options->nonLinearType) {
     89      case PS_DATA_VECTOR:
     90        ppImageDetrendNonLinearPolynomial (input, options->nonLinearData);
     91        return true;
     92
     93      case PS_DATA_STRING:
     94        ppImageDetrendNonLinearLookup (input, options->nonLinearData);
     95        return true;
     96
     97      case PS_DATA_METADATA:
     98        // Go looking for the value in the hierarchy
     99        concept = psMetadataLookup(cell->concepts, options->nonLinearSource);
     100        if (! concept) {
     101            pmChip *chip = cell->parent;// Parent chip
     102            concept = psMetadataLookup(chip->concepts, options->nonLinearSource);
     103            if (! concept) {
     104                pmFPA *fpa = chip->parent; // Parent FPA
     105                concept = psMetadataLookup(fpa->concepts, options->nonLinearSource);
     106                if (! concept) {
     107                    psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s "
     108                             "for non-linearity correction --- ignored.\n", (char *)options->nonLinearSource);
     109                    return false;
     110                }
     111            }
     112        }
     113
     114        if (concept->type != PS_DATA_STRING) {
     115            psLogMsg("phase2", PS_LOG_WARN, "Type for concept %p isn't STRING, as"
     116                     " expected for non-linearity correction --- ignored.\n",
     117                     concept);
     118            return false;
     119        }
     120
     121        // Get the value of the concept
     122        psString conceptValue = concept->data.V;
     123        psMetadata *folder = (psMetadata *)options->nonLinearData->data.V;
     124        psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue);
     125        if (!optionItem) {
     126            psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA"
     127                     " --- ignored.\n", conceptValue);
     128            return false;
     129        }
     130
     131        switch (optionItem->type) {
     132          case PS_DATA_VECTOR:
     133            ppImageDetrendNonLinearPolynomial (input, optionItem);
     134            return true;
     135          case PS_DATA_STRING:
     136            ppImageDetrendNonLinearLookup (input, optionItem);
     137            return true;
     138          default:
     139            psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "
     140                     "desired but unable to interpret NONLIN.DATA for %s"
     141                     " --- ignored\n", conceptValue);
     142            return false;
     143        }
     144      default:
     145        psAbort("Invalid options->nonLinearType");
     146    }
     147    return true;
    75148}
    76   /* bool ppImageDetrendNonLinear(pmReadout *input, ppImageOptions *options) { */
    77 /*     psMetadataItem *concept; */
    78 /*     pmCell *cell = input->parent; */
    79149
    80 /*     switch (options->nonLinearType) { */
    81 /*       case PS_DATA_VECTOR: */
    82 /*         ppImageDetrendNonLinearPolynomial (input, options->nonLinearData); */
    83 /*         return true; */
    84 
    85 /*       case PS_DATA_STRING: */
    86 /*         ppImageDetrendNonLinearLookup (input, options->nonLinearData); */
    87 /*         return true; */
    88 
    89 /*       case PS_DATA_METADATA: */
    90 /*         // XXX EAM: this is somewhat confusing : let's wrap in a function when i understand it */
    91 
    92 /*         // Go looking for the value in the hierarchy */
    93 /*         concept = psMetadataLookup(cell->concepts, options->nonLinearSource); */
    94 /*         if (! concept) { */
    95 /*             pmChip *chip = cell->parent;// Parent chip */
    96 /*             concept = psMetadataLookup(chip->concepts, options->nonLinearSource); */
    97 /*             if (! concept) { */
    98 /*                 pmFPA *fpa = chip->parent; // Parent FPA */
    99 /*                 concept = psMetadataLookup(fpa->concepts, options->nonLinearSource); */
    100 /*                 if (! concept) { */
    101 /*                     psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " */
    102 /*                              "for non-linearity correction --- ignored.\n", (char *)options->nonLinearSource); */
    103 /*                     return false; */
    104 /*                 } */
    105 /*             } */
    106 /*         } */
    107 
    108 /*         if (concept->type != PS_DATA_STRING) { */
    109 /*             psLogMsg("phase2", PS_LOG_WARN, "Type for concept %p isn't STRING, as" */
    110 /*                      " expected for non-linearity correction --- ignored.\n", */
    111 /*                      concept); */
    112 /*             return false; */
    113 /*         } */
    114 
    115 /*         // Get the value of the concept */
    116 /*         psString conceptValue = concept->data.V; */
    117 /*         psMetadata *folder = (psMetadata *)options->nonLinearData->data.V; */
    118 /*         psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue); */
    119 /*         if (!optionItem) { */
    120 /*             psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA" */
    121 /*                      " --- ignored.\n", conceptValue); */
    122 /*             return false; */
    123 /*         } */
    124 
    125 /*         switch (optionItem->type) { */
    126 /*           case PS_DATA_VECTOR: */
    127 /*             ppImageDetrendNonLinearPolynomial (input, optionItem); */
    128 /*             return true; */
    129 /*           case PS_DATA_STRING: */
    130 /*             ppImageDetrendNonLinearLookup (input, optionItem); */
    131 /*             return true; */
    132 /*           default: */
    133 /*             psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction " */
    134 /*                      "desired but unable to interpret NONLIN.DATA for %s" */
    135 /*                      " --- ignored\n", conceptValue); */
    136 /*             return false; */
    137 /*         } */
    138 /*       default: */
    139 /*         psAbort("Invalid options->nonLinearType"); */
    140 /*     } */
    141 /*     return true; */
    142 /* } */
    143 
Note: See TracChangeset for help on using the changeset viewer.