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();
114 bug_if(allframes == NULL);
116 irplib_check(rawframes
118 "Could not load the raw frames");
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,
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));
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);
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);
218 cpl_image_delete(image);
219 cpl_table_delete(out_table);
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
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)
298 char * filename = NULL;
304 filename = cpl_sprintf(RECIPE_STRING
"_%02d" CPL_DFS_FITS, file_nb);
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();
cpl_frameset * irplib_frameset_cast(const irplib_framelist *self)
Create a CPL frameset from an irplib_framelist.
cpl_error_code irplib_dfs_save_table(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_table *table, const cpl_propertylist *tablelist, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save a table as a DFS-compliant pipeline product.
int naco_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_error_code irplib_framelist_set(irplib_framelist *self, cpl_frame *frame, int pos)
Add a frame to a framelist.
int naco_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, naco_parameter bitmask)
Retrieve the value of a NACO integer parameter.
const cpl_propertylist * irplib_framelist_get_propertylist_const(const irplib_framelist *self, int pos)
Get the propertylist of the specified frame in the framelist.
void irplib_framelist_empty(irplib_framelist *self)
Erase all frames from a framelist.
cpl_error_code irplib_framelist_load_propertylist_all(irplib_framelist *self, int ind, const char *regexp, cpl_boolean invert)
Load the propertylists of all frames in the framelist.
cpl_frame * irplib_framelist_unset(irplib_framelist *self, int pos, cpl_propertylist **plist)
Erase a frame from a framelist and return it to the caller.
irplib_framelist * irplib_framelist_extract(const irplib_framelist *self, const char *tag)
Extract the frames with the given tag from a framelist.
cpl_table * irplib_slitpos_analysis(const cpl_image *imslit, int slit_max_width, double *slit_flux)
Detect the slit position, detect its ends, extract a thin image containing only the slit and find its...
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.
irplib_framelist * irplib_framelist_new(void)
Create an empty framelist.
int irplib_framelist_get_size(const irplib_framelist *self)
Get the size of a framelist.
const char * naco_pfits_get_filter(const cpl_propertylist *self)
find out the filter