Changeset 19432
- Timestamp:
- Sep 8, 2008, 6:10:14 PM (18 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 8 edited
-
pmBias.c (modified) (4 diffs)
-
pmBias.h (modified) (3 diffs)
-
pmDark.c (modified) (9 diffs)
-
pmDark.h (modified) (1 diff)
-
pmFlatField.c (modified) (6 diffs)
-
pmFlatField.h (modified) (2 diffs)
-
pmShutterCorrection.c (modified) (6 diffs)
-
pmShutterCorrection.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmBias.c
r19299 r19432 23 23 PS_ASSERT_THREAD_JOB_NON_NULL(job, false); 24 24 pmReadout *in = job->args->data[0]; 25 pmReadout *sub = job->args->data[1];25 const pmReadout *sub = job->args->data[1]; 26 26 float scale = PS_SCALAR_VALUE(job->args->data[2],F32); 27 27 int xOffset = PS_SCALAR_VALUE(job->args->data[3],S32); … … 29 29 int rowStart = PS_SCALAR_VALUE(job->args->data[5],S32); 30 30 int rowStop = PS_SCALAR_VALUE(job->args->data[6],S32); 31 bool status = pmBiasSubtractScan(in, sub, scale, xOffset, yOffset, rowStart, rowStop);32 return status; 33 } 34 35 bool pmBiasSubtractScan (pmReadout *in, pmReadout *sub, float scale, int xOffset, int yOffset, int rowStart, int rowStop) { 36 31 return pmBiasSubtractScan(in, sub, scale, xOffset, yOffset, rowStart, rowStop); 32 } 33 34 bool pmBiasSubtractScan(pmReadout *in, const pmReadout *sub, float scale, 35 int xOffset, int yOffset, int rowStart, int rowStop) 36 { 37 37 psImage *inImage = in->image; // The input image 38 38 psImage *inMask = in->mask; // The input mask 39 psImage *subImage = sub->image;// The image to be subtracted40 psImage *subMask = sub->mask;// The mask for the subtraction image39 const psImage *subImage = sub->image; // The image to be subtracted 40 const psImage *subMask = sub->mask; // The mask for the subtraction image 41 41 42 42 if (scale == 1.0) { … … 62 62 } 63 63 64 // pmBiasSubtractFrame(): this routine will take as input a readout for the input image and a readout for the bias 64 // pmBiasSubtractFrame(): 65 // this routine will take as input a readout for the input image and a readout for the bias 65 66 // image. The bias image is subtracted in place from the input image. 66 67 bool pmBiasSubtractFrame(pmReadout *in, // Input readout … … 129 130 130 131 for (int rowStart = 0; rowStart < inImage->numRows; rowStart += scanRows) { 131 int rowStop = PS_MIN(rowStart + scanRows, inImage->numRows);132 133 if (threaded) {134 // allocate a job, construct the arguments for this job135 psThreadJob *job = psThreadJobAlloc("PSMODULES_DETREND_BIAS");136 psArrayAdd(job->args, 1, in);137 psArrayAdd(job->args, 1, sub);138 PS_ARRAY_ADD_SCALAR(job->args, scale, PS_TYPE_F32);139 PS_ARRAY_ADD_SCALAR(job->args, xOffset, PS_TYPE_S32);140 PS_ARRAY_ADD_SCALAR(job->args, yOffset, PS_TYPE_S32);141 PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32);142 PS_ARRAY_ADD_SCALAR(job->args, rowStop, PS_TYPE_S32);143 144 // ppImageDetrendReadout(config, options, view)145 if (!psThreadJobAddPending (job)) {146 psFree(job);147 return false;148 }149 psFree(job);150 } else {151 pmBiasSubtractScan (in, sub, scale, xOffset, yOffset, rowStart, rowStop);152 }132 int rowStop = PS_MIN(rowStart + scanRows, inImage->numRows); 133 134 if (threaded) { 135 // allocate a job, construct the arguments for this job 136 psThreadJob *job = psThreadJobAlloc("PSMODULES_DETREND_BIAS"); 137 psArrayAdd(job->args, 1, in); 138 psArrayAdd(job->args, 1, sub); 139 PS_ARRAY_ADD_SCALAR(job->args, scale, PS_TYPE_F32); 140 PS_ARRAY_ADD_SCALAR(job->args, xOffset, PS_TYPE_S32); 141 PS_ARRAY_ADD_SCALAR(job->args, yOffset, PS_TYPE_S32); 142 PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32); 143 PS_ARRAY_ADD_SCALAR(job->args, rowStop, PS_TYPE_S32); 144 145 if (!psThreadJobAddPending(job)) { 146 psFree(job); 147 return false; 148 } 149 psFree(job); 150 } else if (!pmBiasSubtractScan(in, sub, scale, xOffset, yOffset, rowStart, rowStop)) { 151 psError(PS_ERR_UNKNOWN, false, "Unable to apply bias correction."); 152 return false; 153 } 153 154 } 154 155 155 156 if (threaded) { 156 157 // wait here for the threaded jobs to finish 157 if (!psThreadPoolWait(false)) { 158 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 159 return false; 160 } 161 fprintf (stderr, "success for threaded jobs\n"); 162 163 // each job records its own goodPixel values; sum them here 164 // we have only supplied one type of job, so we can assume the types here 165 psThreadJob *job = NULL; 166 while ((job = psThreadJobGetDone()) != NULL) { 167 psFree (job); 158 if (!psThreadPoolWait(true)) { 159 psError(PS_ERR_UNKNOWN, false, "Unable to apply bias correction."); 160 return false; 168 161 } 169 162 } -
trunk/psModules/src/detrend/pmBias.h
r19299 r19432 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $8 * @date $Date: 2008-0 8-30 02:28:07$7 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-09-09 04:10:14 $ 9 9 * Copyright 2004--2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 27 27 ); 28 28 29 // pmBiasSubtractFrame(): this routine will take as input a readout for the input image and a readout for the bias 29 // pmBiasSubtractFrame 30 // this routine will take as input a readout for the input image and a readout for the bias 30 31 // image. The bias image is subtracted in place from the input image. 31 32 bool pmBiasSubtractFrame(pmReadout *in, // Input readout … … 34 35 ); 35 36 36 bool pmBiasSubtractScan_Threaded(psThreadJob *job); 37 bool pmBiasSubtractScan (pmReadout *in, pmReadout *sub, float scan, int xOffset, int yOffset, int rowStart, int rowStop); 37 /// Thread entry point for bias subtraction 38 bool pmBiasSubtractScan_Threaded(psThreadJob *job ///< Job to execute 39 ); 40 41 /// Do bias subtraction for a scan 42 bool pmBiasSubtractScan( 43 pmReadout *in, ///< Input image to correct 44 const pmReadout *sub, ///< Bias+dark image to subtract 45 float scale, ///< Scale to apply 46 int xOffset, int yOffset, ///< Offset between input and bias images 47 int rowStart, int rowStop ///< Scan range 48 ); 38 49 39 50 /// @} -
trunk/psModules/src/detrend/pmDark.c
r19299 r19432 222 222 223 223 // these calls allocate and save the requested images on the output analysis metadata 224 psImage *counts = pmReadoutSetAnalysisImage(output->readouts->data[0], PM_READOUT_STACK_ANALYSIS_COUNT, numCols, numRows, PS_TYPE_U16, 0); 224 psImage *counts = pmReadoutSetAnalysisImage(output->readouts->data[0], PM_READOUT_STACK_ANALYSIS_COUNT, 225 numCols, numRows, PS_TYPE_U16, 0); 225 226 if (!counts) { 226 227 return false; 227 228 } 228 psImage *sigma = pmReadoutSetAnalysisImage(output->readouts->data[0], PM_READOUT_STACK_ANALYSIS_SIGMA, numCols, numRows, PS_TYPE_F32, NAN); 229 psImage *sigma = pmReadoutSetAnalysisImage(output->readouts->data[0], PM_READOUT_STACK_ANALYSIS_SIGMA, 230 numCols, numRows, PS_TYPE_F32, NAN); 229 231 if (!sigma) { 230 232 return false; 231 233 } 232 234 233 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, PM_DARK_ANALYSIS_ORDINATES, PS_DATA_ARRAY | PS_META_REPLACE, "Dark ordinates", ordinates); 234 psMetadataAddStr(output->analysis, PS_LIST_TAIL, PM_DARK_ANALYSIS_NORM, PS_META_REPLACE, "Dark normalisation", normConcept); 235 236 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "DARK.VALUES", PS_DATA_ARRAY | PS_META_REPLACE, "Dark values", values); 237 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "DARK.RO.MASK", PS_DATA_VECTOR | PS_META_REPLACE, "Dark Readout Mask", roMask); 238 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "DARK.NORM", PS_DATA_VECTOR | PS_META_REPLACE, "Dark norm", norm); 239 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "DARK.ORDERS", PS_DATA_VECTOR | PS_META_REPLACE, "Dark orders", orders); 235 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, PM_DARK_ANALYSIS_ORDINATES, 236 PS_DATA_ARRAY | PS_META_REPLACE, "Dark ordinates", ordinates); 237 psMetadataAddStr(output->analysis, PS_LIST_TAIL, PM_DARK_ANALYSIS_NORM, PS_META_REPLACE, 238 "Dark normalisation", normConcept); 239 240 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "DARK.VALUES", PS_DATA_ARRAY | PS_META_REPLACE, 241 "Dark values", values); 242 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "DARK.RO.MASK", PS_DATA_VECTOR | PS_META_REPLACE, 243 "Dark Readout Mask", roMask); 244 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "DARK.NORM", PS_DATA_VECTOR | PS_META_REPLACE, 245 "Dark norm", norm); 246 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "DARK.ORDERS", PS_DATA_VECTOR | PS_META_REPLACE, 247 "Dark orders", orders); 240 248 241 249 for (int i = 0; i < numTerms; i++) { … … 272 280 273 281 // retrieve the required parameter vectors 274 psArray *values = psMetadataLookupPtr(&mdok, output->analysis, "DARK.VALUES"); psAssert (values, "values not supplied"); 275 psVector *roMask = psMetadataLookupPtr(&mdok, output->analysis, "DARK.RO.MASK"); psAssert (roMask, "roMask not supplied"); 276 psVector *orders = psMetadataLookupPtr(&mdok, output->analysis, "DARK.ORDERS"); psAssert (orders, "orders not supplied"); 282 psArray *values = psMetadataLookupPtr(&mdok, output->analysis, "DARK.VALUES"); 283 psAssert(values, "values not supplied"); 284 psVector *roMask = psMetadataLookupPtr(&mdok, output->analysis, "DARK.RO.MASK"); 285 psAssert(roMask, "roMask not supplied"); 286 psVector *orders = psMetadataLookupPtr(&mdok, output->analysis, "DARK.ORDERS"); 287 psAssert(orders, "orders not supplied"); 277 288 278 289 psPolynomialMD *poly = psPolynomialMDAlloc(orders); // Polynomial for fitting … … 307 318 int yOut = i - outReadout->row0; // y position on output readout 308 319 309 # ifdef SHOW_BUSY320 #ifdef SHOW_BUSY 310 321 if (psTraceGetLevel("psModules.detrend") > 9) { 311 322 printf("Processing row %d\r", i); 312 323 fflush(stdout); 313 324 } 314 # endif325 #endif 315 326 316 327 for (int j = minInputCols; j < maxInputCols; j++) { … … 337 348 } 338 349 339 // XXX test340 if (0 && (i == 377) && (j == 80)) {341 FILE *f = fopen ("test.dat", "w");342 for (int r = 0; r < inputs->n; r++) {343 fprintf (f, "%d %d %d ", i, j, mask->data.U8[r]);344 psVector *value = values->data[r];345 for (int tmpj = 0; tmpj < value->n; tmpj++) {346 fprintf (f, "%f ", value->data.F32[tmpj]);347 }348 fprintf (f, "%f\n", pixels->data.F32[r]);349 }350 fclose (f);351 }352 353 350 if (!psPolynomialMDClipFit(poly, pixels, NULL, mask, maskVal, values, iter, rej)) { 354 351 psErrorClear(); // Nothing we can do about it … … 367 364 psFree(mask); 368 365 369 fprintf (stderr, "done with combine %x : %f sec\n", (unsigned int) id, psTimerMark (name));370 366 return true; 371 367 } … … 375 371 PS_ASSERT_THREAD_JOB_NON_NULL(job, false); 376 372 377 pmReadout *readout = job->args->data[0]; 378 pmCell *dark = job->args->data[1]; 379 psPolynomialMD *poly = job->args->data[2]; 380 psVector *values = job->args->data[3]; 381 382 psMaskType bad = PS_SCALAR_VALUE(job->args->data[4],U8); 383 bool doNorm = PS_SCALAR_VALUE(job->args->data[5],U8); 384 float norm = PS_SCALAR_VALUE(job->args->data[6],F32); 385 int rowStart = PS_SCALAR_VALUE(job->args->data[7],S32); 386 int rowStop = PS_SCALAR_VALUE(job->args->data[8],S32); 387 bool status = pmDarkApplyScan (readout, dark, poly, values, bad, doNorm, norm, rowStart, rowStop); 388 return status; 389 } 390 391 bool pmDarkApplyScan (pmReadout *readout, const pmCell *dark, psPolynomialMD *poly, psVector *values, psMaskType bad, bool doNorm, float norm, int rowStart, int rowStop) { 392 373 pmReadout *readout = job->args->data[0]; // Readout to correct 374 pmCell *dark = job->args->data[1]; // Dark to apply 375 const psVector *orders = job->args->data[2]; // Polynomial orders for each ordinate 376 const psVector *values = job->args->data[3]; // Values for each ordinate 377 378 psMaskType bad = PS_SCALAR_VALUE(job->args->data[4], U8); // Mask value to give bad pixels 379 bool doNorm = PS_SCALAR_VALUE(job->args->data[5], U8); // Normalise values? 380 float norm = PS_SCALAR_VALUE(job->args->data[6], F32); // Value by which to normalise 381 int rowStart = PS_SCALAR_VALUE(job->args->data[7], S32); // Starting row for scan 382 int rowStop = PS_SCALAR_VALUE(job->args->data[8], S32); // Stopping row for scan 383 384 return pmDarkApplyScan(readout, dark, orders, values, bad, doNorm, norm, rowStart, rowStop); 385 } 386 387 bool pmDarkApplyScan(pmReadout *readout, const pmCell *dark, const psVector *orders, const psVector *values, 388 psMaskType bad, bool doNorm, float norm, int rowStart, int rowStop) 389 { 393 390 int numCols = readout->image->numCols; 394 391 int numTerms = dark->readouts->n; // Number of polynomial terms 395 392 396 // thread here by scan 393 psPolynomialMD *poly = psPolynomialMDAlloc(orders); // Polynomial to apply 394 397 395 for (int y = rowStart; y < rowStop; y++) { 398 396 for (int x = 0; x < numCols; x++) { … … 411 409 } 412 410 } 411 psFree(poly); 412 413 413 return true; 414 414 } … … 478 478 } 479 479 480 psPolynomialMD *poly = psPolynomialMDAlloc(orders); // Polynomial to apply481 psFree(orders);482 483 480 // thread here by scan 484 481 … … 491 488 492 489 for (int rowStart = 0; rowStart < readout->image->numRows; rowStart += scanRows) { 493 int rowStop = PS_MIN (rowStart + scanRows, readout->image->numRows); 494 495 if (threaded) { 496 // allocate a job, construct the arguments for this job 497 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_DARK"); 498 psArrayAdd (job->args, 1, readout); 499 psArrayAdd (job->args, 1, dark); 500 psArrayAdd (job->args, 1, poly); 501 psArrayAdd (job->args, 1, values); 502 PS_ARRAY_ADD_SCALAR (job->args, bad, PS_TYPE_MASK); 503 PS_ARRAY_ADD_SCALAR (job->args, doNorm, PS_TYPE_U8); 504 PS_ARRAY_ADD_SCALAR (job->args, norm, PS_TYPE_F32); 505 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32); 506 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32); 507 508 // ppImageDetrendReadout(config, options, view) 509 if (!psThreadJobAddPending (job)) { 510 psFree(job); 511 return false; 512 } 513 psFree(job); 514 } else { 515 pmDarkApplyScan (readout, dark, poly, values, bad, doNorm, norm, rowStart, rowStop); 516 } 490 int rowStop = PS_MIN(rowStart + scanRows, readout->image->numRows); 491 492 if (threaded) { 493 psThreadJob *job = psThreadJobAlloc("PSMODULES_DETREND_DARK"); 494 psArrayAdd(job->args, 1, readout); 495 psArrayAdd(job->args, 1, dark); 496 psArrayAdd(job->args, 1, orders); 497 psArrayAdd(job->args, 1, values); 498 PS_ARRAY_ADD_SCALAR(job->args, bad, PS_TYPE_MASK); 499 PS_ARRAY_ADD_SCALAR(job->args, doNorm, PS_TYPE_U8); 500 PS_ARRAY_ADD_SCALAR(job->args, norm, PS_TYPE_F32); 501 PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32); 502 PS_ARRAY_ADD_SCALAR(job->args, rowStop, PS_TYPE_S32); 503 504 if (!psThreadJobAddPending (job)) { 505 psFree(job); 506 psFree(orders); 507 psFree(values); 508 return false; 509 } 510 psFree(job); 511 } else if (!pmDarkApplyScan(readout, dark, orders, values, bad, doNorm, norm, rowStart, rowStop)) { 512 psError(PS_ERR_UNKNOWN, false, "Unable to apply dark."); 513 psFree(orders); 514 psFree(values); 515 return false; 516 } 517 517 } 518 518 519 519 if (threaded) { 520 520 // wait here for the threaded jobs to finish 521 if (!psThreadPoolWait(false)) { 522 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 521 if (!psThreadPoolWait(true)) { 522 psError(PS_ERR_UNKNOWN, false, "Unable to apply dark."); 523 psFree(orders); 524 psFree(values); 523 525 return false; 524 526 } 525 fprintf (stderr, "success for threaded jobs\n"); 526 527 // free the done jobs 528 psThreadJob *job = NULL; 529 while ((job = psThreadJobGetDone()) != NULL) { 530 psFree (job); 531 } 532 } 533 534 psFree(poly); 527 } 528 529 psFree(orders); 535 530 psFree(values); 536 531 -
trunk/psModules/src/detrend/pmDark.h
r19299 r19432 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); 42 // Thread entry point for pmDarkApplyScan 43 bool pmDarkApplyScan_Threaded(psThreadJob *job // Job to execute 44 ); 45 46 // Apply the dark correction to a scan 47 bool pmDarkApplyScan(pmReadout *readout, // Readout to correct 48 const pmCell *dark, // Dark to apply 49 const psVector *orders, // Polynomial orders for each ordinate 50 const psVector *values, // Values for each ordinate 51 psMaskType bad, // Value to give bad pixels 52 bool doNorm, // Normalise values? 53 float norm, // Value by which to normalise 54 int rowStart, int rowStop // Scan range to work on 55 ); 44 56 45 57 // Apply dark -
trunk/psModules/src/detrend/pmFlatField.c
r19299 r19432 17 17 PS_ASSERT_THREAD_JOB_NON_NULL(job, false); 18 18 19 psImage *inImage = job->args->data[0]; 20 psImage *inMask = job->args->data[1]; 21 psImage *flatImage = job->args->data[2];22 psImage *flatMask = job->args->data[3];19 psImage *inImage = job->args->data[0]; // Input image 20 psImage *inMask = job->args->data[1]; // Input mask 21 const psImage *flatImage = job->args->data[2]; // Flat-field image 22 const psImage *flatMask = job->args->data[3]; // Flat-field mask 23 23 24 24 psMaskType badFlat = PS_SCALAR_VALUE(job->args->data[4],U8); … … 27 27 int rowStart = PS_SCALAR_VALUE(job->args->data[7],S32); 28 28 int rowStop = PS_SCALAR_VALUE(job->args->data[8],S32); 29 bool status = pmFlatFieldScan (inImage, inMask, flatImage, flatMask, badFlat, xOffset, yOffset, rowStart, rowStop);30 return status;29 return pmFlatFieldScan(inImage, inMask, flatImage, flatMask, badFlat, 30 xOffset, yOffset, rowStart, rowStop); 31 31 } 32 32 … … 50 50 break; 51 51 52 bool pmFlatFieldScan (psImage *inImage, psImage *inMask, psImage *flatImage, psImage *flatMask, psMaskType badFlat, int xOffset, int yOffset, int rowStart, int rowStop) { 53 52 bool pmFlatFieldScan(psImage *inImage, psImage *inMask, const psImage *flatImage, const psImage *flatMask, 53 psMaskType badFlat, int xOffset, int yOffset, int rowStart, int rowStop) 54 { 54 55 switch (inImage->type.type) { 55 56 FLAT_DIVISION_CASE(U8, 0); … … 138 139 139 140 for (int rowStart = 0; rowStart < inImage->numRows; rowStart += scanRows) { 140 int rowStop = PS_MIN (rowStart + scanRows, inImage->numRows);141 int rowStop = PS_MIN(rowStart + scanRows, inImage->numRows); 141 142 142 143 if (threaded) { 143 144 // allocate a job, construct the arguments for this job 144 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_FLAT");145 psArrayAdd (job->args, 1, inImage);146 psArrayAdd (job->args, 1, inMask);147 psArrayAdd (job->args, 1, flatImage);148 psArrayAdd (job->args, 1, flatMask);149 PS_ARRAY_ADD_SCALAR (job->args, badFlat, PS_TYPE_U8);150 PS_ARRAY_ADD_SCALAR (job->args, xOffset, PS_TYPE_S32);151 PS_ARRAY_ADD_SCALAR (job->args, yOffset, PS_TYPE_S32);152 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32);153 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32);145 psThreadJob *job = psThreadJobAlloc("PSMODULES_DETREND_FLAT"); 146 psArrayAdd(job->args, 1, inImage); 147 psArrayAdd(job->args, 1, inMask); 148 psArrayAdd(job->args, 1, flatImage); 149 psArrayAdd(job->args, 1, flatMask); 150 PS_ARRAY_ADD_SCALAR(job->args, badFlat, PS_TYPE_U8); 151 PS_ARRAY_ADD_SCALAR(job->args, xOffset, PS_TYPE_S32); 152 PS_ARRAY_ADD_SCALAR(job->args, yOffset, PS_TYPE_S32); 153 PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32); 154 PS_ARRAY_ADD_SCALAR(job->args, rowStop, PS_TYPE_S32); 154 155 155 // ppImageDetrendReadout(config, options, view) 156 if (!psThreadJobAddPending (job)) { 156 if (!psThreadJobAddPending(job)) { 157 157 psFree(job); 158 158 return false; 159 159 } 160 160 psFree(job); 161 } else { 162 pmFlatFieldScan (inImage, inMask, flatImage, flatMask, badFlat, xOffset, yOffset, rowStart, rowStop); 161 } else if (!pmFlatFieldScan(inImage, inMask, flatImage, flatMask, badFlat, 162 xOffset, yOffset, rowStart, rowStop)) { 163 psError(PS_ERR_UNKNOWN, false, "Unable to flat-field image."); 164 return false; 163 165 } 164 166 } … … 166 168 if (threaded) { 167 169 // wait here for the threaded jobs to finish 168 if (!psThreadPoolWait( false)) {169 psError(PS_ERR_UNKNOWN, false, "Unable to interpolateimage.");170 if (!psThreadPoolWait(true)) { 171 psError(PS_ERR_UNKNOWN, false, "Unable to flat-field image."); 170 172 return false; 171 }172 fprintf (stderr, "success for threaded jobs\n");173 174 // free done jobs175 psThreadJob *job = NULL;176 while ((job = psThreadJobGetDone()) != NULL) {177 psFree (job);178 173 } 179 174 } … … 187 182 psFree(timeString); 188 183 189 190 184 return true; 191 185 } -
trunk/psModules/src/detrend/pmFlatField.h
r19299 r19432 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2008-0 8-30 02:28:07$7 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-09-09 04:10:14 $ 9 9 * Copyright 2004-2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 28 28 ); 29 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); 30 /// Thread entry point for flat-fielding 31 bool pmFlatFieldScan_Threaded(psThreadJob *job ///< Job to exectute 32 ); 33 34 /// Flat-field a scan 35 bool pmFlatFieldScan( 36 psImage *inImage, ///< Input image to correct 37 psImage *inMask, ///< Input mask image 38 const psImage *flatImage, ///< Flat-field image 39 const psImage *flatMask, ///< Flat-field mask 40 psMaskType badFlag, ///< Mask value to give bad pixels 41 int xOffset, int yOffset, ///< Offset between input and flat-field 42 int rowStart, int rowStop ///< Scan range 43 ); 32 44 33 45 -
trunk/psModules/src/detrend/pmShutterCorrection.c
r19299 r19432 661 661 662 662 psImage *image = job->args->data[0]; 663 psImage *shutterImage = job->args->data[1];663 const psImage *shutterImage = job->args->data[1]; 664 664 psImage *mask = job->args->data[2]; 665 665 … … 668 668 int rowStart = PS_SCALAR_VALUE(job->args->data[5],S32); 669 669 int rowStop = PS_SCALAR_VALUE(job->args->data[6],S32); 670 bool status =pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop);671 return status; 672 } 673 674 bool pmShutterCorrectionApplyScan(psImage *image, psImage *shutterImage, psImage *mask, float exptime,psMaskType blank, int rowStart, int rowStop)670 return pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop); 671 } 672 673 bool pmShutterCorrectionApplyScan(psImage *image, const psImage *shutterImage, psImage *mask, float exptime, 674 psMaskType blank, int rowStart, int rowStop) 675 675 { 676 676 for (int y = rowStart; y < rowStop; y++) { … … 753 753 } 754 754 } 755 psMetadataAddF32 (cell->concepts, PS_LIST_TAIL, "CELL.EXPOSURE", PS_META_REPLACE, "exposure time re-normalized to 1.0", 1.0); // Exposure time 755 psMetadataAddF32(cell->concepts, PS_LIST_TAIL, "CELL.EXPOSURE", PS_META_REPLACE, 756 "exposure time re-normalized to 1.0", 1.0); // Exposure time 756 757 psString line = NULL; 757 psStringAppend (&line, "extreme exposure time %f, re-normalized to 1.0", exptime);758 psStringAppend(&line, "extreme exposure time %f, re-normalized to 1.0", exptime); 758 759 psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, line, ""); 759 psFree (line);760 psFree(line); 760 761 } else { 761 762 for (int rowStart = 0; rowStart < image->numRows; rowStart += scanRows) { … … 764 765 if (threaded) { 765 766 // allocate a job, construct the arguments for this job 766 psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_SHUTTER"); 767 psArrayAdd (job->args, 1, image); 768 psArrayAdd (job->args, 1, shutterImage); 769 psArrayAdd (job->args, 1, mask); 770 PS_ARRAY_ADD_SCALAR (job->args, exptime, PS_TYPE_F32); 771 PS_ARRAY_ADD_SCALAR (job->args, blank, PS_TYPE_MASK); 772 PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32); 773 PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32); 774 775 // ppImageDetrendReadout(config, options, view) 776 if (!psThreadJobAddPending (job)) { 767 psThreadJob *job = psThreadJobAlloc("PSMODULES_DETREND_SHUTTER"); 768 psArrayAdd(job->args, 1, image); 769 psArrayAdd(job->args, 1, shutterImage); 770 psArrayAdd(job->args, 1, mask); 771 PS_ARRAY_ADD_SCALAR(job->args, exptime, PS_TYPE_F32); 772 PS_ARRAY_ADD_SCALAR(job->args, blank, PS_TYPE_MASK); 773 PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32); 774 PS_ARRAY_ADD_SCALAR(job->args, rowStop, PS_TYPE_S32); 775 776 if (!psThreadJobAddPending(job)) { 777 777 psFree(job); 778 778 return false; 779 779 } 780 780 psFree(job); 781 } else { 782 pmShutterCorrectionApplyScan (image, shutterImage, mask, exptime, blank, rowStart, rowStop); 781 } else if (!pmShutterCorrectionApplyScan(image, shutterImage, mask, exptime, blank, 782 rowStart, rowStop)) { 783 psError(PS_ERR_UNKNOWN, false, "Unable to apply shutter correction."); 784 psFree(shutterImage); 785 return false; 783 786 } 784 787 } 785 788 if (threaded) { 786 789 // wait here for the threaded jobs to finish 787 if (!psThreadPoolWait(false)) { 788 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 790 if (!psThreadPoolWait(true)) { 791 psError(PS_ERR_UNKNOWN, false, "Unable to apply shutter correction."); 792 psFree(shutterImage); 789 793 return false; 790 }791 fprintf (stderr, "success for threaded jobs\n");792 793 // free the done jobs794 psThreadJob *job = NULL;795 while ((job = psThreadJobGetDone()) != NULL) {796 psFree (job);797 794 } 798 795 } … … 1024 1021 } 1025 1022 1026 bool pmShutterCorrectionGeneratePrepare(pmReadout *shutter, pmReadout *pattern, const psArray *inputs, psMaskType maskVal) 1023 bool pmShutterCorrectionGeneratePrepare(pmReadout *shutter, pmReadout *pattern, const psArray *inputs, 1024 psMaskType maskVal) 1027 1025 { 1028 1026 PS_ASSERT_PTR_NON_NULL(shutter, false); … … 1043 1041 } 1044 1042 1045 psImage *nums = pmReadoutSetAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_COUNT, numCols, numRows, PS_TYPE_U16, 0); // Image with number fitted per pixel 1043 psImage *nums = pmReadoutSetAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_COUNT, numCols, numRows, 1044 PS_TYPE_U16, 0); // Image with number fitted per pixel 1046 1045 if (!nums) { 1047 1046 return false; 1048 1047 } 1049 psImage *sigma = pmReadoutSetAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_SIGMA, numCols, numRows, PS_TYPE_F32, NAN); // Image with stdev per pixel 1048 psImage *sigma = pmReadoutSetAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_SIGMA, numCols, numRows, 1049 PS_TYPE_F32, NAN); // Image with stdev per pixel 1050 1050 if (!sigma) { 1051 1051 return false; -
trunk/psModules/src/detrend/pmShutterCorrection.h
r19299 r19432 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $8 * @date $Date: 2008-0 8-30 02:28:07$7 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-09-09 04:10:14 $ 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); 126 /// Thread entry point for applying a shutter correction 127 bool pmShutterCorrectionApplyScan_Threaded( 128 psThreadJob *job ///< Job to execute 129 ); 130 131 /// Apply the shutter correction to a scan 132 bool pmShutterCorrectionApplyScan( 133 psImage *image, ///< Input image to correct 134 const psImage *shutterImage, ///< Shutter correction image 135 psImage *mask, ///< Input mask image 136 float exptime, ///< Exposure time to which to correct 137 psMaskType blank, ///< Mask value to give blank pixels 138 int rowStart, int rowStop ///< Range of scan 139 ); 128 140 129 141 /// Apply a shutter correction … … 193 205 194 206 // prepare outputs for shutter correction 195 bool pmShutterCorrectionGeneratePrepare(pmReadout *shutter, pmReadout *pattern, const psArray *inputs, psMaskType maskVal); 207 bool pmShutterCorrectionGeneratePrepare(pmReadout *shutter, pmReadout *pattern, const psArray *inputs, 208 psMaskType maskVal); 196 209 197 210 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
