SINFONI Pipeline Reference Manual  2.5.2
sinfo_rec_lingain.c
1 /* $Id: sinfo_rec_lingain.c,v 1.22 2012-03-03 10:38:03 amodigli Exp $
2  *
3  * This file is part of the DETMON Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; 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: 2012-03-03 10:38:03 $
24  * $Revision: 1.22 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*----------------------------------------------------------------------------
33  Includes and Defines
34  ----------------------------------------------------------------------------*/
35 
36 #include <cpl.h>
37 #include "sinfo_irplib_cpl_wrp.h"
38 
39 #include "sinfo_msg.h"
40 #include "sinfo_utils_wrappers.h"
41 #include "sinfo_error.h"
42 
43 /* Define here the DO.CATG keywords */
44 #define SINFO_LINGAIN_ON_RAW "LINEARITY_LAMP_ON"
45 #define SINFO_LINGAIN_OFF_RAW "LINEARITY_LAMP_OFF"
46 
47 #define RECIPE_NAME "sinfo_rec_lingain"
48 
49 /* Copy here instrument specific keywords which need to be in the PAF file */
50 #define INSTREGEXP "ESO INS SETUP ID"
51 
52 #define PAFREGEXP "^(" REGEXP "|" INSTREGEXP ")$"
53 #define NIR TRUE
54 #define SINFO_BPMBIN 1
55 #define SINFO_KAPPA 9
56 
57 
58 /*----------------------------------------------------------------------------
59  Functions prototypes
60  ----------------------------------------------------------------------------*/
61 
63 /*---------------------------------------------------------------------------*/
67 /*---------------------------------------------------------------------------*/
68 
69 cpl_error_code
70 sinfo_lingain_fill_parlist_default(cpl_parameterlist * parlist);
71 
72 CPL_RECIPE_DEFINE(sinfo_rec_lingain, SINFONI_BINARY_VERSION,
73  /* Replace DETMON_BINARY_VERSION with
74  corresponding pipeline macro */
75  sinfo_lingain_fill_parlist_default(recipe->parameters),
76  /* Replace "sinfoni" with PACKAGE_TARNAME
77  when moved into SINFONI */
78  "Lander de Bilbao", "lbilbao@eso.org", "2008",
79  "Linearity/Gain recipe for the IR domain",
80  LG_DESCR(RECIPE_NAME, "SINFONI",
81  SINFO_LINGAIN_ON_RAW,
82  SINFO_LINGAIN_OFF_RAW));
83 
84 /*---------------------------------------------------------------------------*/
85 /*
86  @brief Interpret the command line options and execute the data processing
87  @param frameset the frames list
88  @param parlist the parameters list
89  @return 0 if everything is ok
90  */
91 /*---------------------------------------------------------------------------*/
92 
93 static int sinfo_rec_lingain(cpl_frameset * frameset,
94  const cpl_parameterlist * parlist)
95 {
96  const char* name_o=NULL;
97  cpl_frame* frm=NULL;
98  cpl_image* ima=NULL;
99  cpl_error_code error = CPL_ERROR_NONE;
100  cpl_propertylist* plist=NULL;
101  cpl_propertylist * lintbl;
102  cpl_propertylist * gaintbl;
103  cpl_propertylist * coeffscube;
104  cpl_propertylist * bpm;
105  cpl_propertylist * corr;
106  cpl_propertylist * diff_flat;
107 
108 
109  lintbl = DETMON_FILL_PROLIST("DET_LIN_INFO", "TYPE", "TECH", CPL_TRUE);
110  gaintbl = DETMON_FILL_PROLIST("GAIN_INFO", "TYPE", "TECH", CPL_TRUE);
111  coeffscube = DETMON_FILL_PROLIST("COEFFS_CUBE", "TYPE", "TECH", CPL_TRUE);
112  bpm = DETMON_FILL_PROLIST("BP_MAP_NL", "TYPE", "TECH", CPL_TRUE);
113  corr = DETMON_FILL_PROLIST("AUTOCORR", "TYPE", "TECH", CPL_TRUE);
114  diff_flat = DETMON_FILL_PROLIST("DIFF_FLAT", "TYPE", "TECH", CPL_TRUE);
115 
116  error = DETMON_LG(frameset,
117  parlist,
118  SINFO_LINGAIN_ON_RAW,
119  SINFO_LINGAIN_OFF_RAW,
120  RECIPE_NAME,
121  /* Replace this string ("sinfoni") with */ PACKAGE_TARNAME,
122  /* PACKAGE_TARNAME when moved into SINFONI */ PAFREGEXP,
123  lintbl, gaintbl,
124  coeffscube, bpm,
125  corr, diff_flat,
126  PACKAGE "/" PACKAGE_VERSION,
127  NULL, NULL, NIR);
128  sinfo_free_propertylist(&lintbl);
129  sinfo_free_propertylist(&gaintbl);
130  sinfo_free_propertylist(&coeffscube);
131  sinfo_free_propertylist(&bpm);
132  sinfo_free_propertylist(&corr);
133  sinfo_free_propertylist(&diff_flat);
134 
135  check_nomsg(frm=cpl_frameset_find(frameset,"BP_MAP_NL"));
136  check_nomsg(name_o=cpl_frame_get_filename(frm));
137  check_nomsg(plist=cpl_propertylist_load(name_o,0));
138  check_nomsg(ima=cpl_image_load(name_o,CPL_TYPE_FLOAT,0,0));
139  check_nomsg(cpl_image_threshold(ima,0.1,0.9,1,0));
140  check_nomsg(cpl_image_save(ima,name_o,CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
141 
142  cleanup:
143  sinfo_free_propertylist(&plist);
144  sinfo_free_image(&ima);
145 
146  /* Propagate the error, if any */
147  cpl_ensure_code(!error, error);
148 
149  return CPL_ERROR_NONE;
150 }
151 
152 cpl_error_code
153 sinfo_lingain_fill_parlist_default(cpl_parameterlist * parlist)
154 {
155 
156  cpl_error_code error = CPL_ERROR_NONE;
157  cpl_parameter * p;
158  error = DETMON_LG_FILL_PARLIST_NIR_DEFAULT(parlist,RECIPE_NAME,
159  PACKAGE_TARNAME);
160  cpl_ensure_code(!error, error);
161  p = cpl_parameterlist_find(parlist, PACKAGE_TARNAME "." RECIPE_NAME ".bpmbin");
162  cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
163  error = cpl_parameter_set_default_bool(p, SINFO_BPMBIN);
164  p = cpl_parameterlist_find(parlist, PACKAGE_TARNAME "." RECIPE_NAME ".kappa");
165  cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
166  error = cpl_parameter_set_default_double(p, SINFO_KAPPA);
167  cpl_ensure_code(!error, error);
168  return error;
169 
170 }
171