36 #include "naco_recipe.h"
37 #include "irplib_slitpos.h"
43 #define RECIPE_STRING "naco_img_slitpos"
49 static cpl_error_code naco_img_slitpos_qc(cpl_propertylist *,
51 const irplib_framelist *);
53 static cpl_error_code naco_img_slitpos_save(cpl_frameset *,
54 const cpl_parameterlist *,
55 const cpl_propertylist *,
56 const cpl_propertylist *,
57 const cpl_table *,
int,
58 const irplib_framelist *);
60 NACO_RECIPE_DEFINE(naco_img_slitpos, NACO_PARAM_SLIT_W,
61 "Slit Position recipe",
62 RECIPE_STRING
" -- NACO imaging slit position recipe.\n"
63 "The Set Of Frames (sof-file) must specify at least one file "
64 "which must be tagged\n"
65 "raw-file.fits " NACO_IMG_SLITPOS_RAW
"\n"
67 "Each image is flipped around the x=y axis before the "
89 static int naco_img_slitpos(cpl_frameset * framelist,
90 const cpl_parameterlist * parlist)
92 irplib_framelist* allframes = NULL;
93 irplib_framelist* rawframes = NULL;
94 irplib_framelist* oneframe = NULL;
95 cpl_frame * frame = NULL;
96 cpl_image * image = NULL;
97 cpl_table * out_table = NULL;
98 cpl_propertylist* qclist = cpl_propertylist_new();
99 cpl_propertylist* paflist = cpl_propertylist_new();
113 allframes = irplib_framelist_cast(framelist);
114 bug_if(allframes == NULL);
116 irplib_check(rawframes
117 = irplib_framelist_extract(allframes, NACO_IMG_SLITPOS_RAW),
118 "Could not load the raw frames");
119 irplib_framelist_empty(allframes);
121 nframes = irplib_framelist_get_size(rawframes);
123 oneframe = irplib_framelist_new();
126 for (i=0 ; i < nframes ; i++) {
129 double xpos, ypos, angle;
130 double slit_y0, slit_yn;
131 double slit_c0, slit_cn;
134 cpl_msg_info(cpl_func,
"Analysing slit of frame %d out of %d", i+1,
137 frame = irplib_framelist_unset(rawframes, 0, NULL);
138 bug_if(irplib_framelist_set(oneframe, frame, 0));
140 name = cpl_frame_get_filename(frame);
142 bug_if(name == NULL);
144 irplib_check(image = cpl_image_load(name, CPL_TYPE_FLOAT, 0, 0),
145 "Could not load FITS-image");
147 bug_if(cpl_image_flip(image, 1));
149 out_table = irplib_slitpos_analysis(image, slit_width, NULL);
150 cpl_image_delete(image);
152 skip_if (out_table == NULL);
156 slit_length = cpl_table_get_nrow(out_table);
158 slit_y0 = cpl_table_get(out_table,
"SLIT_Y", 0, NULL);
159 slit_yn = cpl_table_get(out_table,
"SLIT_Y", slit_length-1, NULL);
162 slit_c0 = cpl_table_get(out_table,
"SLIT_CENTER", 0, NULL);
163 slit_cn = cpl_table_get(out_table,
"SLIT_CENTER", slit_length-1, NULL);
167 angle = 180.0 + CPL_MATH_DEG_RAD * atan2(slit_cn - slit_c0,
171 ypos = (slit_c0 + slit_cn)/2.0;
172 xpos = (slit_y0 + slit_yn)/2.0;
175 cpl_msg_info(cpl_func,
"Slit angle : %g", angle);
176 cpl_msg_info(cpl_func,
"Slit length : %d", slit_length);
177 cpl_msg_info(cpl_func,
"Slit center : %g %g", xpos, ypos);
179 skip_if(irplib_framelist_load_propertylist_all(oneframe, 0,
"^("
180 NACO_PFITS_REGEXP_SLITPOS
"|"
181 NACO_PFITS_REGEXP_SLITPOS_PAF
185 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC SLIT POSANG",
187 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC SLIT XPOS",
189 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC SLIT YPOS",
192 skip_if (naco_img_slitpos_qc(qclist, paflist, oneframe));
195 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
196 NACO_IMG_SLITPOS_RES));
198 skip_if (naco_img_slitpos_save(framelist, parlist, qclist, paflist,
199 out_table, i+1, oneframe));
201 cpl_table_delete(out_table);
204 cpl_propertylist_empty(qclist);
205 cpl_propertylist_empty(paflist);
208 irplib_framelist_empty(oneframe);
210 bug_if(irplib_framelist_get_size(oneframe) != 0);
214 bug_if(irplib_framelist_get_size(rawframes) != 0);
218 cpl_image_delete(image);
219 cpl_table_delete(out_table);
221 irplib_framelist_delete(oneframe);
222 irplib_framelist_delete(allframes);
223 irplib_framelist_delete(rawframes);
224 cpl_propertylist_delete(qclist);
225 cpl_propertylist_delete(paflist);
227 cpl_frame_delete(frame);
229 return cpl_error_get_code();
241 static cpl_error_code naco_img_slitpos_qc(cpl_propertylist * qclist,
242 cpl_propertylist * paflist,
243 const irplib_framelist * rawframes)
246 cpl_errorstate cleanstate = cpl_errorstate_get();
247 const cpl_propertylist * reflist
248 = irplib_framelist_get_propertylist_const(rawframes, 0);
249 const char pafcopy[] =
"^(" NACO_PFITS_REGEXP_SLITPOS_PAF
")$";
256 if (cpl_error_get_code())
257 naco_error_reset(
"Could not get FITS key:");
259 bug_if(cpl_propertylist_append_string(qclist,
"ESO QC FILTER OBS",
265 bug_if(cpl_propertylist_copy_property_regexp(paflist, reflist, pafcopy, 0));
267 bug_if(cpl_propertylist_append(paflist, qclist));
272 return cpl_error_get_code();
288 static cpl_error_code naco_img_slitpos_save(cpl_frameset * set,
289 const cpl_parameterlist * parlist,
290 const cpl_propertylist * qclist,
291 const cpl_propertylist * paflist,
292 const cpl_table * out_table,
294 const irplib_framelist * oneframe)
297 cpl_frameset * rawframes = irplib_frameset_cast(oneframe);
298 char * filename = NULL;
304 filename = cpl_sprintf(RECIPE_STRING
"_%02d" CPL_DFS_FITS, file_nb);
305 skip_if (irplib_dfs_save_table(set, parlist, rawframes, out_table, NULL,
306 RECIPE_STRING, NACO_IMG_SLITPOS_RES, qclist, NULL,
307 naco_pipe_id, filename));
310 filename = cpl_sprintf(RECIPE_STRING
"_%02d" CPL_DFS_PAF, file_nb);
311 skip_if (cpl_dfs_save_paf(
"NACO", RECIPE_STRING, paflist, filename));
316 cpl_frameset_delete(rawframes);
318 return cpl_error_get_code();
int naco_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
int naco_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, naco_parameter bitmask)
Retrieve the value of a NACO integer parameter.
const char * naco_pfits_get_filter(const cpl_propertylist *self)
find out the filter