Changeset 5435 for trunk/psModules/src/detrend/pmNonLinear.c
- Timestamp:
- Oct 20, 2005, 1:06:24 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmNonLinear.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmNonLinear.c
r5170 r5435 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $8 * @date $Date: 2005- 09-28 20:43:52$7 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-10-20 23:06:24 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 56 56 inFluxe, and the corresponding value in outFlux. The image pixel will then 57 57 be set to the value from outFlux. 58 59 XXX: Must assert that filename exists. This should probably happen in 60 the lookup files. 58 61 *****************************************************************************/ 59 pmReadout *pmNonLinearityLookup(pmReadout *inputReadout, 60 const psVector *inFlux, 61 const psVector *outFlux) 62 pmReadout *pmNonLinearityLookup( 63 pmReadout *inputReadout, 64 const char *filename 65 ) 62 66 { 63 67 PS_ASSERT_PTR_NON_NULL(inputReadout,NULL); 64 68 PS_ASSERT_PTR_NON_NULL(inputReadout->image,NULL); 65 69 PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, NULL); 66 PS_ASSERT_PTR_NON_NULL(inFlux,NULL); 67 if (inFlux->n < 2) { 68 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements. Returning inputReadout image."); 69 return(inputReadout); 70 } 71 PS_ASSERT_PTR_NON_NULL(outFlux,NULL); 72 psS32 tableSize = inFlux->n; 73 if (inFlux->n != outFlux->n) { 74 tableSize = PS_MIN(inFlux->n, outFlux->n); 70 psLookupTable *tmpLT = psLookupTableAlloc(filename, "%f %f", 0); 71 psS32 numLines = psLookupTableRead(tmpLT); 72 psS32 numPixels = 0; 73 if (numLines < 2) { 75 74 psLogMsg(__func__, PS_LOG_WARN, 76 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%d, %d)\n", inFlux->n, outFlux->n); 77 } 78 PS_ASSERT_VECTOR_TYPE(inFlux, PS_TYPE_F32, NULL); 79 PS_ASSERT_VECTOR_TYPE(outFlux, PS_TYPE_F32, NULL); 80 81 psS32 i; 82 psS32 j; 83 psS32 binNum; 84 psScalar x; 85 psS32 numPixels = 0; 86 psF32 slope; 87 88 x.type.type = PS_TYPE_F32; 89 for (i=0;i<inputReadout->image->numRows;i++) { 90 for (j=0;j<inputReadout->image->numCols;j++) { 91 x.data.F32 = inputReadout->image->data.F32[i][j]; 92 binNum = p_psVectorBinDisect((psVector *)inFlux, &x); 93 94 if (binNum == -2) { 95 // We get here if x is below the table lookup range. 96 inputReadout->image->data.F32[i][j] = outFlux->data.F32[0]; 97 numPixels++; 98 99 } else if (binNum == -1) { 100 // We get here if x is above the table lookup range. 101 inputReadout->image->data.F32[i][j] = outFlux->data.F32[tableSize-1]; 102 numPixels++; 103 104 } else if (binNum < -2) { 105 // We get here if there was some other problem. 106 psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect(). Returning inputReadout image."); 107 return(inputReadout); 108 numPixels++; 109 } else { 110 // Perform linear interpolation. 111 slope = (outFlux->data.F32[binNum+1] - outFlux->data.F32[binNum]) / 112 (inFlux->data.F32[binNum+1] - inFlux->data.F32[binNum]); 113 inputReadout->image->data.F32[i][j] = outFlux->data.F32[binNum] + 114 ((x.data.F32 - inFlux->data.F32[binNum]) * slope); 75 "WARNING: Lookup Table is too small. Returning original pmReadout.\n"); 76 } else { 77 for (psS32 i=0;i<inputReadout->image->numRows;i++) { 78 for (psS32 j=0;j<inputReadout->image->numCols;j++) { 79 psF64 tmpD = psLookupTableInterpolate(tmpLT, inputReadout->image->data.F32[i][j], 1); 80 if (!isnan(tmpD)) { 81 inputReadout->image->data.F32[i][j] = tmpD; 82 } else { 83 numPixels++; 84 } 115 85 } 116 86 } 87 if (numPixels > 0) { 88 psLogMsg(__func__, PS_LOG_WARN, 89 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels); 90 } 117 91 } 118 if (numPixels > 0) { 119 psLogMsg(__func__, PS_LOG_WARN, 120 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels); 121 } 92 122 93 return(inputReadout); 123 94 }
Note:
See TracChangeset
for help on using the changeset viewer.
