38#include "eris_nix_dfs.h"
39#include "eris_nix_master_dark.h"
40#include "eris_nix_utils.h"
67 const cpl_mask * hot_bpm,
68 const char * filename,
69 const cpl_propertylist * plist) {
71 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
75 cpl_ensure(dark && hot_bpm, CPL_ERROR_NULL_INPUT, NULL);
77 master_dark * result = cpl_malloc(
sizeof(master_dark));
80 result->hot_bpm = cpl_mask_duplicate(hot_bpm);
82 result->filename = cpl_strdup(filename);
84 result->filename = NULL;
87 result->plist = cpl_propertylist_duplicate(plist);
109 cpl_free(target->filename);
111 cpl_mask_delete(target->hot_bpm);
112 cpl_propertylist_delete(target->plist);
132 cpl_frameset * used) {
133 cpl_mask * bpm = NULL;
134 hdrl_image * dark = NULL;
135 const char * filename = NULL;
136 mef_extension_list * mef_extensions = NULL;
137 cpl_propertylist * plist = NULL;
138 master_dark * result = NULL;
140 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
144 cpl_ensure(frameset, CPL_ERROR_NULL_INPUT, NULL);
145 cpl_ensure(tag, CPL_ERROR_NULL_INPUT, NULL);
149 const cpl_frame * target_frame = cpl_frameset_find_const(frameset, tag);
150 enu_check(target_frame != NULL, CPL_ERROR_DATA_NOT_FOUND,
151 "SoF has no file tagged %s", tag);
153 filename = cpl_frame_get_filename(target_frame);
159 enu_check_error_code(
"failed to read file %s", filename);
162 ERIS_NIX_HOT_BPM_EXTENSION);
163 enu_check_error_code(
"failed to find bpm extension %s in %s",
164 ERIS_NIX_HOT_BPM_EXTENSION, filename);
166 cpl_frameset_insert(used, cpl_frame_duplicate(target_frame));
172 if (cpl_error_get_code() != CPL_ERROR_NONE) {
177 cpl_mask_delete(bpm);
180 cpl_propertylist_delete(plist);
209 if (cpl_error_get_code() != CPL_ERROR_NONE)
return NULL;
211 cpl_image * conf = NULL;
212 hdrl_image * dark = NULL;
213 cpl_image * dark_data = NULL;
214 cpl_image * dark_error = NULL;
215 cpl_mask * hotbpm = NULL;
216 cpl_propertylist * plist = NULL;
217 master_dark * result = NULL;
221 dark_data = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
222 cpl_image_fill_window(dark_data, 1, 1, nx, ny, 7.0);
223 dark_error = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
224 cpl_image_fill_window(dark_error, 1, 1, nx, ny, 3.0);
226 hotbpm = cpl_mask_new(nx, ny);
227 conf = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
228 cpl_image_fill_window(conf, 1, 1, nx, ny, 5.0);
230 plist = cpl_propertylist_new();
231 cpl_propertylist_update_string(plist, CPL_DFS_PRO_CATG,
232 ERIS_NIX_MASTER_DARK_IMG_PRO_CATG);
233 cpl_propertylist_update_string(plist,
"PRODCATG",
"ANCILLARY.IMAGE");
235 cpl_propertylist_update_double(plist,
"ESO DET DIT", dit);
236 cpl_propertylist_update_double(plist,
"ESO DET NDIT", ndit);
237 cpl_propertylist_update_string(plist,
"ESO DET READ CURNAME", mode);
238 cpl_propertylist_update_int(plist,
"ESO DET SEQ1 WIN ROT", 0);
239 cpl_propertylist_update_int(plist,
"ESO DET SEQ1 WIN STRX", 1);
240 cpl_propertylist_update_int(plist,
"ESO DET SEQ1 WIN STRY", 1);
241 cpl_propertylist_update_int(plist,
"ESO DET SEQ1 WIN NX", nx);
242 cpl_propertylist_update_int(plist,
"ESO DET SEQ1 WIN NY", ny);
244 cpl_propertylist_append_double(plist,
"ESO QC READ NOISE", 6.2);
245 cpl_propertylist_set_comment(plist,
"ESO QC READ NOISE",
246 "Detector read out noise");
247 cpl_propertylist_append_double(plist,
"ESO QC READ NOISE VAR", 6.3);
248 cpl_propertylist_set_comment(plist,
"ESO QC READ NOISE VAR",
249 "variance on Detector read out noise");
252 cpl_propertylist_append_double(plist,
"ESO QC DARK MED",
253 (
double) dark_median.data);
254 cpl_propertylist_set_comment(plist,
"ESO QC DARK MED",
258 cpl_propertylist_append_double(plist,
"ESO QC DARK MEAN",
259 (
double) dark_mean.data);
260 cpl_propertylist_set_comment(plist,
"ESO QC DARK MEAN",
263 cpl_propertylist_append_double(plist,
"ESO QC DARK RMS", dark_rms);
264 cpl_propertylist_set_comment(plist,
"ESO QC DARK RMS",
266 cpl_size nhot = cpl_mask_count(hotbpm);
267 cpl_propertylist_append_int(plist,
"ESO QC NUMBER HOT PIXEL", (
int)nhot);
268 cpl_propertylist_set_comment(plist,
"ESO QC NUMBER HOT PIXEL",
269 "Number of detected hot pixels");
270 cpl_propertylist_append_double(plist,
"ESO QC PARTICLE_RATE", -1);
271 cpl_propertylist_set_comment(plist,
"ESO QC PARTICLE_RATE",
273 cpl_propertylist_append_double(plist,
"ESO QC GAIN", 8.4);
274 cpl_propertylist_set_comment(plist,
"ESO QC GAIN",
281 cpl_image_delete(conf);
283 cpl_image_delete(dark_data);
284 cpl_image_delete(dark_error);
285 cpl_mask_delete(hotbpm);
286 cpl_propertylist_delete(plist);
288 if (cpl_error_get_code() != CPL_ERROR_NONE) {
master_dark * en_master_dark_create(const hdrl_image *dark, const cpl_mask *hot_bpm, const char *filename, const cpl_propertylist *plist)
Create a new master_dark struct and initialise the contents.
master_dark * en_master_dark_load_from_frameset(const cpl_frameset *frameset, const char *tag, cpl_frameset *used)
Load a 'master_dark' struct from a frameset.
void en_master_dark_delete(master_dark *target)
Delete a 'master_dark' struct.
master_dark * en_master_dark_test(const cpl_size nx, const cpl_size ny, const double dit, const int ndit, const char *mode)
Create a test master_dark struct.
cpl_mask * enu_mef_extension_list_get_mask(mef_extension_list *meflist, const char *target)
Get a cpl_mask from a named mef_extension in a list.
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_value hdrl_image_get_median(const hdrl_image *self)
computes the median and associated error of an image.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
double hdrl_image_get_stdev(const hdrl_image *self)
computes the standard deviation of the data of an image
hdrl_value hdrl_image_get_mean(const hdrl_image *self)
computes mean pixel value and associated error of an image.
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image