IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 20, 2005, 1:06:24 PM (21 years ago)
Author:
gusciora
Message:

....

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmNonLinear.c

    r5170 r5435  
    55 *  @author GLG, MHPCC
    66 *
    7  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-09-28 20:43:52 $
     7 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2005-10-20 23:06:24 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5656inFluxe, and the corresponding value in outFlux.  The image pixel will then
    5757be set to the value from outFlux.
     58 
     59XXX: Must assert that filename exists.  This should probably happen in
     60the lookup files.
    5861 *****************************************************************************/
    59 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout,
    60                                 const psVector *inFlux,
    61                                 const psVector *outFlux)
     62pmReadout *pmNonLinearityLookup(
     63    pmReadout *inputReadout,
     64    const char *filename
     65)
    6266{
    6367    PS_ASSERT_PTR_NON_NULL(inputReadout,NULL);
    6468    PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL);
    6569    PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL);
    66     PS_ASSERT_PTR_NON_NULL(inFlux,NULL);
    67     if (inFlux->n < 2) {
    68         psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements.  Returning inputReadout image.");
    69         return(inputReadout);
    70     }
    71     PS_ASSERT_PTR_NON_NULL(outFlux,NULL);
    72     psS32 tableSize = inFlux->n;
    73     if (inFlux->n != outFlux->n) {
    74         tableSize = PS_MIN(inFlux->n, outFlux->n);
     70    psLookupTable *tmpLT = psLookupTableAlloc(filename, "%f %f", 0);
     71    psS32 numLines = psLookupTableRead(tmpLT);
     72    psS32 numPixels = 0;
     73    if (numLines < 2) {
    7574        psLogMsg(__func__, PS_LOG_WARN,
    76                  "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%d, %d)\n", inFlux->n, outFlux->n);
    77     }
    78     PS_ASSERT_VECTOR_TYPE(inFlux, PS_TYPE_F32, NULL);
    79     PS_ASSERT_VECTOR_TYPE(outFlux, PS_TYPE_F32, NULL);
    80 
    81     psS32 i;
    82     psS32 j;
    83     psS32 binNum;
    84     psScalar x;
    85     psS32 numPixels = 0;
    86     psF32 slope;
    87 
    88     x.type.type = PS_TYPE_F32;
    89     for (i=0;i<inputReadout->image->numRows;i++) {
    90         for (j=0;j<inputReadout->image->numCols;j++) {
    91             x.data.F32 = inputReadout->image->data.F32[i][j];
    92             binNum = p_psVectorBinDisect((psVector *)inFlux, &x);
    93 
    94             if (binNum == -2) {
    95                 // We get here if x is below the table lookup range.
    96                 inputReadout->image->data.F32[i][j] = outFlux->data.F32[0];
    97                 numPixels++;
    98 
    99             } else if (binNum == -1) {
    100                 // We get here if x is above the table lookup range.
    101                 inputReadout->image->data.F32[i][j] = outFlux->data.F32[tableSize-1];
    102                 numPixels++;
    103 
    104             } else if (binNum < -2) {
    105                 // We get here if there was some other problem.
    106                 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect().  Returning inputReadout image.");
    107                 return(inputReadout);
    108                 numPixels++;
    109             } else {
    110                 // Perform linear interpolation.
    111                 slope = (outFlux->data.F32[binNum+1] - outFlux->data.F32[binNum]) /
    112                         (inFlux->data.F32[binNum+1]  - inFlux->data.F32[binNum]);
    113                 inputReadout->image->data.F32[i][j] = outFlux->data.F32[binNum] +
    114                                                       ((x.data.F32 - inFlux->data.F32[binNum]) * slope);
     75                 "WARNING: Lookup Table is too small.  Returning original pmReadout.\n");
     76    } else {
     77        for (psS32 i=0;i<inputReadout->image->numRows;i++) {
     78            for (psS32 j=0;j<inputReadout->image->numCols;j++) {
     79                psF64 tmpD = psLookupTableInterpolate(tmpLT, inputReadout->image->data.F32[i][j], 1);
     80                if (!isnan(tmpD)) {
     81                    inputReadout->image->data.F32[i][j] = tmpD;
     82                } else {
     83                    numPixels++;
     84                }
    11585            }
    11686        }
     87        if (numPixels > 0) {
     88            psLogMsg(__func__, PS_LOG_WARN,
     89                     "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
     90        }
    11791    }
    118     if (numPixels > 0) {
    119         psLogMsg(__func__, PS_LOG_WARN,
    120                  "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
    121     }
     92
    12293    return(inputReadout);
    12394}
Note: See TracChangeset for help on using the changeset viewer.