UVES Pipeline Reference Manual  5.4.6
uves_mbias_impl.c
1 /* *
2  * This file is part of the ESO UVES Pipeline *
3  * Copyright (C) 2004,2005 European Southern Observatory *
4  * *
5  * This library is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA *
18  */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2011-11-02 15:43:23 $
23  * $Revision: 1.62 $
24  */
25 
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 /*----------------------------------------------------------------------------*/
37 /*----------------------------------------------------------------------------*/
38 
39 /*-----------------------------------------------------------------------------
40  Includes
41  -----------------------------------------------------------------------------*/
42 #include <uves_mbias_impl.h>
43 
44 #include <uves_utils.h>
45 #include <uves_corrbadpix.h>
46 #include <uves_parameters.h>
47 #include <uves.h>
48 #include <uves_dfs.h>
49 #include <uves_pfits.h>
50 #include <uves_qclog.h>
51 #include <uves_recipe.h>
52 #include <uves_utils_wrappers.h>
53 #include <uves_error.h>
54 #include <irplib_mkmaster.h>
55 #include <uves_msg.h>
56 
57 /* Library */
58 #include <cpl.h>
59 #include <float.h>
60 #include <ctype.h>
61 #include <string.h>
62 /*-----------------------------------------------------------------------------
63  Functions prototypes
64  -----------------------------------------------------------------------------*/
65 
66 static void uves_mbias_qclog(const cpl_imagelist* raw_imgs,
67  uves_propertylist **raw_headers,
68  enum uves_chip chip,
69  const cpl_image* mbia,
70  /* int sx_pix, Size of X bin in pix
71  int sy_pix, Size of Y bin in pix */
72  cpl_table* qclog
73  );
74 
75 static void
76 uves_mbias_qc_ron_raw(const cpl_image* rbia,
77  enum uves_chip chip,
78  const int x_cent_s,
79  const int x_cent_e,
80  const int y_cent_s,
81  const int y_cent_e,
82  cpl_table* qclog);
83 
84 static int
85 uves_mbias_define_parameters(cpl_parameterlist *parameters);
86 
87 /*-----------------------------------------------------------------------------
88  Recipe standard code
89  -----------------------------------------------------------------------------*/
90 #define cpl_plugin_get_info uves_mbias_get_info
91 UVES_RECIPE_DEFINE(
92  UVES_MBIAS_ID, UVES_MBIAS_DOM,
93  /* Warning: if more parameters are added to this recipe, they
94  need to be propagated to uves_cal_mkmaster! */
95  uves_mbias_define_parameters,
96  "Jonas M. Larsen", "cpl@eso.org",
97  "Creates the master bias frame",
98  "This recipe creates a master bias frame by computing the median of all input\n"
99  "bias frames. All input frames must have same tag and size and must be either\n"
100  "BIAS_BLUE or BIAS_RED.\n"
101  "On blue input the recipe computes one master bias frame; on red input a \n"
102  "master bias frame for each chip is produced. The average, standard deviation\n"
103  "and median of the master bias image(s) are written to the FITS header(s)");
104 
105 
106 /*-----------------------------------------------------------------------------
107  Functions code
108  -----------------------------------------------------------------------------*/
111 /*----------------------------------------------------------------------------*/
118 /*----------------------------------------------------------------------------*/
119 int uves_mbias_define_parameters_body(cpl_parameterlist *parameters,
120  const char *recipe_id)
121 {
122 
123  /*****************
124  * General *
125  *****************/
126  if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
127  {
128  return -1;
129  }
130 
131  /**************************************
132  * detector's trap correction *
133  **************************************/
134 
135  if (uves_corr_traps_define_parameters(parameters,recipe_id)
136  != CPL_ERROR_NONE)
137  {
138  return -1;
139  }
140 
141  /**************************************
142  * Master stack generation *
143  **************************************/
144 
145  if (uves_master_stack_define_parameters(parameters,recipe_id)
146  != CPL_ERROR_NONE)
147  {
148  return -1;
149  }
150 
151  return (cpl_error_get_code() != CPL_ERROR_NONE);
152 }
153 
154 
155 
156 /*----------------------------------------------------------------------------*/
162 /*----------------------------------------------------------------------------*/
163 static int
164 uves_mbias_define_parameters(cpl_parameterlist *parameters)
165 {
166  return uves_mbias_define_parameters_body(parameters, make_str(UVES_MBIAS_ID));
167 }
168 
169 
170 
171 
172 
173 /*----------------------------------------------------------------------------*/
190 /*----------------------------------------------------------------------------*/
191 static cpl_image *
192 uves_mbias_process_chip(const cpl_imagelist *raw_images,
193  uves_propertylist **raw_headers,
194  uves_propertylist *mbias_header,
195  int binx, int biny,
196  enum uves_chip chip,
197  bool CLEAN_TRAPS,
198  const char* STACK_METHOD,
199  const double STACK_KLOW,
200  const double STACK_KHIGH,
201  const int STACK_NITER)
202 {
203  cpl_image *master_bias = NULL; /* Result */
204  double exposure_time = 0;
205  int badpixels_cleaned;
206  int i;
207  int nraw=0;
208  bool red_ccd_is_new=false;
209  cpl_vector* bias_levels=NULL;
210  double bias_mean=0;
211 
212  uves_msg("Calculating master bias...");
213 
214  check_nomsg(red_ccd_is_new=uves_ccd_is_new(raw_headers[0]));
215  /* Get the median at each pixel */
216  if(strcmp(STACK_METHOD,"MEDIAN")==0) {
217  uves_msg("method median");
218  master_bias=irplib_mkmaster_median(raw_images,5.,5,1.e-5);
219  } else {
220  uves_msg("method mean");
221  master_bias=irplib_mkmaster_mean(raw_images,5.,5,1.e-5,STACK_KLOW,STACK_KHIGH,STACK_NITER);
222  }
223 
224  /* Set mbias exposure time to average of inputs */
225  exposure_time = 0;
226  nraw=cpl_imagelist_get_size(raw_images);
227  for (i = 0; i < nraw; i++)
228  {
229  check( exposure_time += uves_pfits_get_exptime(raw_headers[i]),
230  "Error reading exposure time");
231  }
232  exposure_time /= nraw;
233 
234  uves_pfits_set_extname(mbias_header,"Master bias");
235 
236  check( uves_pfits_set_exptime(mbias_header, exposure_time),
237  "Error setting master bias exposure time");
238  if(CLEAN_TRAPS) {
239  check( badpixels_cleaned =
240  uves_correct_badpix_all(master_bias, mbias_header,
241  chip, binx, biny, false,red_ccd_is_new),
242  "Error replacing bad pixels");
243 
244  uves_msg("%d bad pixels replaced", badpixels_cleaned);
245  }
246 
247  cleanup:
248  if (cpl_error_get_code() != CPL_ERROR_NONE)
249  {
250  uves_free_image(&master_bias);
251  }
252 
253  return master_bias;
254 }
255 
256 /*----------------------------------------------------------------------------*/
263 /*----------------------------------------------------------------------------*/
264 static void
265 UVES_CONCAT2X(UVES_MBIAS_ID,exe)(cpl_frameset *frames,
266  const cpl_parameterlist *parameters,
267  const char *starttime)
268 {
269  uves_mbias_exe_body(frames, parameters, starttime, make_str(UVES_MBIAS_ID));
270  return;
271 }
272 
273 /*----------------------------------------------------------------------------*/
284 /*----------------------------------------------------------------------------*/
285 void
286 uves_mbias_exe_body(cpl_frameset *frames,
287  const cpl_parameterlist *parameters,
288  const char *starttime,
289  const char *recipe_id)
290 {
291  /* Input */
292  cpl_imagelist *raw_images[2] = {NULL, NULL};
293  uves_propertylist **raw_headers[2] = {NULL, NULL}; /* Two arrays of pointers */
294 
295  cpl_table* qclog[2] = {NULL, NULL};
296 
297  /* Output */
298  uves_propertylist *product_header[2] = {NULL, NULL};
299  cpl_image *master_bias = NULL;
300  cpl_stats *mbias_stats = NULL;
301 
302  /* Local variables */
303  char *product_filename = NULL;
304  bool blue;
305  enum uves_chip chip;
306  int binx, biny;
307  const char* PROCESS_CHIP=NULL;
308  bool CLEAN_TRAPS;
309  int raw_index = 0;
310  int i=0;
311 
312  const char* STACK_METHOD=NULL;
313  double STACK_KLOW=0;
314  double STACK_KHIGH=0;
315  int STACK_NITER=0;
316 
317  /* Load and check raw bias images and headers, identify arm (blue/red) */
318  /* On success, 'raw_headers' will be arrays with the same length as 'raw_images' */
319  check( uves_load_raw_imagelist(frames,
320  false, /* FLAMES format? (no) */
321  UVES_BIAS(true), UVES_BIAS(false),
322  CPL_TYPE_DOUBLE,
323  raw_images, raw_headers, product_header,
324  &blue), "Error loading raw frames");
325 
326  /* Get binning from first header (i.e. BLUE or REDL chip, first raw frame) */
327  check( binx = uves_pfits_get_binx(raw_headers[0][0]),
328  "Could not get raw frame x-binning");
329  check( biny = uves_pfits_get_biny(raw_headers[0][0]),
330  "Could not get raw frame y-binning");
331  check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
332  "Could not read parameter");
333  uves_string_toupper((char*)PROCESS_CHIP);
334 
335  check( uves_get_parameter(parameters, NULL, recipe_id, "clean_traps", CPL_TYPE_BOOL, &CLEAN_TRAPS),
336  "Could not read parameter");
337 
338  check( uves_get_parameter(parameters, NULL, recipe_id, "stack_method", CPL_TYPE_STRING, &STACK_METHOD),
339  "Could not read parameter");
340  uves_string_toupper((char*)STACK_METHOD);
341 
342  check( uves_get_parameter(parameters, NULL, recipe_id, "klow", CPL_TYPE_DOUBLE, &STACK_KLOW),
343  "Could not read parameter");
344  check( uves_get_parameter(parameters, NULL, recipe_id, "khigh", CPL_TYPE_DOUBLE, &STACK_KHIGH),
345  "Could not read parameter");
346  check( uves_get_parameter(parameters, NULL, recipe_id, "niter", CPL_TYPE_INT, &STACK_NITER),
347  "Could not read parameter");
348 
349  /* Loop over one or two chips */
350  for (chip = uves_chip_get_first(blue);
351  chip != UVES_CHIP_INVALID;
352  chip = uves_chip_get_next(chip))
353  {
354  if(strcmp(PROCESS_CHIP,"REDU") == 0) {
355  chip = uves_chip_get_next(chip);
356  }
357  raw_index = uves_chip_get_index(chip);
358 
359  uves_msg("Processing %s chip",
361 
362  uves_msg_debug("Binning = %dx%d", binx, biny);
363 
364  /* Process chip */
365  uves_free_image(&master_bias);
366  check( master_bias = uves_mbias_process_chip(raw_images[raw_index],
367  raw_headers[raw_index],
368  product_header[raw_index],
369  binx, biny,
370  chip,CLEAN_TRAPS,
371  STACK_METHOD,
372  STACK_KLOW,
373  STACK_KHIGH,
374  STACK_NITER),
375  "Error processing chip");
376 
377 
378  cpl_free(product_filename);
379  check( product_filename = uves_masterbias_filename(chip),
380  "Error getting filename");
381 
382  /* Finished. Calculate QC parameters and save */
383  uves_msg("Calculating QC parameters");
384  uves_qclog_delete(&qclog[0]);
385  qclog[0] = uves_qclog_init(raw_headers[raw_index][0], chip);
386  check(uves_mbias_qclog(raw_images[raw_index],
387  raw_headers[raw_index],
388  chip,
389  master_bias,
390  /* binx,biny, */
391  qclog[0]),"error computing qclog");
392 
393  /* Insert into frame set */
394  uves_msg("Saving product...");
395 
396  check( uves_frameset_insert(frames,
397  master_bias,
398  CPL_FRAME_GROUP_PRODUCT,
399  CPL_FRAME_TYPE_IMAGE,
400  CPL_FRAME_LEVEL_INTERMEDIATE,
401  product_filename,
402  UVES_MASTER_BIAS(chip),
403  raw_headers[raw_index][0], /* First frame */
404  product_header[raw_index],
405  NULL,
406  parameters,
407  recipe_id,
408  PACKAGE "/" PACKAGE_VERSION,qclog,
409  starttime, true,
410  UVES_ALL_STATS),
411  "Could not add master bias %s to frameset", product_filename);
412  uves_qclog_delete(&qclog[0]);
413  uves_msg("Master bias '%s' added to frameset", product_filename);
414 
415  if(strcmp(PROCESS_CHIP,"REDL") == 0) {
416  chip = uves_chip_get_next(chip);
417  }
418 
419 
420  } /* For each chip */
421 
422  cleanup:
423  /* Input */
424  if (raw_images[0] != NULL)
425  {
426 
427  for (i = 0; i < cpl_imagelist_get_size(raw_images[0]); i++)
428  {
429  if (raw_headers[0] != NULL) uves_free_propertylist(&raw_headers[0][i]);
430  if (raw_headers[1] != NULL) uves_free_propertylist(&raw_headers[1][i]);
431  }
432  cpl_free(raw_headers[0]); raw_headers[0] = NULL;
433  cpl_free(raw_headers[1]); raw_headers[1] = NULL;
434  }
435  uves_free_imagelist(&raw_images[0]);
436  uves_free_imagelist(&raw_images[1]);
437  /* Output */
438 
439  uves_qclog_delete(&qclog[0]);
440  uves_free_image(&master_bias);
441  uves_free_propertylist(&product_header[0]);
442  uves_free_propertylist(&product_header[1]);
443  cpl_free(product_filename);
444  uves_free_stats(&mbias_stats);
445 
446  return;
447 }
448 
449 
450 
451 static int
452 count_good(const cpl_image *image)
453 {
454  return
455  cpl_image_get_size_x(image) * cpl_image_get_size_y(image) -
456  cpl_image_count_rejected(image);
457 }
458 /*----------------------------------------------------------------------------*/
465 /*----------------------------------------------------------------------------*/
466 static void
467 reject_lo_hi(cpl_image *image, double min, double max)
468 {
469  cpl_mask *mask_lo = NULL;
470  cpl_mask *mask_hi = NULL;
471 
472  mask_lo = cpl_mask_threshold_image_create(image, -DBL_MAX, min);
473  mask_hi = cpl_mask_threshold_image_create(image, max, DBL_MAX);
474  assure_mem( mask_lo );
475  assure_mem( mask_hi );
476 
477  cpl_mask_or(mask_lo, mask_hi);
478 
479  cpl_image_reject_from_mask(image, mask_lo);
480 
481  cleanup:
482  uves_free_mask(&mask_lo);
483  uves_free_mask(&mask_hi);
484  return;
485 }
486 
497 static void uves_mbias_qclog(const cpl_imagelist* raw_imgs,
498  uves_propertylist **raw_headers,
499  enum uves_chip chip,
500  const cpl_image* mbia,
501  /* int sx_pix, Size of X bin in pix
502  int sy_pix, Size of Y bin in pix */
503  cpl_table* qclog
504  )
505 {
506  int nx_pix= 0; /* No of X pix */
507  int ny_pix= 0; /* No of Y pix */
508 
509  int sample_x= 100; /* X size of sampling window in pix */
510  int sample_y= 100; /* Y size of sampling window in pix */
511  int x_cent_s= 0; /* X sampling window starting point */
512  int x_cent_e= 0; /* X sampling window ending point */
513  int y_cent_s= 0; /* Y sampling window starting point */
514  int y_cent_e= 0; /* Y sampling window ending point */
515 
516 
517 
518 
519 
520  double upp_threshold= 0.0;
521  double low_threshold= 0.0;
522  double extra=0.1;
523  double qc_ron_master= 0.0;
524 
525  double master_median=0.0;
526  int pn= 0;
527 
528 
529  double min=0.0;
530  double max=0.0;
531  double struct_col=0.0;
532  double struct_row=0.0;
533 
534  double time_s=+9999999.0;
535  double time_e=-9999999.0;
536  int nraw=0;
537  double qc_duty_cycle=0.;
538  double exposure_time=0;
539  int i=0;
540  char key_name[80];
541 
542  const cpl_image* rbia=NULL;
543  cpl_image* tima=NULL;
544  cpl_image* avg_col=NULL;
545  cpl_image* avg_row=NULL;
546 
547  uves_qclog_add_string(qclog,
548  "QC TEST1 ID",
549  "Test-on-Master-Bias",
550  "Name of QC test",
551  "%s");
552 
553  uves_msg("Computing duty cycle...");
554 
555  /* Set mbias exposure time to average of inputs */
556  exposure_time = 0;
557  nraw = cpl_imagelist_get_size(raw_imgs);
559  "PRO DATANCOM",
560  nraw,
561  "Number of frames combined",
562  "%d"));
563 
564 
565  for (i = 0; i < nraw; i++)
566  {
567  check( exposure_time = uves_pfits_get_mjdobs(raw_headers[i]),
568  "Error reading exposure time");
569  if(exposure_time >= time_e) time_e = exposure_time;
570  if(exposure_time <= time_s) time_s = exposure_time;
571  }
572  if(nraw > 1) {
573  qc_duty_cycle = (time_e-time_s)/ (nraw-1);
574  }
575  else
576  {
577  qc_duty_cycle = 0;
578  }
579 
581  "QC DUTYCYCL",
582  qc_duty_cycle,
583  "Time to store a frame",
584  "%.5e"));
585 
586  /* The following is not really used in MIDAS so we comment
587  strcpy(date,uves_pfits_get_tpl_start(plist));
588  */
589 
590 
591  /* CONVERT FROM MIDAS
592  nx_pix = m$value({mbia},NPIX(1));
593  ny_pix = m$value({mbia},NPIX(2));
594  */
595 
596  nx_pix = cpl_image_get_size_x(mbia);
597  ny_pix = cpl_image_get_size_y(mbia);
598 
599 
600  x_cent_s = (nx_pix - sample_x)/2;
601  x_cent_e = (nx_pix + sample_x)/2;
602  y_cent_s = (ny_pix - sample_y)/2;
603  y_cent_e = (ny_pix + sample_y)/2;
604 
605 
606  check_nomsg(upp_threshold =
607  cpl_image_get_median_window(mbia,
608  x_cent_s,
609  y_cent_s,
610  x_cent_e,
611  y_cent_e)*(1 + extra));
612  check_nomsg(low_threshold =
613  cpl_image_get_median_window(mbia,
614  x_cent_s,
615  y_cent_s,
616  x_cent_e,
617  y_cent_e)*(1 - extra));
618 
619  /* convert from MIDAS
620  pn = {uves_portid({PATHID})};
621  */
622  check_nomsg(pn = PORT_ID(chip));
623  uves_msg_debug("Port number = %d", pn);
624 
625  rbia = cpl_imagelist_get_const(raw_imgs,0);
626  check_nomsg(uves_mbias_qc_ron_raw(rbia, chip,
627  x_cent_s,x_cent_e,y_cent_s,y_cent_e,qclog));
628 
629 
630  /* convert from MIDAS
631  stat/ima {mbia} + bins=1 exc={low_threshold},{upp_threshold};
632  */
633  check_nomsg(tima=cpl_image_duplicate(mbia));
634 
635  check_nomsg( reject_lo_hi(tima, low_threshold, upp_threshold) );
636  if (count_good(tima) >= 2)
637  {
638  check_nomsg(master_median = cpl_image_get_median(tima));
639  check_nomsg(qc_ron_master = cpl_image_get_stdev(tima));
640  }
641  else
642  {
643  master_median = -1;
644  qc_ron_master = -1;
645  uves_msg_warning("Only %d good pixels in image. Setting QC parameters to -1",
646  count_good(tima));
647  }
648  uves_free_image(&tima);
649 
651  "PRO DATAMED",
652  master_median,
653  "Median of pixel values",
654  "%7.3f"));
655 
656  sprintf(key_name, "QC OUT%d RON MASTER", pn);
658  key_name,
659  qc_ron_master,
660  "Read noise frame in ADU",
661  "%8.4f"));
662 
663  /* ==========================
664  * Calculates Bias struct
665  * ==========================
666  */
667 
668 
669  /*
670  * in case of RED frame cuts out values greater than 300.
671  * as the frame can be affected by this local operation we
672  * do the calculation on a copy of the original frame
673  */
674 
675 
676  check_nomsg(tima=cpl_image_duplicate(mbia));
677  if (chip != UVES_CHIP_BLUE) {
678  /*
679  replace/ima {mbia} {tmpfrm} 300,>=300.;
680  */
681  check_nomsg(cpl_image_threshold(tima,
682  -DBL_MAX,300,
683  -DBL_MAX,300));
684  }
685 
686 
687  check_nomsg(avg_col = cpl_image_collapse_create(tima,1));
688  check_nomsg(cpl_image_divide_scalar(avg_col,cpl_image_get_size_x(tima)));
689 
690  /* restricts statistics to +/- 2 ADU around mean */
691  min = cpl_image_get_mean(avg_col) - 2;
692  max = cpl_image_get_mean(avg_col) + 2;
693 
694  /* replace with MIDAS
695  stat/ima avg_col + exc={min},{max};
696  */
697  check_nomsg( reject_lo_hi(avg_col, min, max) );
698  if (count_good(avg_col) >= 2)
699  {
700  check_nomsg(struct_col = cpl_image_get_stdev(avg_col));
701  }
702  else
703  {
704  struct_col = -1;
705  uves_msg_warning("Only %d good pixels in image. Setting QC parameter to -1",
706  count_good(avg_col));
707  }
708 
709  sprintf(key_name,"%s%d%s","QC OUT",pn," STRUCTY");
711  key_name,
712  struct_col,
713  "structure in Y (bias slope)",
714  "%8.4f"));
715 
716 
717 
718  check_nomsg(avg_row = cpl_image_collapse_create(tima,0));
719  check_nomsg(cpl_image_divide_scalar(avg_row,cpl_image_get_size_y(tima)));
720 
721  /* restricts statistics to +/- 2 ADU around mean */
722  min = cpl_image_get_mean(avg_row) - 2;
723  max = cpl_image_get_mean(avg_row) + 2;
724 
725  /* replace with MIDAS
726  stat/ima avg_row + exc={min},{max};
727  */
728  check_nomsg( reject_lo_hi(avg_row, min, max) );
729  if (count_good(avg_row) >= 2)
730  {
731  check_nomsg(struct_row = cpl_image_get_stdev(avg_row));
732  }
733  else
734  {
735  struct_row = -1;
736  uves_msg_warning("Only %d good pixels in image. Setting QC parameter to -1",
737  count_good(avg_row));
738  }
739 
740 
741  sprintf(key_name,"%s%d%s","QC OUT",pn," STRUCTX");
743  key_name,
744  struct_row,
745  "structure in X (bias slope)",
746  "%8.4f"));
747 
748 
749 
750 
751  cleanup:
752  uves_free_image(&avg_col);
753  uves_free_image(&avg_row);
754  uves_free_image(&tima);
755 
756  return;
757 
758 }
772 static void
773 uves_mbias_qc_ron_raw(const cpl_image* rbia,
774  enum uves_chip chip,
775  const int x_cent_s,
776  const int x_cent_e,
777  const int y_cent_s,
778  const int y_cent_e,
779  cpl_table* qclog)
780 {
781 
782  double qc_ron_raw=0.0;
783  double upp_threshold=0.0;
784  double low_threshold=0.0;
785  double extra=0.1;
786  char key_name[80];
787  int pn=0;
788  cpl_image* tima=NULL;
789 
790  /* replace with MIDAS
791  date = "{{mbia},ESO.TPL.START}";
792  store/frame infrm {incat} 1;
793  */
794  check_nomsg(upp_threshold =
795  cpl_image_get_median_window(rbia,
796  x_cent_s,
797  y_cent_s,
798  x_cent_e,
799  y_cent_e)*(1 + extra));
800 
801  check_nomsg(low_threshold =
802  cpl_image_get_median_window(rbia,
803  x_cent_s,
804  y_cent_s,
805  x_cent_e,
806  y_cent_e)*(1 - extra));
807 
808 
809 
810  /* replace from MIDAS
811  stat/ima {rbia} + bins=1 exc={low_treshold},{upp_treshold};
812  */
813  check_nomsg(tima=cpl_image_duplicate(rbia));
814 
815  check_nomsg( reject_lo_hi(tima, low_threshold, upp_threshold) );
816  if (count_good(tima) >= 2)
817  {
818  check_nomsg(qc_ron_raw = cpl_image_get_stdev(tima));
819  }
820  else
821  {
822  qc_ron_raw = -1;
823  uves_msg_warning("Only %d good pixels in image. Setting QC parameter to -1",
824  count_good(tima));
825  }
826 
827 
828  /* replace from MIDAS
829  pn = {uves_portid({PATHID})};
830  */
831  check_nomsg(pn = PORT_ID(chip));
832 
833 
834  sprintf(key_name,"%s%d%s","QC OUT",pn," RON RAW");
836  key_name,
837  qc_ron_raw,
838  "Read noise frame in ADU",
839  "%8.4f"));
840 
841  cleanup:
842  uves_free_image(&tima);
843  return;
844 }
845 
#define uves_msg_warning(...)
Print an warning message.
Definition: uves_msg.h:87
int uves_qclog_add_string(cpl_table *table, const char *key_name, const char *value, const char *key_help, const char *format)
Add string key to QC-LOG table.
Definition: uves_qclog.c:683
#define check_nomsg(CMD)
Definition: uves_error.h:204
int uves_qclog_delete(cpl_table **table)
delete QC-LOG table
Definition: uves_qclog.c:716
int uves_qclog_add_double(cpl_table *table, const char *key_name, const double value, const char *key_help, const char *format)
Add double key to QC-LOG table.
Definition: uves_qclog.c:641
int uves_qclog_add_int(cpl_table *table, const char *key_name, const int value, const char *key_help, const char *format)
Add integer key to QC-LOG table.
Definition: uves_qclog.c:521
int uves_pfits_get_binx(const uves_propertylist *plist)
Find out the x binning factor.
Definition: uves_pfits.c:1176
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
Definition: uves_msg.h:119
double uves_pfits_get_mjdobs(const uves_propertylist *plist)
Find out the modified julian observation date.
Definition: uves_pfits.c:1086
int uves_pfits_get_biny(const uves_propertylist *plist)
Find out the y binning factor.
Definition: uves_pfits.c:1194
bool uves_ccd_is_new(const uves_propertylist *plist)
Find out if CCD header is new.
Definition: uves_pfits.c:553
double uves_pfits_get_exptime(const uves_propertylist *plist)
Find out the exposure time in seconds.
Definition: uves_pfits.c:922
#define assure_mem(PTR)
Definition: uves_error.h:181
int uves_chip_get_index(enum uves_chip chip)
Convert to integer.
Definition: uves_chip.c:124
enum uves_chip uves_chip_get_first(bool blue)
Get first chip for blue or red arm.
Definition: uves_chip.c:92
cpl_error_code uves_pfits_set_extname(uves_propertylist *plist, const char *extname)
Write the EXTNAME keyword.
Definition: uves_pfits.c:2736
cpl_error_code uves_pfits_set_exptime(uves_propertylist *plist, double exptime)
Write the exposure time.
Definition: uves_pfits.c:944
enum uves_chip uves_chip_get_next(enum uves_chip chip)
Get next chip.
Definition: uves_chip.c:108
#define uves_msg_debug(...)
Print a debug message.
Definition: uves_msg.h:97
const char * uves_chip_tostring_upper(enum uves_chip chip)
Convert to string.
Definition: uves_chip.c:156
int uves_correct_badpix_all(cpl_image *master_bias, uves_propertylist *mbias_header, enum uves_chip chip, int binx, int biny, int mark_bad, bool red_ccd_new)
Correct all bad pixels on a chip.
const char * uves_string_toupper(char *s)
Convert all lowercase characters in a string into uppercase characters.
Definition: uves_utils.c:1493
#define check(CMD,...)
Definition: uves_error.h:198
cpl_table * uves_qclog_init(const uves_propertylist *raw_header, enum uves_chip chip)
Init QC-LOG table.
Definition: uves_qclog.c:410
cpl_image * irplib_mkmaster_median(cpl_imagelist *images, const double kappa, const int nclip, const double tolerance)
Computes master frame by clean stack median of the input imagelist.
cpl_image * irplib_mkmaster_mean(cpl_imagelist *images, const double kappa, const int nclip, const double tolerance, const double klow, const double khigh, const int niter)
Computes master frame by clean stack mean of the input imagelist.