VISIR Pipeline Reference Manual  4.1.0
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 
52 static cpl_error_code visir_img_trans_save(cpl_frameset *,
53  const cpl_parameterlist *,
54  const cpl_table *);
55 
56 VISIR_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 /*----------------------------------------------------------------------------*/
84 static 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 /*----------------------------------------------------------------------------*/
193 static 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_imagelist * visir_imagelist_load_last(const irplib_framelist *rawframes)
Load the last frame of the input files to an image list.
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:173
cpl_error_code irplib_dfs_save_table(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_table *table, const cpl_propertylist *tablelist, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save a table as a DFS-compliant pipeline product.
Definition: irplib_utils.c:335
cpl_error_code irplib_framelist_load_propertylist_all(irplib_framelist *self, int ind, const char *regexp, cpl_boolean invert)
Load the propertylists of all frames in the framelist.
irplib_framelist * irplib_framelist_extract(const irplib_framelist *self, const char *tag)
Extract the frames with the given tag from a framelist.
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: visir_dfs.c:72
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.