00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "visir_recipe.h"
00037
00038 #include <string.h>
00039 #include <strings.h>
00040 #include <math.h>
00041 #ifdef _OPENMP
00042 #include <omp.h>
00043 #endif
00044
00045
00046
00047
00048
00049 #define RECIPE_STRING "visir_util_clip"
00050
00051 #ifndef VISIR_UTIL_CLIP_KEEPFRAC
00052 #define VISIR_UTIL_CLIP_KEEPFRAC 0.9
00053 #endif
00054 #ifndef VISIR_UTIL_CLIP_KAPPA
00055 #define VISIR_UTIL_CLIP_KAPPA 5.0
00056 #endif
00057
00058 #ifndef VISIR_UTIL_CLIP_MAXITE
00059 #define VISIR_UTIL_CLIP_MAXITE 3
00060 #endif
00061
00062 #define VISIR_UTIL_CLIP_QC_MAP_MAX "ESO QC CONTRIBUTION MAX"
00063 #define VISIR_UTIL_CLIP_QC_MAP_MEAN "ESO QC CONTRIBUTION MEAN"
00064 #define VISIR_UTIL_CLIP_QC_MAP_MEDIAN "ESO QC CONTRIBUTION MEDIAN"
00065
00066 typedef enum {
00067 VISIR_ERROR_SRC_IMG_STDEV,
00068 VISIR_ERROR_SRC_TIMESERIES,
00069 } visir_error_source;
00070
00071
00072 static int prnok_nz = 0;
00073 static double * prnok = NULL;
00074
00075
00076
00077
00078 static double median_abs_dev(const cpl_image * img)
00079 {
00080
00081 const size_t npix = cpl_image_get_size_x(img) * cpl_image_get_size_y(img);
00082 const double median = cpl_image_get_median(img);
00083 const cpl_mask * bpm = cpl_image_get_bpm_const(img);
00084 const cpl_binary * bpm_ = cpl_mask_get_data_const(bpm);
00085 const float * data = cpl_image_get_data_float_const(img);
00086 cpl_array * tmp = cpl_array_new(npix, CPL_TYPE_FLOAT);
00087
00088 for (size_t i = 0; i < npix; i++)
00089 if (bpm_[i] != CPL_BINARY_0)
00090 cpl_array_set_invalid(tmp, i);
00091 else
00092 cpl_array_set_float(tmp, i, fabs(data[i] - median));
00093
00094 double mad = cpl_array_get_median(tmp);
00095 cpl_array_delete(tmp);
00096 return mad;
00097 }
00098
00099 static
00100 cpl_error_code visir_util_clip_kappa_sigma_double(cpl_imagelist *,
00101 cpl_imagelist *,
00102 double, double, int,
00103 const int *);
00104 static
00105 cpl_error_code visir_util_clip_kappa_sigma_float(cpl_imagelist *,
00106 cpl_imagelist *,
00107 double, double, int,
00108 const int *);
00109 static
00110 cpl_error_code visir_util_clip_kappa_sigma_int(cpl_imagelist *,
00111 cpl_imagelist *,
00112 double, double, int,
00113 const int *);
00114
00115 static cpl_error_code visir_util_clip_one(cpl_frameset *,
00116 irplib_framelist *,
00117 irplib_framelist *,
00118 const cpl_mask *,
00119 int, cpl_boolean,
00120 const cpl_parameterlist *);
00121
00122 static cpl_error_code visir_util_clip_kappa_sigma(cpl_imagelist *,
00123 cpl_imagelist *,
00124 const cpl_parameterlist *,
00125 const int * shifts);
00126
00127
00128 #ifdef VISIR_CHAIN
00129 #define cpl_plugin_get_info visir_util_clip_get_info
00130 #endif
00131 cpl_recipe_define(visir_util_clip, VISIR_BINARY_VERSION,
00132 "Lars Lundin", PACKAGE_BUGREPORT, "2011",
00133 "Kappa-sigma clipping of outliers for each pixel",
00134 "The files listed in the Set Of Frames (sof-file) "
00135 "must be tagged pair-wise:\n"
00136 "VISIR-raw-file.fits " VISIR_UTIL_INPUTS_RAW "\n"
00137 "VISIR-bpm-file.fits " VISIR_CALIB_BPM "\n"
00138 "\nThe product(s) will have a FITS card\n"
00139 "'HIERARCH ESO PRO CATG' with a value of:\n"
00140 VISIR_IMG_CLIPPED_PROCATG "\n"
00141 "The outliers are marked as rejected in the matching\n"
00142 "bad pixel map.");
00143
00144
00148
00149
00150
00151
00152
00153
00154
00162
00163 static
00164 cpl_error_code visir_util_clip_fill_parameterlist(cpl_parameterlist * self)
00165 {
00166
00167 const char * context = PACKAGE "." RECIPE_STRING;
00168 cpl_error_code err;
00169
00170 cpl_ensure_code(self, CPL_ERROR_NULL_INPUT);
00171
00172
00173
00174
00175 err = irplib_parameterlist_set_double(self, PACKAGE, RECIPE_STRING,
00176 "keepfrac", VISIR_UTIL_CLIP_KEEPFRAC,
00177 NULL, context, "The fraction of "
00178 "pixels to keep for the initial"
00179 "median");
00180 cpl_ensure_code(!err, err);
00181
00182
00183
00184 err = irplib_parameterlist_set_double(self, PACKAGE, RECIPE_STRING,
00185 "kappa", VISIR_UTIL_CLIP_KAPPA,
00186 NULL, context, "Clip outside "
00187 "+ or - kappa * sigma "
00188 "(the standard deviation)");
00189 cpl_ensure_code(!err, err);
00190
00191
00192
00193 err = irplib_parameterlist_set_int(self, PACKAGE, RECIPE_STRING,
00194 "maxite", VISIR_UTIL_CLIP_MAXITE, NULL,
00195 context, "Max number of kappa-sigma "
00196 "clipping iterations");
00197 cpl_ensure_code(!err, err);
00198
00199
00200 err = irplib_parameterlist_set_bool(self, PACKAGE, RECIPE_STRING,
00201 "shift-beams", CPL_TRUE, NULL,
00202 context, "Account for movements of the "
00203 "object defined in CRPIX[12]");
00204 cpl_ensure_code(!err, err);
00205
00206
00207
00208
00209 err = irplib_parameterlist_set_string(self, PACKAGE, RECIPE_STRING,
00210 "error-source", "img-stdev", NULL,
00211 context, "Defines the way errors "
00212 "are generated:\n"
00213 " img-stdev: stdev of image\n"
00214 " timeseries: stdev of each pixel "
00215 "over the time axis of the cube\n"
00216 " none: no error generation");
00217 cpl_ensure_code(!err, err);
00218
00219
00220 err = irplib_parameterlist_set_string(self, PACKAGE, RECIPE_STRING,
00221 "error-out-type", "error", NULL,
00222 context, "Output clipped error as "
00223 "error, variance, weight or none");
00224 cpl_ensure_code(!err, err);
00225
00226
00227 err = irplib_parameterlist_set_double(self, PACKAGE, RECIPE_STRING,
00228 "badimage", 0.2, NULL,
00229 context, "If percentage of clipped "
00230 "pixels above this value the whole "
00231 "image is considered bad");
00232 cpl_ensure_code(!err, err);
00233
00234 return CPL_ERROR_NONE;
00235
00236 }
00237
00238
00245
00246 static int visir_util_clip(cpl_frameset * framelist,
00247 const cpl_parameterlist * parlist)
00248 {
00249 cpl_errorstate cleanstate = cpl_errorstate_get();
00250 cpl_error_code didfail = CPL_ERROR_NONE;
00251 irplib_framelist * allframes = NULL;
00252 irplib_framelist * rawframes = NULL;
00253 irplib_framelist * bpmframes = NULL;
00254 cpl_size n, nbad = 0;
00255 cpl_mask * static_mask = NULL;
00256 prnok = NULL;
00257
00258 #ifdef _OPENMP
00259 omp_set_num_threads(visir_get_num_threads(CPL_FALSE));
00260 #endif
00261
00262
00263 skip_if (visir_dfs_set_groups(framelist));
00264 cpl_fits_set_mode(CPL_FITS_START_CACHING);
00265
00266
00267 allframes = irplib_framelist_cast(framelist);
00268 skip_if(allframes == NULL);
00269 rawframes =
00270 irplib_framelist_extract_regexp(allframes, "^("VISIR_UTIL_INPUTS_RAW
00271 "|"VISIR_UTIL_CORRECTED")$",
00272 CPL_FALSE);
00273 skip_if (rawframes == NULL);
00274 bpmframes = irplib_framelist_extract_regexp(allframes, "^(" VISIR_CALIB_BPM
00275 ")$", CPL_FALSE);
00276
00277 if (bpmframes == NULL)
00278 cpl_errorstate_set(cleanstate);
00279 else
00280 nbad = irplib_framelist_get_size(bpmframes);
00281
00282 {
00283 cpl_frame * static_frm = cpl_frameset_find(framelist,
00284 VISIR_CALIB_STATIC_MASK);
00285 if (static_frm) {
00286 const char * fn = cpl_frame_get_filename(static_frm);
00287 static_mask = cpl_mask_load(fn, 0, 0);
00288 if (!static_mask) {
00289 cpl_errorstate_set(cleanstate);
00290 static_mask = cpl_mask_load(fn, 0, 1);
00291 if (!static_mask)
00292 cpl_errorstate_set(cleanstate);
00293 }
00294 }
00295 }
00296
00297 n = irplib_framelist_get_size(rawframes);
00298 error_if(nbad != n && nbad != 1 && nbad != 0, CPL_ERROR_INCOMPATIBLE_INPUT,
00299 "%d raw-frames <=> %d bpm frames", (int)n, (int)nbad);
00300
00301
00302 #if defined _OPENMP && \
00303 defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(6, 1, 0)
00304 #pragma omp parallel for
00305 #endif
00306 for (cpl_size i = 0; i < n; i++) {
00307 if (!didfail) {
00308
00309
00310
00311
00312
00313
00314
00315
00316 if (visir_util_clip_one(framelist, rawframes, bpmframes,
00317 static_mask, i,
00318 nbad == 1, parlist)) {
00319 const cpl_error_code errori = cpl_error_set_where(cpl_func);
00320 #ifdef _OPENMP
00321
00322
00323 cpl_errorstate_dump(cleanstate, CPL_FALSE, NULL);
00324 cpl_errorstate_set(cleanstate);
00325 #pragma omp critical(visir_util_clip)
00326 #endif
00327 didfail = errori;
00328 }
00329 }
00330 }
00331
00332 error_if(didfail, didfail, "Failed to clip %d frame(s)", (int)n);
00333
00334 end_skip;
00335
00336 irplib_framelist_delete(allframes);
00337 irplib_framelist_delete(rawframes);
00338 irplib_framelist_delete(bpmframes);
00339 cpl_free(prnok);
00340 prnok = NULL;
00341
00342 return cpl_error_get_code();
00343 }
00344
00345
00346
00358
00359 static cpl_error_code visir_util_clip_one(cpl_frameset * framelist,
00360 irplib_framelist * rawframes,
00361 irplib_framelist * bpmframes,
00362 const cpl_mask * static_mask,
00363 int iframe, cpl_boolean bshared,
00364 const cpl_parameterlist * parlist)
00365 {
00366
00367 cpl_frameset * products = cpl_frameset_new();
00368 cpl_frameset * usedframes = cpl_frameset_new();
00369
00370 char * bpmname = cpl_sprintf(RECIPE_STRING "_bpm_%03d" CPL_DFS_FITS, iframe);
00371 char * mapname = cpl_sprintf(RECIPE_STRING "_map_%03d" CPL_DFS_FITS, iframe);
00372 char * errname = cpl_sprintf(RECIPE_STRING "_error_%03d" CPL_DFS_FITS, iframe);
00373
00374 const int n = irplib_framelist_get_size(rawframes);
00375 cpl_frameset * rawone = cpl_frameset_new();
00376 cpl_frameset * bpmone = cpl_frameset_new();
00377 cpl_frame * rawframe =
00378 cpl_frame_duplicate(irplib_framelist_get_const(rawframes, iframe));
00379 cpl_frame * bpmframe = bpmframes ?
00380 cpl_frame_duplicate(irplib_framelist_get_const(bpmframes,
00381 bshared ? 0 : iframe))
00382 : NULL;
00383 const cpl_error_code errr = cpl_frameset_insert(rawone, rawframe);
00384 const cpl_error_code errb = bpmframe ?
00385 cpl_frameset_insert(bpmone, bpmframe) : CPL_ERROR_NONE;
00386
00387 const char * serr = irplib_parameterlist_get_string(parlist, PACKAGE,
00388 RECIPE_STRING,
00389 "error-out-type");
00390 cpl_boolean berr = serr && strcasecmp(serr, "none") != 0;
00391
00392 const cpl_boolean bshifts = irplib_parameterlist_get_bool(parlist, PACKAGE,
00393 RECIPE_STRING,
00394 "shift-beams");
00395
00396 const double badimage = irplib_parameterlist_get_double(parlist, PACKAGE,
00397 RECIPE_STRING,
00398 "badimage");
00399
00400 const char * serr_src =
00401 irplib_parameterlist_get_string(parlist, PACKAGE, RECIPE_STRING,
00402 "error-source");
00403
00404 cpl_imagelist * devlist = cpl_imagelist_new();
00405 cpl_imagelist * rawlist =
00406 cpl_imagelist_load_frameset(rawone, CPL_TYPE_UNSPECIFIED, 0, -1);
00407 cpl_imagelist * bpmlist = bpmframe ?
00408 cpl_imagelist_load_frameset(bpmone, CPL_TYPE_INT, 0, -1) : NULL;
00409
00410 cpl_mask * bpm = NULL;
00411 cpl_image * map = NULL;
00412 cpl_propertylist * qclist = cpl_propertylist_new();
00413 cpl_propertylist * xtlist = cpl_propertylist_new();
00414
00415 const int m = rawlist ? cpl_imagelist_get_size(rawlist) : 0;
00416 const int nbpm = bpmlist ? cpl_imagelist_get_size(bpmlist) : 0;
00417 int mapmax, mapmean, mapmedian;
00418 int * shifts = cpl_calloc(m * 2, sizeof(int));
00419 double fx = 0, fy = 0;
00420
00421 const char * err_procatg = "ERROR_MAP";
00422 visir_error_type terr = VISIR_ERROR;
00423 visir_error_source err_src = VISIR_ERROR_SRC_IMG_STDEV;
00424 if (berr && strcmp(serr, "variance") == 0) {
00425 terr = VISIR_VARIANCE;
00426 err_procatg = "VARIANCE_MAP";
00427 }
00428 else if (berr && strcmp(serr, "weight") == 0) {
00429 terr = VISIR_WEIGHT;
00430 err_procatg = "WEIGHT_MAP";
00431 }
00432
00433 if (serr_src && !strcmp(serr_src, "img-stdev"))
00434 err_src = VISIR_ERROR_SRC_IMG_STDEV;
00435 else if (serr_src && !strcmp(serr_src, "timeseries"))
00436 err_src = VISIR_ERROR_SRC_TIMESERIES;
00437 else if (serr_src && !strcasecmp(serr_src, "none"))
00438 berr = CPL_FALSE;
00439 else if (serr)
00440 error_if(1, CPL_ERROR_ILLEGAL_INPUT, "Unknown error-source: %s",
00441 serr_src);
00442
00443 skip_if(0);
00444
00445 for (int e = 0; bshifts && e < m; e++) {
00446 const cpl_propertylist * plist;
00447 double crpix1, crpix2;
00448 cpl_errorstate prestate = cpl_errorstate_get();
00449
00450 irplib_framelist_load_propertylist(rawframes, iframe, e + 1, "^("
00451 IRPLIB_PFITS_WCS_REGEXP ")$",
00452 CPL_FALSE);
00453 plist = irplib_framelist_get_propertylist_const(rawframes, iframe);
00454 if (!cpl_propertylist_has(plist, "CRPIX1") ||
00455 !cpl_propertylist_has(plist, "CRPIX2")) {
00456 cpl_errorstate_set(prestate);
00457 break;
00458 }
00459
00460 crpix1 = irplib_pfits_get_double(plist, "CRPIX1");
00461 crpix2 = irplib_pfits_get_double(plist, "CRPIX2");
00462
00463 if (e == 0) {
00464 shifts[0] = 0;
00465 shifts[1] = 0;
00466 fx = crpix1;
00467 fy = crpix2;
00468 } else {
00469 shifts[e * 2] = visir_round_to_int(-(fx - crpix1));
00470 shifts[e * 2 + 1] = visir_round_to_int(-(fy - crpix2));
00471 }
00472 cpl_msg_debug(cpl_func, "CRPIX shifts %d %d, %f %f", shifts[e * 2],
00473 shifts[e * 2 + 1], crpix1 - fx, crpix2 - fy);
00474 }
00475
00476 skip_if(rawlist == NULL);
00477
00478 bug_if(errr);
00479 bug_if(errb);
00480
00481 error_if(nbpm != 1 && nbpm != m && nbpm != 0, CPL_ERROR_INCOMPATIBLE_INPUT,
00482 "Frame-pair %d/%d: %d image(s) <=> %d bad pixel map(s)",
00483 1+iframe, n, m, (int)cpl_imagelist_get_size(bpmlist));
00484
00485 bug_if(cpl_frameset_insert(usedframes, cpl_frame_duplicate(rawframe)));
00486 if (bpmframe)
00487 bug_if(cpl_frameset_insert(usedframes, cpl_frame_duplicate(bpmframe)));
00488
00489 for (int j = 0; bpmframe && j < m; j++) {
00490 const cpl_image * bpmimg =
00491 cpl_imagelist_get_const(bpmlist, nbpm > 1 ? j : 0);
00492 cpl_image * rawimg = cpl_imagelist_get(rawlist, j);
00493
00494 cpl_mask_delete(bpm);
00495 bpm = cpl_mask_threshold_image_create(bpmimg, 0.5, FLT_MAX);
00496
00497
00498 if (static_mask)
00499 cpl_mask_or(bpm, static_mask);
00500
00501 bug_if(cpl_image_reject_from_mask(rawimg, bpm));
00502
00503 }
00504
00505
00506 skip_if(visir_util_clip_kappa_sigma(rawlist, devlist, parlist, shifts));
00507
00508
00509 {
00510 cpl_image * img = cpl_imagelist_get(rawlist, 0);
00511 const int total_size =
00512 cpl_image_get_size_x(img) * cpl_image_get_size_y(img);
00513 cpl_mask * allbad = cpl_mask_new(cpl_image_get_size_x(img),
00514 cpl_image_get_size_y(img));
00515 cpl_mask_not(allbad);
00516
00517 for (cpl_size i = 0; i < cpl_imagelist_get_size(rawlist); i++) {
00518 cpl_mask * mask = cpl_image_get_bpm(cpl_imagelist_get(rawlist, i));
00519 img = cpl_imagelist_get(rawlist, i);
00520 if (badimage < (double)cpl_mask_count(mask) / total_size)
00521 cpl_image_reject_from_mask(img, allbad);
00522 }
00523
00524 cpl_mask_delete(allbad);
00525 }
00526
00527
00528 bug_if(cpl_imagelist_get_size(devlist) != 2);
00529
00530 map = cpl_image_new_from_accepted(rawlist);
00531 mapmax = cpl_image_get_max(map);
00532 mapmean = cpl_image_get_mean(map);
00533 mapmedian = cpl_image_get_median(map);
00534 bug_if(cpl_propertylist_append_int(qclist, VISIR_UTIL_CLIP_QC_MAP_MAX,
00535 mapmax));
00536 bug_if(cpl_propertylist_append_int(qclist, VISIR_UTIL_CLIP_QC_MAP_MEAN,
00537 mapmean));
00538 bug_if(cpl_propertylist_append_int(qclist, VISIR_UTIL_CLIP_QC_MAP_MEDIAN,
00539 mapmedian));
00540 bug_if(cpl_propertylist_set_comment(qclist, VISIR_UTIL_CLIP_QC_MAP_MAX,
00541 "The maximum contribution on a pixel"));
00542 bug_if(cpl_propertylist_set_comment(qclist, VISIR_UTIL_CLIP_QC_MAP_MEAN,
00543 "The mean contribution on a pixel"));
00544 bug_if(cpl_propertylist_set_comment(qclist, VISIR_UTIL_CLIP_QC_MAP_MEDIAN,
00545 "The median contribution on a pixel"));
00546
00547 skip_if(irplib_dfs_save_propertylist(products, parlist, usedframes,
00548 RECIPE_STRING,
00549 VISIR_IMG_CLIPPED_PROCATG, qclist,
00550 NULL, visir_pipe_id, bpmname));
00551
00552 if (berr)
00553 skip_if(irplib_dfs_save_propertylist(products, parlist, usedframes,
00554 RECIPE_STRING,
00555 err_procatg, qclist,
00556 NULL, visir_pipe_id, errname));
00557
00558 for (int j = 0; j < m; j++) {
00559 cpl_image * rawimg = cpl_imagelist_get(rawlist, j);
00560 const cpl_mask * newbpm = cpl_image_get_bpm_const(rawimg);
00561 const cpl_size npix =
00562 cpl_image_get_size_x(rawimg) * cpl_image_get_size_y(rawimg);
00563 cpl_image * err;
00564
00565 skip_if(cpl_mask_save(newbpm, bpmname, NULL, CPL_IO_EXTEND));
00566
00567 if (berr == CPL_FALSE)
00568 continue;
00569
00570 if (err_src == VISIR_ERROR_SRC_IMG_STDEV) {
00571 double bkgsigma;
00572 err = cpl_image_new(cpl_image_get_size_x(rawimg),
00573 cpl_image_get_size_y(rawimg),
00574 CPL_TYPE_FLOAT);
00575 if (cpl_mask_count(cpl_image_get_bpm_const(rawimg)) == npix)
00576 bkgsigma = INFINITY;
00577 else {
00578 cpl_image * dupl = cpl_image_cast(rawimg, CPL_TYPE_FLOAT);
00579 const double median = cpl_image_get_median(dupl);
00580 const double sigma = cpl_image_get_stdev(dupl);
00581 const double kappa =
00582 irplib_parameterlist_get_double(parlist, PACKAGE,
00583 RECIPE_STRING, "kappa");
00584
00585 cpl_mask * mask =
00586 cpl_mask_threshold_image_create(dupl, median - kappa * sigma,
00587 median + kappa * sigma);
00588 skip_if(0);
00589
00590 if (!cpl_mask_is_empty(mask))
00591 cpl_mask_not(mask);
00592 cpl_mask_or(mask, cpl_image_get_bpm(dupl));
00593 cpl_image_reject_from_mask(dupl, mask);
00594
00595 bkgsigma = median_abs_dev(dupl) * 1.4826;
00596 cpl_msg_debug(cpl_func, "%d: sigma %.4f", j, bkgsigma);
00597 cpl_image_delete(dupl);
00598 cpl_mask_delete(mask);
00599 skip_if(0);
00600 }
00601 cpl_image_add_scalar(err, bkgsigma);
00602 }
00603 else if (err_src == VISIR_ERROR_SRC_TIMESERIES)
00604 err = cpl_image_duplicate(cpl_imagelist_get_const(devlist, 1));
00605 else
00606 bug_if(1);
00607
00608 cpl_image_reject_from_mask(err, newbpm);
00609 if (terr == VISIR_ERROR)
00610 cpl_image_fill_rejected(err, INFINITY);
00611 else if (terr == VISIR_VARIANCE) {
00612 cpl_image_power(err, 2);
00613 cpl_image_fill_rejected(err, INFINITY);
00614 }
00615 else if (terr == VISIR_WEIGHT) {
00616 cpl_image_power(err, -2);
00617 cpl_image_fill_rejected(err, 0);
00618 }
00619 cpl_image_save(err, errname, CPL_TYPE_FLOAT, NULL, CPL_IO_EXTEND);
00620 cpl_image_delete(err);
00621 skip_if(0);
00622 }
00623
00624 skip_if(irplib_dfs_save_image(products, parlist, usedframes,
00625 map, m < 256 ? CPL_BPP_8_UNSIGNED
00626 : (m < 65536 ? CPL_BPP_16_UNSIGNED
00627 : CPL_BPP_32_SIGNED), RECIPE_STRING,
00628 VISIR_IMG_CLIPPED_MAP_PROCATG, qclist,
00629 NULL, visir_pipe_id, mapname));
00630
00631 bug_if(cpl_propertylist_append_string(xtlist, "EXTNAME", "NO CLIP STANDARD "
00632 "DEVIATION MAP"));
00633
00634 skip_if(cpl_image_save(cpl_imagelist_get_const(devlist, 0), mapname,
00635 CPL_TYPE_FLOAT, xtlist, CPL_IO_EXTEND));
00636
00637 bug_if(cpl_propertylist_update_string(xtlist, "EXTNAME", "CLIPPED STANDARD "
00638 "DEVIATION MAP"));
00639
00640 skip_if(cpl_image_save(cpl_imagelist_get_const(devlist, 1), mapname,
00641 CPL_TYPE_FLOAT, xtlist, CPL_IO_EXTEND));
00642
00643 #ifdef _OPENMP
00644 #pragma omp critical(visir_util_clip_one)
00645 #endif
00646 FOR_EACH_FRAMESET_C(frame, products)
00647 cpl_frameset_insert(framelist, cpl_frame_duplicate(frame));
00648
00649 end_skip;
00650
00651 cpl_free(bpmname);
00652 cpl_free(mapname);
00653 cpl_free(errname);
00654 cpl_free(shifts);
00655
00656 cpl_frameset_delete(rawone);
00657 cpl_frameset_delete(bpmone);
00658 cpl_frameset_delete(usedframes);
00659 cpl_frameset_delete(products);
00660
00661 cpl_propertylist_delete(qclist);
00662 cpl_propertylist_delete(xtlist);
00663
00664 cpl_mask_delete(bpm);
00665 cpl_image_delete(map);
00666 cpl_imagelist_delete(rawlist);
00667 cpl_imagelist_delete(bpmlist);
00668 cpl_imagelist_delete(devlist);
00669
00670 return cpl_error_get_code();
00671
00672 }
00673
00674
00675
00683
00684 static
00685 cpl_error_code visir_util_clip_kappa_sigma(cpl_imagelist * self,
00686 cpl_imagelist * devlist,
00687 const cpl_parameterlist * parlist,
00688 const int * shifts)
00689 {
00690
00691 const double keepfrac = irplib_parameterlist_get_double(parlist, PACKAGE,
00692 RECIPE_STRING,
00693 "keepfrac");
00694 const double kappa = irplib_parameterlist_get_double(parlist, PACKAGE,
00695 RECIPE_STRING,
00696 "kappa");
00697 const int maxite = irplib_parameterlist_get_int(parlist, PACKAGE,
00698 RECIPE_STRING,
00699 "maxite");
00700 const cpl_image * img = cpl_imagelist_get_const(self, 0);
00701
00702 switch (cpl_image_get_type(img)) {
00703 case CPL_TYPE_DOUBLE:
00704 skip_if(visir_util_clip_kappa_sigma_double(self, devlist, keepfrac,
00705 kappa, maxite, shifts));
00706 break;
00707 case CPL_TYPE_FLOAT:
00708 skip_if(visir_util_clip_kappa_sigma_float(self, devlist, keepfrac,
00709 kappa, maxite, shifts));
00710 break;
00711 case CPL_TYPE_INT:
00712 skip_if(visir_util_clip_kappa_sigma_int(self, devlist, keepfrac,
00713 kappa, maxite, shifts));
00714 break;
00715 default:
00716 bug_if( 1 );
00717 }
00718
00719 end_skip;
00720
00721 return cpl_error_get_code();
00722
00723 }
00724
00725
00726
00727
00728 #define CONCAT(a,b) a ## _ ## b
00729 #define CONCAT2X(a,b) CONCAT(a,b)
00730
00731 #define PIXEL_TYPE double
00732 #define STDEV_TYPE CPL_TYPE_DOUBLE
00733 #define PIXEL_TYPE_CPL CPL_TYPE_DOUBLE
00734 #include "visir_util_clip_body.c"
00735 #undef PIXEL_TYPE
00736 #undef STDEV_TYPE
00737 #undef PIXEL_TYPE_CPL
00738
00739 #define PIXEL_TYPE float
00740 #define PIXEL_TYPE_CPL CPL_TYPE_FLOAT
00741 #define STDEV_TYPE CPL_TYPE_FLOAT
00742 #include "visir_util_clip_body.c"
00743 #undef PIXEL_TYPE
00744 #undef STDEV_TYPE
00745 #undef PIXEL_TYPE_CPL
00746
00747 #define PIXEL_TYPE int
00748 #define PIXEL_TYPE_CPL CPL_TYPE_INT
00749 #define STDEV_TYPE CPL_TYPE_FLOAT
00750 #include "visir_util_clip_body.c"
00751 #undef PIXEL_TYPE
00752 #undef STDEV_TYPE
00753 #undef PIXEL_TYPE_CPL