26 #include <muclipm_make_image.h>
28 #include "muse_quick_image_z.h"
51 cpl_image *raw_img, *bias, *flat, *mask;
52 cpl_propertylist *mask_hdr;
53 cpl_image *computed_img;
54 cpl_propertylist *output_header = NULL;
56 long xstart[MUCLIPM_NB_SLICES*MUCLIPM_NB_SUBSLICERS],
57 xend[MUCLIPM_NB_SLICES*MUCLIPM_NB_SUBSLICERS];
60 if (aParams->
nifu < 0 || aParams->
nifu > kMuseNumIFUs) {
61 cpl_msg_error(__func__,
"Illegal IFU number %d", aParams->
nifu);
66 computed_img = cpl_image_new(MUCLIPM_NB_SUBSLICERS * MUCLIPM_NB_SPEC_PER_SLICE,
67 MUCLIPM_NB_SLICES * MUCLIPM_NB_IFU,
70 n1 = aParams->
nifu ? aParams->
nifu : 1,
71 n2 = aParams->
nifu ? aParams->
nifu : kMuseNumIFUs;
72 for (nifu = n1; nifu <= n2; nifu++) {
74 cpl_frameset *input_frames;
78 cpl_msg_info(__func__,
"Processing IFU %d", nifu);
81 input_frames = cpl_frameset_duplicate(aProcessing->
inputFrames);
83 frame = cpl_frameset_find(input_frames, MUSE_TAG_MASK_IMAGE);
86 mask = cpl_image_load(cpl_frame_get_filename(frame), CPL_TYPE_INT, 0,
90 cpl_error_set_message(__func__, cpl_error_get_code(),
"extension for "
91 "IFU %d not found", nifu);
93 cpl_msg_error(__func__,
"Could not load frame %s (%s): %s",
94 cpl_frame_get_filename(frame), MUSE_TAG_MASK_IMAGE,
95 cpl_error_get_message());
96 cpl_frameset_delete(input_frames);
101 mask_hdr = cpl_propertylist_load(cpl_frame_get_filename(frame), extension);
103 cpl_frameset_erase(input_frames, MUSE_TAG_MASK_IMAGE);
107 for (i = 0; i < MUCLIPM_NB_SLICES*MUCLIPM_NB_SUBSLICERS; i++) {
108 char *p1 = cpl_sprintf(
"ESO DET SLICE%ld XSTART", i + 1),
109 *p2 = cpl_sprintf(
"ESO DET SLICE%ld XEND", i + 1);
110 xstart[i] = cpl_propertylist_get_int(mask_hdr, p1);
111 xend[i] = cpl_propertylist_get_int(mask_hdr, p2);
115 cpl_msg_debug(__func__,
"Slice %ld: limits [%ld,%ld]", i + 1,
118 if (xstart[i] >= xend[i]) {
119 cpl_msg_error(__func__,
"IFU %d: inconsistant slice limits in X "
120 "[%ld,%ld] for slice %ld", nifu,
121 xstart[i], xend[i], i + 1);
125 for (i = 1; i < MUCLIPM_NB_SLICES*MUCLIPM_NB_SUBSLICERS; i++) {
126 if (xstart[i] <= xend[i-1]) {
127 cpl_msg_error(__func__,
"IFU %d: inconsistant interslice for slices "
128 "%ld and %ld (%ld,%ld)", nifu,
129 i - 1, i, xend[i-1], xstart[i]);
134 cpl_errorstate prestate = cpl_errorstate_get();
135 frame = cpl_frameset_find(input_frames, MUSE_TAG_BIAS);
138 bias = cpl_image_load(cpl_frame_get_filename(frame),
139 CPL_TYPE_FLOAT, 0, extension);
141 cpl_msg_debug(__func__,
"Proceeding without %s that could not be loaded: "
142 "%s", MUSE_TAG_BIAS, cpl_error_get_message());
143 cpl_errorstate_set(prestate);
148 cpl_frameset_erase(input_frames, MUSE_TAG_BIAS);
150 prestate = cpl_errorstate_get();
151 frame = cpl_frameset_find(input_frames, MUSE_TAG_FLAT);
154 flat = cpl_image_load(cpl_frame_get_filename(frame), CPL_TYPE_FLOAT, 0,
157 cpl_msg_debug(__func__,
"Proceeding without %s that could not be loaded: "
158 "%s", MUSE_TAG_FLAT, cpl_error_get_message());
159 cpl_errorstate_set(prestate);
163 cpl_frameset_erase(input_frames, MUSE_TAG_FLAT);
166 frame = cpl_frameset_get_position(input_frames, 0);
169 raw_img = cpl_image_load(cpl_frame_get_filename(frame), CPL_TYPE_FLOAT, 0,
173 cpl_error_set_message(__func__, cpl_error_get_code(),
"extension for "
174 "IFU %d not found", nifu);
176 cpl_msg_error(__func__,
"Could not load data frame %s: %s",
177 cpl_frame_get_filename(frame), cpl_error_get_message());
178 cpl_frameset_delete(input_frames);
179 cpl_image_delete(mask);
180 cpl_propertylist_delete(mask_hdr);
181 cpl_image_delete(bias);
182 cpl_image_delete(flat);
187 if (!output_header) {
188 output_header = cpl_propertylist_load(cpl_frame_get_filename(frame), 0);
190 cpl_frameset_delete(input_frames);
193 ifu_img = cpl_image_new(MUCLIPM_NB_SUBSLICERS * MUCLIPM_NB_SPEC_PER_SLICE,
194 MUCLIPM_NB_SLICES, CPL_TYPE_FLOAT);
197 cpl_msg_info(__func__,
"Error while computing reconstructed image: %s",
198 cpl_error_get_message());
199 cpl_image_delete(computed_img);
200 cpl_propertylist_delete(output_header);
201 cpl_image_delete(mask);
202 cpl_propertylist_delete(mask_hdr);
203 cpl_image_delete(bias);
204 cpl_image_delete(flat);
209 cpl_image_copy(computed_img, ifu_img, 1, (24 - nifu) * MUCLIPM_NB_SLICES + 1);
212 cpl_image_delete(bias);
213 cpl_image_delete(flat);
214 cpl_image_delete(mask);
215 cpl_propertylist_delete(mask_hdr);
216 cpl_image_delete(raw_img);
217 cpl_image_delete(ifu_img);
220 cpl_image_flip(computed_img, 0);
222 output_header, MUSE_TAG_QUICK_IMAGE);
223 cpl_image_delete(computed_img);
224 cpl_propertylist_delete(output_header);
Structure to hold the parameters of the muse_quick_image recipe.
int muse_processing_save_cimage(muse_processing *aProcessing, int aIFU, cpl_image *aImage, cpl_propertylist *aHeader, const char *aTag)
Save a computed FITS image to disk.
int muse_utils_get_extension_for_ifu(const char *aFilename, unsigned char aIFU)
Return extension number that corresponds to this IFU/channel number.
void muse_processing_append_used(muse_processing *aProcessing, cpl_frame *aFrame, cpl_frame_group aGroup, int aDuplicate)
Add a frame to the set of used frames.
cpl_error_code muclipm_make_image(const cpl_image *raw_img, const cpl_image *offset, const cpl_image *flat, const cpl_image *mask, const long *slice_xstart, const long *slice_xend, cpl_image **out_img)
Collapses spectra over the spectral direction.
cpl_frameset * inputFrames
int nifu
IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in ...