IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 16, 2005, 5:18:39 PM (21 years ago)
Author:
Paul Price
Message:

Importing PAP code from phase 2. NOTE: Reverted files in detrend/ and imsubtract/ to a previous version. DO NOT merge these files back!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_051214/psModules/src/detrend/pmFlatField.c

    r5543 r5795  
     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.4.8.1 $ $Name: not supported by cvs2svn $
     27 *  @date $Date: 2005-12-17 03:18:39 $
    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, pmReadout *mask, 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 
    5948    // 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     }
     49    PS_ASSERT_PTR_NON_NULL(mask, false);
    6650    int i = 0;
    6751    int j = 0;
     
    7155    psElemType flatType;
    7256    psElemType maskType;
     57    psImage *inImage = NULL;
    7358    psImage *inMask = NULL;
    7459    psImage *flatImage = NULL;
    7560
    76     //
    77     // Determine trimmed image from metadata.
    78     //
    79     psImage *trimmedImg = p_psDetermineTrimmedImage(in);
     61
     62    // Check for nulls
     63    if (in == NULL) {
     64        return true;       // Readout may not have data in it
     65    } else if(flat==NULL) {
     66        psError( PS_ERR_BAD_PARAMETER_NULL, true,
     67                 PS_ERRORTEXT_pmFlatField_NULL_FLAT_READOUT);
     68        return false;
     69    }
     70
     71    inImage = in->image;
    8072    flatImage = flat->image;
    81     inMask = in->mask;
     73    if (inImage == NULL) {
     74        psError( PS_ERR_BAD_PARAMETER_NULL, true,
     75                 PS_ERRORTEXT_pmFlatField_NULL_INPUT_IMAGE);
     76        return false;
     77    } else if(flatImage == NULL) {
     78        psError( PS_ERR_BAD_PARAMETER_NULL, true,
     79                 PS_ERRORTEXT_pmFlatField_NULL_FLAT_IMAGE);
     80        return false;
     81    }
     82    inMask = mask->image;
    8283
    8384    // Check input image and its mask are not larger than flat image
    8485
    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) {
     86    if (inImage->numRows>flatImage->numRows || inImage->numCols>flatImage->numCols) {
    9187        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    9288                 PS_ERRORTEXT_pmFlatField_SIZE_INPUT_IMAGE,
    93                  trimmedImg->numRows, trimmedImg->numCols, flatImage->numRows, flatImage->numCols);
     89                 inImage->numRows, inImage->numCols, flatImage->numRows, flatImage->numCols);
    9490        return false;
    9591    }
     
    10298
    10399    // Determine total offset based on image offset with chip offset
    104     totOffCol = trimmedImg->col0 + in->col0;
    105     totOffRow = trimmedImg->row0 + in->row0;
     100    totOffCol = inImage->col0 + in->col0;
     101    totOffRow = inImage->row0 + in->row0;
    106102
    107103    // Check that offsets are within image limits
     
    111107                 totOffRow, totOffCol, flatImage->numRows, flatImage->numCols);
    112108        return false;
    113     } else if(totOffRow>=trimmedImg->numRows || totOffCol>=trimmedImg->numCols) {
     109    } else if(totOffRow>=inImage->numRows || totOffCol>=inImage->numCols) {
    114110        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
    115111                 PS_ERRORTEXT_pmFlatField_OFFSET_INPUT_IMAGE,
    116                  totOffRow, totOffCol, trimmedImg->numRows, trimmedImg->numCols);
     112                 totOffRow, totOffCol, inImage->numRows, inImage->numCols);
    117113        return false;
    118114    } else if(totOffRow>=inMask->numRows || totOffCol>=inMask->numCols) {
     
    124120
    125121    // Check for incorrect types
    126     inType = trimmedImg->type.type;
     122    inType = inImage->type.type;
    127123    flatType = flatImage->type.type;
    128124    maskType = inMask->type.type;
     
    153149case PS_TYPE_##TYPE:                                                                                         \
    154150    /* 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++) {                                                      \
     151    for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
     152        for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
    157153            if(flatImage->data.TYPE[j][i] <= 0.0) {                                                          \
    158154                /* Negative or zero flat pixels shall be masked in input image as  PM_MASK_FLAT */           \
     
    162158        }                                                                                                    \
    163159    }                                                                                                        \
    164     for(j = totOffRow; j < trimmedImg->numRows; j++) {                                                          \
    165         for(i = totOffCol; i < trimmedImg->numCols; i++) {                                                      \
     160    for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
     161        for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
    166162            if(!inMask->data.PS_TYPE_MASK_DATA[j][i]) {                                                      \
    167163                /* Module shall divide the input image by the flat-fielded image */                          \
    168                 trimmedImg->data.TYPE[j][i] /= flatImage->data.TYPE[j][i];                                      \
     164                inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i];                                      \
    169165            }                                                                                                \
    170166        }                                                                                                    \
Note: See TracChangeset for help on using the changeset viewer.