IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29486


Ignore:
Timestamp:
Oct 19, 2010, 5:41:33 PM (16 years ago)
Author:
watersc1
Message:

Still broken with weird memory errors, but committing anyway due to JHU trip

Location:
branches/czw_branch/20100817
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100817/ippconfig/gpc1/ppImage.config

    r27407 r29486  
    262262  NOISEMAP METADATA
    263263  END   
     264  LINEARITY METADATA
     265  END
    264266END
    265267
  • branches/czw_branch/20100817/ippconfig/recipes/filerules-mef.mdc

    r28541 r29486  
    6363PPIMAGE.FRINGE          INPUT    @DETDB        CHIP       FRINGE
    6464PPIMAGE.SHUTTER         INPUT    @DETDB        CHIP       IMAGE     
     65PPIMAGE.LINEARITY       INPUT    @DETDB        CHIP       LINEARITY
    6566
    6667## Files used by ppMerge
  • branches/czw_branch/20100817/ippconfig/recipes/filerules-simple.mdc

    r28541 r29486  
    2525PPIMAGE.FRINGE            INPUT    @DETDB        CHIP       FRINGE
    2626PPIMAGE.SHUTTER           INPUT    @DETDB        CHIP       IMAGE     
     27PPIMAGE.LINEARITY         INPUT    @DETDB        CHIP       LINEARITY
    2728                         
    2829## Files used by ppMerge 
  • branches/czw_branch/20100817/ippconfig/recipes/filerules-split.mdc

    r28619 r29486  
    3636PPIMAGE.FRINGE            INPUT    @DETDB        CHIP       FRINGE
    3737PPIMAGE.SHUTTER           INPUT    @DETDB        CHIP       IMAGE
     38PPIMAGE.LINEARITY         INPUT    @DETDB        CHIP       LINEARITY
    3839
    3940## Files used by ppMerge
  • branches/czw_branch/20100817/ppImage/src/ppImage.h

    r28043 r29486  
    155155bool ppImageDetrendBias(pmReadout *inputReadout, pmReadout *bias, pmReadout *dark, ppImageOptions *options);
    156156
    157 bool ppImageDetrendNonLinear(pmReadout *input, ppImageOptions *options);
     157//bool ppImageDetrendNonLinear(pmReadout *input, ppImageOptions *options);
     158bool ppImageDetrendNonLinear(pmReadout *input, pmFPAview *linearity, pmConfig *config);
    158159bool ppImageDetrendNonLinearLookup(pmReadout *input, psMetadataItem *dataItem);
    159160bool ppImageDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem);
  • branches/czw_branch/20100817/ppImage/src/ppImageDefineFile.c

    r26494 r29486  
    1515        file = pmFPAfileDefineFromArgs(&status, config, filerule, argname);
    1616        if (!status) {
    17             psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
     17            psError(PS_ERR_UNKNOWN, false, "failed to load file definition ARG LIST");
    1818            return false;
    1919        }
     
    2323        file = pmFPAfileDefineFromRun(&status, NULL, config, filerule);
    2424        if (!status) {
    25             psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
     25            psError(PS_ERR_UNKNOWN, false, "failed to load file definition RUN");
    2626            return false;
    2727        }
     
    3131        file = pmFPAfileDefineFromConf(&status, config, filerule);
    3232        if (!status) {
    33             psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
     33            psError(PS_ERR_UNKNOWN, false, "failed to load file definition CONFIG");
    3434            return false;
    3535        }
     
    3939        file = pmFPAfileDefineFromDetDB(&status, config, filerule, input, detrendType);
    4040        if (!status) {
    41             psError(PS_ERR_UNKNOWN, false, "failed to load file definition");
     41            psError(PS_ERR_UNKNOWN, false, "failed to load file definition DETREND");
    4242            return false;
    4343        }
  • branches/czw_branch/20100817/ppImage/src/ppImageDetrendFree.c

    r24485 r29486  
    1313    "PPIMAGE.FLAT",
    1414    "PPIMAGE.SHUTTER",
     15    "PPIMAGE.LINEARITY",
    1516    NULL
    1617};
     
    2324
    2425        pmFPAfile *file = psMetadataLookupPtr(&status, config->files, detrendTypes[i]); // File of interest
     26        psTrace("pmFPAfileFree",1,"Working on %s\n",detrendTypes[i]);
    2527        if (!file) continue; // not all detrends are used in any given run
    2628
  • branches/czw_branch/20100817/ppImage/src/ppImageDetrendNonLinear.c

    r11702 r29486  
    44
    55#include "ppImage.h"
     6
    67
    78bool ppImageDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem) {
     
    4445}
    4546
    46 bool ppImageDetrendNonLinear(pmReadout *input, ppImageOptions *options) {
    4747
    48     psMetadataItem *concept;
    49     pmCell *cell = input->parent;
     48bool ppImageDetrendNonLinear(pmReadout *input, pmFPAview *detview, pmConfig  *config) {
     49  bool status;
    5050
    51     switch (options->nonLinearType) {
    52       case PS_DATA_VECTOR:
    53         ppImageDetrendNonLinearPolynomial (input, options->nonLinearData);
    54         return true;
     51  pmFPAfile *linearity_file = psMetadataLookupPtr(&status,config->files,"PPIMAGE.LINEARITY");
     52  psFits *linearity_fits = linearity_file->fits;
    5553
    56       case PS_DATA_STRING:
    57         ppImageDetrendNonLinearLookup (input, options->nonLinearData);
    58         return true;
     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  }
     58 
     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  }
    5964
    60       case PS_DATA_METADATA:
    61         // XXX EAM: this is somewhat confusing : let's wrap in a function when i understand it
     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.
     67 
     68  if (!pmNonLinearityApply(input,table)) {
     69    psError(PS_ERR_UNKNOWN, false, "Unable to apply non-linearity corrections.\n");
     70    return(false);
     71  }         
    6272
    63         // Go looking for the value in the hierarchy
    64         concept = psMetadataLookup(cell->concepts, options->nonLinearSource);
    65         if (! concept) {
    66             pmChip *chip = cell->parent;// Parent chip
    67             concept = psMetadataLookup(chip->concepts, options->nonLinearSource);
    68             if (! concept) {
    69                 pmFPA *fpa = chip->parent; // Parent FPA
    70                 concept = psMetadataLookup(fpa->concepts, options->nonLinearSource);
    71                 if (! concept) {
    72                     psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s "
    73                              "for non-linearity correction --- ignored.\n", (char *)options->nonLinearSource);
    74                     return false;
    75                 }
    76             }
    77         }
    7873
    79         if (concept->type != PS_DATA_STRING) {
    80             psLogMsg("phase2", PS_LOG_WARN, "Type for concept %p isn't STRING, as"
    81                      " expected for non-linearity correction --- ignored.\n",
    82                      concept);
    83             return false;
    84         }
     74  return(true);
     75}
     76  /* bool ppImageDetrendNonLinear(pmReadout *input, ppImageOptions *options) { */
     77/*     psMetadataItem *concept; */
     78/*     pmCell *cell = input->parent; */
    8579
    86         // Get the value of the concept
    87         psString conceptValue = concept->data.V;
    88         psMetadata *folder = (psMetadata *)options->nonLinearData->data.V;
    89         psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue);
    90         if (!optionItem) {
    91             psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA"
    92                      " --- ignored.\n", conceptValue);
    93             return false;
    94         }
     80/*     switch (options->nonLinearType) { */
     81/*       case PS_DATA_VECTOR: */
     82/*         ppImageDetrendNonLinearPolynomial (input, options->nonLinearData); */
     83/*         return true; */
    9584
    96         switch (optionItem->type) {
    97           case PS_DATA_VECTOR:
    98             ppImageDetrendNonLinearPolynomial (input, optionItem);
    99             return true;
    100           case PS_DATA_STRING:
    101             ppImageDetrendNonLinearLookup (input, optionItem);
    102             return true;
    103           default:
    104             psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "
    105                      "desired but unable to interpret NONLIN.DATA for %s"
    106                      " --- ignored\n", conceptValue);
    107             return false;
    108         }
    109       default:
    110         psAbort("Invalid options->nonLinearType");
    111     }
    112     return true;
    113 }
     85/*       case PS_DATA_STRING: */
     86/*         ppImageDetrendNonLinearLookup (input, options->nonLinearData); */
     87/*         return true; */
    11488
     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
  • branches/czw_branch/20100817/ppImage/src/ppImageDetrendReadout.c

    r26653 r29486  
    5151    }
    5252
    53 
    54 # if 0
    5553    // Non-linearity correction
    5654    if (options->doNonLin) {
    57         ppImageDetrendNonLinear(detrend->input, input, options);
    58     }
    59 # endif
     55      //      linearity = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.LINEARITY");
     56      if (!ppImageDetrendNonLinear(input,detview,config)) {
     57        psError(PS_ERR_UNKNOWN, false, "Unable to correct NonLinearity");
     58        psFree(detview);
     59        return(false);
     60      }
     61/*       ppImageDetrendNonLinear(detrend->input, input, options); */
     62    }
    6063
    6164    // set up the dark and bias
  • branches/czw_branch/20100817/ppImage/src/ppImageLoop.c

    r28375 r29486  
    152152            ESCAPE("Unable to free detrend images");
    153153        }
    154 
     154   
    155155        // Apply the fringe correction
    156156        if (options->doFringe) {
  • branches/czw_branch/20100817/ppImage/src/ppImageParseCamera.c

    r26895 r29486  
    7373            return NULL;
    7474        }
     75    }
     76
     77    if (options->doNonLin) {
     78      if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.LINEARITY", "LINEARITY",
     79                             PM_FPA_FILE_LINEARITY, PM_DETREND_TYPE_LINEARITY)) {
     80        psError(PS_ERR_IO, false, "Can't find a non-linearity correction source");
     81        psFree(options);
     82        return NULL;
     83      }
    7584    }
    7685
  • branches/czw_branch/20100817/psLib/src/types/psMetadata.c

    r27646 r29486  
    109109    type = metadataItem->type;
    110110
    111 
     111    //    fprintf(stderr,"%s %s %d\n",metadataItem->name,metadataItem->comment,type);
    112112    psMemDecrRefCounter(metadataItem->name);
    113113    psMemDecrRefCounter(metadataItem->comment);
  • branches/czw_branch/20100817/psModules/src/camera/pmFPAfile.c

    r27657 r29486  
    3636        return;
    3737    }
    38 
     38    psTrace ("pmFPAfileFree", 5, "freeing %s %ld\n", file->name,(psU64) file->fits);
    3939    psAssert(!fpaFileFreeStrict || file->fits == NULL, "File %s wasn't closed.", file->name);
    4040
     
    523523    if (!strcasecmp(type, "HEADER"))     {
    524524        return PM_FPA_FILE_HEADER;
     525    }
     526    if (!strcasecmp(type, "LINEARITY"))  {
     527      return PM_FPA_FILE_LINEARITY;
    525528    }
    526529    // deprecate this?
  • branches/czw_branch/20100817/psModules/src/camera/pmFPAfile.h

    r27657 r29486  
    5050    PM_FPA_FILE_SRCTEXT,
    5151    PM_FPA_FILE_PATTERN,
     52    PM_FPA_FILE_LINEARITY,
    5253} pmFPAfileType;
    5354
  • branches/czw_branch/20100817/psModules/src/camera/pmFPAfileFitsIO.c

    r27989 r29486  
    145145      case PM_FPA_FILE_FRINGE:
    146146      case PM_FPA_FILE_DARK:
     147      case PM_FPA_FILE_LINEARITY:
    147148      case PM_FPA_FILE_CMP:
    148149      case PM_FPA_FILE_CMF:
  • branches/czw_branch/20100817/psModules/src/camera/pmFPAfileIO.c

    r28340 r29486  
    224224      case PM_FPA_FILE_JPEG:
    225225      case PM_FPA_FILE_KAPA:
     226      case PM_FPA_FILE_LINEARITY:
    226227        break;
    227228      default:
     
    551552      case PM_FPA_FILE_ASTROM_MODEL:
    552553      case PM_FPA_FILE_ASTROM_REFSTARS:
     554    case PM_FPA_FILE_LINEARITY:
    553555        psTrace ("psModules.camera", 5, "closing %s (%s) (%d:%d:%d)\n", file->filename, file->name, view->chip, view->cell, view->readout);
    554556        status = psFitsClose (file->fits);
     
    566568      case PM_FPA_FILE_JPEG:
    567569      case PM_FPA_FILE_KAPA:
     570
    568571        break;
    569572
     
    610613      case PM_FPA_FILE_FRINGE:
    611614      case PM_FPA_FILE_DARK:
     615        //
    612616        status = pmFPAviewFreeData(view, file);
    613617        break;
     
    627631      case PM_FPA_FILE_JPEG:
    628632      case PM_FPA_FILE_KAPA:
     633    case PM_FPA_FILE_LINEARITY:
    629634        psTrace ("psModules.camera", 5, "nothing to free for %s (%s)\n", file->filename, file->name);
    630635        return true;
     
    782787      case PM_FPA_FILE_ASTROM_MODEL:
    783788      case PM_FPA_FILE_ASTROM_REFSTARS:
     789      case PM_FPA_FILE_LINEARITY:
    784790        psTrace ("psModules.camera", 5, "opening %s (%s) (%d:%d:%d)\n",
    785791                 file->filename, file->name, view->chip, view->cell, view->readout);
  • branches/czw_branch/20100817/psModules/src/detrend/pmDetrendDB.c

    r24490 r29486  
    106106        DETREND_STRING_CASE(ASTROM);
    107107        DETREND_STRING_CASE(NOISEMAP);
     108        DETREND_STRING_CASE(LINEARITY);
    108109    default:
    109110        return NULL;
  • branches/czw_branch/20100817/psModules/src/detrend/pmDetrendDB.h

    r24490 r29486  
    3636    PM_DETREND_TYPE_ASTROM,
    3737    PM_DETREND_TYPE_NOISEMAP,
     38    PM_DETREND_TYPE_LINEARITY,
    3839} pmDetrendType;
    3940
  • branches/czw_branch/20100817/psModules/src/detrend/pmNonLinear.c

    r12696 r29486  
    4545        } }
    4646
     47
     48# define PS_BIN_INTERPOLATE(RESULT, VECTOR, BOUNDS, BIN, VALUE) { \
     49    float dX, dY, Xo, Yo, Xt;                                     \
     50    if (BIN == BOUNDS->n - 1) {                                   \
     51      dX = 0.5*(BOUNDS->data.F32[BIN+1] - BOUNDS->data.F32[BIN-1]);     \
     52      dY = VECTOR->data.F32[BIN] - VECTOR->data.F32[BIN-1];             \
     53      Xo = 0.5*(BOUNDS->data.F32[BIN+1] + BOUNDS->data.F32[BIN]);       \
     54      Yo = VECTOR->data.F32[BIN];                                       \
     55    } else {                                                            \
     56      dX = 0.5*(BOUNDS->data.F32[BIN+2] - BOUNDS->data.F32[BIN]);       \
     57      dY = VECTOR->data.F32[BIN+1] - VECTOR->data.F32[BIN];             \
     58      Xo = 0.5*(BOUNDS->data.F32[BIN+1] + BOUNDS->data.F32[BIN]);       \
     59      Yo = VECTOR->data.F32[BIN];                                       \
     60    }                                                                   \
     61    if (dY != 0) {                                                      \
     62      Xt = (VALUE - Yo)*dX/dY + Xo;                                     \
     63    } else {                                                            \
     64      Xt = Xo;                                                          \
     65    }                                                                   \
     66    Xt = PS_MIN (BOUNDS->data.F32[BIN+1], PS_MAX(BOUNDS->data.F32[BIN], Xt)); \
     67    psTrace("pmNonLinear", 6, "(Xo, Yo, dX, dY, Xt, Yt) is (%.2f %.2f %.2f %.2f %.2f %.2f)\n",  \
     68            Xo, Yo, dX, dY, Xt, VALUE);                                 \
     69    RESULT = Xt; }
     70
    4771pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, const psVector *inFlux, const psVector *outFlux)
    4872{
     
    92116    return inputReadout;
    93117}
     118
     119bool pmNonLinearityApply(pmReadout *inputReadout, psArray *Ltab)
     120{
     121  PS_ASSERT_PTR_NON_NULL(inputReadout, false);
     122  PS_ASSERT_PTR_NON_NULL(inputReadout->image, false);
     123  PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, false);
     124  PS_ASSERT_PTR_NON_NULL(Ltab, false);
     125
     126  //  psS32 tableSize = Ltab->n;
     127
     128  psImage *image = inputReadout->image;
     129  psS32 numSamples = 39;
     130 
     131  psS32 numBorder  = 10;
     132  // Load default data.
     133  psVector *default_row_correction_fluxes = psVectorAlloc(numSamples,PS_TYPE_F32);
     134  psVector *default_col_correction_fluxes = psVectorAlloc(numSamples,PS_TYPE_F32);
     135  psVector *row_correction_fluxes;
     136  psVector *col_correction_fluxes;
     137
     138  psVector *default_row_correction_factors = psVectorAlloc(numSamples,PS_TYPE_F32);
     139  psVector *default_col_correction_factors = psVectorAlloc(numSamples,PS_TYPE_F32);
     140  psVector *row_correction_factors;
     141  psVector *col_correction_factors;
     142
     143  int n = 0;
     144  int m = 0;
     145  for (int k = 0; k < Ltab->n; k++) { // Begin load default tables
     146    psMetadata *row = Ltab->data[k];   
     147    if (psMetadataLookupS32(NULL,row,"POSITION") != -1) {
     148      continue;
     149    }
     150    if (psMetadataLookupS32(NULL,row,"DIRECTION") == 0) {
     151      psVectorSet(default_row_correction_fluxes,n,psMetadataLookupF32(NULL,row,"FLUX"));
     152      psVectorSet(default_row_correction_factors,n,psMetadataLookupF32(NULL,row,"FACTOR"));
     153      n++;
     154    }
     155    else {
     156      psVectorSet(default_col_correction_fluxes,m,psMetadataLookupF32(NULL,row,"FLUX"));
     157      psVectorSet(default_col_correction_factors,m,psMetadataLookupF32(NULL,row,"FACTOR"));
     158      m++;
     159    }
     160  } // End load default tables
     161 
     162  for (int i = 0; i < image->numRows; i++) { // Loop over rows : note: problem with discontinuity here
     163    n = 0;
     164    if ((i < numBorder)||(image->numRows - i < numBorder)) {     // Load row correction data
     165      row_correction_fluxes = psVectorAlloc(numSamples,PS_TYPE_F32);
     166      row_correction_factors = psVectorAlloc(numSamples,PS_TYPE_F32);
     167
     168      for (int k = 0; k < Ltab->n; k++) {
     169        psMetadata *row = Ltab->data[k];       
     170        if ((psMetadataLookupS32(NULL,row,"DIRECTION") != 0)||
     171            (psMetadataLookupS32(NULL,row,"POSITION") != i + 1)) { // image data is 0 indexed, but correction data is 1 indexed.
     172          continue;
     173        }
     174        psVectorSet(row_correction_fluxes,n,psMetadataLookupF32(NULL,row,"FLUX"));
     175        psVectorSet(row_correction_factors,n,psMetadataLookupF32(NULL,row,"FACTOR"));
     176        //      psTrace("psModules.camera",6,"rows: %d\n",n);
     177        n++;
     178      }
     179    } // End load specific row
     180    else {
     181      row_correction_fluxes = default_row_correction_fluxes;
     182      row_correction_factors = default_row_correction_factors;
     183    } // End load default row
     184     
     185    for (int j = 0; j < image->numCols; j++) { // Loop over columns
     186      m = 0;
     187
     188      if ((j < numBorder)||(image->numCols - j < numBorder)) {       // Load col correction data
     189        col_correction_fluxes = psVectorAlloc(numSamples,PS_TYPE_F32);
     190        col_correction_factors = psVectorAlloc(numSamples,PS_TYPE_F32);
     191        for (int k = 0; k < Ltab->n; k++) {
     192          psMetadata *row = Ltab->data[k];     
     193          if ((psMetadataLookupS32(NULL,row,"DIRECTION") != 1)||
     194              (psMetadataLookupS32(NULL,row,"POSITION") != j + 1)) {
     195            continue;
     196          }
     197          psVectorSet(col_correction_fluxes,m,psMetadataLookupF32(NULL,row,"FLUX"));
     198          psVectorSet(col_correction_factors,m,psMetadataLookupF32(NULL,row,"FACTOR"));
     199          //      psTrace("psModules.camera",6,"columns: %d\n",m);
     200          m++;
     201        }
     202      } // End load specific col
     203      else {
     204        col_correction_fluxes = default_col_correction_fluxes;
     205        col_correction_factors = default_col_correction_factors;
     206      } // End load default col
     207
     208      // Calculate correction factor contribution for this pixel.
     209      psF32 factor_row = pmNonLinearityMeasure(image->data.F32[i][j],
     210                                               row_correction_fluxes,row_correction_factors);
     211      psF32 factor_col = pmNonLinearityMeasure(image->data.F32[i][j],
     212                                               col_correction_fluxes,col_correction_factors);
     213
     214      if (((i <= 9)&&(j <= 9))||((i == 9)&&(j == 5))) { // Print out if we're looking at a test case.
     215        psTrace("psModules.camera",6,"Linearity: %d %d %s %f %f %f %d %d\n",i,j,
     216                psMetadataLookupStr(NULL,inputReadout->parent->concepts,"CELL.NAME"),
     217                image->data.F32[i][j],factor_row,factor_col,numBorder,numSamples);
     218        psTrace("psModules.camera",6,"Linearity: R: %d %d %d C: %d %d %d\n",
     219                i,(i < numBorder),(image->numRows - i),
     220                j,(j < numBorder),(image->numCols - j));
     221
     222/*      psTrace("psModules.camera",6,"Linearity: V: "); */
     223/*      for (int k = 0; k < numSamples; k++) { */
     224/*        psTrace("psModules.camera",6,"(%f %f) ", */
     225/*                col_correction_fluxes->data.F32[k],col_correction_factors->data.F32[k]); */
     226/*      } */
     227/*      psTrace("psModules.camera",6,"\n"); */
     228      } // End Test case
     229
     230      // Apply correction to image data
     231      image->data.F32[i][j] = image->data.F32[i][j] * ( factor_row * factor_col ) ;
     232
     233      // Free correction if we allocated
     234      if ((j < numBorder)||(image->numCols - j < numBorder)) {
     235        psFree(col_correction_fluxes);
     236        psFree(col_correction_factors);
     237      }
     238
     239    } // End loop over columns
     240
     241    // Free correction if we allocated
     242    if ((i < numBorder)||(image->numRows - i < numBorder)) {
     243      psFree(row_correction_fluxes);
     244      psFree(row_correction_factors);
     245    }
     246
     247  } // End loop over rows
     248
     249  psFree(default_row_correction_fluxes);
     250  psFree(default_row_correction_factors);
     251  psFree(default_col_correction_fluxes);
     252  psFree(default_col_correction_factors);
     253 
     254  return(true);
     255}
     256
     257psF32 pmNonLinearityMeasure(psF32 flux, psVector *correction_fluxes, psVector *correction_factors) {
     258  //  psS32 numPixels = 0;
     259  psF32 result = 0;
     260  psU32 bin = 0;
     261
     262  bin = correction_fluxes->n - 1;
     263  if (flux < correction_fluxes->data.F32[0]) {
     264    return(1.0);
     265  }
     266  if (flux > correction_fluxes->data.F32[bin]) {
     267    return(1.0);
     268  }
     269 
     270  for (int i = 0; i < correction_fluxes->n - 1; i++) {
     271    if ((flux >= correction_fluxes->data.F32[i])&&
     272        (flux <  correction_fluxes->data.F32[i+1])) {
     273      result = correction_factors->data.F32[i] +
     274        (flux - correction_fluxes->data.F32[i]) *
     275        ((correction_factors->data.F32[i+1] - correction_factors->data.F32[i]) /
     276         (correction_fluxes->data.F32[i+1] - correction_fluxes->data.F32[i]));
     277      continue;
     278    }
     279  }
     280
     281/*   PS_BIN_FOR_VALUE(bin,correction_fluxes,flux); */
     282/*   if ((bin < 0)||(bin > correction_fluxes->n)) { */
     283/*     return(1.0); */
     284/*   } */
     285 
     286/*   PS_BIN_INTERPOLATE(result,correction_fluxes,correction_factors,bin,flux); */
     287  if (!isfinite(result)) {
     288    result = 1.0;
     289  }
     290  if (result <= 0) {
     291    result = 1.0;
     292  }
     293  return(result);
     294}
     295 
     296 
     297 
  • branches/czw_branch/20100817/psModules/src/detrend/pmNonLinear.h

    r12696 r29486  
    3131                                const psVector *outFlux ///< Table column with output fluxes
    3232                               );
    33 
     33bool pmNonLinearityApply(pmReadout *inputReadout, psArray *Ltab);
     34psF32 pmNonLinearityMeasure(psF32 flux, psVector *correction_fluxes, psVector *correction_factors);
    3435/// @}
    3536#endif
Note: See TracChangeset for help on using the changeset viewer.