crires_test_model_compute.c

00001 /* $Id: crires_test_model_compute.c,v 1.3 2009/05/08 09:37:12 yjung Exp $
00002  *
00003  * This file is part of the CRIRES Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: yjung $
00023  * $Date: 2009/05/08 09:37:12 $
00024  * $Revision: 1.3 $
00025  * $Name: crire-2_1_1 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 
00037 #include <cpl.h>
00038 #include <math.h>
00039 
00040 #include "crires_utils.h"
00041 #include "crires_pfits.h"
00042 #include "crires_dfs.h"
00043 #include "crires_model_computation.h"
00044 
00045 /*-----------------------------------------------------------------------------
00046                             Functions prototypes
00047  -----------------------------------------------------------------------------*/
00048 
00049 static int crires_test_model_compute_create(cpl_plugin *) ;
00050 static int crires_test_model_compute_exec(cpl_plugin *) ;
00051 static int crires_test_model_compute_destroy(cpl_plugin *) ;
00052 static int crires_test_model_compute(cpl_parameterlist *, cpl_frameset *) ;
00053 
00054 /*-----------------------------------------------------------------------------
00055                             Static variables
00056  -----------------------------------------------------------------------------*/
00057 
00058 static struct {
00059     int     order_calc_flag ;
00060     int     order_out_flag ;
00061     int     trace_out_flag ;
00062     int     is_out_flag ;
00063     int     back_map_flag ;
00064     int     continuum ;
00065     int     morder ;
00066     double  flux_scale ;
00067     double  spotsize ;
00068 } crires_test_model_compute_config ;
00069 
00070 static char crires_test_model_compute_description[] =
00071 " This recipe uses a specified physical model configuration\n (model-cfg.fits in the sof, see below), to generate a variety of\n simulated datasets. There are three principle tasks that may be\n performed with this recipe:\n1. Generate a 2D simulated image of a calibration emission lamp and\n   write it to the FITS file <chips_out.fits>. Statistics are also\n   written to the ascii file <centres.dat>. The calibration source\n   line list should be a FITS table with two columns: wavelength(nm);\n   relative intensity. This is the line-list.fits wile in the sof (see\n   below).\n2. Generate a wavelength map and write to FITS. This is now superseded\n   by the crires_model_wlmap recipe.\n3. Trace the locus of the spectrum for a given instrument\n   configuration (see the crires_model_profile function above) and\n   write the result to the ascii file <trace.dat>\nThe files listed in the Set Of Frames (sof-file) must be tagged:\n  model-cfg.fits CRIRES_MODEL_CONFIG\n  line-list.fits CRIRES_MODEL_WAVE_EG\n";
00072 
00073 /*-----------------------------------------------------------------------------
00074                                 Functions code
00075  -----------------------------------------------------------------------------*/
00076 
00077 /*----------------------------------------------------------------------------*/
00086 /*----------------------------------------------------------------------------*/
00087 int cpl_plugin_get_info(cpl_pluginlist * list)
00088 {
00089     cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
00090     cpl_plugin  *   plugin = &recipe->interface ;
00091 
00092     cpl_plugin_init(plugin,
00093                     CPL_PLUGIN_API,
00094                     CRIRES_BINARY_VERSION,
00095                     CPL_PLUGIN_TYPE_RECIPE,
00096                     "crires_test_model_compute",
00097                     "Compute detector locations for given wavelength and cfg",
00098                     crires_test_model_compute_description,
00099                     "Paul Bristow",
00100                     "bristowp@eso.org",
00101                     crires_get_license(),
00102                     crires_test_model_compute_create,
00103                     crires_test_model_compute_exec,
00104                     crires_test_model_compute_destroy) ;
00105 
00106     cpl_pluginlist_append(list, plugin) ;
00107     
00108     return 0;
00109 }
00110 
00111 /*----------------------------------------------------------------------------*/
00119 /*----------------------------------------------------------------------------*/
00120 static int crires_test_model_compute_create(cpl_plugin * plugin)
00121 {
00122     cpl_recipe      * recipe ;
00123     cpl_parameter   * p ;
00124 
00125     /* Check that the plugin is part of a valid recipe */
00126     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00127         recipe = (cpl_recipe *)plugin ;
00128     else return -1 ;
00129 
00130     /* Create the parameters list in the cpl_recipe object */
00131     recipe->parameters = cpl_parameterlist_new() ; 
00132 
00133     /* Fill the parameters list */
00134     /* --order_calc */
00135     p = cpl_parameter_new_value("crires.crires_test_model_compute.order_calc", 
00136             CPL_TYPE_BOOL,"order_calc flag","crires.crires_test_model_compute",
00137             FALSE);
00138     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "order_calc") ;
00139     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00140     cpl_parameterlist_append(recipe->parameters, p) ;
00141     /* --order_out */
00142     p = cpl_parameter_new_value("crires.crires_test_model_compute.order_out", 
00143             CPL_TYPE_BOOL,"order_out flag","crires.crires_test_model_compute",FALSE);
00144     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "order_out") ;
00145     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00146     cpl_parameterlist_append(recipe->parameters, p) ;
00147     /* --trace_out */
00148     p = cpl_parameter_new_value("crires.crires_test_model_compute.trace_out", 
00149             CPL_TYPE_BOOL,"trace_out flag","crires.crires_test_model_compute",FALSE);
00150     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "trace_out") ;
00151     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00152     cpl_parameterlist_append(recipe->parameters, p) ;
00153     /* --is_out */
00154     p = cpl_parameter_new_value("crires.crires_test_model_compute.is_out", 
00155             CPL_TYPE_BOOL, "is_out flag", "crires.crires_test_model_compute", FALSE);
00156     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "is_out") ;
00157     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00158     cpl_parameterlist_append(recipe->parameters, p) ;
00159     /* --back_map */
00160     p = cpl_parameter_new_value("crires.crires_test_model_compute.back_map", 
00161             CPL_TYPE_BOOL, "back_map flag","crires.crires_test_model_compute",FALSE);
00162     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "back_map") ;
00163     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00164     cpl_parameterlist_append(recipe->parameters, p) ;
00165     /* --continuum */
00166     p = cpl_parameter_new_value("crires.crires_test_model_compute.continuum", 
00167             CPL_TYPE_INT, "continuum", "crires.crires_test_model_compute", 0);
00168     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "continuum") ;
00169     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00170     cpl_parameterlist_append(recipe->parameters, p) ;
00171     /* --morder */
00172     p = cpl_parameter_new_value("crires.crires_test_model_compute.morder", 
00173             CPL_TYPE_INT, "morder", "crires.crires_test_model_compute", 31);
00174     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "morder") ;
00175     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00176     cpl_parameterlist_append(recipe->parameters, p) ;
00177     /* --flux_scale */
00178     p = cpl_parameter_new_value("crires.crires_test_model_compute.flux_scale", 
00179             CPL_TYPE_DOUBLE, "flux_scale", "crires.crires_test_model_compute",100.0);
00180     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flux_scale") ;
00181     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00182     cpl_parameterlist_append(recipe->parameters, p) ;
00183     /* --spotsize1000 */
00184     p = cpl_parameter_new_value("crires.crires_test_model_compute.spotsize", 
00185             CPL_TYPE_DOUBLE, "spotsize", "crires.crires_test_model_compute", 0.025);
00186     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "spotsize") ;
00187     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00188     cpl_parameterlist_append(recipe->parameters, p) ;
00189  
00190     /* Return */
00191     return 0;
00192 }
00193 
00194 /*----------------------------------------------------------------------------*/
00200 /*----------------------------------------------------------------------------*/
00201 static int crires_test_model_compute_exec(cpl_plugin * plugin)
00202 {
00203     cpl_recipe  *   recipe ;
00204     
00205     /* Get the recipe out of the plugin */
00206     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00207         recipe = (cpl_recipe *)plugin ;
00208     else return -1 ;
00209 
00210     return crires_test_model_compute(recipe->parameters, recipe->frames) ;
00211 }
00212 
00213 /*----------------------------------------------------------------------------*/
00219 /*----------------------------------------------------------------------------*/
00220 static int crires_test_model_compute_destroy(cpl_plugin * plugin)
00221 {
00222     cpl_recipe  *   recipe ;
00223     
00224     /* Get the recipe out of the plugin */
00225     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00226         recipe = (cpl_recipe *)plugin ;
00227     else return -1 ;
00228 
00229     cpl_parameterlist_delete(recipe->parameters) ; 
00230     return 0 ;
00231 }
00232 
00233 /*----------------------------------------------------------------------------*/
00240 /*----------------------------------------------------------------------------*/
00241 static int crires_test_model_compute(
00242         cpl_parameterlist   *   parlist, 
00243         cpl_frameset        *   frameset)
00244 {
00245     cpl_parameter       *   par ;
00246     cpl_frame           *   cri_config ;
00247     cpl_frame           *   wave_eg ;
00248 
00249     /* Retrieve input parameters */
00250     /* order_calc */
00251     par = cpl_parameterlist_find(parlist, 
00252             "crires.crires_test_model_compute.order_calc");
00253     crires_test_model_compute_config.order_calc_flag = cpl_parameter_get_bool(par) ;
00254     /* order_out */
00255     par = cpl_parameterlist_find(parlist, 
00256             "crires.crires_test_model_compute.order_out");
00257     crires_test_model_compute_config.order_out_flag = cpl_parameter_get_bool(par) ;
00258     /* trace_out */
00259     par = cpl_parameterlist_find(parlist, 
00260             "crires.crires_test_model_compute.trace_out");
00261     crires_test_model_compute_config.trace_out_flag = cpl_parameter_get_bool(par) ;
00262     /* is_out */
00263     par = cpl_parameterlist_find(parlist, "crires.crires_test_model_compute.is_out");
00264     crires_test_model_compute_config.is_out_flag = cpl_parameter_get_bool(par) ;
00265     /* back_map */
00266     par = cpl_parameterlist_find(parlist, 
00267             "crires.crires_test_model_compute.back_map");
00268     crires_test_model_compute_config.back_map_flag = cpl_parameter_get_bool(par) ;
00269     /* continuum */
00270     par = cpl_parameterlist_find(parlist, 
00271             "crires.crires_test_model_compute.continuum");
00272     crires_test_model_compute_config.continuum = cpl_parameter_get_int(par) ;
00273     /* morder */
00274     par = cpl_parameterlist_find(parlist, 
00275             "crires.crires_test_model_compute.morder");
00276     crires_test_model_compute_config.morder = cpl_parameter_get_int(par) ;
00277     /* flux_scale */
00278     par = cpl_parameterlist_find(parlist, 
00279             "crires.crires_test_model_compute.flux_scale");
00280     crires_test_model_compute_config.flux_scale = cpl_parameter_get_double(par) ;
00281     /* spotsize */
00282     par = cpl_parameterlist_find(parlist, 
00283             "crires.crires_test_model_compute.spotsize");
00284     crires_test_model_compute_config.spotsize = cpl_parameter_get_double(par) ;
00285 
00286     /* Identify the RAW and CALIB frames in the input frameset */
00287     if (crires_dfs_set_groups(frameset, NULL)) {
00288         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00289         return -1 ;
00290     }
00291  
00292     /* RETRIEVE INPUT DATA */
00293     cri_config  = cpl_frameset_find(frameset, CRIRES_CALPRO_MODEL_CONFIG) ;
00294     wave_eg     = cpl_frameset_find(frameset, CRIRES_CALPRO_MODEL_WAVEEG) ;
00295 
00296     /* Apply the computation here */
00297     if (crires_model_computation(cpl_frame_get_filename(cri_config),
00298                 cpl_frame_get_filename(wave_eg),
00299                 crires_test_model_compute_config.order_calc_flag,
00300                 crires_test_model_compute_config.order_out_flag,
00301                 crires_test_model_compute_config.trace_out_flag,
00302                 crires_test_model_compute_config.is_out_flag,
00303                 crires_test_model_compute_config.back_map_flag,
00304                 crires_test_model_compute_config.continuum,
00305                 crires_test_model_compute_config.morder,
00306                 crires_test_model_compute_config.flux_scale,
00307                 crires_test_model_compute_config.spotsize) == -1) {
00308         cpl_msg_error(__func__, "Failed computing the model") ;
00309         return -1 ;
00310     }
00311     
00312     /* Return */
00313     if (cpl_error_get_code()) 
00314         return -1 ;
00315     else 
00316         return 0 ;
00317 }
00318 

Generated on 22 Mar 2011 for CRIRES Pipeline Reference Manual by  doxygen 1.6.1