31#include "kmo_priv_noise_map.h"
32#include "kmo_constants.h"
35static int kmo_noise_map_create(cpl_plugin *);
36static int kmo_noise_map_exec(cpl_plugin *);
37static int kmo_noise_map_destroy(cpl_plugin *);
38static int kmo_noise_map(cpl_parameterlist *, cpl_frameset *);
40static char kmo_noise_map_description[] =
41"The noise in each pixel of the input data is estimated using gain and readnoise.\n"
42"The readnoise is expected to be in the primary header (ESO DET CHIP RON), the\n"
43"gain (ESO DET CHIP GAIN) has to be in each of the subsequent headers of each \n"
44"detector frame. The output is the initial noise map of the data frame.\n"
46"-------------------------------------------------------------------------------\n"
50" category Type Explanation Required #Frames\n"
51" -------- ----- ----------- -------- -------\n"
52" <none or any> RAW raw data frame Y 1 \n"
57" category Type Explanation\n"
58" -------- ----- -----------\n"
59" NOISE_MAP F2D Initial noise map\n"
60" (6 Extensions, 3 data and 3 noise)\n"
61"-------------------------------------------------------------------------------\n"
82 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
83 cpl_plugin *plugin = &recipe->interface;
85 cpl_plugin_init(plugin,
88 CPL_PLUGIN_TYPE_RECIPE,
90 "Generate a noise map from a raw frame",
91 kmo_noise_map_description,
93 "https://support.eso.org/",
97 kmo_noise_map_destroy);
99 cpl_pluginlist_append(list, plugin);
111static int kmo_noise_map_create(cpl_plugin *plugin)
116 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
117 recipe = (cpl_recipe *)plugin;
122 recipe->parameters = cpl_parameterlist_new();
132static int kmo_noise_map_exec(cpl_plugin *plugin)
137 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
138 recipe = (cpl_recipe *)plugin;
141 return kmo_noise_map(recipe->parameters, recipe->frames);
149static int kmo_noise_map_destroy(cpl_plugin *plugin)
154 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
155 recipe = (cpl_recipe *)plugin;
158 cpl_parameterlist_delete(recipe->parameters);
180static int kmo_noise_map(cpl_parameterlist *parlist, cpl_frameset *frameset)
185 cpl_propertylist *sub_header = NULL,
187 cpl_image *img = NULL,
192 cpl_frame *frame = NULL;
193 const char *readmode = NULL;
197 kmo_init_fits_desc(&desc);
200 KMO_TRY_ASSURE((parlist != NULL) &&
202 CPL_ERROR_NULL_INPUT,
203 "Not all input data is provided!");
205 KMO_TRY_ASSURE(cpl_frameset_get_size(frameset) == 1,
206 CPL_ERROR_NULL_INPUT,
207 "A fits-file must be provided!");
209 KMO_TRY_EXIT_IF_NULL(
210 frame = kmo_dfs_get_frame(frameset,
"0"));
212 desc = kmo_identify_fits_header(
213 cpl_frame_get_filename(frame));
214 KMO_TRY_CHECK_ERROR_STATE_MSG(
"Provided fits file doesn't seem to be "
217 KMO_TRY_ASSURE((desc.fits_type == raw_fits),
218 CPL_ERROR_ILLEGAL_INPUT,
219 "Input data hasn't correct data type "
220 "(KMOSTYPE must be RAW)!");
222 KMO_TRY_ASSURE(kmo_dfs_set_groups(frameset) == 1,
223 CPL_ERROR_ILLEGAL_INPUT,
224 "Cannot identify RAW and CALIB frames!");
226 cpl_msg_info(
"",
"--- Parameter setup for kmo_noise_map ----");
228 cpl_msg_info(
"",
"No parameters to set.");
229 cpl_msg_info(
"",
"-------------------------------------------");
232 KMO_TRY_EXIT_IF_ERROR(
233 kmo_dfs_save_main_header(frameset, NOISE_MAP,
"", frame,
234 NULL, parlist, cpl_func));
238 for (i = 0; i < desc.nr_ext; i++)
241 KMO_TRY_EXIT_IF_NULL(
242 sub_header = kmo_dfs_load_sub_header(frameset,
"0", i + 1,
245 KMO_TRY_EXIT_IF_NULL(
246 img = kmo_dfs_load_image(frameset,
"0", i + 1, FALSE, TRUE, NULL));
248 KMO_TRY_EXIT_IF_ERROR(
249 kmo_update_sub_keywords(sub_header,
253 desc.sub_desc[i].device_nr));
255 KMO_TRY_EXIT_IF_ERROR(
256 kmo_dfs_save_image(img, NOISE_MAP,
"", sub_header, 0./0.));
259 KMO_TRY_EXIT_IF_NULL(
260 main_header = kmo_dfs_load_primary_header(frameset,
"0"));
262 readmode = cpl_propertylist_get_string(main_header, READMODE);
263 KMO_TRY_CHECK_ERROR_STATE(
"ESO DET READ CURNAME keyword in main "
265 gain = kmo_dfs_get_property_double(sub_header, GAIN);
266 KMO_TRY_CHECK_ERROR_STATE_MSG(
267 "GAIN-keyword in fits-header is missing!");
269 if (strcmp(readmode,
"Nondest") == 0) {
271 ndsamples = cpl_propertylist_get_int(main_header, NDSAMPLES);
272 KMO_TRY_CHECK_ERROR_STATE(
"ESO DET READ NDSAMPLES keyword in main "
275 readnoise = kmo_calc_readnoise_ndr(ndsamples);
276 KMO_TRY_CHECK_ERROR_STATE();
279 readnoise = kmo_dfs_get_property_double(sub_header, RON);
280 KMO_TRY_CHECK_ERROR_STATE_MSG(
281 "READNOISE-keyword in fits-header is missing!");
284 KMO_TRY_EXIT_IF_NULL(
285 noise_img = kmo_calc_noise_map(img, gain, readnoise));
287 cpl_propertylist_delete(main_header); main_header = NULL;
290 KMO_TRY_EXIT_IF_ERROR(
291 kmo_update_sub_keywords(sub_header,
295 desc.sub_desc[i].device_nr));
297 KMO_TRY_EXIT_IF_ERROR(
298 kmo_dfs_save_image(noise_img, NOISE_MAP,
"", sub_header, 0./0.));
300 cpl_propertylist_delete(sub_header); sub_header = NULL;
301 cpl_image_delete(img); img = NULL;
302 cpl_image_delete(noise_img); noise_img= NULL;
312 cpl_propertylist_delete(sub_header); sub_header = NULL;
313 cpl_image_delete(img); img = NULL;
314 cpl_image_delete(noise_img); noise_img = NULL;
315 kmo_free_fits_desc(&desc);
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.