00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036
00037 #include "visir_recipe.h"
00038
00039
00040
00041
00042
00043
00044 #define VISIR_LIMIT_FOR_BAD_PIXELS 32000.0
00045
00046 #define RECIPE_STRING "visir_img_trans"
00047
00048
00049
00050
00051
00052 static cpl_error_code visir_img_trans_save(cpl_frameset *,
00053 const cpl_parameterlist *,
00054 const cpl_table *);
00055
00056 VISIR_RECIPE_DEFINE(visir_img_trans, 0, "Instrument Transmission recipe",
00057 "This recipe computes the transmission at different "
00058 "wavelengths by\n"
00059 "comparing the flux of a bright star for different "
00060 "observations.\n"
00061 "The files listed in the Set Of Frames (sof-file) "
00062 "must be tagged:\n"
00063 "VISIR-transmission-file.fits IM_TEC_TRANS\n"
00064 "The resuts are given in a table.\n");
00065
00066
00070
00071
00072
00073
00074
00075
00076
00083
00084 static int visir_img_trans(cpl_frameset * framelist,
00085 const cpl_parameterlist * parlist)
00086 {
00087 irplib_framelist * allframes = NULL;
00088 irplib_framelist * rawframes = NULL;
00089 cpl_imagelist * loaded = NULL;
00090 double * wls = NULL;
00091 int nfiles;
00092 cpl_table * tab = NULL;
00093 cpl_table * tab2 = NULL;
00094 int i;
00095
00096
00097
00098 skip_if (visir_dfs_set_groups(framelist));
00099
00100
00101 allframes = irplib_framelist_cast(framelist);
00102 skip_if(allframes == NULL);
00103 rawframes = irplib_framelist_extract(allframes, VISIR_IMG_TRANS_RAW);
00104 skip_if (rawframes == NULL);
00105
00106 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0,
00107 visir_property_regexp,
00108 CPL_FALSE));
00109 skip_if(visir_dfs_check_framelist_tag(rawframes));
00110
00111
00112 cpl_msg_info(cpl_func, "Load the input frames");
00113 if ((loaded = visir_imagelist_load_last(rawframes)) == NULL) {
00114 cpl_msg_error(cpl_func, "Could not load the input frames");
00115 skip_if(1);
00116 }
00117
00118 nfiles = cpl_imagelist_get_size(loaded);
00119
00120 skip_if( nfiles <= 0);
00121
00122
00123 for (i=0 ; i < nfiles ; i++) {
00124 cpl_mask * map = cpl_mask_threshold_image_create(
00125 cpl_imagelist_get(loaded, i),
00126 VISIR_LIMIT_FOR_BAD_PIXELS,
00127 DBL_MAX);
00128 if (map == NULL) continue;
00129 cpl_image_reject_from_mask(cpl_imagelist_get(loaded, i), map);
00130 cpl_mask_delete(map);
00131 }
00132
00133 skip_if(0);
00134
00135
00136 cpl_msg_info(cpl_func, "Get the wavelengths from the input headers");
00137 if ((wls = visir_utils_get_wls(rawframes)) == NULL) {
00138 cpl_msg_error(cpl_func, "Could not get wavelengths");
00139 skip_if(1);
00140 }
00141
00142
00143 tab = visir_table_new_xypos(loaded, "FLUX");
00144 skip_if (tab == NULL);
00145
00146 tab2 = cpl_table_new(nfiles);
00147 skip_if (tab2 == NULL);
00148
00149
00150 skip_if (cpl_table_move_column(tab2, "FLUX", tab));
00151
00152 skip_if (cpl_table_wrap_double(tab, wls, "WAVELENGTH"));
00153 wls = NULL;
00154
00155 skip_if (cpl_table_move_column(tab, "FLUX", tab2));
00156
00157
00158 for (i=0; i < nfiles; i++) {
00159 if (cpl_table_get_double(tab, "FLUX", i, NULL) > 0) continue;
00160 skip_if (cpl_table_set_double(tab, "FLUX", i,
00161 cpl_image_get_median(cpl_imagelist_get(loaded, i))));
00162 }
00163
00164
00165 skip_if (cpl_table_divide_scalar(tab, "FLUX",
00166 cpl_table_get_column_max(tab, "FLUX")));
00167
00168
00169 cpl_msg_info(cpl_func, "Save the products");
00170 skip_if (visir_img_trans_save(framelist, parlist, tab));
00171
00172 end_skip;
00173
00174 irplib_framelist_delete(allframes);
00175 irplib_framelist_delete(rawframes);
00176 cpl_free(wls);
00177 cpl_table_delete(tab);
00178 cpl_table_delete(tab2);
00179 cpl_imagelist_delete(loaded);
00180
00181 return cpl_error_get_code();
00182 }
00183
00184
00192
00193 static cpl_error_code visir_img_trans_save(cpl_frameset * set,
00194 const cpl_parameterlist * parlist,
00195 const cpl_table * tab)
00196 {
00197
00198 skip_if(irplib_dfs_save_table(set, parlist, set, tab, NULL, RECIPE_STRING,
00199 VISIR_IMG_TRANS_TAB_PROCATG, NULL, NULL,
00200 visir_pipe_id, RECIPE_STRING CPL_DFS_FITS));
00201
00202 end_skip;
00203
00204 return cpl_error_get_code();
00205
00206 }