UVES Pipeline Reference Manual  5.4.6
uves_response_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 02111-1307 USA *
18  * */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2013-08-08 13:36:46 $
23  * $Revision: 1.85 $
24  * $Name: not supported by cvs2svn $
25  *
26  */
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 /*----------------------------------------------------------------------------*/
39 /*----------------------------------------------------------------------------*/
40 
41 /*-----------------------------------------------------------------------------
42  Includes
43  -----------------------------------------------------------------------------*/
44 
45 /* Definitions */
46 #include <uves.h>
47 
48 /* Macro steps */
49 #include <uves_reduce.h>
50 #include <uves_reduce_utils.h>
51 #include <uves_response_efficiency.h>
52 #include <uves_response_utils.h>
53 
54 /* Utility functions */
55 #include <uves_extract.h>
56 #include <uves_plot.h>
57 #include <uves_dfs.h>
58 #include <uves_pfits.h>
59 #include <uves_parameters.h>
60 #include <uves_utils.h>
61 #include <uves_utils_wrappers.h>
62 #include <uves_utils_cpl.h>
63 #include <uves_qclog.h>
64 #include <uves_recipe.h>
65 #include <uves_error.h>
66 #include <uves_msg.h>
67 #include <uves_merge.h>
68 
69 /* Library */
70 #include <cpl.h>
71 #include <stdbool.h>
72 #include <string.h>
73 
74 /*-----------------------------------------------------------------------------
75  Functions prototypes
76  -----------------------------------------------------------------------------*/
77 static void uves_efficiency_qclog(cpl_table* table,
78  uves_propertylist* raw_header,
79  enum uves_chip chip,
80  cpl_table* qclog,
81  const char *ref_obj_name);
82 
83 static int
84 uves_response_define_parameters(cpl_parameterlist *parameters);
85 
86 /*-----------------------------------------------------------------------------
87  Recipe standard code
88  -----------------------------------------------------------------------------*/
89 #define cpl_plugin_get_info uves_response_get_info
90 UVES_RECIPE_DEFINE(
91  UVES_RESPONSE_ID, UVES_RESPONSE_DOM, uves_response_define_parameters,
92  "Jonas M. Larsen", "cpl@eso.org",
93  "Determines response function and quantum efficiency",
94 "This recipe reduces a standard star frame (STANDARD_xxx or STANDARD_xxx,\n"
95 "where xxx = BLUE, RED) using a combination (depending on recipe parameters\n"
96 "and provided input frames) of the steps:\n"
97 " - bias subtraction,\n"
98 " - dark subtraction,\n"
99 " - background subtraction,\n"
100 " - extraction/cosmic ray removal,\n"
101 " - flat-field correction,\n"
102 " - wavelength rebinning,\n"
103 " - sky subtraction,\n"
104 " - order merging.\n"
105 "\n"
106 " Expected input for this recipe is an raw std star frame, STANDARD_xxx or \n"
107 "order table(s) for each chip, ORDER_TABLE_xxxx (where xxxx=BLUE, REDL, REDU),\n"
108 "line table(s) for each chip, LINE_TABLE_xxxx, a master bias frame,\n"
109 "MASTER_BIAS_xxxx, a master flat, MASTER_FLAT_xxxx, a reference standard star\n"
110 "flux table, FLUX_STD_TABLE, a table describing the atmospheric extintion,\n"
111 "EXTCOEFF_TABLE. \n"
112 
113 "Two reductions are performed, the first using optimal extraction (used to\n"
114 "compute the instrument response function), the second using linear extraction\n"
115 "(used to get the Quantum Detection Efficiency)\n"
116 "\n"
117 "For each chip (xxxx = BLUE, REDL, REDU) the recipe produces\n"
118 " INSTR_RESPONSE_xxxx Response curve\n"
119 " WCALIB_FF_RESPONSE_xxxx Response curve in (lambda,order) space before\n"
120 " correcting for exposure time, gain, binning and\n"
121 " atmospheric absorption\n"
122 " RED_STD_xxxx Reduced spectrum\n"
123 " EFFICIENCY_TABLE_xxxx Efficiency table\n"
124  " BKG_STD_xxxx The subtracted background\n");
125 
127 /*----------------------------------------------------------------------------*/
133 /*----------------------------------------------------------------------------*/
134 static int
135 uves_response_define_parameters(cpl_parameterlist *parameters)
136 {
137  /*****************
138  * General *
139  *****************/
140 
141  if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
142  {
143  return -1;
144  }
145 
146  /*******************
147  * Reduce *
148  ******************/
149  /* Get reduce parameters for the top level and also for 'efficiency' substep */
150  if (uves_propagate_parameters_step(
151  UVES_REDUCE_ID, parameters, make_str(UVES_RESPONSE_ID), NULL) != 0)
152  {
153  return -1;
154  }
155 
156 
157  check(uves_define_efficiency_parameters(parameters),
158  "Defining efficiency parameters");
159 
160 
161  cleanup:
162  return (cpl_error_get_code() != CPL_ERROR_NONE);
163 }
164 
165 /*----------------------------------------------------------------------------*/
219 /*----------------------------------------------------------------------------*/
220 
221 static cpl_error_code
222 uves_response_process_chip(const cpl_image *raw_image,
223  const uves_propertylist *raw_header,
224  const uves_propertylist *rotated_header,
225  const cpl_image *master_bias,
226  const uves_propertylist *mbias_header,
227  const cpl_image *master_dark,
228  const uves_propertylist *mdark_header,
229  const cpl_image *master_flat,
230  const uves_propertylist *mflat_header,
231  const cpl_table *ordertable,
232  const polynomial *order_locations,
233  const cpl_table *linetable[3],
234  const uves_propertylist *linetable_header[3],
235  const polynomial *dispersion_relation[3],
236  const cpl_table *flux_table,
237  const cpl_table *atm_extinction,
238  enum uves_chip chip,
239  /* General */
240  bool debug_mode,
241  /* Backsub */
242  /* Flat fielding */
243  /* Extraction */
244  /* Rebinning */
245  const cpl_parameterlist *parameters,
246  bool calc_response,
247  /* Identification */
248  double PACCURACY,
249  /* Output */
250  char **ref_obj_id,
251  cpl_image **reduced_spectrum,
252  uves_propertylist **reduced_header,
253  cpl_image **background,
254  cpl_image **response_orders,
255  uves_propertylist **response_header_2d,
256  cpl_image **response_curve,
257  uves_propertylist **response_header,
258  cpl_table **efficiency,
259  cpl_table** blaze_efficiency,
260  cpl_table** info_tbl,
261  double *extraction_slit)
262 {
263  cpl_image *rebinned_spectrum = NULL;
264  cpl_image *rebinned_noise = NULL;
265  uves_propertylist *rebinned_header = NULL;
266  cpl_image *reduced_rebinned = NULL;
267  cpl_image *reduced_rebinned_noise = NULL;
268 
269  cpl_image *reduced_noise = NULL;
270 
271  cpl_table *cosmic_mask = NULL; /* Cosmic ray table (not a product of this recipe) */
272  cpl_table *order_trace = NULL; /* Order trace table (not a product of this recipe) */
273  cpl_image *merged_spectrum = NULL; /* Not sky-subtracted (if simple extraction) */
274  cpl_image *wave_map = NULL;
275  cpl_image *merged_sky = NULL;
276  cpl_image *merged_noise = NULL;
277  cpl_image *reduced_scaled = NULL; /* Merged, sky-subtracted and normalized
278  (exposure time, gain...) */
279 
280  cpl_table *catalogue_flux = NULL; /* Std star catalogue flux */
281 
282  /* Do the science reduction. Produces wave.cal. spectra. */
283  uves_msg("Reducing standard star");
284 
285  check( uves_reduce(raw_image,
286  raw_header,
287  rotated_header,
288  master_bias,
289  mbias_header,
290  master_dark,
291  mdark_header,
292  master_flat,
293  mflat_header,
294  ordertable,
295  order_locations,
296  linetable,
297  linetable_header,
298  dispersion_relation,
299  chip,
300  debug_mode,
301  parameters,
302  make_str(UVES_RESPONSE_ID),
303  "",
304  /* Output */
305  NULL,
306  NULL,
307  NULL, /* 2d products */
308  &cosmic_mask,
309  &wave_map,
310  background,
311  NULL,
312  NULL, /* Variance of flat-fielded */
313  NULL,
314  NULL, /* Don't need these
315  intermediate products */
316  &merged_sky,
317  &rebinned_spectrum,
318  &rebinned_noise,
319  &rebinned_header,
320  &merged_spectrum,
321  &merged_noise,
322  reduced_header,
323  &reduced_rebinned,
324  &reduced_rebinned_noise,
325  reduced_spectrum,
326  &reduced_noise,
327  info_tbl,
328  extraction_slit,
329  &order_trace),
330  "Could not reduce frame");
331 
332 
333  check( uves_plot_image_rows(*reduced_spectrum, 1, 1, 1,
334  "Wavelength (arbitrary units)", NULL,
335  "Reduced spectrum (%s chip)",
337  "Plotting failed");
338 
339  if (calc_response)
340  {
341  /* Calculate 2d response curve (but don't scale to unit exposure time, ...) */
342  uves_msg("Filtering rebinned spectrum");
343  check( uves_filter_image_median(&reduced_rebinned, 10, 0, false),
344  "Could not smooth spectrum");
345  check( uves_filter_image_average(reduced_rebinned, 10, 0),
346  "Could not smooth spectrum");
347 
348  uves_msg("Calculating 2d response curve");
349 
350  check( *response_orders = uves_calculate_response(reduced_rebinned,
351  rebinned_header,
352  flux_table,
353  raw_header,
354  PACCURACY,
355  true,
356  /* std_flux / flux */
357  ref_obj_id),
358  "Could not calculate response curve");
359 
360  check( *response_header_2d = uves_propertylist_duplicate(rebinned_header),
361  "Error creating FITS header for 2d response curve");
362 
363  check( uves_pfits_set_bunit(*response_header_2d, "FLUX_CAT / FLUX_STD"),
364  "Error writing BUNIT keyword");
365 
366  /*
367  * Calculate 1d response curve
368  */
369 
370  uves_msg("Normalizing reduced spectrum");
371 
372  {
373  int n_traces = cpl_image_get_size_y(*reduced_spectrum);
374  assure( n_traces == 1, CPL_ERROR_ILLEGAL_INPUT,
375  "2d extraction/reduction not supported");
376 
377  check( reduced_scaled = uves_normalize_spectrum(*reduced_spectrum,
378  reduced_noise,
379  *reduced_header,
380  raw_header,
381  n_traces,
382  chip,
383  atm_extinction,
384  true, /* Yes, divide by binning */
385  NULL), /* Noise spectrum */
386  "Error normalizing reduced spectrum");
387  }
388 
389  uves_msg("Filtering reduced spectrum");
390  check( uves_filter_image_median(&reduced_scaled, 10, 0, false),
391  "Could not smooth spectrum");
392  check( uves_filter_image_average(reduced_scaled, 10, 0),
393  "Could not smooth spectrum");
394 
395  uves_msg("Calculating response curve from scaled spectrum");
396 
397  cpl_free(*ref_obj_id); *ref_obj_id = NULL;
398  check( *response_curve = uves_calculate_response(reduced_scaled,
399  *reduced_header,
400  flux_table,
401  raw_header,
402  PACCURACY,
403  true, /* catalogue_flux / flux */
404  ref_obj_id),
405  "Could not calculate response curve");
406 
407  check( *response_header = uves_propertylist_duplicate(*reduced_header),
408  "Error creating FITS header for response curve");
409 
410  check( uves_pfits_set_bunit(*response_header, "FLUX_CAT / FLUX_STD"),
411  "Error writing BUNIT keyword");
412 
413  if (debug_mode)
414  {
415  check( uves_save_image_local("Pre-smoothed response curve", "raw_response",
416  *response_curve, chip, -1, -1, *response_header, true),
417  "Error saving image");
418  }
419 
420  check( uves_plot_image_rows(*response_curve, 1, 1, 1, "Wavelength (arbitrary units)",
421  NULL,
422  "Raw response (%s chip)", uves_chip_tostring_upper(chip)),
423  "Plotting failed");
424 
425 
426  /* Rebin the response curve to 50 wlu:
427  1) smooth it using a radius of 25 wlu,
428  2) then extract every n'th pixel where n = 50/step */
429  uves_msg("Rebinning response curve to step size = 50 w.l.u.");
430  {
431  double dlambda, lambda_start;
432  int n, bin, newbin;
433 
434  check( lambda_start = uves_pfits_get_crval1(*response_header),
435  "Error reading start wavelength from header");
436  check( dlambda = uves_pfits_get_cdelt1(*response_header),
437  "Error reading wavelength step from header");
438 
439  n = uves_round_double(50.0/dlambda);
440 
441  assure( n >= 1, CPL_ERROR_ILLEGAL_OUTPUT,
442  "Cannot rebin to 50 w.l.u. Current step is only %f w.l.u.", dlambda);
443 
444  /* Filter radius = 25 wlu, 0 (It's a 1d image) */
445  check( uves_filter_image_average(*response_curve, n/2, 0),
446  "Error filtering response curve");
447 
448  newbin = 1;
449  for (bin = 1+n/2; bin <= cpl_image_get_size_x(*response_curve); bin += n)
450  {
451  int pis_rejected;
452 
453  /* Write to the same image buffer */
454  cpl_image_set(*response_curve,
455  newbin, 1,
456  cpl_image_get(*response_curve, bin, 1, &pis_rejected)
457  );
458  newbin++;
459  }
460 
461 
462  /* Extract image, update start+step wavelengths */
463  uves_crop_image(response_curve, 1, 1, newbin-1, 1);
464 
465  lambda_start = lambda_start + dlambda * ((1+n/2) - 1); /* Center of first bin */
466  dlambda = n * dlambda;
467 
468  check( uves_pfits_set_crval1(*response_header, lambda_start),
469  "Error updating start wavelength");
470  check( uves_pfits_set_cdelt1(*response_header, dlambda),
471  "Error updating wavelength step");
472 
473  }
474 
475  check( uves_plot_image_rows(*response_curve, 1, 1, 1, "Wavelength (arbitrary units)",
476  NULL,
477  "Response curve (%s chip)",
479  "Plotting failed");
480 
481  /* Calculate efficiency table */
482  uves_msg("Calculating efficiency curve");
483 
484  check( uves_response_efficiency(raw_image,
485  raw_header,
486  rotated_header,
487  master_bias,
488  mbias_header,
489  master_dark,
490  mdark_header,
491  ordertable,
492  order_locations,
493  linetable,
494  linetable_header,
495  dispersion_relation,
496  flux_table,
497  atm_extinction,
498  chip,
499  debug_mode,
500  parameters,
501  PACCURACY,
502  efficiency,
503  blaze_efficiency),
504  "Efficiency calculation failed");
505 
506  check( uves_plot_table(*efficiency, "Wave", "Eff",
507  "Detection Quantum Efficiency (%s chip)",
508  uves_chip_tostring_upper(chip)),
509  "Plotting failed");
510 
511  /* Save blaze function efficiency (efficiency at center of order) */
512  if (debug_mode) check( uves_save_table_local("Blaze efficiency table",
513  "blaze_efficiency",
514  *blaze_efficiency, chip, -1, -1, rotated_header, NULL),
515  "Error saving blaze efficiency table");
516  }
517  else
518  {
519  uves_msg("Skipping response/efficiency computation");
520  }
521 
522  cleanup:
523  uves_free_propertylist(&rebinned_header);
524  uves_free_image(&rebinned_noise);
525  uves_free_image(&rebinned_spectrum);
526  uves_free_table(&cosmic_mask);
527  uves_free_table(&order_trace);
528  uves_free_image(&merged_spectrum);
529  uves_free_image(&merged_noise);
530  uves_free_image(&merged_sky);
531  uves_free_image(&reduced_rebinned);
532  uves_free_image(&reduced_rebinned_noise);
533  uves_free_image(&reduced_noise);
534  uves_free_image(&reduced_scaled);
535  uves_free_table(&catalogue_flux);
536 
537  if (cpl_error_get_code() != CPL_ERROR_NONE)
538  {
539  /* Output */
540  uves_free_image(reduced_spectrum);
541  uves_free_image(background);
542  uves_free_image(response_orders);
543  uves_free_image(response_curve);
544  uves_free_propertylist(reduced_header);
545  uves_free_propertylist(response_header);
546  uves_free_propertylist(response_header_2d);
547  uves_free_table(efficiency);
548  }
549 
550  return cpl_error_get_code();
551 }
552 
553 /*----------------------------------------------------------------------------*/
560 /*----------------------------------------------------------------------------*/
561 static void
562 UVES_CONCAT2X(UVES_RESPONSE_ID,exe)(cpl_frameset *frames,
563  const cpl_parameterlist *parameters,
564  const char *starttime)
565 {
566  /*
567  * Variables containg the values of recipe parameters
568  */
569 
570  /* General */
571  bool debug_mode;
572 
573  /* Background subtraction */
574  /* Implicitly passed */
575 
576  /* Flat-fielding */
577 
578  /* Extraction */
579  /* Implicitly passed */
580 
581  /* Rebinning */
582  /* Implicitly passed */
583 
584  /* Efficiency */
585  double PACCURACY;
586 
587  /* CPL objects */
588  /* Input, raw */
589  cpl_image *raw_image[2] = {NULL, NULL};
590  uves_propertylist *raw_header[2] = {NULL, NULL};
591  uves_propertylist *rotated_header[2] = {NULL, NULL};
592 
593  /* Input, calib */
594  cpl_image *master_bias = NULL;
595  uves_propertylist *master_bias_header = NULL;
596 
597  cpl_image *master_dark = NULL;
598  uves_propertylist *master_dark_header = NULL;
599 
600  cpl_image *master_flat = NULL;
601  uves_propertylist *master_flat_header = NULL;
602 
603  cpl_table *ordertable = NULL;
604  uves_propertylist *ordertable_header= NULL;
605  polynomial *order_locations = NULL;
606  cpl_table *traces = NULL;
607 
608  cpl_table *flux_table = NULL;
609 
610  cpl_table *atm_extinction = NULL;
611  uves_propertylist *table_header= NULL;
612  /* Line tables for sky, object, sky (UVES specific) */
613  const cpl_table *linetable[3] = {NULL, NULL, NULL};
614  const uves_propertylist *linetable_header[3] = {NULL, NULL, NULL};
615  const polynomial *dispersion_relation[3] = {NULL, NULL, NULL};
616 
617  /* Output */
618  cpl_image *background = NULL;
619  cpl_image *reduced_spectrum = NULL;
620  uves_propertylist *spectrum_header = NULL;
621  cpl_image *response_orders = NULL;
622  uves_propertylist *response_header_2d = NULL;
623  cpl_image *response_curve = NULL;
624  uves_propertylist *response_header = NULL;
625  cpl_table *efficiency = NULL;
626  cpl_table *blaze_efficiency = NULL;
627  uves_propertylist *efficiency_header = NULL;
628  cpl_table* info_tbl=NULL;
629 
630  /* Local variables */
631  cpl_table *qclog[2] = {NULL, NULL};
632  cpl_table *qclog_optext[2] = {NULL, NULL};
633  cpl_table *catalogue_flux = NULL;
634  const char *raw_filename = ""; /* Static */
635  const char *flux_table_filename = ""; /* Static */
636  const char *atm_ext_filename = ""; /* Static */
637  char *product_filename = NULL; /* Dynamically allocated */
638  char *prod_catg = NULL;
639  char *ref_obj_name = NULL; /* Reference object id */
640  bool calc_response = false; /* Calculate instr response? */
641  double extraction_slit;
642 
643  bool blue = false;
644  enum uves_chip chip;
645  int binx = 0;
646  int biny = 0;
647  const char* PROCESS_CHIP=NULL;
648 
649  const char *ordertable_filename = "";
650  const char *linetable_filename = "";
651  const char *master_bias_filename = "";
652  const char *master_dark_filename = "";
653  const char *master_flat_filename = "";
654  const char *chip_name = "";
655  int tracerow=0; /* Index of table row */
656 
657  int raw_index = 0;
658 
659  char extname[80];
660  double trace_offset=0;
661  int trace_number=0;
662  int trace_enabled=0;
663  int window=0; /* window number */
664  merge_method m_method;
665 
666  /* Read recipe parameters */
667  {
668  /* General */
669  check( uves_get_parameter(parameters, NULL, "uves", "debug",
670  CPL_TYPE_BOOL , &debug_mode ), "Could not read parameter");
671 
672  check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
673  "Could not read parameter");
674  uves_string_toupper((char*)PROCESS_CHIP);
675 
676  /* Background subtraction, Flat-fielding, Rebinning */
677  /* The input parameter list is passed */
678 
679  /* For both response curve and efficiency step:
680  Allow only extraction methods average/linear/optimal */
681  {
682  extract_method em;
683 
684  /* Validate uves_response.reduce.extract.method */
686  parameters, NULL,
687  make_str(UVES_RESPONSE_ID) "." UVES_REDUCE_ID "." UVES_EXTRACT_ID),
688  "Could not read extraction method");
689 
690  assure( em == EXTRACT_LINEAR || em == EXTRACT_AVERAGE || em == EXTRACT_OPTIMAL,
691  CPL_ERROR_UNSUPPORTED_MODE,
692  "Use linear/average/optimal extraction method to calculate response curve");
693 
694  /* Validate uves_response.efficiency.reduce.extract.method */
696  parameters, NULL,
697  make_str(UVES_RESPONSE_ID) ".efficiency." UVES_REDUCE_ID "." UVES_EXTRACT_ID),
698  "Could not read extraction method");
699 
700  assure( em == EXTRACT_LINEAR || em == EXTRACT_AVERAGE || em == EXTRACT_OPTIMAL,
701  CPL_ERROR_UNSUPPORTED_MODE,
702  "Use linear/average/optimal extraction "
703  "method to calculate quantum efficiency");
704  }
705 
706  /* Identification */
707  check( uves_get_parameter(parameters, NULL,
708  make_str(UVES_RESPONSE_ID) ".efficiency", "paccuracy",
709  CPL_TYPE_DOUBLE, &PACCURACY),
710  "Could not read parameter");
711  }
712 
713  /* Load raw image and header, and identify input frame as red or blue */
714  check( uves_load_standard(frames,
715  &raw_filename, raw_image, raw_header, rotated_header,
716  &blue),
717  "Error loading raw frame");
718 
719  /* Load flux table */
720  check( uves_load_flux_table(frames, &flux_table_filename, &flux_table),
721  "Error loading standard flux table");
722 
723  uves_msg_low("Using standard star flux table in '%s'", flux_table_filename);
724 
725  /* Before doing the reduction, find out if the standard star is in the table.
726  * If not, still do the science reduction, but skip the instr.response part
727  */
728  catalogue_flux = uves_align(raw_header[0], flux_table, PACCURACY, &ref_obj_name);
729 
730  calc_response = true;
731  if (cpl_error_get_code() == CPL_ERROR_INCOMPATIBLE_INPUT)
732  {
734 
735  uves_msg_warning("No catalogue object found within %.2f arcsecs. "
736  "Instrument response curve will not be computed",
737  PACCURACY);
738 
739  calc_response = false;
740  }
741 
742  /* Load atmospheric extinction table */
743  check( uves_load_atmo_ext(frames, &atm_ext_filename, &atm_extinction),
744  "Error loading extinction coefficients");
745 
746  uves_msg_low("Using atmospheric extinction table in '%s'", atm_ext_filename);
747 
748  //cpl_parameterlist_dump(parameters,stdout);
749  //uves_msg("recipe=%s",UVES_RESPONSE_ID);
750  check( m_method = uves_get_merge_method(parameters, "uves_cal_response", "reduce"),
751  "Could not get merging method");
752  /* Adjust parameters according to binning
753  */
754  check (binx = uves_pfits_get_binx(raw_header[0]),
755  "Could not read x binning factor from input header");
756  check (biny = uves_pfits_get_biny(raw_header[0]),
757  "Could not read y binning factor from input header");
758 
759  /* Loop over one or two chips, over traces and
760  over extraction windows */
761  for (chip = uves_chip_get_first(blue);
762  chip != UVES_CHIP_INVALID;
763  chip = uves_chip_get_next(chip))
764  {
765  table_header = uves_propertylist_new();
766 
767 
768  if(strcmp(PROCESS_CHIP,"REDU") == 0) {
769  chip = uves_chip_get_next(chip);
770  }
771 
772 
773  /* const char *drs_filename = ""; not used */
774  raw_index = uves_chip_get_index(chip);
775  uves_msg("Processing %s chip in '%s'",
776  uves_chip_tostring_upper(chip), raw_filename);
777 
778  check_nomsg( chip_name = uves_pfits_get_chipid(raw_header[raw_index], chip));
779 
780  uves_msg_debug("Binning = %dx%d", binx, biny);
781 
782  /* Load master bias, set pointer to NULL if not present */
783  uves_free_image(&master_bias);
784  uves_free_propertylist(&master_bias_header);
785  if (cpl_frameset_find(frames, UVES_MASTER_BIAS(chip)) != NULL)
786  {
787  check( uves_load_mbias(frames, chip_name,
788  &master_bias_filename,
789  &master_bias,
790  &master_bias_header, chip),
791  "Error loading master bias");
792 
793  uves_msg_low("Using master bias in '%s'", master_bias_filename);
794  }
795  else
796  {
797  uves_msg_low("No master bias in SOF. Bias subtraction not done");
798  }
799 
800 
801  /* Load master dark, set pointer to NULL if not present */
802  uves_free_image(&master_dark);
803  uves_free_propertylist(&master_dark_header);
804  if (cpl_frameset_find(frames, UVES_MASTER_DARK(chip)) != NULL)
805  {
806  check( uves_load_mdark(frames, chip_name,
807  &master_dark_filename,
808  &master_dark,
809  &master_dark_header, chip),
810  "Error loading master dark");
811 
812  uves_msg_low("Using master dark in '%s'", master_dark_filename);
813  }
814  else
815  {
816  uves_msg_low("No master dark in SOF. Dark subtraction not done");
817  }
818 
819  /* Load master flat */
820  uves_free_image(&master_flat);
821  uves_free_propertylist(&master_flat_header);
822  check( uves_load_mflat_const(frames, chip_name,
823  &master_flat_filename,
824  &master_flat,
825  &master_flat_header,
826  chip, NULL), "Error loading master flat");
827 
828  uves_msg_low("Using master flat in '%s'", master_flat_filename);
829 
830 
831  /* Load the order table for this chip */
832  uves_free_table (&ordertable);
833  uves_free_propertylist(&ordertable_header);
834  uves_polynomial_delete(&order_locations);
835  uves_free_table (&traces);
836 
837  check( uves_load_ordertable(frames,
838  false, /* FLAMES? */
839  chip_name,
840  &ordertable_filename,
841  &ordertable,
842  &ordertable_header,
843  NULL,
844  &order_locations, &traces,
845  NULL, NULL,
846  NULL, NULL, /* fibre_pos,fibre_mask */
847  chip, false),
848  "Could not load order table");
849  uves_msg_low("Using order table in '%s'", ordertable_filename);
850 
851 
852  /* Loop over all traces (1 trace for UVES) */
853  for(tracerow = 0; tracerow < cpl_table_get_nrow(traces); tracerow++)
854  {
855 
856 
857  trace_offset = cpl_table_get_double(traces, "Offset" , tracerow, NULL);
858  trace_number = cpl_table_get_int (traces, "TraceID" , tracerow, NULL);
859  trace_enabled = cpl_table_get_int (traces, "Tracemask" , tracerow, NULL);
860 
861  if (trace_enabled != 0)
862  {
863 
864  if (cpl_table_get_nrow(traces) > 1) {
865  uves_msg("Processing trace %d", trace_number);
866  }
867 
868  /* This is UVES specific. Load linetable for the
869  two sky windows (number 1, 3) and for the object
870  window (number 2) */
871 
872  for (window = 1; window <= 3; window ++)
873  {
874  uves_free_table_const ( &(linetable[window-1]) );
875  uves_free_propertylist_const( &(linetable_header[window-1]) );
876  uves_polynomial_delete_const( &(dispersion_relation[window-1]) );
877  check( uves_load_linetable_const(
878  frames,
879  false, /* FLAMES? */
880  chip_name,
881  order_locations,
882  cpl_table_get_column_min(ordertable, "Order"),
883  cpl_table_get_column_max(ordertable, "Order"),
884  &linetable_filename,
885  &(linetable [window-1]),
886  &(linetable_header [window-1]),
887  &(dispersion_relation[window-1]),
888  NULL,
889  chip,
890  trace_number,
891  window),
892  "Could not load line table, window #%d", window);
893  }
894 
895  uves_msg_low("Using line tables in '%s'", linetable_filename);
896  /* end, UVES specific */
897 
898  /* Do the reduction + response calculation */
899  cpl_free(ref_obj_name); ref_obj_name = NULL;
900  uves_free_image(&reduced_spectrum);
901  uves_free_image(&background);
902  uves_free_image(&response_orders);
903  uves_free_image(&response_curve);
904  uves_free_propertylist(&response_header);
905  uves_free_propertylist(&spectrum_header);
906  uves_free_propertylist(&response_header_2d);
907  uves_free_table(&efficiency);
908  uves_free_table(&blaze_efficiency);
909  uves_free_table(&info_tbl);
910 
911  check( uves_response_process_chip(
912  raw_image[raw_index], /* Raw */
913  raw_header[raw_index],
914  rotated_header[raw_index],
915  master_bias, /* Calibration */
916  master_bias_header,
917  master_dark,
918  master_dark_header,
919  master_flat,
920  master_flat_header,
921  ordertable,
922  order_locations,
923  linetable,
924  linetable_header,
925  dispersion_relation,
926  flux_table,
927  atm_extinction,
928  chip, /* Parameters */
929  debug_mode,
930  parameters,
931  calc_response,
932  PACCURACY, /* Identification */
933  &ref_obj_name,
934  &reduced_spectrum,
935  &spectrum_header,
936  &background,
937  &response_orders,
938  &response_header_2d,
939  &response_curve,
940  &response_header,
941  &efficiency,
942  &blaze_efficiency,
943  &info_tbl,
944  &extraction_slit),
945  "Response computation failed");
946 
947  uves_msg("Saving products...");
948 
949  /* Calculate QC (two tables) */
950 
951  if (calc_response)
952  {
953  uves_qclog_delete(&qclog[0]);
954  qclog[0] = uves_qclog_init(raw_header[raw_index], chip);
955 
956  check( uves_efficiency_qclog(blaze_efficiency,
957  raw_header[raw_index],
958  chip,
959  qclog[0],
960  ref_obj_name),
961  "Error generating efficiency QC log");
962  }
963 
964  uves_qclog_delete(&qclog_optext[0]);
965  qclog_optext[0] = cpl_table_new(0);
966  /* Do not:
967  qclog_optext[0] = uves_qclog_init(raw_header[raw_index], chip);
968  because we don't want QC.DID for this
969  */
970  cpl_table_new_column(qclog_optext[0],"key_name", CPL_TYPE_STRING);
971  cpl_table_new_column(qclog_optext[0],"key_type", CPL_TYPE_STRING);
972  cpl_table_new_column(qclog_optext[0],"key_value",CPL_TYPE_STRING);
973  cpl_table_new_column(qclog_optext[0],"key_help", CPL_TYPE_STRING);
974 
975  check( uves_qclog_add_sci(qclog_optext[0],
976  raw_header[raw_index],
977  raw_image[raw_index],
978  extraction_slit,
979  info_tbl),
980  "Error generating extraction QC log");
981 
982  if (calc_response)
983  {
984  /* Save response curve */
985  cpl_free(product_filename);
986  check( product_filename = uves_response_curve_filename(chip),
987  "Error getting filename");
988  uves_pfits_set_extname(response_header,"instrument response");
989 
990  check( uves_frameset_insert(
991  frames,
992  response_curve,
993  CPL_FRAME_GROUP_PRODUCT,
994  CPL_FRAME_TYPE_IMAGE,
995  CPL_FRAME_LEVEL_INTERMEDIATE,
996  product_filename,
997  UVES_INSTR_RESPONSE(chip),
998  raw_header[raw_index],
999  response_header,
1000  NULL,
1001  parameters,
1002  make_str(UVES_RESPONSE_ID),
1003  PACKAGE "/" PACKAGE_VERSION,
1004  qclog_optext,
1005  starttime, false,
1006  UVES_ALL_STATS),
1007  "Could not add response curve '%s' (%s) to frameset",
1008  product_filename, UVES_INSTR_RESPONSE(chip));
1009 
1010  uves_msg("Response curve '%s' (%s) added to frameset",
1011  product_filename, UVES_INSTR_RESPONSE(chip));
1012 
1013  /* Save response curve (2d) */
1014  cpl_free(product_filename);
1015  check( product_filename =
1016  uves_response_curve_2d_filename(chip),
1017  "Error getting filename");
1018  uves_pfits_set_extname(response_header_2d,"2D instrument response");
1019  check( uves_frameset_insert(
1020  frames,
1021  response_orders,
1022  CPL_FRAME_GROUP_PRODUCT,
1023  CPL_FRAME_TYPE_IMAGE,
1024  CPL_FRAME_LEVEL_INTERMEDIATE,
1025  product_filename,
1026  UVES_WCALIB_FF_RESPONSE(chip),
1027  raw_header[raw_index],
1028  response_header_2d,
1029  NULL,
1030  parameters,
1031  make_str(UVES_RESPONSE_ID),
1032  PACKAGE "/" PACKAGE_VERSION,
1033  qclog_optext,
1034  starttime, false,
1035  UVES_ALL_STATS),
1036  "Could not add response curve (2d) "
1037  "'%s' (%s) to frameset",
1038  product_filename, UVES_WCALIB_FF_RESPONSE(chip));
1039 
1040  uves_msg("Response curve (2d) '%s' (%s) added to frameset",
1041  product_filename, UVES_WCALIB_FF_RESPONSE(chip));
1042  }
1043 
1044  /* Save reduced spectrum */
1045  cpl_free(product_filename);
1046  if (m_method == MERGE_NOAPPEND) {
1047  check( product_filename = uves_response_red_noappend_standard_filename(chip),
1048  "Error getting filename");
1049  prod_catg=UVES_RED_NOAPPEND_STD(chip);
1050  } else {
1051 
1052  check( product_filename = uves_response_red_standard_filename(chip),
1053  "Error getting filename");
1054  prod_catg=UVES_RED_STD(chip);
1055 
1056  }
1057  uves_pfits_set_extname(spectrum_header,"reduced spectrum");
1058  check( uves_frameset_insert(frames,
1059  reduced_spectrum,
1060  CPL_FRAME_GROUP_PRODUCT,
1061  CPL_FRAME_TYPE_IMAGE,
1062  CPL_FRAME_LEVEL_INTERMEDIATE,
1063  product_filename,
1064  prod_catg,
1065  raw_header[raw_index],
1066  spectrum_header,
1067  NULL,
1068  parameters,
1069  make_str(UVES_RESPONSE_ID),
1070  PACKAGE "/" PACKAGE_VERSION,
1071  qclog_optext,
1072  starttime, false,
1073  UVES_ALL_STATS),
1074  "Could not add reduced spectrum '%s' (%s) to frameset",
1075  product_filename, UVES_RED_STD(chip));
1076 
1077  uves_msg("Reduced spectrum '%s' (%s) added to frameset",
1078  product_filename, UVES_RED_STD(chip));
1079 
1080  if (calc_response)
1081  {
1082  /* Save efficiency table */
1083  uves_free_propertylist(&efficiency_header);
1084  efficiency_header = uves_propertylist_new();
1085 
1086  cpl_free(product_filename);
1087  check( product_filename =
1088  uves_response_efficiency_filename(chip),
1089  "Error getting filename");
1090  uves_pfits_set_extname(efficiency_header,"efficiency");
1091  sprintf(extname,"EFFICIENCY");
1092  uves_pfits_set_extname(table_header,extname);
1093  check( uves_frameset_insert(
1094  frames,
1095  efficiency,
1096  CPL_FRAME_GROUP_PRODUCT,
1097  CPL_FRAME_TYPE_TABLE,
1098  CPL_FRAME_LEVEL_INTERMEDIATE,
1099  product_filename,
1100  UVES_EFFICIENCY_TABLE(chip),
1101  raw_header[raw_index],
1102  efficiency_header,
1103  table_header,
1104  parameters,
1105  make_str(UVES_RESPONSE_ID),
1106  PACKAGE "/" PACKAGE_VERSION,
1107  qclog,
1108  starttime, true, 0),
1109  "Could not add background image '%s' (%s) to frameset",
1110  product_filename, UVES_EFFICIENCY_TABLE(chip));
1111 
1112  uves_msg("Efficiency table '%s' (%s) added to frameset",
1113  product_filename, UVES_EFFICIENCY_TABLE(chip));
1114  } /* end if calc_response */
1115 
1116  /* Save background image */
1117  cpl_free(product_filename);
1118  check( product_filename =
1119  uves_response_bkg_standard_filename(chip),
1120  "Error getting filename");
1121  uves_pfits_set_extname(rotated_header[raw_index],"background");
1122  check( uves_frameset_insert(frames,
1123  background,
1124  CPL_FRAME_GROUP_PRODUCT,
1125  CPL_FRAME_TYPE_IMAGE,
1126  CPL_FRAME_LEVEL_INTERMEDIATE,
1127  product_filename,
1128  UVES_BKG_STD(chip),
1129  raw_header[raw_index],
1130  rotated_header[raw_index],
1131  NULL,
1132  parameters,
1133  make_str(UVES_RESPONSE_ID),
1134  PACKAGE "/" PACKAGE_VERSION, NULL,
1135  starttime, false,
1136  CPL_STATS_MIN | CPL_STATS_MAX),
1137  "Could not add background image '%s' (%s) to frameset",
1138  product_filename, UVES_BKG_STD(chip));
1139 
1140  uves_msg("Background image '%s' (%s) added to frameset",
1141  product_filename, UVES_BKG_STD(chip));
1142 
1143 
1144  /* Save info table */
1145  cpl_free(product_filename);
1146  check( product_filename =
1147  uves_order_extract_qc_standard_filename(chip),
1148  "Error getting filename");
1149  uves_pfits_set_extname(rotated_header[raw_index],"quality control table");
1150  sprintf(extname,"QC_INFO");
1151  uves_pfits_set_extname(table_header,extname);
1152 
1153  check( uves_frameset_insert(frames,
1154  info_tbl,
1155  CPL_FRAME_GROUP_PRODUCT,
1156  CPL_FRAME_TYPE_TABLE,
1157  CPL_FRAME_LEVEL_INTERMEDIATE,
1158  product_filename,
1159  UVES_ORDER_EXTRACT_QC(chip),
1160  raw_header[raw_index],
1161  rotated_header[raw_index],
1162  table_header,
1163  parameters,
1164  make_str(UVES_RESPONSE_ID),
1165  PACKAGE "/" PACKAGE_VERSION, NULL,
1166  starttime, true,
1167  0),
1168  "Could not add extraction quality table '%s' (%s) to frameset",
1169  product_filename, UVES_ORDER_EXTRACT_QC(chip));
1170 
1171  uves_msg("Extraction quality table '%s' (%s) added to frameset",
1172  product_filename, UVES_ORDER_EXTRACT_QC(chip));
1173 
1174 
1175 
1176  }/* ... if trace is enabled */
1177  else
1178  {
1179  uves_msg_low("Skipping trace number %d", trace_number);
1180  }
1181 
1182  }/* For each trace */
1183 
1184 
1185  if(strcmp(PROCESS_CHIP,"REDL") == 0) {
1186  chip = uves_chip_get_next(chip);
1187  }
1188 
1189  uves_free_propertylist(&table_header);
1190 
1191 
1192 
1193  } /* For each chip */
1194 
1195  cleanup:
1196  /* Input */
1197  uves_free_image(&raw_image[0]);
1198  uves_free_image(&raw_image[1]);
1199  uves_free_propertylist(&raw_header[0]);
1200  uves_free_propertylist(&raw_header[1]);
1201  uves_free_propertylist(&rotated_header[0]);
1202  uves_free_propertylist(&rotated_header[1]);
1203 
1204  /* Input, calib */
1205  uves_free_image(&master_bias);
1206  uves_free_propertylist(&master_bias_header);
1207 
1208  uves_free_image(&master_dark);
1209  uves_free_propertylist(&master_dark_header);
1210 
1211  uves_free_image(&master_flat);
1212  uves_free_propertylist(&master_flat_header);
1213 
1214  uves_free_table(&ordertable);
1215  uves_free_propertylist(&ordertable_header);
1216  uves_polynomial_delete(&order_locations);
1217  uves_free_table(&traces);
1218  uves_free_propertylist(&table_header);
1219  uves_free_table_const( &(linetable[0]) );
1220  uves_free_table_const( &(linetable[1]) );
1221  uves_free_table_const( &(linetable[2]) );
1222  uves_free_propertylist_const( &(linetable_header[0]) );
1223  uves_free_propertylist_const( &(linetable_header[1]) );
1224  uves_free_propertylist_const( &(linetable_header[2]) );
1225  uves_polynomial_delete_const( &(dispersion_relation[0]) );
1226  uves_polynomial_delete_const( &(dispersion_relation[1]) );
1227  uves_polynomial_delete_const( &(dispersion_relation[2]) );
1228  uves_free_table( &flux_table );
1229  uves_free_table( &atm_extinction );
1230 
1231  /* Output */
1232  uves_qclog_delete(&qclog[0]);
1233  uves_qclog_delete(&qclog_optext[0]);
1234  uves_free_image(&background);
1235  uves_free_image(&reduced_spectrum);
1236  uves_free_propertylist(&spectrum_header);
1237  uves_free_propertylist(&response_header_2d);
1238  uves_free_propertylist(&response_header);
1239  uves_free_propertylist(&efficiency_header);
1240  uves_free_image(&response_orders);
1241  uves_free_image(&response_curve);
1242  uves_free_table(&efficiency);
1243  uves_free_table(&blaze_efficiency);
1244  uves_free_table(&info_tbl);
1245 
1246  /* Local */
1247  uves_free_table(&catalogue_flux);
1248  cpl_free(product_filename);
1249  cpl_free(ref_obj_name);
1250 
1251  return;
1252 }
1253 
1263 static void uves_efficiency_qclog(cpl_table* table,
1264  uves_propertylist* raw_header,
1265  enum uves_chip chip,
1266  cpl_table* qclog,
1267  const char *ref_obj_name)
1268 {
1269  int i=0;
1270  bool new_format;
1271 
1272  check( new_format = uves_format_is_new(raw_header),
1273  "Error determining FITS header format");
1274 
1276  "QC TEST1 ID",
1277  "Efficiency-Test-Results",
1278  "Name of QC test",
1279  "%s"));
1280 
1282  uves_remove_string_prefix(UVES_INSPATH,"ESO "),
1283  uves_pfits_get_inspath(raw_header),
1284  "Optical path used.",
1285  "%s"));
1286 
1288  uves_remove_string_prefix(UVES_INSMODE,"ESO "),
1289  uves_pfits_get_insmode(raw_header),
1290  "Instrument mode used.",
1291  "%s"));
1292 
1294  uves_remove_string_prefix(UVES_GRATNAME(chip),"ESO "),
1295  uves_pfits_get_gratname(raw_header,chip),
1296  "Cross disperser ID",
1297  "%s"));
1298 
1300  chip, qclog));
1301 
1302  check_nomsg(
1303  uves_qclog_add_string(qclog,
1304  uves_remove_string_prefix(UVES_CHIP_NAME(chip),"ESO "),
1305  /* UVES_QC_CHIP_VAL(chip), */
1306  uves_pfits_get_chip_name(raw_header, chip),
1307  "Detector chip name",
1308  "%s"));
1309 
1310  check_nomsg(
1311  uves_qclog_add_double(qclog,
1312  uves_remove_string_prefix(UVES_GRATWLEN(chip),"ESO "),
1313  uves_pfits_get_gratwlen(raw_header,chip),
1314  "Grating central wavelength [nm] (hs).",
1315  "%.1f"));
1316 
1317  check_nomsg(
1318  uves_qclog_add_double(qclog,
1319  uves_remove_string_prefix(UVES_CONAD(new_format, chip),"ESO "),
1320  uves_pfits_get_conad(raw_header, chip),
1321  "Conversion from ADUs to electrons",
1322  "%8.2f"));
1323 
1324 
1325  check_nomsg(
1326  uves_qclog_add_double(qclog,
1327  uves_remove_string_prefix(UVES_QC_UIT(new_format, chip), "ESO "),
1328  uves_pfits_get_uit(raw_header),
1329  "user defined subintegration time",
1330  "%8.0f"));
1331 
1332  check_nomsg(
1333  uves_qclog_add_double(qclog,
1334  "AIRMASS",
1335  (uves_pfits_get_airmass_start(raw_header) +
1336  uves_pfits_get_airmass_end(raw_header))/2.0,
1337  "Averaged airmass",
1338  "%8.4f"));
1339 
1340  check_nomsg(
1341  uves_qclog_add_string(qclog,
1342  uves_remove_string_prefix(UVES_TARG_NAME, "ESO "),
1343  ref_obj_name,
1344  "OB target name",
1345  "%s"));
1346 
1347 
1348  for(i = 0; i < cpl_table_get_nrow(table); i++)
1349  {
1350  char key_name[25];
1351 
1352  int order = cpl_table_get_int(table, "Order", i, NULL);
1353 
1354  sprintf(key_name,"QC BLAZEFF%d", order);
1355 
1357  key_name,
1358  cpl_table_get_double(table, "Eff", i, NULL),
1359  "Blaze Efficiency",
1360  "%13.6f"));
1361  /*
1362  uves_msg("QC-LOG: Wlen =%g Eff=%g",
1363  cpl_table_get_double(table,"Wave",i,NULL),
1364  cpl_table_get_double(table,"Eff",i,NULL));
1365  */
1366 
1367  sprintf(key_name,"QC BLAZWLEN%d", order);
1369  key_name,
1370  cpl_table_get_double(table, "Wave", i, NULL)/10.,
1371  "Blaze wavelength", /* nm */
1372  "%13.6f"));
1373  }
1374 
1375  /* Are these QC parameters needed anywhere? */
1376 #if 0
1377  for(i = 0; i < cpl_table_get_nrow(info_tbl); i++)
1378  {
1379  char key_name[25];
1380 
1381  int order = cpl_table_get_int(info_tbl, "Order", i, NULL);
1382 
1383  sprintf(key_name,"QC ORDER NUM%d", order);
1385  key_name,
1386  order,
1387  "Order Number",
1388  "%d"));
1389  /*
1390  uves_msg("QC-LOG: Order =%d S/N=%g",
1391  cpl_table_get_int(info_tbl,"Order",i,NULL),
1392  cpl_table_get_double(info_tbl,"S/N",i,NULL));
1393  */
1394 
1395  sprintf(key_name,"QC OBJ SN%d", order);
1397  key_name,
1398  cpl_table_get_double(info_tbl,"S/N",i,NULL),
1399  "Order S/N",
1400  "%f13.6"));
1401  }
1402 #endif
1403 
1404  cleanup:
1405  return;
1406 }
1407 
double uves_pfits_get_uit(const uves_propertylist *plist)
Find out the user integration time.
Definition: uves_pfits.c:2100
cpl_error_code uves_filter_image_median(cpl_image **image, int xwindow, int ywindow, bool extrapolate_border)
Median filter.
void uves_polynomial_delete(polynomial **p)
Delete a polynomial.
#define uves_msg_warning(...)
Print an warning message.
Definition: uves_msg.h:87
cpl_error_code uves_pfits_set_cdelt1(uves_propertylist *plist, double cdelt1)
Write the cdelt1 keyword.
Definition: uves_pfits.c:2899
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
cpl_table * uves_align(const uves_propertylist *object_header, const cpl_table *flux_table, double accuracy, char **ref_name_dynamic)
Match a star against a catalogue of stars.
#define check_nomsg(CMD)
Definition: uves_error.h:204
cpl_error_code uves_pfits_set_crval1(uves_propertylist *plist, double crval1)
Write the crval1 keyword.
Definition: uves_pfits.c:2829
cpl_error_code uves_filter_image_average(cpl_image *image, int radius_x, int radius_y)
Average filter.
int uves_qclog_delete(cpl_table **table)
delete QC-LOG table
Definition: uves_qclog.c:716
double uves_pfits_get_gratwlen(const uves_propertylist *plist, enum uves_chip chip)
find out the central wavelength
Definition: uves_pfits.c:1371
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
const char * uves_pfits_get_chip_name(const uves_propertylist *plist, enum uves_chip chip)
Find out the chip name.
Definition: uves_pfits.c:639
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
uves_propertylist * uves_propertylist_new(void)
Create an empty property list.
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
int uves_pfits_get_biny(const uves_propertylist *plist)
Find out the y binning factor.
Definition: uves_pfits.c:1194
void uves_qclog_add_sci(cpl_table *qclog, const uves_propertylist *raw_header, const cpl_image *raw_image, double slit, const cpl_table *info_tbl)
Write QC parameters related to science reduction.
Definition: uves_qclog.c:803
const char * uves_remove_string_prefix(const char *s, const char *prefix)
Remove named prefix from string.
Definition: uves_utils.c:3612
void uves_polynomial_delete_const(const polynomial **p)
Delete a const polynomial.
const char * uves_pfits_get_gratname(const uves_propertylist *plist, enum uves_chip chip)
find out the grating name value
Definition: uves_pfits.c:1427
extract_method uves_get_extract_method(const cpl_parameterlist *parameters, const char *context, const char *subcontext)
Read extraction method from parameter list.
Definition: uves_extract.c:462
const char * uves_pfits_get_insmode(const uves_propertylist *plist)
find out the chip name value
Definition: uves_pfits.c:1391
const char * uves_pfits_get_inspath(const uves_propertylist *plist)
find out the chip name value
Definition: uves_pfits.c:1409
cpl_image * uves_normalize_spectrum(const cpl_image *spectrum, const cpl_image *spectrum_error, const uves_propertylist *spectrum_header, const uves_propertylist *raw_header, int n_traces, enum uves_chip chip, const cpl_table *atm_extinction, bool correct_binning, cpl_image **scaled_error)
Normalize a spectrum.
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
merge_method uves_get_merge_method(const cpl_parameterlist *parameters, const char *context, const char *subcontext)
Read merging method from parameter list.
Definition: uves_merge.c:777
cpl_error_code uves_pfits_set_extname(uves_propertylist *plist, const char *extname)
Write the EXTNAME keyword.
Definition: uves_pfits.c:2736
double uves_pfits_get_airmass_end(const uves_propertylist *plist)
Find out the end airmass.
Definition: uves_pfits.c:820
#define uves_error_reset()
Definition: uves_error.h:215
#define uves_msg_low(...)
Print a message on a lower message level.
Definition: uves_msg.h:105
bool uves_format_is_new(const uves_propertylist *plist)
Find out FITS header format.
Definition: uves_pfits.c:573
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
double uves_pfits_get_cdelt1(const uves_propertylist *plist)
Find out the cdelt1.
Definition: uves_pfits.c:2465
double uves_pfits_get_crval1(const uves_propertylist *plist)
Find out the crval1.
Definition: uves_pfits.c:2393
uves_propertylist * uves_propertylist_duplicate(const uves_propertylist *self)
Create a copy of the given property list.
cpl_error_code uves_pfits_set_bunit(uves_propertylist *plist, const char *bunit)
Write the bunit keyword.
Definition: uves_pfits.c:2660
cpl_error_code uves_response_efficiency(const cpl_image *raw_image, const uves_propertylist *raw_header, const uves_propertylist *rotated_header, const cpl_image *master_bias, const uves_propertylist *mbias_header, const cpl_image *master_dark, const uves_propertylist *mdark_header, const cpl_table *ordertable, const polynomial *order_locations, const cpl_table *linetable[3], const uves_propertylist *linetable_header[3], const polynomial *dispersion_relation[3], const cpl_table *flux_table, const cpl_table *atm_extinction, enum uves_chip chip, bool debug_mode, const cpl_parameterlist *parameters, double PACCURACY, cpl_table **efficiency, cpl_table **blaze_efficiency)
Calculate quantum detection efficiency.
const char * uves_string_toupper(char *s)
Convert all lowercase characters in a string into uppercase characters.
Definition: uves_utils.c:1493
void uves_qclog_add_common_wave(const uves_propertylist *raw_header, enum uves_chip chip, cpl_table *qclog)
Write common QC parameters.
Definition: uves_qclog.c:942
cpl_image * uves_calculate_response(const cpl_image *spectrum, const uves_propertylist *spectrum_header, const cpl_table *flux_table, const uves_propertylist *raw_header, double PACCURACY, bool inverse, char **ref_obj_id)
Calculate response.
#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
const char * uves_pfits_get_chipid(const uves_propertylist *plist, enum uves_chip chip)
Find out the chip ID.
Definition: uves_pfits.c:619
double uves_pfits_get_airmass_start(const uves_propertylist *plist)
Find out the start airmass.
Definition: uves_pfits.c:801
cpl_error_code uves_reduce(const cpl_image *raw_image, const uves_propertylist *raw_header, const uves_propertylist *rotated_header, const cpl_image *master_bias, const uves_propertylist *mbias_header, const cpl_image *master_dark, const uves_propertylist *mdark_header, const cpl_image *master_flat, const uves_propertylist *mflat_header, const cpl_table *ordertable, const polynomial *order_locations, const cpl_table *linetable[3], const uves_propertylist *linetable_header[3], const polynomial *dispersion_relation[3], enum uves_chip chip, bool debug_mode, const cpl_parameterlist *parameters, const char *rec_id, const char *mode, cpl_image **x, uves_propertylist **x_header, cpl_image **fx, cpl_table **cosmic_mask, cpl_image **wave_map, cpl_image **background, cpl_image **flatfielded_variance, uves_propertylist **flatfielded_variance_header, cpl_image **resampled_spectrum, cpl_image **resampled_mf, cpl_image **merged_sky, cpl_image **rebinned_spectrum, cpl_image **rebinned_noise, uves_propertylist **rebinned_header, cpl_image **merged_spectrum, cpl_image **merged_noise, uves_propertylist **merged_header, cpl_image **reduced_rebinned_spectrum, cpl_image **reduced_rebinned_noise, cpl_image **reduced_spectrum, cpl_image **reduced_noise, cpl_table **info_tbl, double *extraction_slit, cpl_table **order_trace)
Reduce a science frame.
Definition: uves_reduce.c:575
double uves_pfits_get_conad(const uves_propertylist *plist, enum uves_chip chip)
Find out the conad.
Definition: uves_pfits.c:840