crires_model_wlmap.c
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 #include "crires_recipe.h"
00037
00038 #include "crires_model_kernel.h"
00039
00040
00041
00042
00043
00044 #define RECIPE_STRING "crires_model_wlmap"
00045
00046
00047
00048
00049
00050 static int crires_model_wlmap_save(const cpl_imagelist *,
00051 const cpl_parameterlist *, cpl_frameset *) ;
00052
00053 static char crires_model_wlmap_description[] =
00054 "crires_model_wlmap -- Wavelength map creation using the model\n"
00055 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00056 "raw-file.fits "CRIRES_MODEL_WLMAP_RAW" or\n"
00057 "config-file.fits "CRIRES_CALPRO_MODEL_CONFIG" or\n"
00058 "config-file.fits "CRIRES_CALPRO_MODEL_REFINE_CONF".\n" ;
00059
00060 CRIRES_RECIPE_DEFINE(crires_model_wlmap,
00061 CRIRES_PARAM_ORDER,
00062 "Model wavelength map recipe",
00063 crires_model_wlmap_description) ;
00064
00065
00066
00067
00068
00069 static struct {
00070
00071 int order ;
00072
00073 crires_illum_period period ;
00074 } crires_model_wlmap_config ;
00075
00076
00077
00078
00079
00080
00087
00088 static int crires_model_wlmap(
00089 cpl_frameset * frameset,
00090 const cpl_parameterlist * parlist)
00091 {
00092 cpl_frameset * rawframes ;
00093 const char * config ;
00094 cpl_frame * ref_frame ;
00095 cpl_imagelist * wlmap ;
00096
00097
00098
00099 if (crires_model_off()) {
00100 return 0 ;
00101 }
00102
00103
00104 rawframes = NULL ;
00105
00106
00107 crires_model_wlmap_config.order = crires_parameterlist_get_int(parlist,
00108 RECIPE_STRING, CRIRES_PARAM_ORDER) ;
00109
00110
00111 if (crires_dfs_set_groups(frameset, "crires_model_wlmap")) {
00112 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00113 return -1 ;
00114 }
00115
00116
00117 config = crires_extract_filename(frameset, CRIRES_CALPRO_MODEL_CONFIG) ;
00118 if (config == NULL) {
00119 config = crires_extract_filename(frameset,
00120 CRIRES_CALPRO_MODEL_REFINE_CONF) ;
00121 }
00122 if (config == NULL) {
00123 cpl_msg_error(__func__, "No config file in input") ;
00124 return -1 ;
00125 }
00126
00127
00128 if ((rawframes = crires_extract_frameset(frameset,
00129 CRIRES_MODEL_WLMAP_RAW)) == NULL) {
00130 cpl_msg_error(__func__, "No raw frame in input") ;
00131 return -1 ;
00132 }
00133 ref_frame = cpl_frameset_get_frame(rawframes, 0) ;
00134
00135
00136 if (crires_model_config_check(config,
00137 cpl_frame_get_filename(ref_frame)) != 0) {
00138 cpl_msg_error(__func__,
00139 "The model configuration file version is wrong") ;
00140 cpl_frameset_delete(rawframes) ;
00141 return -1 ;
00142 }
00143
00144
00145 crires_model_wlmap_config.period =
00146 crires_get_detector_illum_period(cpl_frame_get_filename(ref_frame)) ;
00147 if (crires_model_wlmap_config.period == CRIRES_ILLUM_UNKNOWN) {
00148 cpl_msg_error(__func__,
00149 "Cannot determine the detector illumination period") ;
00150 cpl_frameset_delete(rawframes) ;
00151 return -1 ;
00152 } else {
00153 crires_display_detector_illum(crires_model_wlmap_config.period) ;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 if ((wlmap = crires_model_wavpix(cpl_frame_get_filename(ref_frame),
00181 config, crires_model_wlmap_config.order)) == NULL) {
00182 cpl_msg_error(__func__, "Cannot compute the WL map") ;
00183 cpl_frameset_delete(rawframes) ;
00184 return -1 ;
00185 }
00186 cpl_frameset_delete(rawframes) ;
00187
00188
00189 if (crires_model_wlmap_save(wlmap, parlist, frameset) == -1) {
00190 cpl_msg_error(__func__, "Cannot save products") ;
00191 cpl_imagelist_delete(wlmap) ;
00192 return -1 ;
00193 }
00194 cpl_imagelist_delete(wlmap) ;
00195
00196
00197 if (cpl_error_get_code()) return -1 ;
00198 else return 0 ;
00199 }
00200
00201
00209
00210 static int crires_model_wlmap_save(
00211 const cpl_imagelist * wlmap,
00212 const cpl_parameterlist * parlist,
00213 cpl_frameset * set)
00214 {
00215 const char * recipe_name = "crires_model_wlmap" ;
00216
00217
00218 crires_image_save(set,
00219 parlist,
00220 set,
00221 wlmap,
00222 recipe_name,
00223 CRIRES_WL_MAP_MODEL_IMA,
00224 CRIRES_PROTYPE_WL_MAP,
00225 crires_model_wlmap_config.period,
00226 NULL,
00227 NULL,
00228 PACKAGE "/" PACKAGE_VERSION,
00229 "crires_model_wlmap.fits") ;
00230
00231 return 0;
00232 }