00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032 #include <fors_img_sky_flat_impl.h>
00033
00034 #include <fors_stack.h>
00035 #include <fors_dfs.h>
00036 #include <fors_qc.h>
00037 #include <fors_utils.h>
00038
00039 #include <cpl.h>
00040
00047 const char *const fors_img_sky_flat_name = "fors_img_sky_flat";
00048 const char *const fors_img_sky_flat_description_short = "Compute master img_sky_flat frame";
00049 const char *const fors_img_sky_flat_author = "Jonas M. Larsen";
00050 const char *const fors_img_sky_flat_email = PACKAGE_BUGREPORT;
00051 const char *const fors_img_sky_flat_description =
00052 "Input files:\n"
00053 " DO category: Type: Explanation: Number:\n"
00054 " SKY_FLAT_IMG Raw Jittered sky flat fields 1+\n"
00055 " MASTER_BIAS FITS image Master bias 1\n"
00056 "\n"
00057 "Output files:\n"
00058 " DO category: Data type: Explanation:\n"
00059 " MASTER_SKY_FLAT_IMG FITS image Master sky flat field\n";
00065 void fors_img_sky_flat_define_parameters(cpl_parameterlist *parameters)
00066 {
00067 const char *context = cpl_sprintf("fors.%s", fors_img_sky_flat_name);
00068
00069 fors_stack_define_parameters(parameters, context, "median");
00070
00071 cpl_free((void *)context);
00072
00073 return;
00074 }
00075
00076 #undef cleanup
00077 #define cleanup \
00078 do { \
00079 cpl_frameset_delete(sflat_frames); \
00080 cpl_frameset_delete(master_bias_frame); \
00081 fors_stack_method_delete(&sm); \
00082 cpl_free((void *)context); \
00083 fors_image_delete_const(&master_bias); \
00084 fors_image_delete(&master_sky_flat); \
00085 fors_image_list_delete(&sflats, fors_image_delete); \
00086 cpl_propertylist_delete(qc); \
00087 fors_setting_delete(&setting); \
00088 } while (0)
00089
00098 void fors_img_sky_flat(cpl_frameset *frames, const cpl_parameterlist *parameters)
00099 {
00100
00101 cpl_frameset *sflat_frames = NULL;
00102 fors_image_list *sflats = NULL;
00103
00104
00105 cpl_frameset *master_bias_frame = NULL;
00106 const fors_image *master_bias = NULL;
00107
00108
00109 fors_image *master_sky_flat = NULL;
00110 cpl_propertylist *qc = cpl_propertylist_new();
00111 double saturation;
00112
00113
00114 stack_method *sm = NULL;
00115
00116
00117 const char *context = cpl_sprintf("fors.%s", fors_img_sky_flat_name);
00118 fors_setting *setting = NULL;
00119
00120
00121 sm = fors_stack_method_new(parameters, context);
00122 assure( !cpl_error_get_code(), return, "Could not get stacking method");
00123
00124
00125 sflat_frames = fors_frameset_extract(frames, SKY_FLAT_IMG);
00126 assure( cpl_frameset_get_size(sflat_frames) > 0, return,
00127 "No %s provided", SKY_FLAT_IMG);
00128
00129
00130 master_bias_frame = fors_frameset_extract(frames, MASTER_BIAS);
00131 assure( cpl_frameset_get_size(master_bias_frame) == 1, return,
00132 "One %s required. %d found",
00133 MASTER_BIAS, cpl_frameset_get_size(master_bias_frame));
00134
00135
00136 setting = fors_setting_new(cpl_frameset_get_first_const(sflat_frames));
00137 assure( !cpl_error_get_code(), return, "Could not get instrument setting" );
00138
00139 master_bias = fors_image_load(cpl_frameset_get_first(master_bias_frame),
00140 NULL, setting, NULL);
00141 assure( !cpl_error_get_code(), return,
00142 "Could not load master bias");
00143
00144
00145 sflats = fors_image_load_list(sflat_frames, master_bias, setting, &saturation);
00146 assure( !cpl_error_get_code(), return, "Could not load sky flat images");
00147
00148
00149
00150
00151
00152
00153
00154 {
00155 fors_image *image;
00156
00157 for (image = fors_image_list_first(sflats);
00158 image != NULL;
00159 image = fors_image_list_next(sflats)) {
00160
00161 fors_image_divide_scalar(image, fors_image_get_median(image, NULL), -1.0);
00162
00163 assure( !cpl_error_get_code(), return, "Raw sky flat normalization failed");
00164 }
00165 }
00166
00167
00168
00169 master_sky_flat = fors_stack(sflats, sm);
00170 assure( !cpl_error_get_code(), return, "Sky flat stacking failed");
00171
00172
00173 fors_qc_start_group(qc, fors_qc_dic_version, setting->instrument);
00174
00175 fors_qc_write_group_heading(cpl_frameset_get_first(sflat_frames),
00176 MASTER_SKY_FLAT_IMG,
00177 setting->instrument);
00178 assure( !cpl_error_get_code(), return, "Could not write %s QC parameters",
00179 MASTER_SKY_FLAT_IMG);
00180
00181 fors_qc_write_qc_double(qc,
00182 saturation,
00183 "QC.OVEREXPO",
00184 "%",
00185 "Percentage of overexposed pixels",
00186 setting->instrument);
00187 fors_qc_end_group();
00188
00189
00190 fors_dfs_save_image(frames, master_sky_flat, MASTER_SKY_FLAT_IMG,
00191 qc, parameters, fors_img_sky_flat_name,
00192 cpl_frameset_get_first(sflat_frames));
00193 assure( !cpl_error_get_code(), return, "Saving %s failed",
00194 MASTER_SKY_FLAT_IMG);
00195
00196 cleanup;
00197 return;
00198 }
00199
00200