Changeset 18893
- Timestamp:
- Aug 4, 2008, 3:24:47 PM (18 years ago)
- Location:
- trunk/psModules/src
- Files:
-
- 2 added
- 10 edited
-
detrend/Makefile.am (modified) (2 diffs)
-
detrend/pmBias.c (modified) (4 diffs)
-
detrend/pmBias.h (modified) (3 diffs)
-
detrend/pmDark.c (modified) (3 diffs)
-
detrend/pmDark.h (modified) (1 diff)
-
detrend/pmDetrendThreads.c (added)
-
detrend/pmDetrendThreads.h (added)
-
detrend/pmFlatField.c (modified) (2 diffs)
-
detrend/pmFlatField.h (modified) (2 diffs)
-
detrend/pmShutterCorrection.c (modified) (4 diffs)
-
detrend/pmShutterCorrection.h (modified) (2 diffs)
-
psmodules.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/Makefile.am
r16841 r18893 13 13 pmDetrendDB.c \ 14 14 pmShutterCorrection.c \ 15 pmDetrendThreads.c \ 15 16 pmShifts.c \ 16 17 pmDark.c … … 28 29 pmDetrendDB.h \ 29 30 pmShutterCorrection.h \ 31 pmDetrendThreads.h \ 30 32 pmShifts.h \ 31 33 pmDark.h -
trunk/psModules/src/detrend/pmBias.c
r16841 r18893 14 14 #include "pmFPAview.h" 15 15 #include "pmFPACalibration.h" 16 #include "pmDetrendThreads.h" 16 17 17 18 #include "pmOverscan.h" 18 19 #include "pmBias.h" 20 21 bool pmBiasSubtractScan_Threaded (psThreadJob *job) { 22 pmReadout *in = job->args->data[0]; 23 pmReadout *sub = job->args->data[1]; 24 float scale = PS_SCALAR_VALUE(job->args->data[2],F32); 25 int xOffset = PS_SCALAR_VALUE(job->args->data[3],S32); 26 int yOffset = PS_SCALAR_VALUE(job->args->data[4],S32); 27 int rowStart = PS_SCALAR_VALUE(job->args->data[5],S32); 28 int rowStop = PS_SCALAR_VALUE(job->args->data[6],S32); 29 bool status = pmBiasSubtractScan (in, sub, scale, xOffset, yOffset, rowStart, rowStop); 30 return status; 31 } 32 33 bool pmBiasSubtractScan (pmReadout *in, pmReadout *sub, float scale, int xOffset, int yOffset, int rowStart, int rowStop) { 34 35 psImage *inImage = in->image; // The input image 36 psImage *inMask = in->mask; // The input mask 37 psImage *subImage = sub->image; // The image to be subtracted 38 psImage *subMask = sub->mask; // The mask for the subtraction image 39 40 if (scale == 1.0) { 41 for (int i = rowStart; i < rowStop; i++) { 42 for (int j = 0; j < inImage->numCols; j++) { 43 inImage->data.F32[i][j] -= subImage->data.F32[i+yOffset][j+xOffset]; 44 if (inMask && subMask) { 45 inMask->data.U8[i][j] |= subMask->data.U8[i+yOffset][j+xOffset]; 46 } 47 } 48 } 49 } else { 50 for (int i = rowStart; i < rowStop; i++) { 51 for (int j = 0; j < inImage->numCols; j++) { 52 inImage->data.F32[i][j] -= subImage->data.F32[i+yOffset][j+xOffset] * scale; 53 if (inMask && subMask) { 54 inMask->data.U8[i][j] |= subMask->data.U8[i+yOffset][j+xOffset]; 55 } 56 } 57 } 58 } 59 return true; 60 } 19 61 20 62 // pmBiasSubtractFrame(): this routine will take as input a readout for the input image and a readout for the bias 21 63 // image. The bias image is subtracted in place from the input image. 22 64 bool pmBiasSubtractFrame(pmReadout *in, // Input readout 23 constpmReadout *sub, // Readout to be subtracted from input24 float scale // Scale to apply before subtracting25 )65 pmReadout *sub, // Readout to be subtracted from input 66 float scale // Scale to apply before subtracting 67 ) 26 68 { 27 69 PS_ASSERT_PTR_NON_NULL(in, false); … … 36 78 37 79 psImage *inImage = in->image; // The input image 38 psImage *inMask = in->mask; // The input mask39 80 psImage *subImage = sub->image; // The image to be subtracted 40 psImage *subMask = sub->mask; // The mask for the subtraction image41 81 42 82 // Check parities … … 76 116 } 77 117 78 if (scale == 1.0) { 79 for (int i = 0; i < inImage->numRows; i++) { 80 for (int j = 0; j < inImage->numCols; j++) { 81 inImage->data.F32[i][j] -= subImage->data.F32[i+y0in-y0sub][j+x0in-x0sub]; 82 if (inMask && subMask) { 83 inMask->data.U8[i][j] |= subMask->data.U8[i+y0in-y0sub][j+x0in-x0sub]; 84 } 85 } 86 } 87 } else { 88 for (int i = 0; i < inImage->numRows; i++) { 89 for (int j = 0; j < inImage->numCols; j++) { 90 inImage->data.F32[i][j] -= subImage->data.F32[i+y0in-y0sub][j+x0in-x0sub] * scale; 91 if (inMask && subMask) { 92 inMask->data.U8[i][j] |= subMask->data.U8[i+y0in-y0sub][j+x0in-x0sub]; 93 } 94 } 95 } 118 int xOffset = x0in - x0sub; 119 int yOffset = y0in - y0sub; 120 121 bool threaded = true; 122 int scanRows = pmDetrendGetScanRows(); 123 if (scanRows == 0) { 124 threaded = false; 125 scanRows = inImage->numRows; 126 } 127 128 for (int rowStart = 0; rowStart < inImage->numRows; rowStart += scanRows) { 129 int rowStop = PS_MIN (rowStart + scanRows, inImage->numRows); 130 131 # define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \ 132 psScalar *scalar = psScalarAlloc(VALUE, TYPE); \ 133 psArrayAdd(ARRAY, 1, scalar); \ 134 psFree (scalar); } 135 136 if (threaded) { 137 // allocate a job, construct the arguments for this job 138 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_BIAS"); 139 psArrayAdd (job->args, 1, in); 140 psArrayAdd (job->args, 1, sub); 141 PS_ARRAY_ADD_SCALAR (job->args, scale, PS_TYPE_F32); 142 PS_ARRAY_ADD_SCALAR (job->args, xOffset, PS_TYPE_S32); 143 PS_ARRAY_ADD_SCALAR (job->args, yOffset, PS_TYPE_S32); 144 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32); 145 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32); 146 147 // ppImageDetrendReadout(config, options, view) 148 if (!psThreadJobAddPending (job)) { 149 return false; 150 } 151 } else { 152 pmBiasSubtractScan (in, sub, scale, xOffset, yOffset, rowStart, rowStop); 153 } 154 } 155 156 if (threaded) { 157 // wait here for the threaded jobs to finish 158 if (!psThreadPoolWait ()) { 159 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 160 return false; 161 } 162 fprintf (stderr, "success for threaded jobs\n"); 163 164 // each job records its own goodPixel values; sum them here 165 // we have only supplied one type of job, so we can assume the types here 166 psThreadJob *job = NULL; 167 while ((job = psThreadJobGetDone()) != NULL) { 168 psFree (job); 169 } 96 170 } 97 171 … … 100 174 101 175 bool pmBiasSubtract(pmReadout *in, pmOverscanOptions *overscanOpts, 102 const pmReadout *bias, constpmReadout *dark, const pmFPAview *view)176 pmReadout *bias, pmReadout *dark, const pmFPAview *view) 103 177 { 104 178 psTrace("psModules.detrend", 4, -
trunk/psModules/src/detrend/pmBias.h
r14505 r18893 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $8 * @date $Date: 200 7-08-15 20:21:18$7 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-08-05 01:24:47 $ 9 9 * Copyright 2004--2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 22 22 bool pmBiasSubtract(pmReadout *in, ///< Input readout, to be overscan/bias/dark corrected 23 23 pmOverscanOptions *overscanOpts, ///< Options for overscan subtraction, or NULL 24 constpmReadout *bias, ///< Bias to subtract, or NULL25 constpmReadout *dark, ///< Dark to scale and subtract, or NULL24 pmReadout *bias, ///< Bias to subtract, or NULL 25 pmReadout *dark, ///< Dark to scale and subtract, or NULL 26 26 const pmFPAview *view ///< View for readout of interest 27 27 ); … … 30 30 // image. The bias image is subtracted in place from the input image. 31 31 bool pmBiasSubtractFrame(pmReadout *in, // Input readout 32 constpmReadout *sub, // Readout to be subtracted from input33 float scale // Scale to apply before subtracting32 pmReadout *sub, // Readout to be subtracted from input 33 float scale // Scale to apply before subtracting 34 34 ); 35 36 bool pmBiasSubtractScan_Threaded (psThreadJob *job); 37 bool pmBiasSubtractScan (pmReadout *in, pmReadout *sub, float scan, int xOffset, int yOffset, int rowStart, int rowStop); 35 38 36 39 /// @} -
trunk/psModules/src/detrend/pmDark.c
r18859 r18893 11 11 #include "pmFPAWrite.h" 12 12 #include "pmReadoutStack.h" 13 #include "pmDetrendThreads.h" 13 14 14 15 #include "pmDark.h" … … 366 367 } 367 368 368 bool pmDarkApply(pmReadout *readout, const pmCell *dark, psMaskType bad) 369 bool pmDarkApplyScan_Threaded (psThreadJob *job) { 370 pmReadout *readout = job->args->data[0]; 371 pmCell *dark = job->args->data[1]; 372 psPolynomialMD *poly = job->args->data[2]; 373 psVector *values = job->args->data[3]; 374 375 psMaskType bad = PS_SCALAR_VALUE(job->args->data[4],U8); 376 bool doNorm = PS_SCALAR_VALUE(job->args->data[5],U8); 377 float norm = PS_SCALAR_VALUE(job->args->data[6],F32); 378 int rowStart = PS_SCALAR_VALUE(job->args->data[7],S32); 379 int rowStop = PS_SCALAR_VALUE(job->args->data[8],S32); 380 bool status = pmDarkApplyScan (readout, dark, poly, values, bad, doNorm, norm, rowStart, rowStop); 381 return status; 382 } 383 384 bool pmDarkApplyScan (pmReadout *readout, const pmCell *dark, psPolynomialMD *poly, psVector *values, psMaskType bad, bool doNorm, float norm, int rowStart, int rowStop) { 385 386 int numCols = readout->image->numCols; 387 int numTerms = dark->readouts->n; // Number of polynomial terms 388 389 // thread here by scan 390 for (int y = rowStart; y < rowStop; y++) { 391 for (int x = 0; x < numCols; x++) { 392 for (int i = 0; i < numTerms; i++) { 393 pmReadout *ro = dark->readouts->data[i]; // Dark readout 394 poly->coeff->data.F64[i] = ro->image->data.F32[y][x]; 395 } 396 float value = psPolynomialMDEval(poly, values); // Value of dark current 397 if (doNorm) { 398 value *= norm; 399 } 400 readout->image->data.F32[y][x] -= value; 401 if (readout->mask && !isfinite(value)) { 402 readout->mask->data.PS_TYPE_MASK_DATA[y][x] = bad; 403 } 404 } 405 } 406 return true; 407 } 408 409 bool pmDarkApply(pmReadout *readout, pmCell *dark, psMaskType bad) 369 410 { 370 411 PS_ASSERT_PTR_NON_NULL(readout, false); … … 433 474 psFree(orders); 434 475 435 for (int y = 0; y < numRows; y++) { 436 for (int x = 0; x < numCols; x++) { 437 for (int i = 0; i < numTerms; i++) { 438 pmReadout *ro = dark->readouts->data[i]; // Dark readout 439 poly->coeff->data.F64[i] = ro->image->data.F32[y][x]; 440 } 441 float value = psPolynomialMDEval(poly, values); // Value of dark current 442 if (doNorm) { 443 value *= norm; 444 } 445 readout->image->data.F32[y][x] -= value; 446 if (readout->mask && !isfinite(value)) { 447 readout->mask->data.PS_TYPE_MASK_DATA[y][x] = bad; 448 } 449 } 476 // thread here by scan 477 478 bool threaded = true; 479 int scanRows = pmDetrendGetScanRows(); 480 if (scanRows == 0) { 481 threaded = false; 482 scanRows = readout->image->numRows; 483 } 484 485 for (int rowStart = 0; rowStart < readout->image->numRows; rowStart += scanRows) { 486 int rowStop = PS_MIN (rowStart + scanRows, readout->image->numRows); 487 488 # define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \ 489 psScalar *scalar = psScalarAlloc(VALUE, TYPE); \ 490 psArrayAdd(ARRAY, 1, scalar); \ 491 psFree (scalar); } 492 493 if (threaded) { 494 // allocate a job, construct the arguments for this job 495 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_DARK"); 496 psArrayAdd (job->args, 1, readout); 497 psArrayAdd (job->args, 1, dark); 498 psArrayAdd (job->args, 1, poly); 499 psArrayAdd (job->args, 1, values); 500 PS_ARRAY_ADD_SCALAR (job->args, bad, PS_TYPE_MASK); 501 PS_ARRAY_ADD_SCALAR (job->args, doNorm, PS_TYPE_U8); 502 PS_ARRAY_ADD_SCALAR (job->args, norm, PS_TYPE_F32); 503 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32); 504 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32); 505 506 // ppImageDetrendReadout(config, options, view) 507 if (!psThreadJobAddPending (job)) { 508 return false; 509 } 510 } else { 511 pmDarkApplyScan (readout, dark, poly, values, bad, doNorm, norm, rowStart, rowStop); 512 } 513 } 514 515 if (threaded) { 516 // wait here for the threaded jobs to finish 517 if (!psThreadPoolWait ()) { 518 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 519 return false; 520 } 521 fprintf (stderr, "success for threaded jobs\n"); 522 523 // free the done jobs 524 psThreadJob *job = NULL; 525 while ((job = psThreadJobGetDone()) != NULL) { 526 psFree (job); 527 } 450 528 } 451 529 -
trunk/psModules/src/detrend/pmDark.h
r18859 r18893 40 40 ); 41 41 42 bool pmDarkApplyScan_Threaded (psThreadJob *job); 43 bool pmDarkApplyScan (pmReadout *readout, const pmCell *dark, psPolynomialMD *poly, psVector *values, psMaskType bad, bool doNorm, float norm, int rowStart, int rowStop); 44 42 45 // Apply dark 43 46 bool pmDarkApply(pmReadout *readout, // Readout to which to apply dark 44 constpmCell *dark, // Dark to apply47 pmCell *dark, // Dark to apply 45 48 psMaskType bad // Mask value to give bad pixels 46 49 ); -
trunk/psModules/src/detrend/pmFlatField.c
r15673 r18893 11 11 #include "pmFPAMaskWeight.h" 12 12 #include "pmFlatField.h" 13 #include "pmDetrendThreads.h" 14 15 bool pmFlatFieldScan_Threaded (psThreadJob *job) { 16 psImage *inImage = job->args->data[0]; 17 psImage *inMask = job->args->data[1]; 18 psImage *flatImage = job->args->data[2]; 19 psImage *flatMask = job->args->data[3]; 20 21 psMaskType badFlat = PS_SCALAR_VALUE(job->args->data[4],U8); 22 int xOffset = PS_SCALAR_VALUE(job->args->data[5],S32); 23 int yOffset = PS_SCALAR_VALUE(job->args->data[6],S32); 24 int rowStart = PS_SCALAR_VALUE(job->args->data[7],S32); 25 int rowStop = PS_SCALAR_VALUE(job->args->data[8],S32); 26 bool status = pmFlatFieldScan (inImage, inMask, flatImage, flatMask, badFlat, xOffset, yOffset, rowStart, rowStop); 27 return status; 28 } 29 30 // Macro for all PS types 31 #define FLAT_DIVISION_CASE(TYPE, SPECIAL) \ 32 case PS_TYPE_##TYPE: \ 33 for (int j = rowStart; j < rowStop; j++) { \ 34 for (int i = 0; i < inImage->numCols; i++) { \ 35 ps##TYPE flatValue = flatImage->data.TYPE[j + yOffset][i + xOffset]; \ 36 if (!isfinite(flatValue) || flatValue <= 0.0 || \ 37 (flatMask && flatMask->data.U8[j + yOffset][i + xOffset])) { \ 38 if (inMask) { \ 39 inMask->data.PS_TYPE_MASK_DATA[j][i] |= badFlat; \ 40 } \ 41 inImage->data.TYPE[j][i] = SPECIAL; \ 42 } else { \ 43 inImage->data.TYPE[j][i] /= flatValue; \ 44 } \ 45 } \ 46 } \ 47 break; 48 49 bool pmFlatFieldScan (psImage *inImage, psImage *inMask, psImage *flatImage, psImage *flatMask, psMaskType badFlat, int xOffset, int yOffset, int rowStart, int rowStop) { 50 51 switch (inImage->type.type) { 52 FLAT_DIVISION_CASE(U8, 0); 53 FLAT_DIVISION_CASE(U16, 0); 54 FLAT_DIVISION_CASE(U32, 0); 55 FLAT_DIVISION_CASE(U64, 0); 56 FLAT_DIVISION_CASE(S8, 0); 57 FLAT_DIVISION_CASE(S16, 0); 58 FLAT_DIVISION_CASE(S32, 0); 59 FLAT_DIVISION_CASE(S64, 0); 60 FLAT_DIVISION_CASE(F32, NAN); 61 FLAT_DIVISION_CASE(F64, NAN); 62 default: 63 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unsupported type for input image: %x\n", 64 inImage->type.type); 65 return false; 66 } 67 return true; 68 } 13 69 14 70 bool pmFlatField(pmReadout *in, const pmReadout *flat, psMaskType badFlat) … … 71 127 } 72 128 73 // Macro for all PS types 74 #define FLAT_DIVISION_CASE(TYPE, SPECIAL) \ 75 case PS_TYPE_##TYPE: \ 76 for (int j = 0; j < inImage->numRows; j++) { \ 77 for (int i = 0; i < inImage->numCols; i++) { \ 78 ps##TYPE flatValue = flatImage->data.TYPE[j + yOffset][i + xOffset]; \ 79 if (!isfinite(flatValue) || flatValue <= 0.0 || \ 80 (flatMask && flatMask->data.U8[j + yOffset][i + xOffset])) { \ 81 if (inMask) { \ 82 inMask->data.PS_TYPE_MASK_DATA[j][i] |= badFlat; \ 83 } \ 84 inImage->data.TYPE[j][i] = SPECIAL; \ 85 } else { \ 86 inImage->data.TYPE[j][i] /= flatValue; \ 87 } \ 88 } \ 89 } \ 90 break; 129 bool threaded = true; 130 int scanRows = pmDetrendGetScanRows(); 131 if (scanRows == 0) { 132 threaded = false; 133 scanRows = inImage->numRows; 134 } 91 135 92 switch (inImage->type.type) { 93 FLAT_DIVISION_CASE(U8, 0); 94 FLAT_DIVISION_CASE(U16, 0); 95 FLAT_DIVISION_CASE(U32, 0); 96 FLAT_DIVISION_CASE(U64, 0); 97 FLAT_DIVISION_CASE(S8, 0); 98 FLAT_DIVISION_CASE(S16, 0); 99 FLAT_DIVISION_CASE(S32, 0); 100 FLAT_DIVISION_CASE(S64, 0); 101 FLAT_DIVISION_CASE(F32, NAN); 102 FLAT_DIVISION_CASE(F64, NAN); 103 default: 104 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unsupported type for input image: %x\n", 105 inImage->type.type); 106 return false; 136 for (int rowStart = 0; rowStart < inImage->numRows; rowStart += scanRows) { 137 int rowStop = PS_MIN (rowStart + scanRows, inImage->numRows); 138 139 # define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \ 140 psScalar *scalar = psScalarAlloc(VALUE, TYPE); \ 141 psArrayAdd(ARRAY, 1, scalar); \ 142 psFree (scalar); } 143 144 if (threaded) { 145 // allocate a job, construct the arguments for this job 146 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_FLAT"); 147 psArrayAdd (job->args, 1, inImage); 148 psArrayAdd (job->args, 1, inMask); 149 psArrayAdd (job->args, 1, flatImage); 150 psArrayAdd (job->args, 1, flatMask); 151 PS_ARRAY_ADD_SCALAR (job->args, badFlat, PS_TYPE_U8); 152 PS_ARRAY_ADD_SCALAR (job->args, xOffset, PS_TYPE_S32); 153 PS_ARRAY_ADD_SCALAR (job->args, yOffset, PS_TYPE_S32); 154 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32); 155 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32); 156 157 // ppImageDetrendReadout(config, options, view) 158 if (!psThreadJobAddPending (job)) { 159 return false; 160 } 161 } else { 162 pmFlatFieldScan (inImage, inMask, flatImage, flatMask, badFlat, xOffset, yOffset, rowStart, rowStop); 163 } 164 } 165 166 if (threaded) { 167 // wait here for the threaded jobs to finish 168 if (!psThreadPoolWait ()) { 169 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 170 return false; 171 } 172 fprintf (stderr, "success for threaded jobs\n"); 173 174 // free done jobs 175 psThreadJob *job = NULL; 176 while ((job = psThreadJobGetDone()) != NULL) { 177 psFree (job); 178 } 107 179 } 108 180 -
trunk/psModules/src/detrend/pmFlatField.h
r13591 r18893 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $8 * @date $Date: 200 7-06-02 03:51:03$7 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-08-05 01:24:47 $ 9 9 * Copyright 2004-2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 27 27 psMaskType badFlat ///< Mask value to give bad flat pixels 28 28 ); 29 30 bool pmFlatFieldScan_Threaded (psThreadJob *job); 31 bool pmFlatFieldScan (psImage *inImage, psImage *inMask, psImage *flatImage, psImage *flatMask, psMaskType badFlag, int xOffset, int yOffset, int rowStart, int rowStop); 32 33 29 34 /// @} 30 35 #endif -
trunk/psModules/src/detrend/pmShutterCorrection.c
r18860 r18893 14 14 #include "pmConceptsAverage.h" 15 15 #include "pmReadoutStack.h" 16 #include "pmDetrendThreads.h" 16 17 17 18 #include "pmShutterCorrection.h" … … 655 656 656 657 658 bool pmShutterCorrectionApplyScan_Threaded (psThreadJob *job) { 659 psImage *image = job->args->data[0]; 660 psImage *shutterImage = job->args->data[1]; 661 psImage *mask = job->args->data[2]; 662 663 float exptime = PS_SCALAR_VALUE(job->args->data[3],F32); 664 psMaskType blank = PS_SCALAR_VALUE(job->args->data[4],U8); 665 int rowStart = PS_SCALAR_VALUE(job->args->data[5],S32); 666 int rowStop = PS_SCALAR_VALUE(job->args->data[6],S32); 667 bool status = pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop); 668 return status; 669 } 670 671 bool pmShutterCorrectionApplyScan(psImage *image, psImage *shutterImage, psImage *mask, float exptime, psMaskType blank, int rowStart, int rowStop) 672 { 673 for (int y = rowStart; y < rowStop; y++) { 674 for (int x = 0; x < image->numCols; x++) { 675 if (mask && !isfinite(shutterImage->data.F32[y][x])) { 676 mask->data.PS_TYPE_MASK_DATA[y][x] |= blank; 677 image->data.F32[y][x] = NAN; 678 continue; 679 } 680 image->data.F32[y][x] *= exptime / (exptime + shutterImage->data.F32[y][x]); 681 } 682 } 683 return true; 684 } 685 657 686 bool pmShutterCorrectionApply(pmReadout *readout, const pmReadout *shutter, psMaskType blank) 658 687 { … … 700 729 psImage *image = readout->image; // Image to correct 701 730 psImage *mask = readout->mask; // Corresponding mask 731 732 bool threaded = true; 733 int scanRows = pmDetrendGetScanRows(); 734 if (scanRows == 0) { 735 threaded = false; 736 scanRows = image->numRows; 737 } 702 738 703 739 if (exptime <= 0.0) { … … 720 756 psFree (line); 721 757 } else { 722 for (int y = 0; y < image->numRows; y++) { 723 for (int x = 0; x < image->numCols; x++) { 724 if (mask && !isfinite(shutterImage->data.F32[y][x])) { 725 mask->data.PS_TYPE_MASK_DATA[y][x] |= blank; 726 image->data.F32[y][x] = NAN; 727 continue; 728 } 729 image->data.F32[y][x] *= exptime / (exptime + shutterImage->data.F32[y][x]); 730 } 731 } 758 for (int rowStart = 0; rowStart < image->numRows; rowStart += scanRows) { 759 int rowStop = PS_MIN (rowStart + scanRows, image->numRows); 760 761 # define PS_ARRAY_ADD_SCALAR(ARRAY, VALUE, TYPE) { \ 762 psScalar *scalar = psScalarAlloc(VALUE, TYPE); \ 763 psArrayAdd(ARRAY, 1, scalar); \ 764 psFree (scalar); } 765 766 if (threaded) { 767 // allocate a job, construct the arguments for this job 768 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_SHUTTER"); 769 psArrayAdd (job->args, 1, image); 770 psArrayAdd (job->args, 1, shutterImage); 771 psArrayAdd (job->args, 1, mask); 772 PS_ARRAY_ADD_SCALAR (job->args, exptime, PS_TYPE_F32); 773 PS_ARRAY_ADD_SCALAR (job->args, blank, PS_TYPE_MASK); 774 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32); 775 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32); 776 777 // ppImageDetrendReadout(config, options, view) 778 if (!psThreadJobAddPending (job)) { 779 return false; 780 } 781 } else { 782 pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop); 783 } 784 } 785 if (threaded) { 786 // wait here for the threaded jobs to finish 787 if (!psThreadPoolWait ()) { 788 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 789 return false; 790 } 791 fprintf (stderr, "success for threaded jobs\n"); 792 793 // free the done jobs 794 psThreadJob *job = NULL; 795 while ((job = psThreadJobGetDone()) != NULL) { 796 psFree (job); 797 } 798 } 732 799 } 733 800 psFree(shutterImage); -
trunk/psModules/src/detrend/pmShutterCorrection.h
r18860 r18893 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $8 * @date $Date: 2008-08-0 1 23:58:37 $7 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-08-05 01:24:47 $ 9 9 * Copyright 2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 124 124 ); 125 125 126 bool pmShutterCorrectionApplyScan_Threaded (psThreadJob *job); 127 bool pmShutterCorrectionApplyScan(psImage *image, psImage *shutterImage, psImage *mask, float exptime, psMaskType blank, int rowStart, int rowStop); 128 126 129 /// Apply a shutter correction 127 130 /// -
trunk/psModules/src/psmodules.h
r18828 r18893 13 13 #include <pmConfig.h> 14 14 #include <pmDetrendDB.h> 15 #include <pmDetrendThreads.h> 15 16 #include <pmHDU.h> 16 17 #include <pmFPA.h>
Note:
See TracChangeset
for help on using the changeset viewer.
