00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "naco_recipe.h"
00037 #include "irplib_slitpos.h"
00038
00039
00040
00041
00042
00043 #define RECIPE_STRING "naco_img_slitpos"
00044
00045
00046
00047
00048
00049 static cpl_error_code naco_img_slitpos_qc(cpl_propertylist *,
00050 cpl_propertylist *,
00051 const irplib_framelist *);
00052
00053 static cpl_error_code naco_img_slitpos_save(cpl_frameset *,
00054 const cpl_parameterlist *,
00055 const cpl_propertylist *,
00056 const cpl_propertylist *,
00057 const cpl_table *, int,
00058 const irplib_framelist *);
00059
00060 NACO_RECIPE_DEFINE(naco_img_slitpos, NACO_PARAM_SLIT_W,
00061 "Slit Position recipe",
00062 RECIPE_STRING " -- NACO imaging slit position recipe.\n"
00063 "The Set Of Frames (sof-file) must specify at least one file "
00064 "which must be tagged\n"
00065 "raw-file.fits " NACO_IMG_SLITPOS_RAW "\n"
00066 "\n"
00067 "Each image is flipped around the x=y axis before the "
00068 "analysis.");
00069
00070
00074
00075
00076
00077
00078
00079
00080
00081
00088
00089 static int naco_img_slitpos(cpl_frameset * framelist,
00090 const cpl_parameterlist * parlist)
00091 {
00092 irplib_framelist* allframes = NULL;
00093 irplib_framelist* rawframes = NULL;
00094 irplib_framelist* oneframe = NULL;
00095 cpl_frame * frame = NULL;
00096 cpl_image * image = NULL;
00097 cpl_table * out_table = NULL;
00098 cpl_propertylist* qclist = cpl_propertylist_new();
00099 cpl_propertylist* paflist = cpl_propertylist_new();
00100
00101 int slit_width;
00102 int nframes;
00103 int i;
00104
00105
00106 slit_width = naco_parameterlist_get_int(parlist, RECIPE_STRING,
00107 NACO_PARAM_SLIT_W);
00108 bug_if(0);
00109
00110
00111 skip_if (naco_dfs_set_groups(framelist));
00112
00113 allframes = irplib_framelist_cast(framelist);
00114 bug_if(allframes == NULL);
00115
00116 irplib_check(rawframes
00117 = irplib_framelist_extract(allframes, NACO_IMG_SLITPOS_RAW),
00118 "Could not load the raw frames");
00119 irplib_framelist_empty(allframes);
00120
00121 nframes = irplib_framelist_get_size(rawframes);
00122
00123 oneframe = irplib_framelist_new();
00124
00125
00126 for (i=0 ; i < nframes ; i++) {
00127 const char * name;
00128 int slit_length;
00129 double xpos, ypos, angle;
00130 double slit_y0, slit_yn;
00131 double slit_c0, slit_cn;
00132
00133
00134 cpl_msg_info(cpl_func, "Analysing slit of frame %d out of %d", i+1,
00135 nframes);
00136
00137 frame = irplib_framelist_unset(rawframes, 0, NULL);
00138 bug_if(irplib_framelist_set(oneframe, frame, 0));
00139
00140 name = cpl_frame_get_filename(frame);
00141 frame = NULL;
00142 bug_if(name == NULL);
00143
00144 irplib_check(image = cpl_image_load(name, CPL_TYPE_FLOAT, 0, 0),
00145 "Could not load FITS-image");
00146
00147 bug_if(cpl_image_flip(image, 1));
00148
00149 out_table = irplib_slitpos_analysis(image, slit_width, NULL);
00150 cpl_image_delete(image);
00151 image = NULL;
00152 skip_if (out_table == NULL);
00153
00154
00155
00156 slit_length = cpl_table_get_nrow(out_table);
00157
00158 slit_y0 = cpl_table_get(out_table, "SLIT_Y", 0, NULL);
00159 slit_yn = cpl_table_get(out_table, "SLIT_Y", slit_length-1, NULL);
00160 bug_if(0);
00161
00162 slit_c0 = cpl_table_get(out_table, "SLIT_CENTER", 0, NULL);
00163 slit_cn = cpl_table_get(out_table, "SLIT_CENTER", slit_length-1, NULL);
00164 bug_if(0);
00165
00166
00167 angle = 180.0 + CPL_MATH_DEG_RAD * atan2(slit_cn - slit_c0,
00168 slit_yn - slit_y0);
00169
00170
00171 ypos = (slit_c0 + slit_cn)/2.0;
00172 xpos = (slit_y0 + slit_yn)/2.0;
00173
00174
00175 cpl_msg_info(cpl_func, "Slit angle : %g", angle);
00176 cpl_msg_info(cpl_func, "Slit length : %d", slit_length);
00177 cpl_msg_info(cpl_func, "Slit center : %g %g", xpos, ypos);
00178
00179 skip_if(irplib_framelist_load_propertylist_all(oneframe, 0, "^("
00180 NACO_PFITS_REGEXP_SLITPOS "|"
00181 NACO_PFITS_REGEXP_SLITPOS_PAF
00182 ")$", CPL_FALSE));
00183
00184
00185 bug_if(cpl_propertylist_append_double(qclist, "ESO QC SLIT POSANG",
00186 angle));
00187 bug_if(cpl_propertylist_append_double(qclist, "ESO QC SLIT XPOS",
00188 xpos));
00189 bug_if(cpl_propertylist_append_double(qclist, "ESO QC SLIT YPOS",
00190 ypos));
00191
00192 skip_if (naco_img_slitpos_qc(qclist, paflist, oneframe));
00193 skip_if (naco_img_slitpos_save(framelist, parlist, qclist, paflist,
00194 out_table, i+1, oneframe));
00195
00196 cpl_table_delete(out_table);
00197 out_table = NULL;
00198
00199 cpl_propertylist_empty(qclist);
00200 cpl_propertylist_empty(paflist);
00201
00202
00203 irplib_framelist_empty(oneframe);
00204
00205 bug_if(irplib_framelist_get_size(oneframe) != 0);
00206
00207 }
00208
00209 bug_if(irplib_framelist_get_size(rawframes) != 0);
00210
00211 end_skip;
00212
00213 cpl_image_delete(image);
00214 cpl_table_delete(out_table);
00215
00216 irplib_framelist_delete(oneframe);
00217 irplib_framelist_delete(allframes);
00218 irplib_framelist_delete(rawframes);
00219 cpl_propertylist_delete(qclist);
00220 cpl_propertylist_delete(paflist);
00221
00222 cpl_frame_delete(frame);
00223
00224 return cpl_error_get_code();
00225 }
00226
00227
00235
00236 static cpl_error_code naco_img_slitpos_qc(cpl_propertylist * qclist,
00237 cpl_propertylist * paflist,
00238 const irplib_framelist * rawframes)
00239 {
00240
00241 cpl_errorstate cleanstate = cpl_errorstate_get();
00242 const cpl_propertylist * reflist
00243 = irplib_framelist_get_propertylist_const(rawframes, 0);
00244 const char pafcopy[] = "^(" NACO_PFITS_REGEXP_SLITPOS_PAF ")$";
00245 const char * filter;
00246
00247
00248 bug_if (0);
00249
00250 filter = naco_pfits_get_filter(reflist);
00251 if (cpl_error_get_code())
00252 naco_error_reset("Could not get FITS key:");
00253 else
00254 bug_if(cpl_propertylist_append_string(qclist, "ESO QC FILTER OBS",
00255 filter));
00256
00257
00258
00259
00260 bug_if(cpl_propertylist_copy_property_regexp(paflist, reflist, pafcopy, 0));
00261
00262 bug_if(cpl_propertylist_append(paflist, qclist));
00263
00264
00265 end_skip;
00266
00267 return cpl_error_get_code();
00268 }
00269
00270
00282
00283 static cpl_error_code naco_img_slitpos_save(cpl_frameset * set,
00284 const cpl_parameterlist * parlist,
00285 const cpl_propertylist * qclist,
00286 const cpl_propertylist * paflist,
00287 const cpl_table * out_table,
00288 int file_nb,
00289 const irplib_framelist * oneframe)
00290 {
00291
00292 cpl_frameset * rawframes = irplib_frameset_cast(oneframe);
00293 char * filename = NULL;
00294
00295
00296 bug_if (0);
00297
00298
00299 filename = cpl_sprintf(RECIPE_STRING "_%02d" CPL_DFS_FITS, file_nb);
00300 skip_if (irplib_dfs_save_table(set, parlist, rawframes, out_table, NULL,
00301 RECIPE_STRING, NACO_IMG_SLITPOS_RES, qclist, NULL,
00302 naco_pipe_id, filename));
00303
00304 cpl_free(filename);
00305 filename = cpl_sprintf(RECIPE_STRING "_%02d" CPL_DFS_PAF, file_nb);
00306 skip_if (cpl_dfs_save_paf("NACO", RECIPE_STRING, paflist, filename));
00307
00308 end_skip;
00309
00310 cpl_free(filename);
00311 cpl_frameset_delete(rawframes);
00312
00313 return cpl_error_get_code();
00314 }