32#include "moo_params.h"
33#include "moo_products.h"
43int cpl_plugin_get_info(cpl_pluginlist *list);
49static int _moons_mbias_create(cpl_plugin *plugin);
50static int _moons_mbias_exec(cpl_plugin *plugin);
51static int _moons_mbias_destroy(cpl_plugin *plugin);
53_moons_mbias(cpl_frameset *frameset,
const cpl_parameterlist *parlist);
59static const char *
const _moons_mbias_description =
61 " * RawList n>=3 files (RAW) with tag BIAS : "
63 " * [OPTIONAL] ReferenceBadPixMask 1 file (QUA) with tag BP_MAP_RP : "
64 "cosmetic bad pixel map\n"
66 " * MASTER_BIAS.fits (DET) with tag MASTER_BIAS : "
67 "the master bias file\n";
86cpl_plugin_get_info(cpl_pluginlist *list)
88 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
89 cpl_plugin *plugin = &recipe->interface;
91 if (cpl_plugin_init(plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
92 CPL_PLUGIN_TYPE_RECIPE,
"moons_mbias",
93 "Create a master bias product",
94 _moons_mbias_description,
"Regis Haigron",
96 _moons_mbias_create, _moons_mbias_exec,
97 _moons_mbias_destroy)) {
98 cpl_msg_error(cpl_func,
"Plugin initialization failed");
99 (void)cpl_error_set_where(cpl_func);
103 if (cpl_pluginlist_append(list, plugin)) {
104 cpl_msg_error(cpl_func,
"Error adding plugin to list");
105 (void)cpl_error_set_where(cpl_func);
124_moons_mbias_create(cpl_plugin *plugin)
129 if (cpl_error_get_code() != CPL_ERROR_NONE) {
130 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
131 cpl_func, __LINE__, cpl_error_get_where());
132 return (
int)cpl_error_get_code();
135 if (plugin == NULL) {
136 cpl_msg_error(cpl_func,
"Null plugin");
137 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
141 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
142 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
143 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
147 recipe = (cpl_recipe *)plugin;
150 recipe->parameters = cpl_parameterlist_new();
151 if (recipe->parameters == NULL) {
152 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
153 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
175_moons_mbias_exec(cpl_plugin *plugin)
179 cpl_errorstate initial_errorstate = cpl_errorstate_get();
182 if (cpl_error_get_code() != CPL_ERROR_NONE) {
183 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
184 cpl_func, __LINE__, cpl_error_get_where());
185 return (
int)cpl_error_get_code();
188 if (plugin == NULL) {
189 cpl_msg_error(cpl_func,
"Null plugin");
190 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
194 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
195 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
196 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
200 recipe = (cpl_recipe *)plugin;
203 if (recipe->parameters == NULL) {
204 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
205 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
207 if (recipe->frames == NULL) {
208 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
209 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
213 recipe_status = _moons_mbias(recipe->frames, recipe->parameters);
216 if (cpl_dfs_update_product_header(recipe->frames)) {
218 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;
240_moons_mbias_destroy(cpl_plugin *plugin)
244 if (plugin == NULL) {
245 cpl_msg_error(cpl_func,
"Null plugin");
246 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
250 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
251 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
252 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
256 recipe = (cpl_recipe *)plugin;
258 cpl_parameterlist_delete(recipe->parameters);
278_moons_prepare(moo_products *products,
279 const cpl_frame *frame,
280 const char *bpmap_name,
282 moo_prepare_params *params)
284 cpl_frame *result = NULL;
285 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
287 char *detname = NULL;
290 detname = cpl_sprintf(
"%s_%d.fits", MOONS_TAG_BIAS_PREPARE, i);
292 moo_prepare(frame, bpmap_name, NULL, NULL, NULL, params),
294 moo_try_check(result =
296 CPL_FRAME_LEVEL_INTERMEDIATE,
297 MOONS_TAG_BIAS_PREPARE, detname, frame),
320_moons_prepare_set(cpl_frameset *in,
321 const char *bpmap_name,
322 moo_products *products,
323 moo_prepare_params *params)
325 cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL);
326 cpl_ensure(products != NULL, CPL_ERROR_NULL_INPUT, NULL);
328 cpl_frameset *result = cpl_frameset_new();
331 cpl_errorstate prestate = cpl_errorstate_get();
333 for (i = 0; i < cpl_frameset_get_size(in); ++i) {
334 const cpl_frame *current_frame = NULL;
335 cpl_frame *pframe = NULL;
336 moo_try_check(current_frame = cpl_frameset_get_position_const(in, i),
338 moo_try_check(pframe = _moons_prepare(products, current_frame,
339 bpmap_name, i, params),
341 moo_try_check(cpl_frameset_insert(result, cpl_frame_duplicate(pframe)),
345 if (!cpl_errorstate_is_equal(prestate)) {
346 cpl_msg_error(__func__,
"dump error ");
347 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
348 cpl_frameset_delete(result);
370_moons_create_masterbias(cpl_frameset *in,
371 moo_products *products,
372 moo_crh_params *crh_params,
373 moo_bias_params *bias_params)
375 cpl_error_code status = CPL_ERROR_NONE;
376 moo_det *cleanBias = NULL;
377 moo_detlist *detlist = NULL;
379 cpl_errorstate prestate = cpl_errorstate_get();
380 cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT);
381 cpl_ensure_code(products != NULL, CPL_ERROR_NULL_INPUT);
384 moo_try_check(cleanBias =
moo_remove_CRH(detlist, NULL, crh_params),
" ");
385 moo_try_check(status =
393 if (!cpl_errorstate_is_equal(prestate)) {
394 cpl_msg_error(__func__,
"Can't create master bias");
395 status = cpl_error_get_code();
396 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
416_moons_mbias_check_sof(cpl_frameset *frameset,
417 cpl_frameset **rawframes,
418 const char **bpmap_rp_name)
420 cpl_ensure_code(rawframes != NULL, CPL_ERROR_NULL_INPUT);
421 cpl_ensure_code(frameset != NULL, CPL_ERROR_NULL_INPUT);
422 cpl_ensure_code(bpmap_rp_name != NULL, CPL_ERROR_NULL_INPUT);
426 cpl_error_get_code());
429 moo_try_check(*rawframes = cpl_frameset_new(),
" ");
432 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
433 const cpl_frame *current_frame = NULL;
434 moo_try_check(current_frame =
435 cpl_frameset_get_position_const(frameset, i),
438 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_BIAS)) {
439 cpl_frame *new_frame = cpl_frame_duplicate(current_frame);
440 cpl_frameset_insert(*rawframes, new_frame);
443 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_BP_MAP_RP)) {
444 *bpmap_rp_name = cpl_frame_get_filename(current_frame);
447 moo_try_assure(nraw >= 3, CPL_ERROR_DATA_NOT_FOUND,
448 "SOF does not have enough files (%d<3) tagged with %s", nraw,
452 return cpl_error_get_code();
463_moons_mbias(cpl_frameset *frameset,
const cpl_parameterlist *parlist)
466 moo_prepare_params *prepare_params = NULL;
467 moo_crh_params *crh_params = NULL;
468 moo_bias_params *bias_params = NULL;
470 cpl_frameset *rawframes = NULL;
471 const char *bpmap_name = NULL;
473 cpl_frameset *detset = NULL;
478 PACKAGE
"/" PACKAGE_VERSION);
485 prepare_params->ignore_detector[1] = 1;
486 prepare_params->ignore_detector[2] = 1;
487 prepare_params->ignore_detector[4] = 1;
488 prepare_params->ignore_detector[5] = 1;
493 moo_try_check(_moons_mbias_check_sof(frameset, &rawframes, &bpmap_name),
497 moo_try_check(detset = _moons_prepare_set(rawframes, bpmap_name, products,
500 moo_try_check(_moons_create_masterbias(detset, products, crh_params,
505 cpl_frameset_delete(detset);
506 cpl_frameset_delete(rawframes);
507 moo_bias_params_delete(bias_params);
508 moo_prepare_params_delete(prepare_params);
509 moo_crh_params_delete(crh_params);
510 moo_products_delete(products);
511 return (
int)cpl_error_get_code();
void moo_det_delete(moo_det *self)
Delete a moo_det.
moo_detlist * moo_detlist_create(cpl_frameset *frameset)
Create a new moo_detlist from the given DET frameset.
void moo_detlist_delete(moo_detlist *self)
Free all memory used by a moo_detlist object including the DET.
moo_prepare_params * moo_params_get_prepare(const moo_params *self, const cpl_parameterlist *list)
Get remove prepare parameters from moons parameters list.
moo_bias_params * moo_params_get_bias(const moo_params *self, const cpl_parameterlist *list)
Get bias parameters from moons parameters list.
cpl_error_code moo_params_add_crh(moo_params *self, cpl_parameterlist *list, const char *method)
Add default parameters for remove crh.
void moo_params_delete(moo_params *self)
Delete a moo_params.
moo_crh_params * moo_params_get_crh(const moo_params *self, const cpl_parameterlist *list)
Get remove crh parameters from moons parameters list.
cpl_error_code moo_params_add_bias(moo_params *self, cpl_parameterlist *list)
Add default parameters for bias.
cpl_error_code moo_params_add_keep_temp(moo_params *self, cpl_parameterlist *list)
Add default parameters for keep-temp.
cpl_error_code moo_params_add_prepare(moo_params *self, cpl_parameterlist *list)
Add default parameters for prepare.
moo_params * moo_params_new(const char *pid, const char *recipe_id)
Create a new moo_params.
cpl_error_code moo_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
moo_det * moo_remove_CRH(moo_detlist *detlist, moo_masklist *cosmiclist, moo_crh_params *params)
Remove CRH in single frames or in a combination of multiple frames.
moo_det * moo_prepare(const cpl_frame *rawframe, const char *const badpixmask_rp, const char *const badpixmask_nl, const cpl_frame *masterbias, const cpl_frame *cube_frame, moo_prepare_params *params)
This function transforms RAW frames in DET frames attaching the default bad pixel map and an error im...
moo_products * moo_products_new(cpl_frameset *framelist, const cpl_parameterlist *parlist, const char *recid, const char *pipeline_id)
create a moo_product object for a recipe
cpl_frame * moo_products_add(moo_products *self, moo_det *det, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a DET object
cpl_error_code moo_masterbias(moo_det *det, moo_detlist *bias_list, moo_bias_params *bias_params, moo_products *products)
This function creates the master bias frame as a product and essentially produces a standard output a...
const moo_params * moo_products_get_params(const moo_products *self)
get the moo_params object
const char * moo_get_license(void)
Get the pipeline copyright and license.