SINFONI Pipeline Reference Manual  2.5.2
sinfo_step_distortion.c
1 /* $Id: sinfo_step_distortion.c,v 1.20 2008-02-12 14:56:50 amodigli Exp $
2  *
3  * This file is part of the CPL (Common Pipeline Library)
4  * Copyright (C) 2002 European Southern Observatory
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2008-02-12 14:56:50 $
24  * $Revision: 1.20 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 /****************************************************************
29  * Distortion Frames Data Reduction *
30  ****************************************************************/
31 #include <strings.h>
32 #include <string.h>
33 #include <irplib_utils.h>
34 #include <stdio.h>
35 
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39 
40 #include <cpl.h>
41 
42 
43 #include <sinfo_key_names.h>
44 #include <sinfo_globals.h>
45 #include <sinfo_pro_types.h>
46 #include <sinfo_product_config.h>
47 #include <sinfo_prepare_stacked_frames_config.h>
48 #include <sinfo_north_south_test_config.h>
49 
50 #include <sinfo_new_prepare_stacked_frames.h>
51 #include <sinfo_distortion_config.h>
52 #include <sinfo_new_find_distortions.h>
53 #include <sinfo_new_nst.h>
54 #include <sinfo_hidden.h>
55 #include <sinfo_tpl_dfs.h>
56 #include <sinfo_globals.h>
57 #include <sinfo_functions.h>
58 #include <sinfo_tpl_utils.h>
59 #include <sinfo_error.h>
60 #include <sinfo_utils_wrappers.h>
61 //Only for sinfo_propertylist_has
62 #include <sinfo_dfs.h>
63 
64 int sinfo_step_distortion_create(cpl_plugin *plugin);
65 int sinfo_step_distortion_exec(cpl_plugin *plugin);
66 int sinfo_step_distortion_destroy(cpl_plugin *plugin);
67 static int sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set);
68 
69 
70 /*---------------------------------------------------------------------------*/
74 /*---------------------------------------------------------------------------*/
75 
76 
77 void sinfo_find_distortion_config_add(cpl_parameterlist *);
78 
79 /*
80  *
81  * Create the recipe instance, i.e. setup the parameter list for this
82  * recipe and make it available to the application using the interface.
83  *
84  */
85 
86 
87 int
88 sinfo_step_distortion_create(cpl_plugin *plugin)
89 {
90 
91  /*
92  * We have to provide the option we accept to the application.
93  * We need to setup our parameter list and hook it into the recipe
94  * interface.
95  */
96  cpl_recipe *recipe = (cpl_recipe *)plugin;
97  recipe->parameters = cpl_parameterlist_new();
98  if(recipe->parameters == NULL) {
99  return 1;
100  }
101  cpl_error_reset();
102  irplib_reset();
103 
104  /*
105  * Fill the parameter list.
106  */
107  sinfo_product_config_add(recipe->parameters);
108  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
109  sinfo_distortion_config_add(recipe->parameters);
110  sinfo_north_south_test_config_add(recipe->parameters);
111 
112  return 0;
113 
114 }
115 
116 int
117 sinfo_step_distortion_exec(cpl_plugin *plugin)
118 {
119 
120  cpl_recipe *recipe = (cpl_recipe *) plugin;
121  if(recipe->parameters == NULL) {
122  return 1;
123  }
124  if(recipe->frames == NULL) {
125  return 1;
126  }
127 
128 
129  return sinfo_step_distortion(recipe->parameters, recipe->frames);
130 
131 }
132 
133 int
134 sinfo_step_distortion_destroy(cpl_plugin *plugin)
135 {
136 
137  cpl_recipe *recipe = (cpl_recipe *) plugin;
138  /*
139  * We just destroy what was created during the plugin initializzation phase
140  * i.e. the parameter list. The frame set is managed by the application which
141  * called us, so that we must not touch it.
142  */
143 
144  cpl_parameterlist_delete(recipe->parameters);
145 
146  return 0;
147 
148 }
149 
150 int
151 cpl_plugin_get_info(cpl_pluginlist *list)
152 {
153 
154  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
155  cpl_plugin *plugin = &recipe->interface;
156 
157 
158  cpl_plugin_init(plugin,
159  CPL_PLUGIN_API,
160  SINFONI_BINARY_VERSION,
161  CPL_PLUGIN_TYPE_RECIPE,
162  "sinfo_step_distortion",
163  "Find Distortions in frames",
164  "TBD",
165  "A. Modigliani",
166  "amodigli@eso.org",
167  "No license",
168  sinfo_step_distortion_create,
169  sinfo_step_distortion_exec,
170  sinfo_step_distortion_destroy);
171 
172  cpl_pluginlist_append(list, plugin);
173 
174  return 0;
175 
176 }
177 
178 
179 /*
180  * The actual recipe actually start here.
181  */
182 
183 static int
184 sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set)
185 {
186 
187 
188  cpl_frame* frame=NULL;
189  char file_name[FILE_NAME_SZ];
190  cpl_propertylist* plist=NULL;
191 
192  cpl_image* ima=NULL;
193  fake* fk=NULL;
194 
195  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
196 
197  /*
198  ---------------------------------------------------------
199  DISTORTIONS
200  ---------------------------------------------------------
201  */
202 
203 
204  sinfo_msg("COMPUTE DISTORTIONS") ;
205  ck0(sinfo_new_find_distortions(cpl_func,config,set),
206  "COMPUTE DISTORTION FAILED");
207 
208  if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED)) {
209  frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED);
210  strcpy(file_name,cpl_frame_get_filename(frame));
211  } else {
212  sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED);
213  goto cleanup;
214  }
215  ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
216 
217  cknull(plist = cpl_propertylist_load(file_name, 0),
218  "getting header from reference ima frame %s",file_name);
219 
220 
221  if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
222  cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
223  } else {
224  cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
225  }
226 
227  sinfo_free_image(&ima);
228  sinfo_free_propertylist(&plist);
229  sinfo_msg("SUCCESS: COMPUTED DISTORTIONS") ;
230 
231  /*
232  ---------------------------------------------------------
233  4th iteration: distort fake frame
234  ---------------------------------------------------------
235  */
236 
237  sinfo_msg("DISTORT FAKE FRAME");
238  fk=sinfo_fake_new();
239 
240  strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
241  fk->frm_switch=1;
242  fk->mask_index=1;
243  fk->ind_index=1;
244  fk->flat_index=0;
245  fk->wfix_index=1;
246  fk->low_rej=0.0;
247  fk->hig_rej=0.0;
248  ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set,
249  PRO_FIBRE_NS_STACKED_DIST, 0,fk),
250  "FAILED STACKING FRAME") ;
251 
252  sinfo_msg("SUCCESS: DISTORTED FAKE FRAME\n") ;
253  sinfo_fake_delete(&fk);
254 
255 
256  if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST)) {
257  frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST);
258  strcpy(file_name,cpl_frame_get_filename(frame));
259  } else {
260  sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED_DIST);
261  goto cleanup;
262  }
263  ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
264 
265  cknull(plist = cpl_propertylist_load(file_name, 0),
266  "getting header from reference ima frame %s",file_name);
267 
268 
269  if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
270  cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
271  } else {
272  cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
273  }
274  sinfo_free_propertylist(&plist);
275  sinfo_free_image(&ima);
276  sinfo_msg("SUCCESS: COMPUTED DISTORTIONS\n") ;
277 
278 
279 
280 
281  /*
282  ---------------------------------------------------------
283  NST
284  ---------------------------------------------------------
285  */
286 
287  sinfo_msg("RUN NORD SUD TEST") ;
288  ck0(sinfo_new_nst(cpl_func,config, set ),"NORTH SOUTH TEST FAILED") ;
289  sinfo_msg("SUCCESS: RUNNED NORD SUD TEST") ;
290  sinfo_msg("SUCCESS: RECIPE\n") ;
291 
292 
293  cleanup:
294 
295  sinfo_fake_delete(&fk);
296  sinfo_free_propertylist(&plist) ;
297  sinfo_free_image(&ima);
298 
299  if (cpl_error_get_code() != CPL_ERROR_NONE) {
300  return -1;
301  } else {
302  return 0;
303  }
304 }
305