IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23205


Ignore:
Timestamp:
Mar 6, 2009, 10:28:07 AM (17 years ago)
Author:
eugene
Message:

adding option to supply per-imfile normalizations

Location:
branches/eam_branches/eam_branch_20090303/ppImage/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/eam_branch_20090303/ppImage/src/ppImage.h

    r23125 r23205  
    8686    int remnanceSize;                   // Size for remnance detection
    8787    float remnanceThresh;               // Threshold for remnance detection
     88
     89    char *normClass;                    // class to use for per-class normalization
    8890} ppImageOptions;
    8991
  • branches/eam_branches/eam_branch_20090303/ppImage/src/ppImageArguments.c

    r19943 r23205  
    1414    fprintf(stderr, "\t-chip CHIPNUM: Only process this chip number.\n");
    1515    fprintf(stderr, "\t-norm VALUE: Divide through by this value when done.\n");
     16    fprintf(stderr, "\t-normlist file.mdc: normalizations by class_id.\n");
    1617    fprintf(stderr, "\n");
    1718    fprintf(stderr, "Input options (single file / file list):\n");
     
    128129    }
    129130
    130     // Optional normalisation factor
     131    // Optional normalization factor
    131132    if ((argnum = psArgumentGet(argc, argv, "-norm"))) {
    132133        psArgumentRemove(argnum, &argc, argv);
    133134        float norm = atof(argv[argnum]);
    134         psMetadataAddF32(config->arguments, PS_LIST_TAIL, "NORMALISATION", 0,
     135        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "NORMALIZATION", 0,
    135136                         "Normalisation to apply", norm);
     137        psArgumentRemove(argnum, &argc, argv);
     138    }
     139
     140    // Optional per-class normalization table
     141    if ((argnum = psArgumentGet(argc, argv, "-normlist"))) {
     142        psArgumentRemove(argnum, &argc, argv);
     143
     144        unsigned int nFail = 0;
     145        psMetadata *normlist = psMetadataConfigRead (NULL, &nFail, argv[argnum], false);
     146        // XXX allow this file to be in nebulous?
     147
     148        psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "NORMALIZATION.TABLE", 0, "Normalization to apply", normlist);
     149        psFree (normlist);
    136150        psArgumentRemove(argnum, &argc, argv);
    137151    }
  • branches/eam_branches/eam_branch_20090303/ppImage/src/ppImageDetrendReadout.c

    r21364 r23205  
    5454        if (!pmBiasSubtract(input, options->overscan, bias, oldDark, view)) {
    5555            psError(PS_ERR_UNKNOWN, false, "Unable to subtract bias.");
     56            psFree(detview);
    5657            return false;
    5758        }
     
    6768        if (!pmDarkApply(input, dark, options->maskValue)) {
    6869            psError(PS_ERR_UNKNOWN, false, "Unable to subtract dark.");
     70            psFree(detview);
    6971            return false;
    7072        }
     
    7577                        options->remnanceSize, options->remnanceThresh)) {
    7678            psError(PS_ERR_UNKNOWN, false, "Unable to mask remnance.");
     79            psFree(detview);
    7780            return false;
    7881        }
     
    8386        pmReadout *shutter = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.SHUTTER");
    8487        if (!pmShutterCorrectionApply(input, shutter, pmConfigMaskGet("FLAT", config))) {
     88            psFree(detview);
    8589            return false;
    8690        }
     
    9195        pmReadout *flat = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.FLAT");
    9296        if (!pmFlatField(input, flat, options->flatMask)) {
     97            psFree(detview);
    9398            return false;
    9499        }
    95100    }
    96101
    97     // Normalisation by a (known) constant
     102    // Normalization by a single (known) constant
    98103    bool mdok;                          // Status of MD lookup
    99     float norm = psMetadataLookupF32(&mdok, config->arguments, "NORMALISATION");
     104    float norm = psMetadataLookupF32(&mdok, config->arguments, "NORMALIZATION");
    100105    if (mdok && isfinite(norm) && norm != 1.0) {
    101106        pmHDU *hdu = pmHDUFromReadout(input); // HDU of interest
     
    108113    }
    109114
     115# if (1)
     116    // Normalization by per-class values
     117    psMetadata *normlist = psMetadataLookupMetadata(&mdok, config->arguments, "NORMALIZATION.TABLE");
     118    if (normlist) {
     119        pmFPAfile *inputFile = psMetadataLookupPtr(&mdok, config->files, "PPIMAGE.INPUT");
     120
     121        // get the menu of class IDs
     122        psMetadata *menu = psMetadataLookupMetadata(&mdok, inputFile->camera, "CLASSID");
     123        if (!menu) {
     124            psError(PS_ERR_IO, false, "Unable to find CLASSID metadata in camera configuration");
     125            psFree(detview);
     126            return false;
     127        }
     128        // get the rule for class_id for the desired class
     129        const char *rule = psMetadataLookupStr(&mdok, menu, options->normClass);
     130        if (!rule) {
     131            psError(PS_ERR_IO, false, "Unable to find NORM.CLASS value %s in CLASSID in camera configuration", options->normClass);
     132            psFree(detview);
     133            return false;
     134        }
     135        // get the class_id from the rule
     136        char *classID = pmFPAfileNameFromRule(rule, inputFile, view);
     137        if (!classID) {
     138            psError(PS_ERR_IO, false, "error converting CLASSID rule %s to name\n", rule);
     139            psFree(detview);
     140            return false;
     141        }
     142
     143        // get normalization from the class_id
     144        float norm = psMetadataLookupF32 (&mdok, normlist, classID);
     145
     146        pmHDU *hdu = pmHDUFromReadout(input); // HDU of interest
     147        psString comment = NULL;        // Comment to add
     148        psStringAppend(&comment, "Normalization: %f", norm);
     149        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     150        psFree(comment);
     151
     152        // apply the normalization
     153        psBinaryOp(input->image, input->image, "*", psScalarAlloc(norm, PS_TYPE_F32));
     154
     155        psFree (classID);
     156    }
     157# endif
     158
    110159    if (options->doFringe) {
    111160        pmCell *fringe = pmFPAfileThisCell(config->files, detview, "PPIMAGE.FRINGE");
    112161        if (!ppImageDetrendFringeMeasure(input, fringe, false, options)) {
     162            psFree(detview);
    113163            return false;
    114164        }
  • branches/eam_branches/eam_branch_20090303/ppImage/src/ppImageOptions.c

    r21364 r23205  
    8181    options->remnanceThresh  = 25.0;    // Threshold for remnance detection
    8282
     83    // per-class normalization source
     84    options->normClass       = NULL;    // per-class normalizations refer to this class
     85
    8386    return options;
    8487}
     
    278281    options->remnanceThresh = psMetadataLookupS32(NULL, recipe, "REMNANCE.THRESH");
    279282
     283    // per-class normalization source (just a reference; don't free)
     284    options->normClass = psMetadataLookupStr(NULL, recipe, "NORM.CLASS");
     285
    280286    return options;
    281287}
Note: See TracChangeset for help on using the changeset viewer.