49 #include <uves_reduce.h>
50 #include <uves_reduce_utils.h>
51 #include <uves_response_efficiency.h>
52 #include <uves_response_utils.h>
55 #include <uves_extract.h>
56 #include <uves_plot.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>
67 #include <uves_merge.h>
77 static void uves_efficiency_qclog(cpl_table* table,
81 const char *ref_obj_name);
84 uves_response_define_parameters(cpl_parameterlist *parameters);
89 #define cpl_plugin_get_info uves_response_get_info
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"
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"
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"
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");
135 uves_response_define_parameters(cpl_parameterlist *parameters)
141 if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
150 if (uves_propagate_parameters_step(
151 UVES_REDUCE_ID, parameters, make_str(UVES_RESPONSE_ID), NULL) != 0)
157 check(uves_define_efficiency_parameters(parameters),
158 "Defining efficiency parameters");
162 return (cpl_error_get_code() != CPL_ERROR_NONE);
221 static cpl_error_code
222 uves_response_process_chip(
const cpl_image *raw_image,
225 const cpl_image *master_bias,
227 const cpl_image *master_dark,
229 const cpl_image *master_flat,
231 const cpl_table *ordertable,
233 const cpl_table *linetable[3],
236 const cpl_table *flux_table,
237 const cpl_table *atm_extinction,
245 const cpl_parameterlist *parameters,
251 cpl_image **reduced_spectrum,
253 cpl_image **background,
254 cpl_image **response_orders,
256 cpl_image **response_curve,
258 cpl_table **efficiency,
259 cpl_table** blaze_efficiency,
260 cpl_table** info_tbl,
261 double *extraction_slit)
263 cpl_image *rebinned_spectrum = NULL;
264 cpl_image *rebinned_noise = NULL;
266 cpl_image *reduced_rebinned = NULL;
267 cpl_image *reduced_rebinned_noise = NULL;
269 cpl_image *reduced_noise = NULL;
271 cpl_table *cosmic_mask = NULL;
272 cpl_table *order_trace = NULL;
273 cpl_image *merged_spectrum = NULL;
274 cpl_image *wave_map = NULL;
275 cpl_image *merged_sky = NULL;
276 cpl_image *merged_noise = NULL;
277 cpl_image *reduced_scaled = NULL;
280 cpl_table *catalogue_flux = NULL;
302 make_str(UVES_RESPONSE_ID),
324 &reduced_rebinned_noise,
330 "Could not reduce frame");
333 check( uves_plot_image_rows(*reduced_spectrum, 1, 1, 1,
334 "Wavelength (arbitrary units)", NULL,
335 "Reduced spectrum (%s chip)",
342 uves_msg(
"Filtering rebinned spectrum");
344 "Could not smooth spectrum");
346 "Could not smooth spectrum");
348 uves_msg(
"Calculating 2d response curve");
358 "Could not calculate response curve");
361 "Error creating FITS header for 2d response curve");
364 "Error writing BUNIT keyword");
370 uves_msg(
"Normalizing reduced spectrum");
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");
386 "Error normalizing reduced spectrum");
389 uves_msg(
"Filtering reduced spectrum");
391 "Could not smooth spectrum");
393 "Could not smooth spectrum");
395 uves_msg(
"Calculating response curve from scaled spectrum");
397 cpl_free(*ref_obj_id); *ref_obj_id = NULL;
405 "Could not calculate response curve");
408 "Error creating FITS header for response curve");
411 "Error writing BUNIT keyword");
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");
420 check( uves_plot_image_rows(*response_curve, 1, 1, 1,
"Wavelength (arbitrary units)",
429 uves_msg(
"Rebinning response curve to step size = 50 w.l.u.");
431 double dlambda, lambda_start;
435 "Error reading start wavelength from header");
437 "Error reading wavelength step from header");
439 n = uves_round_double(50.0/dlambda);
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);
446 "Error filtering response curve");
449 for (bin = 1+n/2; bin <= cpl_image_get_size_x(*response_curve); bin += n)
454 cpl_image_set(*response_curve,
456 cpl_image_get(*response_curve, bin, 1, &pis_rejected)
463 uves_crop_image(response_curve, 1, 1, newbin-1, 1);
465 lambda_start = lambda_start + dlambda * ((1+n/2) - 1);
466 dlambda = n * dlambda;
469 "Error updating start wavelength");
471 "Error updating wavelength step");
475 check( uves_plot_image_rows(*response_curve, 1, 1, 1,
"Wavelength (arbitrary units)",
477 "Response curve (%s chip)",
482 uves_msg(
"Calculating efficiency curve");
504 "Efficiency calculation failed");
506 check( uves_plot_table(*efficiency,
"Wave",
"Eff",
507 "Detection Quantum Efficiency (%s chip)",
512 if (debug_mode)
check( uves_save_table_local(
"Blaze efficiency table",
514 *blaze_efficiency, chip, -1, -1, rotated_header, NULL),
515 "Error saving blaze efficiency table");
519 uves_msg(
"Skipping response/efficiency computation");
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);
537 if (cpl_error_get_code() != CPL_ERROR_NONE)
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);
550 return cpl_error_get_code();
562 UVES_CONCAT2X(UVES_RESPONSE_ID,exe)(cpl_frameset *frames,
563 const cpl_parameterlist *parameters,
564 const char *starttime)
589 cpl_image *raw_image[2] = {NULL, NULL};
594 cpl_image *master_bias = NULL;
597 cpl_image *master_dark = NULL;
600 cpl_image *master_flat = NULL;
603 cpl_table *ordertable = NULL;
606 cpl_table *traces = NULL;
608 cpl_table *flux_table = NULL;
610 cpl_table *atm_extinction = NULL;
613 const cpl_table *linetable[3] = {NULL, NULL, NULL};
615 const polynomial *dispersion_relation[3] = {NULL, NULL, NULL};
618 cpl_image *background = NULL;
619 cpl_image *reduced_spectrum = NULL;
621 cpl_image *response_orders = NULL;
623 cpl_image *response_curve = NULL;
625 cpl_table *efficiency = NULL;
626 cpl_table *blaze_efficiency = NULL;
628 cpl_table* info_tbl=NULL;
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 =
"";
635 const char *flux_table_filename =
"";
636 const char *atm_ext_filename =
"";
637 char *product_filename = NULL;
638 char *prod_catg = NULL;
639 char *ref_obj_name = NULL;
640 bool calc_response =
false;
641 double extraction_slit;
647 const char* PROCESS_CHIP=NULL;
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 =
"";
660 double trace_offset=0;
664 merge_method m_method;
669 check( uves_get_parameter(parameters, NULL,
"uves",
"debug",
670 CPL_TYPE_BOOL , &debug_mode ),
"Could not read parameter");
672 check( uves_get_parameter(parameters, NULL,
"uves",
"process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
673 "Could not read parameter");
687 make_str(UVES_RESPONSE_ID)
"." UVES_REDUCE_ID
"." UVES_EXTRACT_ID),
688 "Could not read extraction method");
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");
697 make_str(UVES_RESPONSE_ID)
".efficiency." UVES_REDUCE_ID
"." UVES_EXTRACT_ID),
698 "Could not read extraction method");
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");
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");
714 check( uves_load_standard(frames,
715 &raw_filename, raw_image, raw_header, rotated_header,
717 "Error loading raw frame");
720 check( uves_load_flux_table(frames, &flux_table_filename, &flux_table),
721 "Error loading standard flux table");
723 uves_msg_low(
"Using standard star flux table in '%s'", flux_table_filename);
728 catalogue_flux =
uves_align(raw_header[0], flux_table, PACCURACY, &ref_obj_name);
730 calc_response =
true;
731 if (cpl_error_get_code() == CPL_ERROR_INCOMPATIBLE_INPUT)
736 "Instrument response curve will not be computed",
739 calc_response =
false;
743 check( uves_load_atmo_ext(frames, &atm_ext_filename, &atm_extinction),
744 "Error loading extinction coefficients");
746 uves_msg_low(
"Using atmospheric extinction table in '%s'", atm_ext_filename);
751 "Could not get merging method");
755 "Could not read x binning factor from input header");
757 "Could not read y binning factor from input header");
762 chip != UVES_CHIP_INVALID;
768 if(strcmp(PROCESS_CHIP,
"REDU") == 0) {
775 uves_msg(
"Processing %s chip in '%s'",
783 uves_free_image(&master_bias);
784 uves_free_propertylist(&master_bias_header);
785 if (cpl_frameset_find(frames, UVES_MASTER_BIAS(chip)) != NULL)
787 check( uves_load_mbias(frames, chip_name,
788 &master_bias_filename,
790 &master_bias_header, chip),
791 "Error loading master bias");
793 uves_msg_low(
"Using master bias in '%s'", master_bias_filename);
797 uves_msg_low(
"No master bias in SOF. Bias subtraction not done");
802 uves_free_image(&master_dark);
803 uves_free_propertylist(&master_dark_header);
804 if (cpl_frameset_find(frames, UVES_MASTER_DARK(chip)) != NULL)
806 check( uves_load_mdark(frames, chip_name,
807 &master_dark_filename,
809 &master_dark_header, chip),
810 "Error loading master dark");
812 uves_msg_low(
"Using master dark in '%s'", master_dark_filename);
816 uves_msg_low(
"No master dark in SOF. Dark subtraction not done");
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,
826 chip, NULL),
"Error loading master flat");
828 uves_msg_low(
"Using master flat in '%s'", master_flat_filename);
832 uves_free_table (&ordertable);
833 uves_free_propertylist(&ordertable_header);
835 uves_free_table (&traces);
837 check( uves_load_ordertable(frames,
840 &ordertable_filename,
844 &order_locations, &traces,
848 "Could not load order table");
849 uves_msg_low(
"Using order table in '%s'", ordertable_filename);
853 for(tracerow = 0; tracerow < cpl_table_get_nrow(traces); tracerow++)
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);
861 if (trace_enabled != 0)
864 if (cpl_table_get_nrow(traces) > 1) {
865 uves_msg(
"Processing trace %d", trace_number);
872 for (window = 1; window <= 3; window ++)
874 uves_free_table_const ( &(linetable[window-1]) );
875 uves_free_propertylist_const( &(linetable_header[window-1]) );
877 check( uves_load_linetable_const(
882 cpl_table_get_column_min(ordertable,
"Order"),
883 cpl_table_get_column_max(ordertable,
"Order"),
885 &(linetable [window-1]),
886 &(linetable_header [window-1]),
887 &(dispersion_relation[window-1]),
892 "Could not load line table, window #%d", window);
895 uves_msg_low(
"Using line tables in '%s'", linetable_filename);
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);
911 check( uves_response_process_chip(
912 raw_image[raw_index],
913 raw_header[raw_index],
914 rotated_header[raw_index],
945 "Response computation failed");
956 check( uves_efficiency_qclog(blaze_efficiency,
957 raw_header[raw_index],
961 "Error generating efficiency QC log");
965 qclog_optext[0] = cpl_table_new(0);
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);
976 raw_header[raw_index],
977 raw_image[raw_index],
980 "Error generating extraction QC log");
985 cpl_free(product_filename);
986 check( product_filename = uves_response_curve_filename(chip),
987 "Error getting filename");
990 check( uves_frameset_insert(
993 CPL_FRAME_GROUP_PRODUCT,
994 CPL_FRAME_TYPE_IMAGE,
995 CPL_FRAME_LEVEL_INTERMEDIATE,
997 UVES_INSTR_RESPONSE(chip),
998 raw_header[raw_index],
1002 make_str(UVES_RESPONSE_ID),
1003 PACKAGE
"/" PACKAGE_VERSION,
1007 "Could not add response curve '%s' (%s) to frameset",
1008 product_filename, UVES_INSTR_RESPONSE(chip));
1010 uves_msg(
"Response curve '%s' (%s) added to frameset",
1011 product_filename, UVES_INSTR_RESPONSE(chip));
1014 cpl_free(product_filename);
1015 check( product_filename =
1016 uves_response_curve_2d_filename(chip),
1017 "Error getting filename");
1019 check( uves_frameset_insert(
1022 CPL_FRAME_GROUP_PRODUCT,
1023 CPL_FRAME_TYPE_IMAGE,
1024 CPL_FRAME_LEVEL_INTERMEDIATE,
1026 UVES_WCALIB_FF_RESPONSE(chip),
1027 raw_header[raw_index],
1031 make_str(UVES_RESPONSE_ID),
1032 PACKAGE
"/" PACKAGE_VERSION,
1036 "Could not add response curve (2d) "
1037 "'%s' (%s) to frameset",
1038 product_filename, UVES_WCALIB_FF_RESPONSE(chip));
1040 uves_msg(
"Response curve (2d) '%s' (%s) added to frameset",
1041 product_filename, UVES_WCALIB_FF_RESPONSE(chip));
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);
1052 check( product_filename = uves_response_red_standard_filename(chip),
1053 "Error getting filename");
1054 prod_catg=UVES_RED_STD(chip);
1058 check( uves_frameset_insert(frames,
1060 CPL_FRAME_GROUP_PRODUCT,
1061 CPL_FRAME_TYPE_IMAGE,
1062 CPL_FRAME_LEVEL_INTERMEDIATE,
1065 raw_header[raw_index],
1069 make_str(UVES_RESPONSE_ID),
1070 PACKAGE
"/" PACKAGE_VERSION,
1074 "Could not add reduced spectrum '%s' (%s) to frameset",
1075 product_filename, UVES_RED_STD(chip));
1077 uves_msg(
"Reduced spectrum '%s' (%s) added to frameset",
1078 product_filename, UVES_RED_STD(chip));
1083 uves_free_propertylist(&efficiency_header);
1086 cpl_free(product_filename);
1087 check( product_filename =
1088 uves_response_efficiency_filename(chip),
1089 "Error getting filename");
1091 sprintf(extname,
"EFFICIENCY");
1093 check( uves_frameset_insert(
1096 CPL_FRAME_GROUP_PRODUCT,
1097 CPL_FRAME_TYPE_TABLE,
1098 CPL_FRAME_LEVEL_INTERMEDIATE,
1100 UVES_EFFICIENCY_TABLE(chip),
1101 raw_header[raw_index],
1105 make_str(UVES_RESPONSE_ID),
1106 PACKAGE
"/" PACKAGE_VERSION,
1108 starttime,
true, 0),
1109 "Could not add background image '%s' (%s) to frameset",
1110 product_filename, UVES_EFFICIENCY_TABLE(chip));
1112 uves_msg(
"Efficiency table '%s' (%s) added to frameset",
1113 product_filename, UVES_EFFICIENCY_TABLE(chip));
1117 cpl_free(product_filename);
1118 check( product_filename =
1119 uves_response_bkg_standard_filename(chip),
1120 "Error getting filename");
1122 check( uves_frameset_insert(frames,
1124 CPL_FRAME_GROUP_PRODUCT,
1125 CPL_FRAME_TYPE_IMAGE,
1126 CPL_FRAME_LEVEL_INTERMEDIATE,
1129 raw_header[raw_index],
1130 rotated_header[raw_index],
1133 make_str(UVES_RESPONSE_ID),
1134 PACKAGE
"/" PACKAGE_VERSION, NULL,
1136 CPL_STATS_MIN | CPL_STATS_MAX),
1137 "Could not add background image '%s' (%s) to frameset",
1138 product_filename, UVES_BKG_STD(chip));
1140 uves_msg(
"Background image '%s' (%s) added to frameset",
1141 product_filename, UVES_BKG_STD(chip));
1145 cpl_free(product_filename);
1146 check( product_filename =
1147 uves_order_extract_qc_standard_filename(chip),
1148 "Error getting filename");
1150 sprintf(extname,
"QC_INFO");
1153 check( uves_frameset_insert(frames,
1155 CPL_FRAME_GROUP_PRODUCT,
1156 CPL_FRAME_TYPE_TABLE,
1157 CPL_FRAME_LEVEL_INTERMEDIATE,
1159 UVES_ORDER_EXTRACT_QC(chip),
1160 raw_header[raw_index],
1161 rotated_header[raw_index],
1164 make_str(UVES_RESPONSE_ID),
1165 PACKAGE
"/" PACKAGE_VERSION, NULL,
1168 "Could not add extraction quality table '%s' (%s) to frameset",
1169 product_filename, UVES_ORDER_EXTRACT_QC(chip));
1171 uves_msg(
"Extraction quality table '%s' (%s) added to frameset",
1172 product_filename, UVES_ORDER_EXTRACT_QC(chip));
1179 uves_msg_low(
"Skipping trace number %d", trace_number);
1185 if(strcmp(PROCESS_CHIP,
"REDL") == 0) {
1189 uves_free_propertylist(&table_header);
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]);
1205 uves_free_image(&master_bias);
1206 uves_free_propertylist(&master_bias_header);
1208 uves_free_image(&master_dark);
1209 uves_free_propertylist(&master_dark_header);
1211 uves_free_image(&master_flat);
1212 uves_free_propertylist(&master_flat_header);
1214 uves_free_table(&ordertable);
1215 uves_free_propertylist(&ordertable_header);
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]) );
1228 uves_free_table( &flux_table );
1229 uves_free_table( &atm_extinction );
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);
1247 uves_free_table(&catalogue_flux);
1248 cpl_free(product_filename);
1249 cpl_free(ref_obj_name);
1263 static void uves_efficiency_qclog(cpl_table* table,
1265 enum uves_chip chip,
1267 const char *ref_obj_name)
1273 "Error determining FITS header format");
1277 "Efficiency-Test-Results",
1284 "Optical path used.",
1290 "Instrument mode used.",
1296 "Cross disperser ID",
1307 "Detector chip name",
1314 "Grating central wavelength [nm] (hs).",
1321 "Conversion from ADUs to electrons",
1329 "user defined subintegration time",
1348 for(i = 0; i < cpl_table_get_nrow(table); i++)
1352 int order = cpl_table_get_int(table,
"Order", i, NULL);
1354 sprintf(key_name,
"QC BLAZEFF%d", order);
1358 cpl_table_get_double(table,
"Eff", i, NULL),
1367 sprintf(key_name,
"QC BLAZWLEN%d", order);
1370 cpl_table_get_double(table,
"Wave", i, NULL)/10.,
1377 for(i = 0; i < cpl_table_get_nrow(info_tbl); i++)
1381 int order = cpl_table_get_int(info_tbl,
"Order", i, NULL);
1383 sprintf(key_name,
"QC ORDER NUM%d", order);
1395 sprintf(key_name,
"QC OBJ SN%d", order);
1398 cpl_table_get_double(info_tbl,
"S/N",i,NULL),
double uves_pfits_get_uit(const uves_propertylist *plist)
Find out the user integration time.
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.
cpl_error_code uves_pfits_set_cdelt1(uves_propertylist *plist, double cdelt1)
Write the cdelt1 keyword.
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.
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.
cpl_error_code uves_pfits_set_crval1(uves_propertylist *plist, double crval1)
Write the crval1 keyword.
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
double uves_pfits_get_gratwlen(const uves_propertylist *plist, enum uves_chip chip)
find out the central wavelength
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.
const char * uves_pfits_get_chip_name(const uves_propertylist *plist, enum uves_chip chip)
Find out the chip name.
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.
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.
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
int uves_pfits_get_biny(const uves_propertylist *plist)
Find out the y binning factor.
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.
const char * uves_remove_string_prefix(const char *s, const char *prefix)
Remove named prefix from string.
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
const char * uves_pfits_get_insmode(const uves_propertylist *plist)
find out the chip name value
const char * uves_pfits_get_inspath(const uves_propertylist *plist)
find out the chip name value
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.
enum uves_chip uves_chip_get_first(bool blue)
Get first chip for blue or red arm.
merge_method uves_get_merge_method(const cpl_parameterlist *parameters, const char *context, const char *subcontext)
Read merging method from parameter list.
cpl_error_code uves_pfits_set_extname(uves_propertylist *plist, const char *extname)
Write the EXTNAME keyword.
double uves_pfits_get_airmass_end(const uves_propertylist *plist)
Find out the end airmass.
#define uves_error_reset()
#define uves_msg_low(...)
Print a message on a lower message level.
bool uves_format_is_new(const uves_propertylist *plist)
Find out FITS header format.
enum uves_chip uves_chip_get_next(enum uves_chip chip)
Get next chip.
#define uves_msg_debug(...)
Print a debug message.
const char * uves_chip_tostring_upper(enum uves_chip chip)
Convert to string.
double uves_pfits_get_cdelt1(const uves_propertylist *plist)
Find out the cdelt1.
double uves_pfits_get_crval1(const uves_propertylist *plist)
Find out the crval1.
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.
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.
void uves_qclog_add_common_wave(const uves_propertylist *raw_header, enum uves_chip chip, cpl_table *qclog)
Write common QC parameters.
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.
cpl_table * uves_qclog_init(const uves_propertylist *raw_header, enum uves_chip chip)
Init QC-LOG table.
const char * uves_pfits_get_chipid(const uves_propertylist *plist, enum uves_chip chip)
Find out the chip ID.
double uves_pfits_get_airmass_start(const uves_propertylist *plist)
Find out the start airmass.
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.
double uves_pfits_get_conad(const uves_propertylist *plist, enum uves_chip chip)
Find out the conad.