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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }                                                                                                    \
Note: See TracChangeset for help on using the changeset viewer.