34 #include "gravi_data.h" 35 #include "gravi_pfits.h" 36 #include "gravi_dfs.h" 38 #include "gravi_utils.h" 40 #include "gravi_calib.h" 47 static int gravity_biasmask_create(cpl_plugin *);
48 static int gravity_biasmask_exec(cpl_plugin *);
49 static int gravity_biasmask_destroy(cpl_plugin *);
50 static int gravity_biasmask(cpl_frameset *,
const cpl_parameterlist *);
56 static char gravity_biasmask_short[] = GRAVI_UNOFFERED
"Determine which pixels can be used to measure the bias of SC detector.";
57 static char gravity_biasmask_description[] = GRAVI_UNOFFERED
"The recipe creates a binary mask (BIASPIX) indentifying which pixels of the SC detector are not illuminated, and thus could be used as bias-pixels in further processing. The idea would be to input such a mask, as static calibration, in all reductions. However this is not yet implemented, nor demonstrated as necessary.\n" 59 "* Load the input files\n" 60 "* Identify the mask\n" 62 GRAVI_RECIPE_INPUT
"\n" 63 GRAVI_DARK_RAW
" : raw dark, all shutters closed (DPR.TYPE=DARK)\n" 64 GRAVI_FLAT_RAW
" x4 : raw flats, one sutter open (DPR.TYPE=FLAT)\n" 65 GRAVI_RECIPE_OUTPUT
"\n" 66 GRAVI_BIASMASK_MAP
" : biaspixel mask calibration \n" 84 int cpl_plugin_get_info(cpl_pluginlist * list)
86 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
87 cpl_plugin * plugin = &recipe->interface;
89 if (cpl_plugin_init(plugin,
92 CPL_PLUGIN_TYPE_RECIPE,
94 gravity_biasmask_short,
95 gravity_biasmask_description,
96 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
99 gravity_biasmask_create,
100 gravity_biasmask_exec,
101 gravity_biasmask_destroy)) {
102 cpl_msg_error(cpl_func,
"Plugin initialization failed");
103 (void)cpl_error_set_where(cpl_func);
107 if (cpl_pluginlist_append(list, plugin)) {
108 cpl_msg_error(cpl_func,
"Error adding plugin to list");
109 (void)cpl_error_set_where(cpl_func);
125 static int gravity_biasmask_create(cpl_plugin * plugin)
131 if (cpl_error_get_code() != CPL_ERROR_NONE) {
132 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
133 cpl_func, __LINE__, cpl_error_get_where());
134 return (
int)cpl_error_get_code();
137 if (plugin == NULL) {
138 cpl_msg_error(cpl_func,
"Null plugin");
139 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
143 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
144 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
145 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
149 recipe = (cpl_recipe *)plugin;
152 recipe->parameters = cpl_parameterlist_new();
153 if (recipe->parameters == NULL) {
154 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
155 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
161 gravi_parameter_add_static_name (recipe->parameters);
173 static int gravity_biasmask_exec(cpl_plugin * plugin)
178 cpl_errorstate initial_errorstate = cpl_errorstate_get();
181 if (cpl_error_get_code() != CPL_ERROR_NONE) {
182 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
183 cpl_func, __LINE__, cpl_error_get_where());
184 return (
int)cpl_error_get_code();
187 if (plugin == NULL) {
188 cpl_msg_error(cpl_func,
"Null plugin");
189 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
193 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
194 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
195 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
199 recipe = (cpl_recipe *)plugin;
202 if (recipe->parameters == NULL) {
203 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
204 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
206 if (recipe->frames == NULL) {
207 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
208 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
212 recipe_status = gravity_biasmask(recipe->frames, recipe->parameters);
215 if (cpl_dfs_update_product_header(recipe->frames)) {
216 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
219 if (!cpl_errorstate_is_equal(initial_errorstate)) {
222 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
225 return recipe_status;
235 static int gravity_biasmask_destroy(cpl_plugin * plugin)
239 if (plugin == NULL) {
240 cpl_msg_error(cpl_func,
"Null plugin");
241 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
245 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
246 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
247 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
251 recipe = (cpl_recipe *)plugin;
253 cpl_parameterlist_delete(recipe->parameters);
267 static int gravity_biasmask(cpl_frameset * frameset,
268 const cpl_parameterlist * parlist)
270 cpl_frameset * dark_frameset=NULL, * flat_frameset=NULL, * used_frameset=NULL;
272 cpl_frame * frame=NULL;
274 gravi_data * data = NULL, * dark_map=NULL;
275 gravi_data ** raw_data=NULL, * biasmask_map=NULL;
277 int nb_frame_gain = 0;
280 gravity_print_banner ();
281 cpl_msg_set_time_on();
282 cpl_msg_set_component_on();
283 gravi_msg_function_start(1);
289 used_frameset = cpl_frameset_new ();
295 flat_frameset = gravi_frameset_extract_flat_data (frameset);
299 if ( cpl_frameset_is_empty (dark_frameset) ||
300 cpl_frameset_get_size (dark_frameset) != 1 ||
301 cpl_frameset_is_empty (flat_frameset) ||
302 cpl_frameset_get_size (flat_frameset) != 4 ) {
303 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
304 "Need 1 DARK_RAW and 4 FLAT_RAW");
313 cpl_msg_info (cpl_func,
" ***** Compute DARK map ***** ");
316 frame = cpl_frameset_get_position (dark_frameset, 0);
324 CPLCHECK_CLEAN (
"Cannot compute the DARK map");
330 cpl_msg_info (cpl_func,
" ***** Load FLATs ***** ");
333 nb_frame_gain = cpl_frameset_get_size (flat_frameset);
334 raw_data = cpl_calloc (nb_frame_gain,
sizeof(gravi_data *));
337 for (
int i = 0; i < nb_frame_gain; i++) {
338 frame = cpl_frameset_get_position (flat_frameset, i);
347 cpl_msg_info (cpl_func,
" ***** Compute BIAS_MASK map ***** ");
349 nb_frame_gain, parlist);
351 CPLCHECK_CLEAN(
"Cannot compute the BIAS_MASK");
357 frame = cpl_frameset_get_position (dark_frameset, 0);
359 NULL, frame,
"gravity_biasmask",
360 NULL, GRAVI_BIASMASK_MAP);
362 CPLCHECK_CLEAN (
"Could not save the BAD pixel map");
366 cpl_msg_info (cpl_func,
"Cleanup memory");
368 FREE (cpl_frameset_delete, dark_frameset);
372 FREE (cpl_frameset_delete, flat_frameset);
373 FREE (cpl_frameset_delete, used_frameset);
377 CPLCHECK_INT (
"Could not cleanup memory");
379 gravi_msg_function_exit(1);
380 return (
int)cpl_error_get_code();
cpl_frameset * gravi_frameset_extract_dark_data(cpl_frameset *frameset)
Extract DARK_RAW frame from the input frameset.
gravi_data * gravi_data_load_rawframe(cpl_frame *frame, cpl_frameset *used_frameset)
Load a RAW FITS file and create a gravi_data.
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
gravi_data * gravi_compute_biasmask(gravi_data *dark_map, gravi_data **flats_data, int nflat, const cpl_parameterlist *params)
Create BIASMASK for SC from raw FLATs and raw DARK.
const char * gravi_get_license(void)
Get the pipeline copyright and license.
cpl_error_code gravi_data_detector_cleanup(gravi_data *data, const cpl_parameterlist *parlist)
Perform self-bias correction to the SC raw data.
cpl_error_code gravi_data_save_new(gravi_data *self, cpl_frameset *allframes, const char *filename, const char *suffix, const cpl_parameterlist *parlist, cpl_frameset *usedframes, cpl_frame *frame, const char *recipe, cpl_propertylist *applist, const char *proCatg)
Save a gravi data in a CPL-complian FITS file.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.