38#include "eris_nix_master_flat.h"
39#include "eris_nix_utils.h"
69 const cpl_mask * cold_bpm,
70 const cpl_image * confidence,
71 const char * filename,
72 const cpl_propertylist * plist) {
74 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
78 cpl_ensure(flat, CPL_ERROR_NULL_INPUT, NULL);
79 cpl_ensure(confidence, CPL_ERROR_NULL_INPUT, NULL);
81 master_flat * result = cpl_malloc(
sizeof(master_flat));
85 result->cold_bpm = cpl_mask_duplicate(cold_bpm);
87 result->cold_bpm = NULL;
89 result->confidence = cpl_image_duplicate(confidence);
91 result->filename = cpl_strdup(filename);
93 result->filename = NULL;
96 result->plist = cpl_propertylist_duplicate(plist);
118void en_master_flat_delete(master_flat * target) {
121 cpl_free(target->filename);
123 cpl_mask_delete(target->cold_bpm);
124 cpl_image_delete(target->confidence);
125 cpl_propertylist_delete(target->plist);
143master_flat * en_master_flat_load_from_frameset(
const cpl_frameset * frameset,
146 const int required) {
148 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
150 cpl_mask * cold_bpm = NULL;
151 cpl_image * confidence = NULL;
152 const char * filename = NULL;
153 hdrl_image * flat = NULL;
154 cpl_mask * full_cold_bpm = NULL;
155 cpl_image * full_conf = NULL;
156 hdrl_image * full_flat = NULL;
157 mef_extension_list * mefs = NULL;
158 cpl_propertylist * plist = NULL;
159 master_flat * result = NULL;
163 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
164 cpl_ensure(tag, CPL_ERROR_NULL_INPUT, NULL);
168 const cpl_frame * target_frame = cpl_frameset_find_const(frameset, tag);
169 enu_check(target_frame != NULL, CPL_ERROR_DATA_NOT_FOUND,
170 "SoF has no file tagged %s", tag);
171 filename = cpl_frame_get_filename(target_frame);
176 enu_check_error_code(
"failed to read file %s", filename);
180 for (
int i=0; i < mefs->size; i++) {
181 if (!strcmp(mefs->mef[i]->name,
"COLD_BPM")) {
182 cold_bpm = cpl_mask_duplicate(
183 (
const cpl_mask *) (mefs->mef[i]->data));
190 for (
int i=0; i<mefs->size; i++) {
191 if (!strcmp(mefs->mef[i]->name,
"CONFIDENCE")) {
192 confidence = cpl_image_duplicate(
193 (
const cpl_image *) (mefs->mef[i]->data));
197 if (!confidence) cpl_msg_warning(cpl_func,
"confidence array not found");
206 cpl_size nx_chip = 0;
207 cpl_size ny_chip = 0;
208 cpl_boolean windowed = 0;
218 enu_check_error_code(
"Failed to read flatfield window information");
220 if (nx != nx_chip || ny != ny_chip) {
221 cpl_msg_info(cpl_func,
"windowed flatfield, extending to cover full chip");
230 full_conf = cpl_image_new(nx_chip,
232 cpl_image_get_type(confidence));
233 cpl_image_copy(full_conf,
241 full_cold_bpm = cpl_mask_new(nx_chip,
243 cpl_mask_copy(full_cold_bpm,
250 full_flat = flat; flat = NULL;
251 full_conf = confidence; confidence = NULL;
252 full_cold_bpm = cold_bpm; cold_bpm = NULL;
263 if (cpl_error_get_code() == CPL_ERROR_NONE) {
264 cpl_frame * dup_frame = cpl_frame_duplicate(target_frame);
265 cpl_frameset_insert(used, dup_frame);
267 en_master_flat_delete(result);
275 cpl_msg_warning(cpl_func,
"no file tagged %s in SoF", tag);
280 cpl_mask_delete(full_cold_bpm);
281 cpl_mask_delete(cold_bpm);
282 cpl_image_delete(full_conf);
283 cpl_image_delete(confidence);
287 cpl_propertylist_delete(plist);
master_flat * en_master_flat_create(const hdrl_image *flat, const cpl_mask *cold_bpm, const cpl_image *confidence, const char *filename, const cpl_propertylist *plist)
Create a new master_flat struct and initialise the contents.
cpl_error_code enu_get_window_info(cpl_size *nx, cpl_size *ny, int *rot, cpl_size *strx, cpl_size *stry, cpl_size *nx_chip, cpl_size *ny_chip, cpl_boolean *windowed, const cpl_propertylist *plist)
Get the detector 'window' information.
cpl_error_code enu_himage_load_from_fits(const char *filename, hdrl_image **result, mef_extension_list **mef_extensions, cpl_propertylist **plist)
Load an hdrl_image from a multi-extension FITS file.
void enu_mef_extension_list_delete(mef_extension_list *list)
Delete a mef_extension_list and its contents.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
cpl_error_code hdrl_image_copy(hdrl_image *dst, const hdrl_image *src, cpl_size xpos, cpl_size ypos)
Copy one image into another.
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image