IIINSTRUMENT Pipeline Reference Manual 4.6.2
visir_img_trans.c
1/* $Id: visir_img_trans.c,v 1.70 2009-01-29 08:56:58 llundin Exp $
2 *
3 * This file is part of the VISIR 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., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: llundin $
23 * $Date: 2009-01-29 08:56:58 $
24 * $Revision: 1.70 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32
33/*-----------------------------------------------------------------------------
34 Includes
35 -----------------------------------------------------------------------------*/
36
37#include "visir_recipe.h"
38
39/*-----------------------------------------------------------------------------
40 Defines
41 -----------------------------------------------------------------------------*/
42
43/* FIXME: Use VISIR_HCYCLE_BPM_THRESHOLD */
44#define VISIR_LIMIT_FOR_BAD_PIXELS 32000.0
45
46#define RECIPE_STRING "visir_img_trans"
47
48/*-----------------------------------------------------------------------------
49 Private Functions prototypes
50 -----------------------------------------------------------------------------*/
51
52static cpl_error_code visir_img_trans_save(cpl_frameset *,
53 const cpl_parameterlist *,
54 const cpl_table *);
55
56VISIR_RECIPE_DEFINE(visir_img_trans, 0, "Instrument Transmission recipe",
57 "This recipe computes the transmission at different "
58 "wavelengths by\n"
59 "comparing the flux of a bright star for different "
60 "observations.\n"
61 "The files listed in the Set Of Frames (sof-file) "
62 "must be tagged:\n"
63 "VISIR-transmission-file.fits IM_TEC_TRANS\n"
64 "The resuts are given in a table.\n");
65
66/*----------------------------------------------------------------------------*/
70/*----------------------------------------------------------------------------*/
71
72/*-----------------------------------------------------------------------------
73 Functions code
74 -----------------------------------------------------------------------------*/
75
76/*----------------------------------------------------------------------------*/
83/*----------------------------------------------------------------------------*/
84static int visir_img_trans(cpl_frameset * framelist,
85 const cpl_parameterlist * parlist)
86{
87 irplib_framelist * allframes = NULL;
88 irplib_framelist * rawframes = NULL;
89 cpl_imagelist * loaded = NULL;
90 double * wls = NULL;
91 int nfiles;
92 cpl_table * tab = NULL;
93 cpl_table * tab2 = NULL;
94 int i;
95
96
97 /* Identify the RAW and CALIB frames in the input frameset */
98 skip_if (visir_dfs_set_groups(framelist));
99
100 /* Objects observation */
101 allframes = irplib_framelist_cast(framelist);
102 skip_if(allframes == NULL);
103 rawframes = irplib_framelist_extract(allframes, VISIR_IMG_TRANS_RAW);
104 skip_if (rawframes == NULL);
105
106 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0,
107 visir_property_regexp,
108 CPL_FALSE));
109 skip_if(visir_dfs_check_framelist_tag(rawframes));
110
111 /* Load the frames */
112 cpl_msg_info(cpl_func, "Load the input frames");
113 if ((loaded = visir_imagelist_load_last(rawframes)) == NULL) {
114 cpl_msg_error(cpl_func, "Could not load the input frames");
115 skip_if(1);
116 }
117
118 nfiles = cpl_imagelist_get_size(loaded);
119
120 skip_if( nfiles <= 0);
121
122 /* Set the pixels above VISIR_LIMIT_FOR_BAD_PIXELS as bad */
123 for (i=0 ; i < nfiles ; i++) {
124 cpl_mask * map = cpl_mask_threshold_image_create(
125 cpl_imagelist_get(loaded, i),
126 VISIR_LIMIT_FOR_BAD_PIXELS,
127 DBL_MAX);
128 if (map == NULL) continue;
129 cpl_image_reject_from_mask(cpl_imagelist_get(loaded, i), map);
130 cpl_mask_delete(map);
131 }
132
133 skip_if(0);
134
135 /* Get the wavelengths from the headers */
136 cpl_msg_info(cpl_func, "Get the wavelengths from the input headers");
137 if ((wls = visir_utils_get_wls(rawframes)) == NULL) {
138 cpl_msg_error(cpl_func, "Could not get wavelengths");
139 skip_if(1);
140 }
141
142 /* Create the table and fill it with the relevant information */
143 tab = visir_table_new_xypos(loaded, "FLUX");
144 skip_if (tab == NULL);
145
146 tab2 = cpl_table_new(nfiles);
147 skip_if (tab2 == NULL);
148
149 /* FIXME: A better way to do this, if at all necessary ? */
150 skip_if (cpl_table_move_column(tab2, "FLUX", tab));
151
152 skip_if (cpl_table_wrap_double(tab, wls, "WAVELENGTH"));
153 wls = NULL;
154
155 skip_if (cpl_table_move_column(tab, "FLUX", tab2));
156
157 /* FIXME: Verify that this is requested */
158 for (i=0; i < nfiles; i++) {
159 if (cpl_table_get_double(tab, "FLUX", i, NULL) > 0) continue;
160 skip_if (cpl_table_set_double(tab, "FLUX", i,
161 cpl_image_get_median(cpl_imagelist_get(loaded, i))));
162 }
163
164 /* Normalise the FLUX column */
165 skip_if (cpl_table_divide_scalar(tab, "FLUX",
166 cpl_table_get_column_max(tab, "FLUX")));
167
168 /* Save the products */
169 cpl_msg_info(cpl_func, "Save the products");
170 skip_if (visir_img_trans_save(framelist, parlist, tab));
171
172 end_skip;
173
174 irplib_framelist_delete(allframes);
175 irplib_framelist_delete(rawframes);
176 cpl_free(wls);
177 cpl_table_delete(tab);
178 cpl_table_delete(tab2);
179 cpl_imagelist_delete(loaded);
180
181 return cpl_error_get_code();
182}
183
184/*----------------------------------------------------------------------------*/
192/*----------------------------------------------------------------------------*/
193static cpl_error_code visir_img_trans_save(cpl_frameset * set,
194 const cpl_parameterlist * parlist,
195 const cpl_table * tab)
196{
197
198 skip_if(irplib_dfs_save_table(set, parlist, set, tab, NULL, RECIPE_STRING,
199 VISIR_IMG_TRANS_TAB_PROCATG, NULL, NULL,
200 visir_pipe_id, RECIPE_STRING CPL_DFS_FITS));
201
202 end_skip;
203
204 return cpl_error_get_code();
205
206}
cpl_error_code visir_dfs_check_framelist_tag(const irplib_framelist *self)
Check the tags in a frameset (group raw only)
Definition: visir_dfs.c:234
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: visir_dfs.c:72
cpl_imagelist * visir_imagelist_load_last(const irplib_framelist *rawframes)
Load the last frame of the input files to an image list.