IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9617


Ignore:
Timestamp:
Oct 17, 2006, 12:57:27 PM (20 years ago)
Author:
Paul Price
Message:

Documenting pmNonLinear.h. Cleaning up pmNonLinear.c

Location:
trunk/psModules/src/detrend
Files:
2 edited

Legend:

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

    r8669 r9617  
    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 
    6 /** @file  pmNonLinear.c
    7  *
    8  *  Provides polynomial or table lookup non-linearity corrections to readouts.
    9  *
    10  *  @author GLG, MHPCC
    11  *
    12  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-08-29 21:39:44 $
    14  *
    15  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    16  *
    17  *  XXX: The SDR is silent about image types.  Only F32 was implemented.
    18  *
    19  */
    20 
    211#if HAVE_CONFIG_H
    222#include <config.h>
     
    244
    255#include <stdio.h>
    26 #include <math.h>
    276#include <pslib.h>
    287
     8#include "pmFPA.h"
    299#include "pmNonLinear.h"
    3010
    31 /******************************************************************************
    32 pmNonLinearityLookup(): This routine will take an pmReadout image as input
    33 and 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 to
    35 that value.
    36  *****************************************************************************/
    37 
    38 pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout,
    39                                     const psPolynomial1D *input1DPoly)
     11pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout, const psPolynomial1D *input1DPoly)
    4012{
    4113    PS_ASSERT_PTR_NON_NULL(inputReadout, NULL);
     
    4416    PS_ASSERT_PTR_NON_NULL(input1DPoly, NULL);
    4517
    46     psS32 i;
    47     psS32 j;
    48 
    49     for (i=0;i<inputReadout->image->numRows;i++) {
    50         for (j=0;j<inputReadout->image->numCols;j++) {
    51             inputReadout->image->data.F32[i][j] = psPolynomial1DEval(input1DPoly, inputReadout->image->data.F32[i][j]);
     18    psImage *image = inputReadout->image; // Image to correct
     19    for (int i = 0; i < image->numRows; i++) {
     20        for (int j = 0; j < image->numCols; j++) {
     21            image->data.F32[i][j] = psPolynomial1DEval(input1DPoly, image->data.F32[i][j]);
    5222        }
    5323    }
    54     return(inputReadout);
     24    return inputReadout;
    5525}
    5626
    5727
    58 /******************************************************************************
    59 pmNonLinearityLookup(): This routine will take an pmReadout image as input
    60 and two input vectors, which constitute a lookup table.  For each pixel in
    61 the input image, that pixels value will be determined in the input vector
    62 inFluxe, and the corresponding value in outFlux.  The image pixel will then
    63 be set to the value from outFlux.
    64  *****************************************************************************/
    65 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout,
    66                                 const psVector *inFlux,
    67                                 const psVector *outFlux)
     28pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, const psVector *inFlux, const psVector *outFlux)
    6829{
    69     PS_ASSERT_PTR_NON_NULL(inputReadout,NULL);
    70     PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL);
     30    PS_ASSERT_PTR_NON_NULL(inputReadout, NULL);
     31    PS_ASSERT_PTR_NON_NULL(inputReadout->image, NULL);
    7132    PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL);
    72     PS_ASSERT_PTR_NON_NULL(inFlux,NULL);
     33    PS_ASSERT_PTR_NON_NULL(inFlux, NULL);
    7334    if (inFlux->n < 2) {
    74         psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements.  Returning inputReadout image.");
     35        psError(PS_ERR_UNKNOWN, true,
     36                "pmNonLinearityLookup(): input vector less than 2 elements.  Returning inputReadout image.");
    7537        return(inputReadout);
    7638    }
     
    8042        tableSize = PS_MIN(inFlux->n, outFlux->n);
    8143        psLogMsg(__func__, PS_LOG_WARN,
    82                  "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%ld, %ld)\n", inFlux->n, outFlux->n);
     44                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): "
     45                 "input vectors have different sizes (%ld, %ld)\n",
     46                 inFlux->n, outFlux->n);
    8347    }
    8448    PS_ASSERT_VECTOR_TYPE(inFlux, PS_TYPE_F32, NULL);
    8549    PS_ASSERT_VECTOR_TYPE(outFlux, PS_TYPE_F32, NULL);
    8650
    87     psS32 i;
    88     psS32 j;
    89     psS32 binNum;
    90     psScalar x;
    91     psS32 numPixels = 0;
    92     psF32 slope;
     51    psImage *image = inputReadout->image; // Input image
     52    psScalar x;                         // Value at pixel, for p_psVectorBinDisect
     53    x.type.type = PS_TYPE_F32;
     54    int numPixels = 0;                  // Number of pixels outside the range
    9355
    94     x.type.type = PS_TYPE_F32;
    95     for (i=0;i<inputReadout->image->numRows;i++) {
    96         for (j=0;j<inputReadout->image->numCols;j++) {
    97             x.data.F32 = inputReadout->image->data.F32[i][j];
    98             binNum = p_psVectorBinDisect((psVector *)inFlux, &x);
     56    for (int i = 0; i < image->numRows; i++) {
     57        for (int j = 0; j < image->numCols; j++) {
     58            x.data.F32 = image->data.F32[i][j];
     59            int binNum = p_psVectorBinDisect((psVector *)inFlux, &x); // Bin below the value
    9960
    10061            if (binNum == -2) {
    10162                // We get here if x is below the table lookup range.
    102                 inputReadout->image->data.F32[i][j] = outFlux->data.F32[0];
     63                image->data.F32[i][j] = outFlux->data.F32[0];
    10364                numPixels++;
    104 
    10565            } else if (binNum == -1) {
    10666                // We get here if x is above the table lookup range.
    107                 inputReadout->image->data.F32[i][j] = outFlux->data.F32[tableSize-1];
     67                image->data.F32[i][j] = outFlux->data.F32[tableSize-1];
    10868                numPixels++;
    109 
    11069            } else if (binNum < -2) {
    11170                // We get here if there was some other problem.
    112                 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect().  Returning inputReadout image.");
    113                 return(inputReadout);
     71                psError(PS_ERR_UNKNOWN, true,
     72                        "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect().  "
     73                        "Returning inputReadout image.");
     74                return inputReadout;
    11475                numPixels++;
    11576            } else {
    11677                // Perform linear interpolation.
    117                 slope = (outFlux->data.F32[binNum+1] - outFlux->data.F32[binNum]) /
    118                         (inFlux->data.F32[binNum+1] - inFlux->data.F32[binNum]);
    119                 inputReadout->image->data.F32[i][j] = outFlux->data.F32[binNum] +
    120                                                       ((x.data.F32 - inFlux->data.F32[binNum]) * slope);
     78                float slope = (outFlux->data.F32[binNum + 1] - outFlux->data.F32[binNum]) /
     79                              (inFlux->data.F32[binNum + 1] - inFlux->data.F32[binNum]);
     80                image->data.F32[i][j] = outFlux->data.F32[binNum] +
     81                                        (x.data.F32 - inFlux->data.F32[binNum]) * slope;
    12182            }
    12283        }
     
    12687                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
    12788    }
    128     return(inputReadout);
     89    return inputReadout;
    12990}
  • trunk/psModules/src/detrend/pmNonLinear.h

    r6872 r9617  
    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 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
     1/// @file pmNonLinear.h
     2///
     3/// @brief Perform non-linear correction through polynomial or table lookup
     4///
     5/// @ingroup Detrend
     6///
     7/// @author George Gusciora, MHPCC
     8/// @author Paul Price, IfA
     9///
     10/// @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     11/// @date $Date: 2006-10-17 22:57:27 $
     12///
     13/// Copyright 2004 Institute for Astronomy, University of Hawaii
     14///
    515
    6 /** @file  pmNonLinear.h
    7  *
    8  *  Provides polynomial or table lookup non-linearity corrections to readouts.
    9  *
    10  *  @author GLG, MHPCC
    11  *
    12  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-04-17 18:01:05 $
    14  *
    15  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    16  *
    17  */
    18 
    19 #if !defined(PM_NON_LINEAR_H)
     16#ifndef PM_NON_LINEAR_H
    2017#define PM_NON_LINEAR_H
    2118
    22 #include "pslib.h"
     19#include <pslib.h>
    2320#include "pmFPA.h"
    2421
    25 pmReadout *pmNonLinearityPolynomial(pmReadout *in,
    26                                     const psPolynomial1D *coeff);
     22/// Correct non-linearity through polynomial
     23///
     24/// Applies a polynomial to the flux of each pixel in the input image to determine the corrected flux.
     25pmReadout *pmNonLinearityPolynomial(pmReadout *in, ///< Input image, to correct
     26                                    const psPolynomial1D *coeff ///< Polynomial for non-linearity correction
     27                                   );
    2728
    28 pmReadout *pmNonLinearityLookup(pmReadout *in,
    29                                 const psVector *inFlux,
    30                                 const psVector *outFlux);
     29/// Correct non-linearity through table lookup
     30///
     31/// For each pixel in the input image, performs linear interpolation on the table (from the two vectors) to
     32/// determine the corrected flux.
     33pmReadout *pmNonLinearityLookup(pmReadout *in, ///< Input image, to correct
     34                                const psVector *inFlux, ///< Table column with input fluxes
     35                                const psVector *outFlux ///< Table column with output fluxes
     36                               );
    3137
    3238#endif
Note: See TracChangeset for help on using the changeset viewer.