Changeset 6872 for trunk/psModules/src/detrend/pmNonLinear.c
- Timestamp:
- Apr 17, 2006, 8:01:05 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmNonLinear.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 1 6 /** @file pmNonLinear.c 2 7 * … … 5 10 * @author GLG, MHPCC 6 11 * 7 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $8 * @date $Date: 200 5-12-05 20:49:40$12 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-04-17 18:01:05 $ 9 14 * 10 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 27 23 28 #include "pmNonLinear.h" 24 #include "pmSubtractBias.h"25 29 26 // XXX: Remove, autoconf must be27 #define PS_WARN_PTR_NON_NULL(NAME) \28 if ((NAME) == NULL) { \29 psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \30 } \31 30 /****************************************************************************** 32 31 pmNonLinearityLookup(): This routine will take an pmReadout image as input 33 32 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 35 to 33 be evaluated at that pixels value, and the image pixel will then be set to 36 34 that value. 37 *****************************************************************************/35 *****************************************************************************/ 38 36 39 pmReadout *pmNonLinearityPolynomial( 40 pmReadout *inputReadout, 41 const psPolynomial1D *input1DPoly) 37 pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout, 38 const psPolynomial1D *input1DPoly) 42 39 { 43 40 PS_ASSERT_PTR_NON_NULL(inputReadout, NULL); … … 45 42 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 46 43 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 }51 44 52 // 53 // Determine trimmed image from metadata. 54 // 55 psImage *trimmedImg = p_psDetermineTrimmedImage(inputReadout); 45 psS32 i; 46 psS32 j; 56 47 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]); 61 51 } 62 52 } … … 71 61 inFluxe, and the corresponding value in outFlux. The image pixel will then 72 62 be set to the value from outFlux. 73 74 XXX: Must assert that filename exists. This should probably happen in75 the lookup files.76 63 *****************************************************************************/ 77 pmReadout *pmNonLinearityLookup( 78 pmReadout *inputReadout, 79 const char *filename 80 ) 64 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, 65 const psVector *inFlux, 66 const psVector *outFlux) 81 67 { 82 68 PS_ASSERT_PTR_NON_NULL(inputReadout,NULL); 83 69 PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL); 84 70 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); 88 75 } 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); 93 85 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; 96 90 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); 109 120 } 110 121 } 111 if (numPixels > 0) {112 psLogMsg(__func__, PS_LOG_WARN,113 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);114 }115 122 } 116 123 if (numPixels > 0) { 124 psLogMsg(__func__, PS_LOG_WARN, 125 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels); 126 } 117 127 return(inputReadout); 118 128 }
Note:
See TracChangeset
for help on using the changeset viewer.
