50static int gravity_badpix(cpl_frameset *,
const cpl_parameterlist *);
56static char gravity_badpix_description[] =
"The recipe creates a BAD calibration map from raw DARKs and raw FLATs observations. Since it is not associated with the calibration of the instrumental transmission, more specific darks or flats can be used. Such as very long darks, fore better statistic; and/or defocused flats to illuminate more pixels. The create BAD map can then be used as an input for further calibration (P2VM) and observations.\n"
58 "* Load input files\n"
59 "* Compute badpixel from dark rms, dark median, and flat value\n"
60 "* Save the product)\n"
85 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
86 cpl_plugin * plugin = &recipe->interface;
88 if (cpl_plugin_init(plugin,
91 CPL_PLUGIN_TYPE_RECIPE,
95 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
101 cpl_msg_error(cpl_func,
"Plugin initialization failed");
102 (void)cpl_error_set_where(cpl_func);
106 if (cpl_pluginlist_append(list, plugin)) {
107 cpl_msg_error(cpl_func,
"Error adding plugin to list");
108 (void)cpl_error_set_where(cpl_func);
130 if (cpl_error_get_code() != CPL_ERROR_NONE) {
131 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
132 cpl_func, __LINE__, cpl_error_get_where());
133 return (
int)cpl_error_get_code();
136 if (plugin == NULL) {
137 cpl_msg_error(cpl_func,
"Null plugin");
138 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
142 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
143 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
144 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
148 recipe = (cpl_recipe *)plugin;
151 recipe->parameters = cpl_parameterlist_new();
152 if (recipe->parameters == NULL) {
153 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
154 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
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_badpix(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;
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);
270 const cpl_parameterlist * parlist)
272 cpl_frameset * dark_frameset=NULL, * flat_frameset=NULL, * used_frameset=NULL;
274 cpl_frame * frame=NULL;
277 gravi_data ** raw_data=NULL, * badpix_map=NULL;
279 int nb_frame_gain = 0;
289 used_frameset = cpl_frameset_new ();
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);
334 nb_frame_gain = cpl_frameset_get_size (flat_frameset);
335 raw_data = cpl_calloc (nb_frame_gain,
sizeof(
gravi_data *));
338 for (
int i = 0; i < nb_frame_gain; i++) {
339 frame = cpl_frameset_get_position (flat_frameset, i);
349 cpl_msg_info (cpl_func,
" ***** Compute BAD pixel map ***** ");
351 nb_frame_gain, parlist);
353 CPLCHECK_CLEAN(
"Cannot compute the BAD pixel from DARK and FLATs");
359 frame = cpl_frameset_get_position (dark_frameset, 0);
361 NULL, frame,
"gravity_badpix",
370 FREE (cpl_frameset_delete, dark_frameset);
374 FREE (cpl_frameset_delete, flat_frameset);
375 FREE (cpl_frameset_delete, used_frameset);
382 return (
int)cpl_error_get_code();
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define GRAVI_RECIPE_OUTPUT
#define GRAVI_RECIPE_FLOW
#define GRAVI_RECIPE_INPUT
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define CPLCHECK_INT(msg)
#define CPLCHECK_CLEAN(msg)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define gravi_msg_function_start(flag)
#define FREELOOP(function, variable, n)
static char gravity_badpix_description[]
static char gravity_badpix_short[]
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int gravity_badpix_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int gravity_badpix(cpl_frameset *, const cpl_parameterlist *)
Compute the DARK, BAD, FLAT, WAVE, P2VM from a list of calibration set.
static int gravity_badpix_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int gravity_badpix_create(cpl_plugin *)
Setup the recipe options
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.
gravi_data * gravi_compute_badpix(gravi_data *dark_map, gravi_data **flats_data, int nflat, const cpl_parameterlist *params)
Identify the bad pixels in the DARK map and create the BAD map.
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_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.
cpl_parameter * gravi_parameter_add_static_name(cpl_parameterlist *self)
cpl_frameset * gravi_frameset_extract_flat_data(cpl_frameset *frameset)
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_parameter * gravi_parameter_add_badpix(cpl_parameterlist *self)
Add badpix parameters to the input parameter list.
void gravity_print_banner(void)
cpl_frameset * gravi_frameset_extract_dark_data(cpl_frameset *frameset)
Extract DARK_RAW frame from the input frameset.
const char * gravi_get_license(void)
Get the pipeline copyright and license.