39#include "eris_utils.h"
40#include "eris_pfits.h"
41#include "eris_ifu_dfs.h"
42#include "eris_ifu_utils.h"
43#include "eris_ifu_functions.h"
44#include "eris_ifu_error.h"
45#include "eris_ifu_debug.h"
46#include "eris_ifu_flat_static.h"
51static const char eris_ifu_flat_description[] =
"\
52This recipe performs ERIS/SPIFFIER flat field frames data reduction.\n\
54Optionally one may have in input also several bad pixel maps to be coadded.\n\
56-----------------------------------------------------------------------------\n\
58 DO CATG Explanation Required #Frames\n\
59 ------- ----------- -------- -------\n\
60 FLAT_LAMP Flatlamp exposures Y 2-n \n\
61 (at least 3 frames recommended) \n\
62 BPM_DARK Bad pixel mask from eris_ifu_dark Y 1 \n\
63 BPM_DETLIN Bad pixel mask from eris_ifu_detlin N [0,1] \n\
64 BPM_DIST Bad pixel mask from eris_ifu_distortion N [0,1] \n\
67 DO CATG Explanation\n\
68 ------- -----------\n\
69 MASTER_FLAT Normalised flat field\n\
70 BPM_FLAT Updated bad pixel mask\n\
71-----------------------------------------------------------------------------\n\
73 --mode=fast Simple subtraction of on- and off-frames and collapsing\n\
74 --collapse* parameters apply as well\n\
75 --mode=hdrl The HDRL-way to create a masterflat (not well suited to\n\
76 spectroscopic raw data)\n\
77 --collapse* + --flat* parameters apply as well\n\
78 --mode=segment The raw data is segmented vertically and inspected individually\n\
80Information on relevant parameters may be found with\n\
81 esorex --params "REC_NAME_FLAT
"\n\
82 esorex --help "REC_NAME_FLAT
"\n";
87cpl_recipe_define(eris_ifu_flat, ERIS_BINARY_VERSION,
"Alex Agudo Berbel",
88 PACKAGE_BUGREPORT,
"2018",
89 "This recipe performs flat field data reduction",
90 eris_ifu_flat_description);
105static cpl_error_code eris_ifu_flat_fill_parameterlist(cpl_parameterlist *pl)
107 cpl_error_code err = CPL_ERROR_NONE;
110 cpl_ensure_code(pl, CPL_ERROR_NULL_INPUT);
129 err = cpl_error_get_code();
143static int eris_ifu_flat(cpl_frameset *frameset,
144 const cpl_parameterlist *parlist)
146 cpl_propertylist *qc_list = NULL;
147 hdrl_image *masterFlatHdrlImg_lo = NULL;
148 cpl_image *qualityImage = NULL,
149 *masterFlatImage = NULL,
152 const cpl_mask *bp_mask_flat = NULL;
153 int productDepth = 0,
155 const char *instrument = NULL;
157 cpl_ensure_code(frameset, CPL_ERROR_NULL_INPUT);
158 cpl_ensure_code(parlist, CPL_ERROR_NULL_INPUT);
163 return CPL_ERROR_BAD_FILE_FORMAT;
169 instrument = cpl_parameter_get_string(
170 cpl_parameterlist_find_const(parlist,
171 "eris.eris_ifu_flat.instrument")));
172 cpl_msg_info(cpl_func,
"Processing %s frames", instrument);
179 nrfr = cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_DARK_BPM);
181 CPL_ERROR_ILLEGAL_INPUT,
182 "Exactly 1 "ERIS_IFU_PRO_DARK_BPM
" frame must be provided.");
184 nrfr = cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_DIST_BPM);
185 ASSURE((nrfr == 0) || (nrfr == 1),
186 CPL_ERROR_ILLEGAL_INPUT,
187 "Either 0 or 1 "ERIS_IFU_PRO_DIST_BPM
" frame must be provided.");
189 nrfr = cpl_frameset_count_tags(frameset, ERIS_IFU_PRO_DETLIN_BPM);
190 ASSURE((nrfr == 0) || (nrfr == 1),
191 CPL_ERROR_ILLEGAL_INPUT,
192 "Either 0 or 1 "ERIS_IFU_PRO_DETLIN_BPM
" frame must be provided.");
195 productDepth = cpl_parameter_get_int(
196 cpl_parameterlist_find_const(parlist,
197 "eris.eris_ifu_flat.product_depth"));
200 const char * tmp = cpl_parameter_get_string(cpl_parameterlist_find_const(parlist,
201 "eris.eris_ifu_flat.mode"));
202 flatMode mode = FLAT_MODE_NONE;
203 if (!strcmp(tmp, flatModes[0])) {
204 mode = FLAT_MODE_SEGMENT;
205 }
else if (!strcmp(tmp, flatModes[1])) {
206 mode = FLAT_MODE_HDRL;
207 }
else if (!strcmp(tmp, flatModes[2])) {
208 mode = FLAT_MODE_FAST;
216 eris_ifu_flat_static(frameset,
225 &masterFlatHdrlImg_lo,
237 cpl_propertylist_update_string(qc_list, CPL_DFS_PRO_CATG, ERIS_IFU_PRO_FLAT));
243 ERIS_IFU_PRO_FLAT_FN,
244 masterFlatImage, errorImage, rmse,
245 qualityImage, flag16bit, UNITLESS));
251 bp_img_flat = cpl_image_new_from_mask(bp_mask_flat));
254 ERIS_IFU_PRO_FLAT_BPM,
255 ERIS_IFU_PRO_FLAT_BPM_FN,
269 if (cpl_memory_is_empty() == 0) {
273 return (
int) cpl_error_get_code();
cpl_error_code eris_ifu_dfs_set_groups(cpl_frameset *self)
Set the frame group (RAW, CALIB, or PRODUCT) for all frames in a frameset.
cpl_error_code eris_ifu_save_deq_image(cpl_frameset *allframes, cpl_propertylist *header, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_frame *inherit, const char *recipe, const cpl_propertylist *applist, const char *remregexp, const char *filename, const cpl_image *image, const cpl_image *error, deqErrorType errorType, const cpl_image *dataQualityMask, deqQualityType dataQualityType, const char *unit)
Save a DFS-compliant image product with data, error, and quality extensions.
#define ASSURE(condition, error,...)
error handling macro (from fors-pipeline)
#define BRK_IF_ERROR(function)
If function is or returns an error != CPL_ERROR_NONE, then the try-block is exited.
#define CHECK_ERROR_STATE(void)
Check the CPL error state, and exit the try-block if not CPL_ERROR_NONE.
#define BRK_WITH_ERROR_MSG(code,...)
Set a new CPL error, and exit the try-block.
#define TRY
Beginning of a TRY-block.
#define CATCH
End of a TRY-block, beginning of a CATCH-block.
#define BRK_IF_NULL(function)
If function is or returns a NULL pointer, then the try-block is exited.
#define CATCH_MSGS()
Displays an error message stack.
cpl_error_code eris_parlist_config_add_flat(cpl_parameterlist *pl, const char *recname)
Add flat field configuration parameters to parameter list.
cpl_error_code eris_parlist_config_add_all_recipes(cpl_parameterlist *pl, const char *recname)
Add common configuration parameters for all recipes.
cpl_error_code eris_parlist_config_add_bpm(cpl_parameterlist *pl, const char *recname)
Add bad pixel mask configuration parameters to parameter list.
void eris_ifu_free_propertylist(cpl_propertylist **item)
Free memory and set pointer to null.
void eris_ifu_free_hdrl_image(hdrl_image **item)
Free memory and set pointer to null.
void eris_ifu_free_image(cpl_image **item)
Free memory and set pointer to null.
cpl_error_code eris_ifu_save_image(cpl_frameset *fs, const cpl_propertylist *plist, const cpl_parameterlist *parlist, const char *recipe, const char *procatg, const char *filename, cpl_type type, const cpl_image *image)
Save image with DFS compliance.
cpl_error_code eris_files_dont_exist(cpl_frameset *frameset)
Check if all SOF files exist.
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
const cpl_mask * hdrl_image_get_mask_const(const hdrl_image *himg)
get cpl bad pixel mask from image
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image