Changeset 13810 for trunk/psModules/src/detrend/pmBias.c
- Timestamp:
- Jun 13, 2007, 4:03:29 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmBias.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmBias.c
r13774 r13810 11 11 #include "pmFPA.h" 12 12 #include "pmHDUUtils.h" 13 #include "pmFPALevel.h" 14 #include "pmFPAview.h" 15 #include "pmFPACalibration.h" 16 13 17 #include "pmBias.h" 14 18 … … 206 210 } 207 211 208 209 bool pmBiasSubtract(pmReadout *in, pmOverscanOptions *overscanOpts, 210 const pmReadout *bias, const pmReadout *dark) 212 bool pmBiasSubtract(pmReadout *inRO, pmOverscanOptions *overscanOpts, 213 const pmReadout *biasRO, const pmReadout *darkRO, const pmFPAview *view) 211 214 { 212 215 psTrace("psModules.detrend", 4, 213 216 "---- pmBiasSubtract() begin ----\n"); 214 PS_ASSERT_PTR_NON_NULL(in, NULL); 215 PS_ASSERT_IMAGE_NON_NULL(in->image, NULL); 216 PS_ASSERT_IMAGE_TYPE(in->image, PS_TYPE_F32, NULL); 217 if (bias) { 218 PS_ASSERT_IMAGE_NON_NULL(bias->image, NULL); 219 PS_ASSERT_IMAGE_TYPE(bias->image, PS_TYPE_F32, NULL); 220 } 221 if (dark) { 222 PS_ASSERT_IMAGE_NON_NULL(dark->image, NULL); 223 PS_ASSERT_IMAGE_TYPE(dark->image, PS_TYPE_F32, NULL); 224 } 225 226 pmHDU *hdu = pmHDUFromReadout(in); // HDU of interest 227 228 psImage *image = in->image; // The input image 217 218 PS_ASSERT_PTR_NON_NULL(inRO, false); 219 PS_ASSERT_IMAGE_NON_NULL(inRO->image, false); 220 PS_ASSERT_IMAGE_TYPE(inRO->image, PS_TYPE_F32, false); 221 if (biasRO) { 222 PS_ASSERT_IMAGE_NON_NULL(biasRO->image, false); 223 PS_ASSERT_IMAGE_TYPE(biasRO->image, PS_TYPE_F32, false); 224 } 225 if (darkRO) { 226 PS_ASSERT_PTR_NON_NULL(view, false); 227 PS_ASSERT_IMAGE_NON_NULL(darkRO->image, false); 228 PS_ASSERT_IMAGE_TYPE(darkRO->image, PS_TYPE_F32, false); 229 } 230 231 pmHDU *hdu = pmHDUFromReadout(inRO); // HDU of interest 232 psImage *image = inRO->image; // The input image 229 233 230 234 // Overscan processing … … 238 242 } 239 243 240 psList *overscans = in ->bias; // List of the overscan images244 psList *overscans = inRO->bias; // List of the overscan images 241 245 242 246 psStatsOptions statistic = psStatsSingleOption(overscanOpts->stat->options); // Statistic to use … … 281 285 psFree(comment); 282 286 283 // write metadata header value 284 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_VAL", PS_META_REPLACE, "Overscan value", reduced); 287 // write metadata header value 288 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_VAL", PS_META_REPLACE, "Overscan value", 289 reduced); 285 290 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_SIG", PS_META_REPLACE, "Overscan stdev", NAN); 286 291 … … 288 293 } else { 289 294 // We do the regular overscan subtraction 290 bool readRows = psMetadataLookupBool(NULL, in->parent->concepts, "CELL.READDIR");// Read direction 295 bool readRows = psMetadataLookupBool(NULL, inRO->parent->concepts, 296 "CELL.READDIR"); // Read direction 291 297 float chi2 = NAN; // chi^2 from fit 292 298 … … 302 308 psImage *overscan = NULL; // Overscan image from iterator 303 309 while ((overscan = psListGetAndIncrement(iter))) { 304 // the overscan and image might not be aligned. pixels->data represents305 // the image row pixels.310 // the overscan and image might not be aligned. pixels->data represents 311 // the image row pixels. 306 312 int diff = overscan->row0 - image->row0; // Offset between the two regions 307 313 for (int i = PS_MAX(0,diff); i < PS_MIN(image->numRows, overscan->numRows + diff); i++) { 308 int j = i - diff;314 int j = i - diff; 309 315 // i is row on image 310 // j is row on overscan316 // j is row on overscan 311 317 psVector *values = pixels->data[i]; 312 318 int index = values->n; // Index in the vector … … 349 355 psImage *overscan = NULL; // Overscan image from iterator 350 356 while ((overscan = psListGetAndIncrement(iter))) { 351 // the overscan and image might not be aligned. pixels->data represents352 // the image row pixels.357 // the overscan and image might not be aligned. pixels->data represents 358 // the image row pixels. 353 359 int diff = overscan->col0 - image->col0; // Offset between the two regions 354 360 for (int i = PS_MAX(0,diff); i < PS_MIN(image->numCols, overscan->numCols + diff); i++) { 355 int I= i - diff;361 int iFixed = i - diff; 356 362 // i is column on image 357 // Iis column on overscan363 // iFixed is column on overscan 358 364 psVector *values = pixels->data[i]; 359 365 int index = values->n; // Index in the vector 360 366 values = psVectorRealloc(values, values->n + overscan->numRows); 361 for (int J = 0; J < overscan->numRows; J++) {362 values->data.F32[index++] = overscan->data.F32[ J][I];367 for (int j = 0; j < overscan->numRows; j++) { 368 values->data.F32[index++] = overscan->data.F32[j][iFixed]; 363 369 } 364 370 values->n += overscan->numRows; … … 397 403 psFree(comment); 398 404 399 // write metadata header value 400 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_VAL", PS_META_REPLACE, "Overscan value", poly->coeff[0]); 401 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_SIG", PS_META_REPLACE, "Overscan stdev", poly->coeffErr[0]); 405 // write metadata header value 406 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_VAL", PS_META_REPLACE, 407 "Overscan value", poly->coeff[0]); 408 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_SIG", PS_META_REPLACE, 409 "Overscan stdev", poly->coeffErr[0]); 402 410 break; 403 411 } … … 414 422 psFree(comment); 415 423 } 416 // write metadata header value 417 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_VAL", PS_META_REPLACE, "Overscan value", NAN); 418 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_SIG", PS_META_REPLACE, "Overscan stdev", NAN); 424 // write metadata header value 425 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_VAL", PS_META_REPLACE, 426 "Overscan value", NAN); 427 psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_SIG", PS_META_REPLACE, 428 "Overscan stdev", NAN); 419 429 break; 420 430 } … … 431 441 432 442 // Bias frame subtraction 433 if (bias ) {434 psVector *md5 = psImageMD5(bias ->image); // md5 hash443 if (biasRO) { 444 psVector *md5 = psImageMD5(biasRO->image); // md5 hash 435 445 psString md5string = psMD5toString(md5); // String 436 446 psFree(md5); … … 440 450 psFree(md5string); 441 451 442 if (!subtractFrame(in , bias, 1.0)) {452 if (!subtractFrame(inRO, biasRO, 1.0)) { 443 453 return false; 444 454 } 445 455 } 446 456 447 if (dark ) {457 if (darkRO) { 448 458 // Get the scaling 449 float inTime = psMetadataLookupF32(NULL, in->parent->concepts, "CELL.DARKTIME"); 450 float darkTime = psMetadataLookupF32(NULL, dark->parent->concepts, "CELL.DARKTIME"); 451 452 psVector *md5 = psImageMD5(dark->image); // md5 hash 459 float inTime = psMetadataLookupF32(NULL, inRO->parent->concepts, "CELL.DARKTIME"); 460 float darkTime = psMetadataLookupF32(NULL, darkRO->parent->concepts, "CELL.DARKTIME"); 461 if (isnan(inTime) || isnan(darkTime)) { 462 psError(PS_ERR_UNKNOWN, false, "Unable to determine dark scaling."); 463 return false; 464 } 465 466 float inNorm = pmFPADarkNorm(inRO->parent->parent->parent, view, inTime); 467 float darkNorm = pmFPADarkNorm(darkRO->parent->parent->parent, view, darkTime); 468 if (isnan(inNorm) || isnan(darkNorm)) { 469 psError(PS_ERR_UNKNOWN, false, "Unable to determine dark normalisations."); 470 return false; 471 } 472 473 float scale = inNorm / darkNorm;// Scaling to apply to dark exposure 474 475 psVector *md5 = psImageMD5(darkRO->image); // md5 hash 453 476 psString md5string = psMD5toString(md5); // String 454 477 psFree(md5); 455 psStringPrepend(&md5string, "DARK image (scale %.3f) MD5: ", inTime/darkTime);478 psStringPrepend(&md5string, "DARK image (scale %.3f) MD5: ", scale); 456 479 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, 457 480 md5string, ""); 458 481 psFree(md5string); 459 482 460 if (!subtractFrame(in , dark, inTime/darkTime)) {483 if (!subtractFrame(inRO, darkRO, scale)) { 461 484 return false; 462 485 }
Note:
See TracChangeset
for help on using the changeset viewer.
