- Timestamp:
- Feb 9, 2010, 8:18:37 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psModules/src/detrend/pmPattern.c
r26819 r26836 1 1 #include <stdio.h> 2 #include <string.h> 2 3 #include <pslib.h> 3 4 … … 9 10 // Mask a row as bad 10 11 static void patternMaskRow(pmReadout *ro, // Readout to mask 11 int y, // Row to mask12 int y, // Row to mask 12 13 psImageMaskType bad // Mask value to give 13 14 ) … … 17 18 psAssert(y < image->numRows, "Row not in image"); 18 19 19 int numCols = image->numCols; // Size of image20 int numCols = image->numCols; // Number of columns 20 21 for (int x = 0; x < numCols; x++) { 21 22 image->data.F32[y][x] = NAN; … … 29 30 return; 30 31 } 32 33 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 // Measurement and application 35 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 31 36 32 37 bool pmPatternRow(pmReadout *ro, int order, int iter, float rej, float thresh, … … 80 85 psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, order); // Polynomial to fit 81 86 psVector *data = psVectorAlloc(numCols, PS_TYPE_F32); // Data to fit 87 psArray *corrs = psArrayAlloc(numRows); // Correction parameters 88 89 psImage *corr = psImageAlloc(order + 1, numRows, PS_TYPE_F64); // Corrections applied 82 90 83 91 for (int y = 0; y < numRows; y++) { … … 105 113 continue; 106 114 } 115 116 memcpy(corr->data.F64[y], poly->coeff, (order + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_F64)); 117 corr->data.F64[y][0] -= background; 118 107 119 psVector *solution = psPolynomial1DEvalVector(poly, indices); // Solution vector 108 120 if (!solution) { … … 118 130 psFree(solution); 119 131 } 132 133 psMetadataAddImage(ro->analysis, PS_LIST_TAIL, PM_PATTERN_ROW_CORRECTION, PS_META_REPLACE, 134 "Pattern row correction", corr); 135 psFree(corrs); 120 136 121 137 psFree(indices); … … 128 144 } 129 145 130 146 bool pmPatternRowApply(pmReadout *ro, psImageMaskType maskBad) 147 { 148 PM_ASSERT_READOUT_NON_NULL(ro, false); 149 PM_ASSERT_READOUT_IMAGE(ro, false); 150 151 bool mdok; // Status of MD lookup 152 psImage *corr = psMetadataLookupPtr(&mdok, ro->analysis, PM_PATTERN_ROW_CORRECTION); // Correction 153 if (!mdok) { 154 // No correction to apply 155 return true; 156 } 157 158 psImage *image = ro->image; // Image of interest 159 int numCols = image->numCols, numRows = image->numRows; // Size of image 160 161 psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, numCols - 1); // Polynomial to apply 162 psVector *indices = psVectorAlloc(numCols, PS_TYPE_F32); // Indices for polynomial 163 float norm = 2.0 / (float)numCols; // Normalisation for indices 164 for (int x = 0; x < numCols; x++) { 165 indices->data.F32[x] = x * norm - 1.0; 166 } 167 168 for (int y = 0; y < numRows; y++) { 169 memcpy(poly->coeff, corr->data.F64[y], numCols * PSELEMTYPE_SIZEOF(PS_TYPE_F64)); 170 psVector *solution = psPolynomial1DEvalVector(poly, indices); // Solution vector 171 if (!solution) { 172 psWarning("Unable to evaluate polynomial for row %d", y); 173 psErrorClear(); 174 patternMaskRow(ro, y, maskBad); 175 continue; 176 } 177 178 for (int x = 0; x < numCols; x++) { 179 image->data.F32[y][x] -= solution->data.F32[x]; 180 } 181 psFree(solution); 182 } 183 184 psFree(poly); 185 psFree(indices); 186 187 return true; 188 } 131 189 132 190 … … 255 313 psImageInit(ro->image, NAN); 256 314 psBinaryOp(ro->mask, ro->mask, "|", psScalarAlloc(maskBad, PS_TYPE_IMAGE_MASK)); 315 psMetadataAddF32(ro->analysis, PS_LIST_TAIL, PM_PATTERN_CELL_CORRECTION, PS_META_REPLACE, 316 "Pattern cell correction solution", NAN); 257 317 continue; 258 318 } … … 262 322 cellName, correction); 263 323 psBinaryOp(ro->image, ro->image, "+", psScalarAlloc(correction, PS_TYPE_F32)); 324 psMetadataAddF32(ro->analysis, PS_LIST_TAIL, PM_PATTERN_CELL_CORRECTION, PS_META_REPLACE, 325 "Pattern cell correction solution", correction); 264 326 } 265 327 … … 269 331 return true; 270 332 } 333 334 bool pmPatternCellApply(pmReadout *ro, psImageMaskType maskBad) 335 { 336 PM_ASSERT_READOUT_NON_NULL(ro, false); 337 PM_ASSERT_READOUT_IMAGE(ro, false); 338 339 bool mdok; // Status of MD lookup 340 float corr = psMetadataLookupF32(&mdok, ro->analysis, PM_PATTERN_CELL_CORRECTION); // Correction to apply 341 if (!mdok) { 342 // No correction to apply 343 return true; 344 } 345 346 psImage *image = ro->image, *mask = ro->mask; // Image and mask of interest 347 int numCols = image->numCols, numRows = image->numRows; // Size of image 348 349 if (!isfinite(corr)) { 350 for (int y = 0; y < numRows; y++) { 351 for (int x = 0; x < numCols; x++) { 352 image->data.F32[y][x] = NAN; 353 } 354 } 355 if (mask) { 356 for (int y = 0; y < numRows; y++) { 357 for (int x = 0; x < numCols; x++) { 358 mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskBad; 359 } 360 } 361 } 362 } else { 363 for (int y = 0; y < numRows; y++) { 364 for (int x = 0; x < numCols; x++) { 365 image->data.F32[y][x] += corr; 366 } 367 } 368 } 369 370 return true; 371 } 372 373
Note:
See TracChangeset
for help on using the changeset viewer.
