41 #include "gravi_utils.h" 42 #include "gravi_pfits.h" 43 #include "gravi_dfs.h" 44 #include "gravi_calib.h" 46 #include "gravi_data.h" 52 static int gravity_dark_create(cpl_plugin *);
53 static int gravity_dark_exec(cpl_plugin *);
54 static int gravity_dark_destroy(cpl_plugin *);
55 static int gravity_dark(cpl_frameset *,
const cpl_parameterlist *);
61 static char gravity_dark_short[] =
"Calibrate the detector noise and background level.";
62 static char gravity_dark_description[] =
63 "This recipe computes the DARK calibration for the SC and the FT detector. The SC detector is first debias using the biaspixels, before computing the dark mean and rms. For both detector, the mean dark level of each pixel and the stdev of each pixel are saved in the output product.\n" 64 GRAVI_RECIPE_INPUT
"\n" 65 GRAVI_DARK_RAW
" : raw dark, all shutters closed (DPR.TYPE=DARK)\n" 66 GRAVI_RECIPE_OUTPUT
"\n" 67 GRAVI_DARK_MAP
" : dark calibration\n" 85 int cpl_plugin_get_info(cpl_pluginlist * list)
87 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
88 cpl_plugin * plugin = &recipe->interface;
90 if (cpl_plugin_init(plugin,
93 CPL_PLUGIN_TYPE_RECIPE,
96 gravity_dark_description,
97 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
102 gravity_dark_destroy)) {
103 cpl_msg_error(cpl_func,
"Plugin initialization failed");
104 (void)cpl_error_set_where(cpl_func);
108 if (cpl_pluginlist_append(list, plugin)) {
109 cpl_msg_error(cpl_func,
"Error adding plugin to list");
110 (void)cpl_error_set_where(cpl_func);
126 static int gravity_dark_create(cpl_plugin * plugin)
132 if (cpl_error_get_code() != CPL_ERROR_NONE) {
133 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
134 cpl_func, __LINE__, cpl_error_get_where());
135 return (
int)cpl_error_get_code();
138 if (plugin == NULL) {
139 cpl_msg_error(cpl_func,
"Null plugin");
140 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
144 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
145 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
146 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
150 recipe = (cpl_recipe *)plugin;
153 recipe->parameters = cpl_parameterlist_new();
154 if (recipe->parameters == NULL) {
155 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
156 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
160 gravi_parameter_add_static_name (recipe->parameters);
163 gravi_parameter_add_biasmethod (recipe->parameters);
175 static int gravity_dark_exec(cpl_plugin * plugin)
180 cpl_errorstate initial_errorstate = cpl_errorstate_get();
183 if (cpl_error_get_code() != CPL_ERROR_NONE) {
184 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
185 cpl_func, __LINE__, cpl_error_get_where());
186 return (
int)cpl_error_get_code();
189 if (plugin == NULL) {
190 cpl_msg_error(cpl_func,
"Null plugin");
191 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
195 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
196 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
197 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
201 recipe = (cpl_recipe *)plugin;
204 if (recipe->parameters == NULL) {
205 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
206 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
208 if (recipe->frames == NULL) {
209 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
210 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
214 recipe_status = gravity_dark(recipe->frames, recipe->parameters);
217 if (cpl_dfs_update_product_header(recipe->frames)) {
218 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
221 if (!cpl_errorstate_is_equal(initial_errorstate)) {
224 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
227 return recipe_status;
237 static int gravity_dark_destroy(cpl_plugin * plugin)
241 if (plugin == NULL) {
242 cpl_msg_error(cpl_func,
"Null plugin");
243 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
247 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
248 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
249 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
253 recipe = (cpl_recipe *)plugin;
255 cpl_parameterlist_delete(recipe->parameters);
269 static int gravity_dark (cpl_frameset * frameset,
270 const cpl_parameterlist * parlist)
272 cpl_frameset * dark_frameset = NULL, * used_frameset = NULL;
273 cpl_frame * frame = NULL;
274 gravi_data * raw_dark = NULL, * reduced_dark = NULL;
279 gravity_print_banner ();
280 cpl_msg_set_time_on();
281 cpl_msg_set_component_on();
282 gravi_msg_function_start(1);
285 cpl_ensure_code (gravi_dfs_set_groups (frameset) == CPL_ERROR_NONE, cpl_error_get_code());
288 dark_frameset = gravi_frameset_extract_dark_data (frameset);
291 if (cpl_frameset_is_empty (dark_frameset)) {
292 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
293 "No DARK_RAW file on the frameset") ;
298 nb_frame = cpl_frameset_get_size (dark_frameset);
299 used_frameset = cpl_frameset_new ();
301 for (comp = 0; comp < nb_frame; comp++){
302 gravi_data * data_tmp;
303 cpl_frame * frame_tmp;
306 frame_tmp = cpl_frameset_get_position (dark_frameset, comp);
307 data_tmp = gravi_data_load_rawframe (frame_tmp, used_frameset);
308 gravi_data_detector_cleanup (data_tmp, parlist);
311 gravi_data_erase (data_tmp, GRAVI_METROLOGY_EXT);
312 gravi_data_erase (data_tmp, GRAVI_OPDC_EXT);
313 gravi_data_erase (data_tmp, GRAVI_FDDL_EXT);
320 raw_dark = data_tmp; data_tmp = NULL;
325 gravi_data_append (raw_dark, data_tmp, force);
326 FREE (gravi_data_delete, data_tmp);
329 CPLCHECK_CLEAN (
"Cannot load all DARK into a single data");
335 reduced_dark = gravi_compute_dark (raw_dark);
336 FREE (gravi_data_delete, raw_dark);
338 CPLCHECK_CLEAN (
"Could not compute the DARK map");
341 gravi_data_save_new (reduced_dark, frameset, NULL, parlist,
342 used_frameset, frame,
"gravity_dark",
343 NULL, GRAVI_DARK_MAP);
345 CPLCHECK_CLEAN (
"Could not save the DARK map");
352 cpl_msg_info (cpl_func,
"Memory cleanup");
354 FREE (gravi_data_delete, reduced_dark);
355 FREE (gravi_data_delete, raw_dark);
356 FREE (cpl_frameset_delete, dark_frameset);
357 FREE (cpl_frameset_delete, used_frameset);
359 gravi_msg_function_exit(1);
360 return (
int)cpl_error_get_code();