IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 17, 2006, 7:13:42 AM (20 years ago)
Author:
magnier
Message:

bulk merge of eam_rel9_p0 onto this branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/detrend/pmNonLinear.c

    r5675 r6448  
     1//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     2// XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
     3// one that was being worked on.
     4//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     5
    16/** @file  pmNonLinear.c
    27 *
     
    510 *  @author GLG, MHPCC
    611 *
    7  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-12-05 20:49:40 $
     12 *  @version $Revision: 1.5.12.1 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-02-17 17:13:41 $
    914 *
    1015 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2227
    2328#include "pmNonLinear.h"
    24 #include "pmSubtractBias.h"
    2529
    26 // XXX: Remove, autoconf must be
    27 #define PS_WARN_PTR_NON_NULL(NAME) \
    28 if ((NAME) == NULL) { \
    29     psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
    30 } \
    3130/******************************************************************************
    3231pmNonLinearityLookup(): This routine will take an pmReadout image as input
    3332and a 1-D polynomial.  For each pixel in the input image, the polynomial will
    34 be evaluated at that pixels value, and the image pixel will then be set
    35 to
     33be evaluated at that pixels value, and the image pixel will then be set to
    3634that value.
    37 *****************************************************************************/
     35 *****************************************************************************/
    3836
    39 pmReadout *pmNonLinearityPolynomial(
    40     pmReadout *inputReadout,
    41     const psPolynomial1D *input1DPoly)
     37pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout,
     38                                    const psPolynomial1D *input1DPoly)
    4239{
    4340    PS_ASSERT_PTR_NON_NULL(inputReadout, NULL);
     
    4542    PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL);
    4643    PS_ASSERT_PTR_NON_NULL(input1DPoly, NULL);
    47     PS_WARN_PTR_NON_NULL(inputReadout->parent);
    48     if (inputReadout->parent != NULL) {
    49         PS_WARN_PTR_NON_NULL(inputReadout->parent->concepts);
    50     }
    5144
    52     //
    53     // Determine trimmed image from metadata.
    54     //
    55     psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout);
     45    psS32 i;
     46    psS32 j;
    5647
    57     for (psS32 i=0;i<trimmedImg->numRows;i++) {
    58         for (psS32 j=0;j<trimmedImg->numCols;j++) {
    59             trimmedImg->data.F32[i][j] = psPolynomial1DEval(input1DPoly,
    60                                          trimmedImg->data.F32[i][j]);
     48    for (i=0;i<inputReadout->image->numRows;i++) {
     49        for (j=0;j<inputReadout->image->numCols;j++) {
     50            inputReadout->image->data.F32[i][j] = psPolynomial1DEval(input1DPoly, inputReadout->image->data.F32[i][j]);
    6151        }
    6252    }
     
    7161inFluxe, and the corresponding value in outFlux.  The image pixel will then
    7262be set to the value from outFlux.
    73  
    74 XXX: Must assert that filename exists.  This should probably happen in
    75 the lookup files.
    7663 *****************************************************************************/
    77 pmReadout *pmNonLinearityLookup(
    78     pmReadout *inputReadout,
    79     const char *filename
    80 )
     64pmReadout *pmNonLinearityLookup(pmReadout *inputReadout,
     65                                const psVector *inFlux,
     66                                const psVector *outFlux)
    8167{
    8268    PS_ASSERT_PTR_NON_NULL(inputReadout,NULL);
    8369    PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL);
    8470    PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL);
    85     PS_WARN_PTR_NON_NULL(inputReadout->parent);
    86     if (inputReadout->parent != NULL) {
    87         PS_WARN_PTR_NON_NULL(inputReadout->parent->concepts);
     71    PS_ASSERT_PTR_NON_NULL(inFlux,NULL);
     72    if (inFlux->n < 2) {
     73        psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements.  Returning inputReadout image.");
     74        return(inputReadout);
    8875    }
    89     //
    90     // Determine trimmed image from metadata.
    91     //
    92     psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout);
     76    PS_ASSERT_PTR_NON_NULL(outFlux,NULL);
     77    psS32 tableSize = inFlux->n;
     78    if (inFlux->n != outFlux->n) {
     79        tableSize = PS_MIN(inFlux->n, outFlux->n);
     80        psLogMsg(__func__, PS_LOG_WARN,
     81                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%d, %d)\n", inFlux->n, outFlux->n);
     82    }
     83    PS_ASSERT_VECTOR_TYPE(inFlux, PS_TYPE_F32, NULL);
     84    PS_ASSERT_VECTOR_TYPE(outFlux, PS_TYPE_F32, NULL);
    9385
    94     psLookupTable *tmpLT = psLookupTableAlloc(filename, "%f %f", 0);
    95     psS32 numLines = psLookupTableRead(tmpLT);
     86    psS32 i;
     87    psS32 j;
     88    psS32 binNum;
     89    psScalar x;
    9690    psS32 numPixels = 0;
    97     if (numLines < 2) {
    98         psLogMsg(__func__, PS_LOG_WARN,
    99                  "WARNING: Lookup Table is too small.  Returning original pmReadout.\n");
    100     } else {
    101         for (psS32 i=0;i<trimmedImg->numRows;i++) {
    102             for (psS32 j=0;j<trimmedImg->numCols;j++) {
    103                 psF64 tmpD = psLookupTableInterpolate(tmpLT, trimmedImg->data.F32[i][j], 1);
    104                 if (!isnan(tmpD)) {
    105                     trimmedImg->data.F32[i][j] = tmpD;
    106                 } else {
    107                     numPixels++;
    108                 }
     91    psF32 slope;
     92
     93    x.type.type = PS_TYPE_F32;
     94    for (i=0;i<inputReadout->image->numRows;i++) {
     95        for (j=0;j<inputReadout->image->numCols;j++) {
     96            x.data.F32 = inputReadout->image->data.F32[i][j];
     97            binNum = p_psVectorBinDisect((psVector *)inFlux, &x);
     98
     99            if (binNum == -2) {
     100                // We get here if x is below the table lookup range.
     101                inputReadout->image->data.F32[i][j] = outFlux->data.F32[0];
     102                numPixels++;
     103
     104            } else if (binNum == -1) {
     105                // We get here if x is above the table lookup range.
     106                inputReadout->image->data.F32[i][j] = outFlux->data.F32[tableSize-1];
     107                numPixels++;
     108
     109            } else if (binNum < -2) {
     110                // We get here if there was some other problem.
     111                psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect().  Returning inputReadout image.");
     112                return(inputReadout);
     113                numPixels++;
     114            } else {
     115                // Perform linear interpolation.
     116                slope = (outFlux->data.F32[binNum+1] - outFlux->data.F32[binNum]) /
     117                        (inFlux->data.F32[binNum+1]  - inFlux->data.F32[binNum]);
     118                inputReadout->image->data.F32[i][j] = outFlux->data.F32[binNum] +
     119                                                      ((x.data.F32 - inFlux->data.F32[binNum]) * slope);
    109120            }
    110121        }
    111         if (numPixels > 0) {
    112             psLogMsg(__func__, PS_LOG_WARN,
    113                      "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
    114         }
    115122    }
    116 
     123    if (numPixels > 0) {
     124        psLogMsg(__func__, PS_LOG_WARN,
     125                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
     126    }
    117127    return(inputReadout);
    118128}
Note: See TracChangeset for help on using the changeset viewer.