SINFONI Pipeline Reference Manual  2.6.0
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 
62 int sinfo_step_distortion_create(cpl_plugin *plugin);
63 int sinfo_step_distortion_exec(cpl_plugin *plugin);
64 int sinfo_step_distortion_destroy(cpl_plugin *plugin);
65 static int sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set);
66 
67 
68 /*---------------------------------------------------------------------------*/
72 /*---------------------------------------------------------------------------*/
73 
74 
75 void sinfo_find_distortion_config_add(cpl_parameterlist *);
76 
77 /*
78  *
79  * Create the recipe instance, i.e. setup the parameter list for this
80  * recipe and make it available to the application using the interface.
81  *
82  */
83 
84 
85 int
86 sinfo_step_distortion_create(cpl_plugin *plugin)
87 {
88 
89  /*
90  * We have to provide the option we accept to the application.
91  * We need to setup our parameter list and hook it into the recipe
92  * interface.
93  */
94  cpl_recipe *recipe = (cpl_recipe *)plugin;
95  recipe->parameters = cpl_parameterlist_new();
96  if(recipe->parameters == NULL) {
97  return 1;
98  }
99  cpl_error_reset();
100  irplib_reset();
101 
102  /*
103  * Fill the parameter list.
104  */
105  sinfo_product_config_add(recipe->parameters);
106  sinfo_prepare_stacked_frames_config_add(recipe->parameters);
107  sinfo_distortion_config_add(recipe->parameters);
108  sinfo_north_south_test_config_add(recipe->parameters);
109 
110  return 0;
111 
112 }
113 
114 int
115 sinfo_step_distortion_exec(cpl_plugin *plugin)
116 {
117 
118  cpl_recipe *recipe = (cpl_recipe *) plugin;
119  if(recipe->parameters == NULL) {
120  return 1;
121  }
122  if(recipe->frames == NULL) {
123  return 1;
124  }
125 
126 
127  return sinfo_step_distortion(recipe->parameters, recipe->frames);
128 
129 }
130 
131 int
132 sinfo_step_distortion_destroy(cpl_plugin *plugin)
133 {
134 
135  cpl_recipe *recipe = (cpl_recipe *) plugin;
136  /*
137  * We just destroy what was created during the plugin initializzation phase
138  * i.e. the parameter list. The frame set is managed by the application which
139  * called us, so that we must not touch it.
140  */
141 
142  cpl_parameterlist_delete(recipe->parameters);
143 
144  return 0;
145 
146 }
147 
148 int
149 cpl_plugin_get_info(cpl_pluginlist *list)
150 {
151 
152  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
153  cpl_plugin *plugin = &recipe->interface;
154 
155 
156  cpl_plugin_init(plugin,
157  CPL_PLUGIN_API,
158  SINFONI_BINARY_VERSION,
159  CPL_PLUGIN_TYPE_RECIPE,
160  "sinfo_step_distortion",
161  "Find Distortions in frames",
162  "TBD",
163  "A. Modigliani",
164  "amodigli@eso.org",
165  "No license",
166  sinfo_step_distortion_create,
167  sinfo_step_distortion_exec,
168  sinfo_step_distortion_destroy);
169 
170  cpl_pluginlist_append(list, plugin);
171 
172  return 0;
173 
174 }
175 
176 
177 /*
178  * The actual recipe actually start here.
179  */
180 
181 static int
182 sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set)
183 {
184 
185 
186  cpl_frame* frame=NULL;
187  char file_name[FILE_NAME_SZ];
188  cpl_propertylist* plist=NULL;
189 
190  cpl_image* ima=NULL;
191  fake* fk=NULL;
192 
193  ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
194 
195  /*
196  ---------------------------------------------------------
197  DISTORTIONS
198  ---------------------------------------------------------
199  */
200 
201 
202  sinfo_msg("COMPUTE DISTORTIONS") ;
203  ck0(sinfo_new_find_distortions(cpl_func,config,set),
204  "COMPUTE DISTORTION FAILED");
205 
206  if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED)) {
207  frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED);
208  strcpy(file_name,cpl_frame_get_filename(frame));
209  } else {
210  sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED);
211  goto cleanup;
212  }
213  ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
214 
215  cknull(plist = cpl_propertylist_load(file_name, 0),
216  "getting header from reference ima frame %s",file_name);
217 
218 
219  if (cpl_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
220  cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
221  } else {
222  cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
223  }
224 
225  sinfo_free_image(&ima);
226  sinfo_free_propertylist(&plist);
227  sinfo_msg("SUCCESS: COMPUTED DISTORTIONS") ;
228 
229  /*
230  ---------------------------------------------------------
231  4th iteration: distort fake frame
232  ---------------------------------------------------------
233  */
234 
235  sinfo_msg("DISTORT FAKE FRAME");
236  fk=sinfo_fake_new();
237 
238  strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
239  fk->frm_switch=1;
240  fk->mask_index=1;
241  fk->ind_index=1;
242  fk->flat_index=0;
243  fk->wfix_index=1;
244  fk->low_rej=0.0;
245  fk->hig_rej=0.0;
246  ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set,
247  PRO_FIBRE_NS_STACKED_DIST, 0,fk),
248  "FAILED STACKING FRAME") ;
249 
250  sinfo_msg("SUCCESS: DISTORTED FAKE FRAME\n") ;
251  sinfo_fake_delete(&fk);
252 
253 
254  if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST)) {
255  frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST);
256  strcpy(file_name,cpl_frame_get_filename(frame));
257  } else {
258  sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED_DIST);
259  goto cleanup;
260  }
261  ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
262 
263  cknull(plist = cpl_propertylist_load(file_name, 0),
264  "getting header from reference ima frame %s",file_name);
265 
266 
267  if (cpl_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
268  cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
269  } else {
270  cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
271  }
272  sinfo_free_propertylist(&plist);
273  sinfo_free_image(&ima);
274  sinfo_msg("SUCCESS: COMPUTED DISTORTIONS\n") ;
275 
276 
277 
278 
279  /*
280  ---------------------------------------------------------
281  NST
282  ---------------------------------------------------------
283  */
284 
285  sinfo_msg("RUN NORD SUD TEST") ;
286  ck0(sinfo_new_nst(cpl_func,config, set ),"NORTH SOUTH TEST FAILED") ;
287  sinfo_msg("SUCCESS: RUNNED NORD SUD TEST") ;
288  sinfo_msg("SUCCESS: RECIPE\n") ;
289 
290 
291  cleanup:
292 
293  sinfo_fake_delete(&fk);
294  sinfo_free_propertylist(&plist) ;
295  sinfo_free_image(&ima);
296 
297  if (cpl_error_get_code() != CPL_ERROR_NONE) {
298  return -1;
299  } else {
300  return 0;
301  }
302 }
303 
void irplib_reset(void)
Reset IRPLIB state.
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.