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, the FT and the ACQ detectors. The SC detector is first debiased using the biaspixels, before computing the dark mean and rms. For detectors, the mean dark level of each pixel and the stdev of each pixel are saved in the output product.\n" 65 "* Loop on input dark files and concatenate them\n" 66 "* Compute the median and rms of these concatenated files\n" 67 "* Save the product (FT, SC, ACQ camera into same product)\n" 68 GRAVI_RECIPE_INPUT
"\n" 69 GRAVI_DARK_RAW
" : raw dark, all shutters closed (DPR.TYPE=DARK)\n" 70 GRAVI_RECIPE_OUTPUT
"\n" 71 GRAVI_DARK_MAP
" : dark calibration\n" 89 int cpl_plugin_get_info(cpl_pluginlist * list)
91 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
92 cpl_plugin * plugin = &recipe->interface;
94 if (cpl_plugin_init(plugin,
97 CPL_PLUGIN_TYPE_RECIPE,
100 gravity_dark_description,
101 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
106 gravity_dark_destroy)) {
107 cpl_msg_error(cpl_func,
"Plugin initialization failed");
108 (void)cpl_error_set_where(cpl_func);
112 if (cpl_pluginlist_append(list, plugin)) {
113 cpl_msg_error(cpl_func,
"Error adding plugin to list");
114 (void)cpl_error_set_where(cpl_func);
130 static int gravity_dark_create(cpl_plugin * plugin)
136 if (cpl_error_get_code() != CPL_ERROR_NONE) {
137 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
138 cpl_func, __LINE__, cpl_error_get_where());
139 return (
int)cpl_error_get_code();
142 if (plugin == NULL) {
143 cpl_msg_error(cpl_func,
"Null plugin");
144 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
148 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
149 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
150 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
154 recipe = (cpl_recipe *)plugin;
157 recipe->parameters = cpl_parameterlist_new();
158 if (recipe->parameters == NULL) {
159 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
160 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
164 gravi_parameter_add_static_name (recipe->parameters);
167 gravi_parameter_add_biasmethod (recipe->parameters);
179 static int gravity_dark_exec(cpl_plugin * plugin)
184 cpl_errorstate initial_errorstate = cpl_errorstate_get();
187 if (cpl_error_get_code() != CPL_ERROR_NONE) {
188 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
189 cpl_func, __LINE__, cpl_error_get_where());
190 return (
int)cpl_error_get_code();
193 if (plugin == NULL) {
194 cpl_msg_error(cpl_func,
"Null plugin");
195 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
199 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
200 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
201 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
205 recipe = (cpl_recipe *)plugin;
208 if (recipe->parameters == NULL) {
209 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
210 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
212 if (recipe->frames == NULL) {
213 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
214 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
218 recipe_status = gravity_dark(recipe->frames, recipe->parameters);
221 if (cpl_dfs_update_product_header(recipe->frames)) {
222 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
225 if (!cpl_errorstate_is_equal(initial_errorstate)) {
228 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
231 return recipe_status;
241 static int gravity_dark_destroy(cpl_plugin * plugin)
245 if (plugin == NULL) {
246 cpl_msg_error(cpl_func,
"Null plugin");
247 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
251 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
252 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
253 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
257 recipe = (cpl_recipe *)plugin;
259 cpl_parameterlist_delete(recipe->parameters);
273 static int gravity_dark (cpl_frameset * frameset,
274 const cpl_parameterlist * parlist)
276 cpl_frameset * dark_frameset = NULL, * used_frameset = NULL;
277 cpl_frame * frame = NULL;
278 gravi_data * raw_dark = NULL, * reduced_dark = NULL;
283 gravity_print_banner ();
284 cpl_msg_set_time_on();
285 cpl_msg_set_component_on();
286 gravi_msg_function_start(1);
295 if (cpl_frameset_is_empty (dark_frameset)) {
296 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
297 "No DARK_RAW file on the frameset") ;
302 nb_frame = cpl_frameset_get_size (dark_frameset);
303 used_frameset = cpl_frameset_new ();
305 for (comp = 0; comp < nb_frame; comp++){
306 gravi_data * data_tmp;
307 cpl_frame * frame_tmp;
310 frame_tmp = cpl_frameset_get_position (dark_frameset, comp);
324 raw_dark = data_tmp; data_tmp = NULL;
334 CPLCHECK_CLEAN (
"Cannot load all DARK into a single data");
342 CPLCHECK_CLEAN (
"Could not compute the DARK map");
346 used_frameset, frame,
"gravity_dark",
347 NULL, GRAVI_DARK_MAP);
349 CPLCHECK_CLEAN (
"Could not save the DARK map");
356 cpl_msg_info (cpl_func,
"Memory cleanup");
360 FREE (cpl_frameset_delete, dark_frameset);
361 FREE (cpl_frameset_delete, used_frameset);
363 gravi_msg_function_exit(1);
364 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.
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.
cpl_error_code gravi_data_erase(gravi_data *self, const char *extname)
Erase an extension by its EXTNAME.
cpl_error_code gravi_data_append(gravi_data *first, const gravi_data *second, int force)
Append a gravi_data into another existing one.
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.