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 #include <string.h>
00036
00037
00038 #include <cpl.h>
00039
00040
00041 #include <irplib_utils.h>
00042
00043 #include <sinfo_tpl_utils.h>
00044 #include <sinfo_pfits.h>
00045 #include <sinfo_tpl_dfs.h>
00046 #include <sinfo_key_names.h>
00047 #include <sinfo_pro_types.h>
00048 #include <sinfo_functions.h>
00049 #include <sinfo_msg.h>
00050 #include <sinfo_error.h>
00051 #include <sinfo_utils_wrappers.h>
00052
00053
00054
00055
00056
00057 static int sinfo_utl_ima_gauss_create(cpl_plugin *) ;
00058 static int sinfo_utl_ima_gauss_exec(cpl_plugin *) ;
00059 static int sinfo_utl_ima_gauss_destroy(cpl_plugin *) ;
00060 static int sinfo_utl_ima_gauss(cpl_parameterlist *, cpl_frameset *) ;
00061
00062
00063
00064
00065
00066 static char sinfo_utl_ima_gauss_description[] =
00067 "This recipe produce an image,\n"
00068 "containing a 2D Gaussian.\n"
00069 "Information on relevant parameters can be found with\n"
00070 "esorex --params sinfo_utl_ima_gauss\n"
00071 "esorex --help sinfo_utl_ima_gauss\n"
00072 "\n";
00073
00074 static char PARAM_NAME_SIZE_X[] = "sinfoni.sinfo_utl_ima_gauss.size_x";
00075 static char PARAM_NAME_SIZE_Y[] = "sinfoni.sinfo_utl_ima_gauss.size_y";
00076 static char PARAM_NAME_FWHM_X[] = "sinfoni.sinfo_utl_ima_gauss.fwhm_x";
00077 static char PARAM_NAME_FWHM_Y[] = "sinfoni.sinfo_utl_ima_gauss.fwhm_y";
00078 static char PARAM_NAME_SIGNAL[] = "sinfoni.sinfo_utl_ima_gauss.total_signal";
00079 static char PARAM_NAME_BKGSIG[] = "sinfoni.sinfo_utl_ima_gauss.bkg_signal";
00080 static char PARAM_NAME_NOISEL[] = "sinfoni.sinfo_utl_ima_gauss.noise_level";
00081
00082 static char RECIPE_NAME[] = "sinfoni.sinfo_utl_ima_gauss";
00083
00084
00085
00086
00087
00091
00092
00094
00102
00103 int cpl_plugin_get_info(cpl_pluginlist * list)
00104 {
00105 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00106 cpl_plugin * plugin = &recipe->interface ;
00107
00108 cpl_plugin_init(plugin,
00109 CPL_PLUGIN_API,
00110 SINFONI_BINARY_VERSION,
00111 CPL_PLUGIN_TYPE_RECIPE,
00112 "sinfo_utl_ima_gauss",
00113 "Produce an image containing 2D Gaussian",
00114 sinfo_utl_ima_gauss_description,
00115 "Konstantin Mirny",
00116 "kmirny@eso.org",
00117 sinfo_get_license(),
00118 sinfo_utl_ima_gauss_create,
00119 sinfo_utl_ima_gauss_exec,
00120 sinfo_utl_ima_gauss_destroy) ;
00121
00122 cpl_pluginlist_append(list, plugin) ;
00123
00124 return 0;
00125 }
00126
00127
00136
00137 static int sinfo_utl_ima_gauss_create(cpl_plugin * plugin)
00138 {
00139 const int SIZE_X_DEFAULT = 1024;
00140 const int SIZE_Y_DEFAULT = 1024;
00141 const int FWHM_X = 100;
00142 const int FWHM_Y = 100;
00143 const double TOTAL_SIGNAL = 10E5;
00144 const double BKG_SIGNAL = 400.;
00145 const double NOISE_VALUE = 20.;
00146
00147 cpl_recipe * recipe ;
00148 cpl_parameter * p ;
00149
00150
00151 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00152 recipe = (cpl_recipe *)plugin ;
00153 else return -1 ;
00154 cpl_error_reset();
00155 irplib_reset();
00156
00157
00158 recipe->parameters = cpl_parameterlist_new() ;
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 p = cpl_parameter_new_value(PARAM_NAME_SIZE_X,
00171 CPL_TYPE_INT, "size X axis", RECIPE_NAME, SIZE_X_DEFAULT) ;
00172 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "size_x") ;
00173 cpl_parameterlist_append(recipe->parameters, p) ;
00174
00175
00176 p = cpl_parameter_new_value(PARAM_NAME_SIZE_Y,
00177 CPL_TYPE_INT, "size Y axis", RECIPE_NAME, SIZE_Y_DEFAULT) ;
00178 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "size_y") ;
00179 cpl_parameterlist_append(recipe->parameters, p) ;
00180
00181
00182 p = cpl_parameter_new_value(PARAM_NAME_FWHM_X,
00183 CPL_TYPE_INT, "FWHM X axis", RECIPE_NAME, FWHM_X) ;
00184 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fwhm_x") ;
00185 cpl_parameterlist_append(recipe->parameters, p) ;
00186
00187
00188 p = cpl_parameter_new_value(PARAM_NAME_FWHM_Y,
00189 CPL_TYPE_INT, "FWHM Y axis", RECIPE_NAME, FWHM_Y) ;
00190 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fwhm_y") ;
00191 cpl_parameterlist_append(recipe->parameters, p) ;
00192
00193
00194 p = cpl_parameter_new_value(PARAM_NAME_SIGNAL,
00195 CPL_TYPE_DOUBLE, "Total signal value", RECIPE_NAME, TOTAL_SIGNAL) ;
00196 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "total_signal") ;
00197 cpl_parameterlist_append(recipe->parameters, p) ;
00198
00199
00200 p = cpl_parameter_new_value(PARAM_NAME_BKGSIG,
00201 CPL_TYPE_DOUBLE, "background signal level", RECIPE_NAME, BKG_SIGNAL) ;
00202 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "bkg_signal") ;
00203 cpl_parameterlist_append(recipe->parameters, p) ;
00204
00205
00206 p = cpl_parameter_new_value(PARAM_NAME_NOISEL,
00207 CPL_TYPE_DOUBLE, "Noise level", RECIPE_NAME, NOISE_VALUE) ;
00208 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "noise_level") ;
00209 cpl_parameterlist_append(recipe->parameters, p) ;
00210
00211 return 0;
00212 }
00213
00214
00220
00221 static int sinfo_utl_ima_gauss_exec(cpl_plugin * plugin)
00222 {
00223 cpl_recipe * recipe ;
00224 int code=0;
00225 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00226
00227
00228 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00229 recipe = (cpl_recipe *)plugin ;
00230 else return -1 ;
00231 cpl_error_reset();
00232 irplib_reset();
00233 code = sinfo_utl_ima_gauss(recipe->parameters, recipe->frames) ;
00234
00235
00236 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00237
00238
00239 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00240 }
00241
00242 return code ;
00243 }
00244
00245
00251
00252 static int sinfo_utl_ima_gauss_destroy(cpl_plugin * plugin)
00253 {
00254 cpl_recipe * recipe ;
00255
00256
00257 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00258 recipe = (cpl_recipe *)plugin ;
00259 else return -1 ;
00260
00261 cpl_parameterlist_delete(recipe->parameters) ;
00262 return 0 ;
00263 }
00264
00265
00272
00273 static int
00274 sinfo_utl_ima_gauss( cpl_parameterlist * parlist,
00275 cpl_frameset * framelist)
00276 {
00277
00278 int iSizeX = 0;
00279 int iSizeY = 0;
00280 int iFWHMX = 0;
00281 int iFWHMY = 0;
00282 double dSignal = 0;
00283 double dBkgSignal = 0;
00284 double dNoiseLvl = 0;
00286
00287 const char * name_o = NULL ;
00288 cpl_parameter * param = NULL ;
00289
00290 cpl_propertylist * plist = NULL ;
00291 cpl_image * imNoise = NULL ;
00292 cpl_image * imGauss = NULL ;
00293 cpl_image * imResult = NULL;
00294 cpl_frame * product_frame = NULL;
00295 const double K = 2.35482;
00296
00297 sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00298 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00299 ck0(sinfo_dfs_set_groups(framelist),"Cannot indentify RAW and CALIB frames");
00300
00301
00302
00303 check_nomsg(param=cpl_parameterlist_find(parlist,
00304 PARAM_NAME_SIZE_X));
00305 check_nomsg(iSizeX=cpl_parameter_get_int(param));
00306
00307
00308 check_nomsg(param=cpl_parameterlist_find(parlist,
00309 PARAM_NAME_SIZE_Y));
00310 check_nomsg(iSizeY=cpl_parameter_get_int(param));
00311
00312
00313 check_nomsg(param=cpl_parameterlist_find(parlist,
00314 PARAM_NAME_FWHM_X));
00315 check_nomsg(iFWHMX=cpl_parameter_get_int(param));
00316
00317
00318 check_nomsg(param=cpl_parameterlist_find(parlist,
00319 PARAM_NAME_FWHM_Y));
00320 check_nomsg(iFWHMY=cpl_parameter_get_int(param));
00321
00322
00323 check_nomsg(param=cpl_parameterlist_find(parlist,
00324 PARAM_NAME_SIGNAL));
00325 check_nomsg(dSignal=cpl_parameter_get_double(param));
00326
00327
00328 check_nomsg(param=cpl_parameterlist_find(parlist,
00329 PARAM_NAME_BKGSIG));
00330 check_nomsg(dBkgSignal=cpl_parameter_get_double(param));
00331
00332
00333 check_nomsg(param=cpl_parameterlist_find(parlist,
00334 PARAM_NAME_NOISEL));
00335 check_nomsg(dNoiseLvl=cpl_parameter_get_double(param));
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 check(plist=cpl_propertylist_new(),"Cannot create a Property List");
00378
00379
00380
00381
00382
00383 check(imNoise = cpl_image_fill_test_create(iSizeX, iSizeY),
00384 "Cannot generate the image") ;
00385 check_nomsg(cpl_image_fill_noise_uniform(imNoise, dBkgSignal - dNoiseLvl, dBkgSignal + dNoiseLvl));
00386 check(imGauss = cpl_image_fill_test_create(iSizeX, iSizeY),
00387 "Cannot generate the image") ;
00388
00389
00390
00391
00392
00393 check(imResult = cpl_image_fill_test_create(iSizeX, iSizeY),
00394 "Cannot generate the image") ;
00395 check_nomsg(cpl_image_fill_gaussian(imGauss, iSizeX/2, iSizeY/2, dSignal, iFWHMX / K, iFWHMY / K));
00396 check(imResult = cpl_image_add_create(imGauss, imNoise), "Cannot generate the image");
00397
00398
00399 name_o = "ima_res.fits" ;
00400
00401
00402 check_nomsg(product_frame = cpl_frame_new());
00403 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00404 check_nomsg(cpl_frame_set_tag(product_frame,"image_gauss" )) ;
00405 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
00406 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00407 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00408 "Error while initialising the product frame") ;
00409
00410
00411 check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00412
00413 check(cpl_dfs_setup_product_header(plist,
00414 product_frame,
00415 framelist,
00416 parlist,
00417 "sinfo_utl_ima_gauss",
00418 "SINFONI",
00419 KEY_VALUE_HPRO_DID,NULL),
00420 "Problem in the product DFS-compliance") ;
00421
00422
00423
00424 check(cpl_image_save(imResult,
00425 name_o,
00426 CPL_BPP_IEEE_FLOAT,
00427 plist,
00428 CPL_IO_DEFAULT),
00429 "Could not save product");
00430
00431
00432 sinfo_free_propertylist(&plist) ;
00433 sinfo_free_image(&imNoise);
00434 sinfo_free_image(&imGauss);
00435 sinfo_free_image(&imResult);
00436
00437 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
00438
00439
00440 cleanup:
00441
00442
00443 sinfo_free_propertylist(&plist) ;
00444
00445
00446
00447 sinfo_free_image(&imNoise) ;
00448
00449 if (cpl_error_get_code()) {
00450 return -1 ;
00451 } else {
00452 return 0 ;
00453 }
00454
00455 }