IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 17, 2006, 8:01:05 AM (20 years ago)
Author:
magnier
Message:

updates relative to rel10_ifa_1

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

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/Makefile.am

    r5170 r6872  
    33libpsmoduledetrend_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS)
    44libpsmoduledetrend_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    5 libpsmoduledetrend_la_SOURCES  = pmFlatField.c \
    6     pmMaskBadPixels.c \
    7     pmNonLinear.c
     5libpsmoduledetrend_la_SOURCES  = \
     6        pmFlatField.c \
     7        pmFringeStats.c \
     8        pmMaskBadPixels.c \
     9        pmNonLinear.c
    810
    911psmoduleincludedir = $(includedir)
    1012psmoduleinclude_HEADERS = \
    11   pmFlatField.h \
    12   pmFlatFieldErrors.h \
    13   pmMaskBadPixelsErrors.h \
    14   pmMaskBadPixels.h \
    15   pmNonLinear.h
     13        pmFlatField.h \
     14        pmFlatFieldErrors.h \
     15        pmFringeStats.h \
     16        pmMaskBadPixelsErrors.h \
     17        pmMaskBadPixels.h \
     18        pmNonLinear.h
    1619
    1720EXTRA_DIST = pmFlatFieldErrors.dat pmMaskBadPixelsErrors.dat
  • trunk/psModules/src/detrend/pmFlatField.c

    r5543 r6872  
     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
    17/** @file  pmFlatField.c
    28 *
     
    1824 *  @author Ross Harman, MHPCC
    1925 *
    20  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    21  *  @date $Date: 2005-11-18 19:43:14 $
     26 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2006-04-17 18:01:05 $
    2228 *
    2329 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3036#include<stdio.h>
    3137#include<math.h>
    32 #include <string.h>
     38#include <strings.h>
    3339
    3440#include "pslib.h"
     
    3642#include "pmMaskBadPixels.h"
    3743#include "pmFlatFieldErrors.h"
    38 #include "pmSubtractBias.h"
    3944
    40 // XXX: This should be removed when the autoconf stuff handles psConstants.h correctly.
    41 #define PS_WARN_PTR_NON_NULL(NAME) \
    42 if ((NAME) == NULL) { \
    43     psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
    44 } \
    4545
    46 bool pmFlatField(
    47     pmReadout *in,
    48     const pmReadout *flat)
     46bool pmFlatField(pmReadout *in, const pmReadout *flat)
    4947{
    50     // XXX: Use the proper image and readout asserts.
    51     PS_ASSERT_PTR_NON_NULL(in, true);
    52     PS_ASSERT_PTR_NON_NULL(in->image, false);
    53     PS_ASSERT_PTR_NON_NULL(in->mask, false);
    54     PS_ASSERT_PTR_NON_NULL(flat, false);
    55     PS_ASSERT_PTR_NON_NULL(flat->image, false);
    56     if (in == NULL)
    57         printf("XXX: NULL\n");
    58 
    59     // XXX: Not sure if this is correct.  Must consult with IfA.
    60     PS_ASSERT_PTR_NON_NULL(in->mask, false);
    61 
    62     PS_WARN_PTR_NON_NULL(in->parent);
    63     if (in->parent != NULL) {
    64         PS_WARN_PTR_NON_NULL(in->parent->concepts);
    65     }
    6648    int i = 0;
    6749    int j = 0;
     
    7153    psElemType flatType;
    7254    psElemType maskType;
    73     psImage *inMask = NULL;
    74     psImage *flatImage = NULL;
    7555
    76     //
    77     // Determine trimmed image from metadata.
    78     //
    79     psImage *trimmedImg = p_psDetermineTrimmedImage(in);
    80     flatImage = flat->image;
    81     inMask = in->mask;
     56    // Check for nulls
     57    if (in == NULL) {
     58        return true;       // Readout may not have data in it
     59    } else if(flat==NULL) {
     60        psError( PS_ERR_BAD_PARAMETER_NULL, true,
     61                 PS_ERRORTEXT_pmFlatField_NULL_FLAT_READOUT);
     62        return false;
     63    }
     64
     65    psImage *inImage   = in->image;     // Input image
     66    psImage *inMask    = in->mask;      // Mask for input image
     67    psImage *flatImage = flat->image;   // Flat-field image
     68
     69    // Offsets on the chip
     70    int x0in = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.X0");
     71    int y0in = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.Y0");
     72    int x0flat = psMetadataLookupS32(NULL, flat->parent->concepts, "CELL.X0");
     73    int y0flat = psMetadataLookupS32(NULL, flat->parent->concepts, "CELL.Y0");
     74
     75    if (inImage == NULL) {
     76        psError( PS_ERR_BAD_PARAMETER_NULL, true,
     77                 PS_ERRORTEXT_pmFlatField_NULL_INPUT_IMAGE);
     78        return false;
     79    } else if(flatImage == NULL) {
     80        psError( PS_ERR_BAD_PARAMETER_NULL, true,
     81                 PS_ERRORTEXT_pmFlatField_NULL_FLAT_IMAGE);
     82        return false;
     83    }
    8284
    8385    // Check input image and its mask are not larger than flat image
    8486
    85     if (trimmedImg == NULL)
    86         printf("XXX: 00\n");
    87     if (flatImage == NULL)
    88         printf("XXX 01\n");
    89 
    90     if (trimmedImg->numRows>flatImage->numRows || trimmedImg->numCols>flatImage->numCols) {
     87    if (inImage->numRows>flatImage->numRows || inImage->numCols>flatImage->numCols) {
    9188        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    9289                 PS_ERRORTEXT_pmFlatField_SIZE_INPUT_IMAGE,
    93                  trimmedImg->numRows, trimmedImg->numCols, flatImage->numRows, flatImage->numCols);
     90                 inImage->numRows, inImage->numCols, flatImage->numRows, flatImage->numCols);
    9491        return false;
    9592    }
    96     if (inMask->numRows > flatImage->numRows || inMask->numCols > flatImage->numCols) {
     93    if (inMask && (inMask->numRows > flatImage->numRows || inMask->numCols > flatImage->numCols)) {
    9794        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    9895                 PS_ERRORTEXT_pmFlatField_SIZE_MASK_IMAGE,
     
    10299
    103100    // Determine total offset based on image offset with chip offset
    104     totOffCol = trimmedImg->col0 + in->col0;
    105     totOffRow = trimmedImg->row0 + in->row0;
     101    totOffCol = inImage->col0 + y0in - flatImage->col0 - y0flat;
     102    totOffRow = inImage->row0 + x0in - flatImage->row0 - x0flat;
    106103
    107104    // Check that offsets are within image limits
     
    111108                 totOffRow, totOffCol, flatImage->numRows, flatImage->numCols);
    112109        return false;
    113     } else if(totOffRow>=trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {
     110    } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) {
    114111        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    115112                 PS_ERRORTEXT_pmFlatField_OFFSET_INPUT_IMAGE,
    116                  totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);
     113                 totOffRow, totOffCol, inImage->numRows, inImage->numCols);
    117114        return false;
    118     } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {
     115    } else if(inMask && (totOffRow>=inMask->numRows || totOffCol>=inMask->numCols)) {
    119116        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    120117                 PS_ERRORTEXT_pmFlatField_OFFSET_MASK_IMAGE,
     
    124121
    125122    // Check for incorrect types
    126     inType = trimmedImg->type.type;
     123    inType = inImage->type.type;
    127124    flatType = flatImage->type.type;
    128125    maskType = inMask->type.type;
     
    137134                 flatType);
    138135        return false;
    139     } else if(maskType != PS_TYPE_MASK) {
     136    } else if(inMask && inMask->type.type != PS_TYPE_MASK) {
    140137        psError( PS_ERR_BAD_PARAMETER_TYPE, true,
    141138                 PS_ERRORTEXT_pmFlatField_TYPE_MASK_IMAGE,
     
    153150case PS_TYPE_##TYPE:                                                                                         \
    154151    /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */  \
    155     for(j = totOffRow; j < trimmedImg->numRows; j++) {                                                          \
    156         for(i = totOffCol; i < trimmedImg->numCols; i++) {                                                      \
     152    for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
     153        for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
    157154            if(flatImage->data.TYPE[j][i] <= 0.0) {                                                          \
    158155                /* Negative or zero flat pixels shall be masked in input image as  PM_MASK_FLAT */           \
    159                 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT;                                        \
     156                if (inMask) {                                                                                \
     157                    inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT;                                    \
     158                }                                                                                            \
    160159                flatImage->data.TYPE[j][i] = 0.0;                                                            \
    161160            }                                                                                                \
    162161        }                                                                                                    \
    163162    }                                                                                                        \
    164     for(j = totOffRow; j < trimmedImg->numRows; j++) {                                                          \
    165         for(i = totOffCol; i < trimmedImg->numCols; i++) {                                                      \
    166             if(!inMask->data.PS_TYPE_MASK_DATA[j][i]) {                                                      \
     163    for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
     164        for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
     165            if(inMask && !inMask->data.PS_TYPE_MASK_DATA[j][i]) {                                            \
    167166                /* Module shall divide the input image by the flat-fielded image */                          \
    168                 trimmedImg->data.TYPE[j][i] /= flatImage->data.TYPE[j][i];                                      \
     167                inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i];                                      \
    169168            }                                                                                                \
    170169        }                                                                                                    \
  • trunk/psModules/src/detrend/pmFlatField.h

    r5435 r6872  
     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
    17/** @file  pmFlatField.h
    28 *
     
    1824 *  @author Ross Harman, MHPCC
    1925 *
    20  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    21  *  @date $Date: 2005-10-20 23:06:24 $
     26 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2006-04-17 18:01:05 $
    2228 *
    2329 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2531
    2632#include "pslib.h"
    27 #include "pmAstrometry.h"
     33#include "pmFPA.h"
    2834
    2935
  • trunk/psModules/src/detrend/pmMaskBadPixels.c

    r5543 r6872  
     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  pmMaskBadPixels.c
    27 *
     
    1924 *  @author Ross Harman, MHPCC
    2025 *
    21  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    22  *  @date $Date: 2005-11-18 19:43:14 $
     26 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2006-04-17 18:01:05 $
    2328 *
    2429 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3136#include<stdio.h>
    3237#include<math.h>
    33 #include<string.h>
     38#include<strings.h>
    3439
    3540#include "pmMaskBadPixels.h"
    3641#include "pmMaskBadPixelsErrors.h"
    37 #include "pmSubtractBias.h"
    3842
    39 //XXX: REmove, autoconf is broken.
    40 #define PS_WARN_PTR_NON_NULL(NAME) \
    41 if ((NAME) == NULL) { \
    42     psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
    43 } \
     43bool pmMaskBadPixels(pmReadout *in, const psImage *mask, unsigned int maskVal, float sat,
     44                     unsigned int growVal, int grow)
     45{
     46    int i = 0;
     47    int j = 0;
     48    int jj = 0;
     49    int ii = 0;
     50    int rRound = 0;
     51    int rowMin = 0;
     52    int rowMax = 0;
     53    int colMin = 0;
     54    int colMax = 0;
     55    int totOffCol = 0;
     56    int totOffRow = 0;
     57    float r = 0.0f;
     58    psElemType inType;
     59    psElemType maskType;
     60    psImage *inImage = NULL;
     61    psImage *inMask = NULL;
    4462
    4563
    46 /******************************************************************************
    47 GrowPixel(inMask, row, col, radius, maskVal): This private routine takes an
    48 input image mask and a pixel location, then sets (logical or) all pixels with
    49 parameter radius if that pixel to maskVal parameter.
    50 *****************************************************************************/
    51 psBool GrowPixel(
    52     psImage *inMask,
    53     psS32 col,
    54     psS32 row,
    55     psS32 radius,
    56     psU32 maskVal)
    57 {
    58     psS32 rowMin = PS_MAX(row-radius, 0);
    59     psS32 rowMax = PS_MIN(row+radius+1, inMask->numRows);
    60     psS32 colMin = PS_MAX(col-radius, 0);
    61     psS32 colMax = PS_MIN(col+radius+1, inMask->numCols);
    62     psF32 squareRadius = PS_SQR(radius);
     64    // Check for nulls
     65    if (in == NULL) {
     66        return true;   // Readout may not have data in it
     67    } else if(mask==NULL) {
     68        psError( PS_ERR_BAD_PARAMETER_NULL, true,
     69                 PS_ERRORTEXT_pmMaskBadPixels_NULL_MASK_IMAGE);
     70        return false;
     71    }
    6372
    64 
    65     for(psS32 i=rowMin; i<rowMax; i++) {
    66         for(psS32 j=colMin; j<colMax; j++) {
    67             // Old code:
    68             //            psF32 rRound = 0.5 + sqrtf((psF32) (((col-j)*(col-j)) + ((row-i)*(row-i))));
    69             //            if(rRound <= radius) {
    70             psF32 squareDis = (psF32) (((col-j)*(col-j)) + ((row-i)*(row-i)));
    71             if (squareDis <= squareRadius) {
    72                 inMask->data.U8[i][j] |= maskVal;
    73             }
    74         }
    75     }
    76     return(true);
    77 }
    78 
    79 /******************************************************************************
    80 GetRadius(inImg, col, row, sat, growVal, grow): This private routine takes an
    81 input image and pixel location and determines what radius that pixel must grow
    82 by.
    83  
    84 //XXX: Inline this or macro it for speed.
    85  *****************************************************************************/
    86 static psS32 GetRadius(
    87     psImage *inImg,
    88     psS32 col,
    89     psS32 row,
    90     psF32 sat,
    91     psU32 growVal,
    92     psS32 grow)
    93 {
    94     psS32 growRadius = 0;
    95     if (inImg->type.type == PS_TYPE_F32) {
    96         if(inImg->data.F32[row][col] == growVal) {
    97             growRadius = grow;
    98         }
    99         if (inImg->data.F32[row][col] > sat) {
    100             growRadius = PS_MAX(growRadius+1, 2);
    101         }
    102     } else if (inImg->type.type == PS_TYPE_S32) {
    103         if(inImg->data.S32[row][col] == growVal) {
    104             growRadius = grow;
    105         }
    106         if (inImg->data.S32[row][col] > sat) {
    107             growRadius = PS_MAX(growRadius+1, 2);
    108         }
    109     } else if (inImg->type.type == PS_TYPE_U16) {
    110         if(inImg->data.U16[row][col] == growVal) {
    111             growRadius = grow;
    112         }
    113         if (inImg->data.U16[row][col] > sat) {
    114             growRadius = PS_MAX(growRadius+1, 2);
    115         }
    116     } else {
    117         psError( PS_ERR_BAD_PARAMETER_TYPE, true,
    118                  PS_ERRORTEXT_pmMaskBadPixels_TYPE_MASK_IMAGE,
    119                  inImg->type.type);
    120     }
    121     return(growRadius);
    122 }
    123 
    124 
    125 bool pmMaskBadPixels(
    126     pmReadout *in,
    127     const pmReadout *mask,
    128     unsigned int maskVal,
    129     float sat,
    130     unsigned int growVal,
    131     int grow)
    132 {
    133     // XXX: Review this code then put all asserts at the top.
    134     PS_ASSERT_PTR_NON_NULL(in, true);
    135     PS_ASSERT_PTR_NON_NULL(in->image, false);
    136     PS_WARN_PTR_NON_NULL(in->parent);
    137     if (in->parent != NULL) {
    138         PS_WARN_PTR_NON_NULL(in->parent->concepts);
    139     }
    140     PS_ASSERT_PTR_NON_NULL(mask, false);
    141     int i = 0;
    142     int j = 0;
    143     int totOffCol = 0;
    144     int totOffRow = 0;
    145     psElemType inType;
    146     psElemType maskType;
    147     psImage *inMask = NULL;
    148 
    149     //
    150     // Determine trimmed image from metadata.
    151     //
    152     psImage *trimmedImg = p_psDetermineTrimmedImage(in);
    153     if(in->mask == NULL) {
    154         in->mask = psImageAlloc(trimmedImg->numCols, trimmedImg->numRows, PS_TYPE_MASK);
    155         PS_IMAGE_SET_U8(in->mask, 0);
     73    inImage = in->image;
     74    if (inImage == NULL) {
     75        psError( PS_ERR_BAD_PARAMETER_NULL, true,
     76                 PS_ERRORTEXT_pmMaskBadPixels_NULL_INPUT_IMAGE);
     77        return false;
     78    } else if(in->mask == NULL) {
     79        in->mask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK);
     80        memset(in->mask->data.V[0], 0, inImage->numCols*inImage->numRows*PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
    15681    }
    15782    inMask = in->mask;
    15883
    15984    // Check input image and its mask are not larger than mask
    160     if(trimmedImg->numRows > mask->image->numRows || trimmedImg->numCols > mask->image->numCols) {
     85    if(inImage->numRows > mask->numRows || inImage->numCols > mask->numCols) {
    16186        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    16287                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
    163                  trimmedImg->numRows, trimmedImg->numCols, mask->image->numRows, mask->image->numCols);
     88                 inImage->numRows, inImage->numCols, mask->numRows, mask->numCols);
    16489        return false;
    165     } else if(inMask->numRows > mask->image->numRows || inMask->numCols > mask->image->numCols) {
     90    } else if(inMask->numRows>mask->numRows || inMask->numCols>mask->numCols) {
    16691        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    16792                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_MASK_IMAGE,
    168                  inMask->numRows, inMask->numCols, mask->image->numRows, mask->image->numCols);
     93                 inMask->numRows, inMask->numCols, mask->numRows, mask->numCols);
    16994        return false;
    17095    }
    17196
    17297    // Determine total offset based on image offset with chip offset
    173     totOffCol = trimmedImg->col0 + in->col0;
    174     totOffRow = trimmedImg->row0 + in->row0;
     98    totOffCol = inImage->col0; // + in->col0;
     99    totOffRow = inImage->row0; // + in->row0;
    175100
    176101    // Check that offsets are within image limits
    177     if(totOffRow>=mask->image->numRows || totOffCol>=mask->image->numCols) {
     102    if(totOffRow>=mask->numRows || totOffCol>=mask->numCols) {
    178103        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    179104                 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE,
    180                  totOffRow, totOffCol, mask->image->numRows, mask->image->numCols);
     105                 totOffRow, totOffCol, mask->numRows, mask->numCols);
    181106        return false;
    182     } else if(totOffRow>=trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {
     107    } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) {
    183108        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    184109                 PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE,
    185                  totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);
     110                 totOffRow, totOffCol, inImage->numRows, inImage->numCols);
    186111        return false;
    187112    } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {
     
    193118
    194119    // Check for incorrect types
    195     inType = trimmedImg->type.type;
    196     maskType = mask->image->type.type;
     120    inType = inImage->type.type;
     121    maskType = mask->type.type;
    197122    if(PS_IS_PSELEMTYPE_COMPLEX(inType)) {
    198123        psError( PS_ERR_BAD_PARAMETER_TYPE, true,
     
    207132    }
    208133
    209     //
    210     // This is the main loop which examines each pixel and masks pixels if
    211     //    A: The mask matches the maskValue
    212     //    B: The pixel is larger than the saturation value
    213     //    C: The pixel equals the grow value (in which case a circle is masked)
    214     //
    215     for(i=totOffRow; i<trimmedImg->numRows; i++) {
    216         for(j=totOffCol; j<trimmedImg->numCols; j++) {
    217             //
    218             // A: Pixels which satisfy maskVal shall be masked
    219             //
    220             if (mask->image->data.U8[i][j] == maskVal) {
    221                 in->mask->data.U8[i][j] |= maskVal;
    222             }
     134    // Macro for all PS types
     135    #define PM_BAD_PIXELS(TYPE)                                                                              \
     136case PS_TYPE_##TYPE:                                                                                         \
     137    for(j=totOffRow; j<inImage->numRows; j++) {                                                              \
     138        for(i=totOffCol; i<inImage->numCols; i++) {                                                          \
     139            \
     140            /* Pixels with flux greater than sat shall be masked */                                          \
     141            if(inImage->data.TYPE[j][i] > sat) {                                                             \
     142                inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT;                                         \
     143            }                                                                                                \
     144            \
     145            /* Pixels which satisfy maskVal shall be masked */                                               \
     146            inMask->data.PS_TYPE_MASK_DATA[j][i] |= (mask->data.PS_TYPE_MASK_DATA[j][i]&maskVal);            \
     147            \
     148            /* Pixels which satisfy growVal and within the grow radius shall be masked */                    \
     149            if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) {                                               \
     150                rowMin = MAX(j-grow, 0);                                                                     \
     151                rowMax = MIN(j+grow+1, inImage->numRows);                                                    \
     152                colMin = MAX(i-grow, 0);                                                                     \
     153                colMax = MIN(i+grow+1, inImage->numCols);                                                    \
     154                for(jj=rowMin; jj<rowMax; jj++) {                                                            \
     155                    for(ii=colMin; ii<colMax; ii++) {                                                        \
     156                        r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j));                                              \
     157                        rRound = r + 0.5;                                                                    \
     158                        if(rRound <= grow) {                                                                 \
     159                            inMask->data.PS_TYPE_MASK_DATA[jj][ii] |=                                        \
     160                                    (mask->data.PS_TYPE_MASK_DATA[j][i]&growVal);                            \
     161                        }                                                                                    \
     162                    }                                                                                        \
     163                }                                                                                            \
     164            }                                                                                                \
     165        }                                                                                                    \
     166    }                                                                                                        \
     167    break;
    223168
    224             //
    225             // We first determine how much we need to grow by and store this in
    226             // growRadius.
    227             //
    228             psS32 growRadius = GetRadius(trimmedImg, j, i, sat, growVal, grow);
    229 
    230             //
    231             // Grow the pixel mask if necessary.
    232             //
    233             if (growRadius != 0) {
    234                 GrowPixel(in->mask, j, i, growRadius, maskVal);
    235             }
    236         }
     169    // Switch to call bad pixel masking macro defined above
     170    switch(inType) {
     171        PM_BAD_PIXELS(U8);
     172        PM_BAD_PIXELS(U16);
     173        PM_BAD_PIXELS(U32);
     174        PM_BAD_PIXELS(U64);
     175        PM_BAD_PIXELS(S8);
     176        PM_BAD_PIXELS(S16);
     177        PM_BAD_PIXELS(S32);
     178        PM_BAD_PIXELS(S64);
     179        PM_BAD_PIXELS(F32);
     180        PM_BAD_PIXELS(F64);
     181    default:
     182        psError( PS_ERR_BAD_PARAMETER_TYPE, true,
     183                 PS_ERRORTEXT_pmMaskBadPixels_TYPE_UNSUPPORTED,
     184                 inType);
    237185    }
    238186
    239     return true;
     187    return false;
    240188}
  • trunk/psModules/src/detrend/pmMaskBadPixels.h

    r5516 r6872  
     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  pmMaskBadPixels.h
    27 *
     
    1924 *  @author Ross Harman, MHPCC
    2025 *
    21  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    22  *  @date $Date: 2005-11-15 20:09:03 $
     26 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2006-04-17 18:01:05 $
    2328 *
    2429 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2631
    2732#include "pslib.h"
    28 #include "pmAstrometry.h"
     33#include "pmFPA.h"
    2934
    3035/** Mask values */
     
    3338    PM_MASK_BADCOL  = 0x0002,   ///< The pixel is a bad column.
    3439    PM_MASK_SAT     = 0x0004,   ///< The pixel is saturated.
    35     PM_MASK_FLAT    = 0x0008    ///< The pixel is non-positive in the flat-field.
     40    PM_MASK_BAD     = 0x0008,   ///< The pixel is low
     41    PM_MASK_FLAT    = 0x0010    ///< The pixel is non-positive in the flat-field.
    3642} pmMaskValue;
    3743
    38 // XXX: Use PS_MIN, PS_MAX
    3944/** Macro to find maximum of two numbers */
    4045#define MAX(A,B)((A)>=(B)?(A):(B))
     
    5459bool pmMaskBadPixels(
    5560    pmReadout *in,          ///< Readout containing input image data.
    56     const pmReadout *mask,   ///< Mask data to be added to readout mask data.
     61    const psImage *mask,    ///< Mask data to be added to readout mask data.
    5762    unsigned int maskVal,   ///< Mask value to determine what to add to input mask.
    5863    float sat,              ///< Saturation limit to mask bad pixels.
  • trunk/psModules/src/detrend/pmMaskBadPixelsErrors.h

    r5170 r6872  
     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  pmMaskBadPixelsErrors.h
    27 *
     
    712 *  @author Ross Harman, MHPCC
    813 *
    9  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-09-28 20:43:52 $
     14 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-04-17 18:01:05 $
    1116 *
    1217 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2328 *     $2  The error text (rest of the line in pmMaskBadPixelsErrors.h)
    2429 *     $n  The order of the source line in pmMaskBadPixelsErrors.h (comments excluded)
    25  * 
     30 *
    2631 * DO NOT EDIT THE LINES BETWEEN //~Start and //~End!  ANY CHANGES WILL BE OVERWRITTEN.
    2732 */
  • trunk/psModules/src/detrend/pmNonLinear.c

    r5675 r6872  
     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.6 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-04-17 18:01:05 $
    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}
  • trunk/psModules/src/detrend/pmNonLinear.h

    r5435 r6872  
     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.h
    27 *
     
    510 *  @author GLG, MHPCC
    611 *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-10-20 23:06:24 $
     12 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-04-17 18:01:05 $
    914 *
    1015 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1621
    1722#include "pslib.h"
    18 #include "pmAstrometry.h"
     23#include "pmFPA.h"
    1924
    20 pmReadout *pmNonLinearityPolynomial(
    21     pmReadout *in,
    22     const psPolynomial1D *coeff
    23 );
     25pmReadout *pmNonLinearityPolynomial(pmReadout *in,
     26                                    const psPolynomial1D *coeff);
    2427
    25 pmReadout *pmNonLinearityLookup(
    26     pmReadout *in,
    27     const char *filename
    28 );
     28pmReadout *pmNonLinearityLookup(pmReadout *in,
     29                                const psVector *inFlux,
     30                                const psVector *outFlux);
    2931
    3032#endif
Note: See TracChangeset for help on using the changeset viewer.