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 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00032 #include "omega_recipe.h"
00033
00034
00056
00057
00058
00059
00060 static int omega_shutter_create(cpl_plugin *);
00061 static int omega_shutter_exec(cpl_plugin *);
00062 static int omega_shutter_destroy(cpl_plugin *);
00063 static int omega_shutter(cpl_frameset *, cpl_parameterlist *);
00064
00065
00066
00067
00068
00069 int omega_shutter_combine(cpl_parameterlist *pars, int xn);
00070 int omega_shutter_biassubtract(cpl_parameterlist *pars, int xn);
00071 static void omega_shutter_init(void);
00072 static void omega_shutter_tidy(void);
00073 static cpl_error_code omega_shutter_basicsteps(cpl_frameset * frameset,
00074 cpl_image * mbias, cpl_imagelist * ilist_shortexp_up,
00075 float exptime_lower, float exptime_upper,
00076 const char * direction, int extension);
00077 static cpl_matrix * omega_fill_ccdlayout(void);
00078 static cpl_error_code omega_average_ccd_table(cpl_imagelist * ilist_in,
00079 cpl_table * table_out );
00080 static cpl_error_code omega_table_insert_xcoordinates(cpl_table * table);
00081 static float omega_get_exptime_limit(cpl_frameset * frameset);
00082
00083
00084
00085
00086
00087 static struct {
00088
00089 int oc;
00090 }omega_shutter_config;
00091
00092
00093 static struct {
00094
00095 cpl_size *labels;
00096 const cpl_frame *mbframe;
00097 cpl_frameset *domelist;
00098 }ps;
00099
00100
00101
00102
00103
00104
00105 #define RECIPE "omega_shutter"
00106
00107 static char omega_shutter_man[] =
00108
00109 "This recipe tests illumination variations due to inhomogeneities "
00110 "in the \nshutter blade speed.\n"
00111 "\n"
00112 "Input files:\n\n"
00113 " DO category: Type: Explanation: Required: \n"
00114 " DOME_SHUTTERTEST Raw Domeflat Y \n"
00115 " and \n"
00116 " MASTER_BIAS Raw Master bias Y \n\n"
00117 "Output files:\n\n"
00118 " DO category: Data type: Explanation: \n"
00119 " SHUTTER_DOWN Products: Collapsed CCD array \n"
00120 " and \n"
00121 " SHUTTER_UP Products: Collapsed CCD array \n\n";
00122
00123 #define omega_shutter_exit(message) \
00124 { \
00125 if (message) cpl_msg_error(cpl_func, message); \
00126 cpl_imagelist_delete(ilist_shortexp_up); \
00127 cpl_imagelist_delete(ilist_longexp_up); \
00128 cpl_imagelist_delete(ilist_shortexp_down); \
00129 cpl_imagelist_delete(ilist_longexp_down); \
00130 cpl_imagelist_delete(ilist_up); \
00131 cpl_imagelist_delete(ilist_down); \
00132 cpl_image_delete(mbias); \
00133 cpl_table_delete(table_up); \
00134 cpl_table_delete(table_down); \
00135 cpl_propertylist_delete(plistHeader); \
00136 cpl_msg_indent_less(); \
00137 return -1; \
00138 }
00139
00140 #define omega_average_ccd_table_exit(message) \
00141 { \
00142 if (message) cpl_msg_error(cpl_func, message); \
00143 cpl_matrix_delete(ccd_mapping); \
00144 cpl_imagelist_delete(ilist_tmp); \
00145 cpl_image_delete(image_tmp); \
00146 cpl_image_delete(image_collapsed); \
00147 cpl_table_delete(table_local); \
00148 cpl_msg_indent_less(); \
00149 return cpl_error_set(cpl_func, cpl_error_get_code()); \
00150 }
00151
00152 #define omega_shutter_basicsteps_exit(message) \
00153 { \
00154 if (message) cpl_msg_error(cpl_func, message); \
00155 cpl_propertylist_delete(plist); \
00156 cpl_image_delete(image_local); \
00157 cpl_image_delete(image_local_collapsed); \
00158 cpl_free(direction_local); \
00159 cpl_msg_indent_less(); \
00160 return cpl_error_set(cpl_func, cpl_error_get_code()); \
00161 }
00162
00163
00171
00172 int cpl_plugin_get_info(cpl_pluginlist * list)
00173 {
00174 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00175 cpl_plugin * plugin = &recipe->interface ;
00176
00177 if (cpl_plugin_init(plugin,
00178 CPL_PLUGIN_API,
00179 OMEGA_BINARY_VERSION,
00180 CPL_PLUGIN_TYPE_RECIPE,
00181 "omega_shutter",
00182 "OMEGA - Test the shutter homogeneity",
00183 omega_shutter_man,
00184 "Armin Gabasch",
00185 PACKAGE_BUGREPORT,
00186 omega_get_license(),
00187 omega_shutter_create,
00188 omega_shutter_exec,
00189 omega_shutter_destroy)) {
00190 cpl_msg_error(cpl_func, "Plugin initialization failed");
00191 (void)cpl_error_set_where(cpl_func);
00192 return 1;
00193 }
00194
00195 if (cpl_pluginlist_append(list, plugin)) {
00196 cpl_msg_error(cpl_func, "Error adding plugin to list");
00197 (void)cpl_error_set_where(cpl_func);
00198 return 1;
00199 }
00200
00201 return 0;
00202 }
00203
00204
00213
00214 static int omega_shutter_create(cpl_plugin * plugin)
00215 {
00216 cpl_recipe * recipe;
00217 cpl_parameter * p ;
00218
00219
00220 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00221 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00222 cpl_func, __LINE__, cpl_error_get_where());
00223 return (int)cpl_error_get_code();
00224 }
00225
00226 if (plugin == NULL) {
00227 cpl_msg_error(cpl_func, "Null plugin");
00228 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00229 }
00230
00231
00232 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00233 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00234 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00235 }
00236
00237
00238 recipe = (cpl_recipe *)plugin;
00239
00240
00241 recipe->parameters = cpl_parameterlist_new() ;
00242
00243 if (recipe->parameters == NULL) {
00244 cpl_msg_error(cpl_func, "Parameter list allocation failed");
00245 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
00246 }
00247
00248
00249
00250
00251
00252
00253 p = cpl_parameter_new_range("omega.omega_shutter.OverscanMethod",
00254 CPL_TYPE_INT,
00255 "Overscan Correction Method",
00256 "omega_shutter",
00257 0, 0, 6);
00258 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"oc-meth") ;
00259 cpl_parameterlist_append(recipe->parameters, p) ;
00260
00261 p = cpl_parameter_new_value("omega.omega_shutter.ExtensionNumber",
00262 CPL_TYPE_INT,
00263 "DUMMY parameter to ensure Paranal DFS compatibility!!",
00264 "omega_shutter",
00265 -1) ;
00266
00267 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ext") ;
00268 cpl_parameterlist_append(recipe->parameters, p) ;
00269
00270
00271
00272 return 0;
00273 }
00274
00275
00281
00282 static int omega_shutter_exec(cpl_plugin * plugin)
00283 {
00284 cpl_recipe * recipe;
00285 int recipe_status;
00286 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00287
00288
00289 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00290 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00291 cpl_func, __LINE__, cpl_error_get_where());
00292 return (int)cpl_error_get_code();
00293 }
00294
00295 if (plugin == NULL) {
00296 cpl_msg_error(cpl_func, "Null plugin");
00297 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00298 }
00299
00300
00301 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00302 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00303 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00304 }
00305
00306
00307 recipe = (cpl_recipe *)plugin;
00308
00309
00310 if (recipe->parameters == NULL) {
00311 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
00312 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00313 }
00314 if (recipe->frames == NULL) {
00315 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
00316 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00317 }
00318
00319
00320 recipe_status = omega_shutter(recipe->frames, recipe->parameters);
00321
00322
00323 if (cpl_dfs_update_product_header(recipe->frames)) {
00324 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
00325 }
00326
00327 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00328
00329
00330 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00331 }
00332
00333 return recipe_status;
00334
00335 }
00336
00337
00343
00344 static int omega_shutter_destroy(cpl_plugin * plugin)
00345 {
00346 cpl_recipe *recipe;
00347
00348 if (plugin == NULL) {
00349 cpl_msg_error(cpl_func, "Null plugin");
00350 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00351 }
00352
00353
00354 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00355 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00356 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00357 }
00358
00359
00360 recipe = (cpl_recipe *)plugin;
00361
00362 cpl_parameterlist_delete(recipe->parameters);
00363
00364 return 0 ;
00365 }
00366
00367 static int omega_shutter(cpl_frameset *set, cpl_parameterlist *pars)
00368 {
00369
00370 int j=0,jst=0,jfn=0;
00371 cpl_size nlab=0;
00372 int nflats = 0;
00373 int oscan1 = 0;
00374 cpl_parameter *par =NULL;
00375 cpl_imagelist * ilist_shortexp_up =NULL;
00376 cpl_imagelist * ilist_longexp_up =NULL;
00377 cpl_imagelist * ilist_shortexp_down =NULL;
00378 cpl_imagelist * ilist_longexp_down =NULL;
00379 cpl_imagelist * ilist_up =NULL;
00380 cpl_imagelist * ilist_down =NULL;
00381 cpl_image * mbias=NULL;
00382 cpl_table * table_up=NULL;
00383 cpl_table * table_down=NULL;
00384 cpl_propertylist * plistHeader=NULL;
00385 float shutter_explimit=0.;
00386
00387
00388
00389
00390 if (!pars) {
00391 cpl_msg_error (cpl_func, "Parameters list not found");
00392 return -1;
00393 }
00394
00395 if (cpl_frameset_is_empty(set) == 1) {
00396 cpl_msg_error (cpl_func, "Frameset not found");
00397 return -1;
00398 }
00399
00400
00401 par = cpl_parameterlist_find(pars, "omega.omega_shutter.OverscanMethod") ;
00402 omega_shutter_config.oc = cpl_parameter_get_int(par) ;
00403
00404
00405 if (oc_dfs_set_groups(set)) {
00406 cpl_msg_error(cpl_func, "Cannot identify RAW and CALIB frames") ;
00407 return -1 ;
00408 }
00409
00410
00411 omega_shutter_init();
00412
00413
00414 if ((ps.labels = cpl_frameset_labelise(set,omega_compare_tags,
00415 &nlab)) == NULL) {
00416 cpl_msg_error(cpl_func,"Cannot labelise the input frameset");
00417 omega_shutter_tidy();
00418 return -1;
00419 }
00420 if ((ps.domelist = omega_frameset_subgroup(set,ps.labels,nlab,
00421 SHUTTER_RAW)) == NULL) {
00422 cpl_msg_error(cpl_func,"Cannot find dome frames in input frameset");
00423 omega_shutter_tidy();
00424 return -1;
00425 }
00426
00427 nflats = cpl_frameset_count_tags(ps.domelist, SHUTTER_RAW);
00428 if (nflats < 4) {
00429 cpl_msg_error (cpl_func, "Need at least 4 (%s) frames to run "
00430 "this recipe", SHUTTER_RAW);
00431 omega_shutter_tidy();
00432 return -1;
00433 }
00434
00435 cpl_msg_info (cpl_func,"There are %d %s in frame set",nflats, SHUTTER_RAW);
00436
00437
00438
00439 ps.mbframe = cpl_frameset_find_const(set, OMEGA_CALIB_BIAS);
00440 if (ps.mbframe == NULL) {
00441 cpl_msg_error (cpl_func, "Need at least 1 (%s) frames to run "
00442 "this recipe", OMEGA_CALIB_BIAS);
00443 omega_shutter_tidy();
00444 return -1;
00445 }
00446 else{
00447 cpl_msg_info(cpl_func,"Using %s %s",OMEGA_CALIB_BIAS,
00448 cpl_frame_get_filename(ps.mbframe));
00449 }
00450
00451
00452
00453 jst=1;
00454 jfn=32;
00455
00456
00457 ilist_shortexp_up =cpl_imagelist_new();
00458 ilist_longexp_up =cpl_imagelist_new();
00459 ilist_shortexp_down =cpl_imagelist_new();
00460 ilist_longexp_down =cpl_imagelist_new();
00461
00462 shutter_explimit=omega_get_exptime_limit(ps.domelist);
00463 cpl_msg_info(cpl_func, "Limit to discriminate long and short exposures:"
00464 " %f second",shutter_explimit);
00465
00466 for (j = jst; j <= jfn; j++) {
00467 cpl_msg_info(cpl_func,"Beginning work on extension %02d",j);
00468 cpl_msg_indent_more();
00469
00470
00471 if(ps.mbframe != NULL){
00472 oscan1 = omega_pfits_get_overscan(ps.mbframe, j);
00473 if(oscan1 != omega_shutter_config.oc) {
00474 cpl_msg_warning (cpl_func, "Overscan correction mode for Master"
00475 " Bias (oc = %d) differs from the one used here "
00476 "(oc = %d)", oscan1, omega_shutter_config.oc);
00477 }
00478 }
00479
00480
00481 mbias = cpl_image_load(cpl_frame_get_filename(ps.mbframe),
00482 CPL_TYPE_FLOAT,0,j);
00483 if(mbias==NULL){
00484 cpl_msg_error (cpl_func, "Unable to load extension %d of the master"
00485 " bias file %s", j, cpl_frame_get_filename(ps.mbframe));
00486 omega_shutter_tidy();
00487 omega_shutter_exit(NULL);
00488 }
00489
00490
00491
00492 if(omega_shutter_basicsteps(ps.domelist, mbias, ilist_shortexp_up ,
00493 FLT_MIN , shutter_explimit, "up" ,j) != CPL_ERROR_NONE) {
00494 cpl_msg_error (cpl_func, "Unable to perform basic image calibration"
00495 " on extension %d ", j);
00496 omega_shutter_tidy();
00497 omega_shutter_exit(NULL);
00498 }
00499
00500 if(omega_shutter_basicsteps(ps.domelist, mbias, ilist_longexp_up ,
00501 shutter_explimit, FLT_MAX , "up" ,j) != CPL_ERROR_NONE){
00502 cpl_msg_error (cpl_func, "Unable to perform basic image calibration"
00503 " on extension %d ", j);
00504 omega_shutter_tidy();
00505 omega_shutter_exit(NULL);
00506 }
00507
00508 if(omega_shutter_basicsteps(ps.domelist, mbias, ilist_shortexp_down,
00509 FLT_MIN , shutter_explimit, "down",j)!= CPL_ERROR_NONE){
00510 cpl_msg_error (cpl_func, "Unable to perform basic image calibration"
00511 " on extension %d ", j);
00512 omega_shutter_tidy();
00513 omega_shutter_exit(NULL);
00514 }
00515
00516 if(omega_shutter_basicsteps(ps.domelist, mbias, ilist_longexp_down ,
00517 shutter_explimit, FLT_MAX , "down",j)!= CPL_ERROR_NONE){
00518 cpl_msg_error (cpl_func, "Unable to perform basic image calibration"
00519 " on extension %d ", j);
00520 omega_shutter_tidy();
00521 omega_shutter_exit(NULL);
00522 }
00523
00524 cpl_image_delete(mbias); mbias=NULL;
00525 cpl_msg_indent_less();
00526 }
00527
00528
00529
00530 cpl_msg_info(cpl_func,"Dividing long exposures through short exposures");
00531
00532 if(cpl_imagelist_divide(ilist_shortexp_up,ilist_longexp_up)!=
00533 CPL_ERROR_NONE){
00534 omega_shutter_tidy();
00535 omega_shutter_exit("Can not divide long exposure through short exposure");
00536 }
00537
00538 if(cpl_imagelist_divide(ilist_shortexp_down,ilist_longexp_down)!=
00539 CPL_ERROR_NONE){
00540 omega_shutter_tidy();
00541 omega_shutter_exit("Can not divide long exposure through short exposure");
00542 }
00543
00544
00545 ilist_up=cpl_imagelist_new();
00546 ilist_down=cpl_imagelist_new();
00547 table_up=cpl_table_new(0);
00548 table_down=cpl_table_new(0);
00549
00550 cpl_table_new_column(table_up,"RowAveraged",CPL_TYPE_FLOAT);
00551 cpl_table_new_column(table_down,"RowAveraged",CPL_TYPE_FLOAT);
00552
00553
00554 cpl_msg_info(cpl_func,"Final average-collapsing the full CCD array in "
00555 "y-direction");
00556
00557 if(omega_average_ccd_table(ilist_shortexp_up, table_up)!= CPL_ERROR_NONE){
00558 omega_shutter_tidy();
00559 omega_shutter_exit("Can not collapse CCD array in y-direction");
00560 }
00561
00562 if(omega_average_ccd_table(ilist_shortexp_down, table_down)!=CPL_ERROR_NONE){
00563 omega_shutter_tidy();
00564 omega_shutter_exit("Can not collapse CCD array in y-direction");
00565 }
00566
00567 if(omega_table_insert_xcoordinates(table_up)!= CPL_ERROR_NONE ||
00568 omega_table_insert_xcoordinates(table_down)!= CPL_ERROR_NONE){
00569 omega_shutter_tidy();
00570 omega_shutter_exit("Can not insert x-coordinates in the product table");
00571 }
00572
00573
00574 plistHeader=cpl_propertylist_new();
00575 cpl_propertylist_append_string(plistHeader, CPL_DFS_PRO_CATG, "SHUTTER_UP");
00576
00577 if(cpl_dfs_save_table(set, NULL, pars, set, NULL, table_up, NULL,
00578 "omega_shutter", plistHeader, NULL, PACKAGE "/" PACKAGE_VERSION ,
00579 "omega_shutter_up.fits") != CPL_ERROR_NONE){
00580 omega_shutter_tidy();
00581 omega_shutter_exit("Can not save the product SHUTTER_UP");
00582 }
00583
00584 cpl_propertylist_update_string(plistHeader, CPL_DFS_PRO_CATG, "SHUTTER_DOWN");
00585 if (cpl_dfs_save_table(set, NULL, pars, set, NULL, table_down, NULL,
00586 "omega_shutter", plistHeader, NULL, PACKAGE "/" PACKAGE_VERSION ,
00587 "omega_shutter_down.fits")!=CPL_ERROR_NONE){
00588 omega_shutter_tidy();
00589 omega_shutter_exit("Can not save the product SHUTTER_DOWN");
00590 }
00591 cpl_propertylist_delete(plistHeader); plistHeader=NULL;
00592
00593
00594 cpl_imagelist_delete(ilist_shortexp_up); ilist_shortexp_up=NULL;
00595 cpl_imagelist_delete(ilist_longexp_up); ilist_longexp_up=NULL;
00596 cpl_imagelist_delete(ilist_shortexp_down); ilist_shortexp_down=NULL;
00597 cpl_imagelist_delete(ilist_longexp_down); ilist_longexp_down=NULL;
00598 cpl_imagelist_delete(ilist_up); ilist_up=NULL;
00599 cpl_imagelist_delete(ilist_down); ilist_down=NULL;
00600 cpl_table_delete(table_up); table_up=NULL;
00601 cpl_table_delete(table_down); table_down=NULL;
00602 omega_shutter_tidy();
00603
00604 return 0;
00605 }
00606
00616 static cpl_error_code omega_average_ccd_table(cpl_imagelist * ilist_in,
00617 cpl_table * table_out ){
00618
00619 cpl_matrix * ccd_mapping=NULL;
00620 cpl_imagelist * ilist_tmp=NULL;
00621 cpl_image * image_tmp=NULL;
00622 cpl_image * image_collapsed=NULL;
00623 cpl_table * table_local=NULL;;
00624 int nrow=0, ncol=0, row=0, col=0;
00625 int ccd_index=0;
00626 cpl_errorstate prestate=cpl_errorstate_get();
00627
00628 ccd_mapping=omega_fill_ccdlayout();
00629
00630 if (!cpl_errorstate_is_equal(prestate)){
00631 omega_average_ccd_table_exit(NULL);
00632 }
00633
00634 nrow=cpl_matrix_get_nrow(ccd_mapping);
00635 ncol=cpl_matrix_get_ncol(ccd_mapping);
00636 if (!cpl_errorstate_is_equal(prestate)){
00637 omega_average_ccd_table_exit(NULL);
00638 }
00639
00640 for (col=0; col<ncol;col++){
00641 cpl_msg_debug(cpl_func,"working on column: %d", col);
00642 cpl_msg_indent_more();
00643 ilist_tmp=cpl_imagelist_new();
00644 for (row=0; row<nrow;row++){
00645 cpl_msg_debug(cpl_func,"working on row: %d", row);
00646 ccd_index=cpl_matrix_get(ccd_mapping,row,col)-1;
00647 cpl_msg_debug(cpl_func,"fits file extension: %d", ccd_index+1);
00648 image_tmp=cpl_image_duplicate(cpl_imagelist_get(ilist_in,ccd_index));
00649 cpl_imagelist_set(ilist_tmp,image_tmp,row);
00650 }
00651 if (!cpl_errorstate_is_equal(prestate)){
00652 omega_average_ccd_table_exit(NULL);
00653 }
00654
00655 image_collapsed=cpl_imagelist_collapse_create(ilist_tmp);
00656 if (!cpl_errorstate_is_equal(prestate)){
00657 omega_average_ccd_table_exit(NULL);
00658 }
00659 table_local=cpl_table_new(cpl_image_get_size_x(image_collapsed));
00660 cpl_table_new_column(table_local,"RowAveraged",CPL_TYPE_FLOAT);
00661 cpl_table_copy_data_float(table_local,"RowAveraged",
00662 cpl_image_get_data_float(image_collapsed));
00663 if (!cpl_errorstate_is_equal(prestate)){
00664 omega_average_ccd_table_exit(NULL);
00665 }
00666
00667 cpl_table_insert(table_out, table_local, cpl_table_get_nrow(table_out));
00668 cpl_table_delete(table_local); table_local=NULL;
00669 cpl_image_delete(image_collapsed); image_collapsed=NULL;
00670 cpl_imagelist_delete(ilist_tmp); ilist_tmp=NULL;
00671 cpl_msg_indent_less();
00672 }
00673
00674 cpl_matrix_delete(ccd_mapping); ccd_mapping=NULL;
00675
00676
00677 return cpl_error_set(cpl_func, cpl_error_get_code());
00678
00679 }
00680
00681
00689 static cpl_matrix * omega_fill_ccdlayout(void){
00690 cpl_matrix * ccd=NULL;
00691
00692
00693 ccd=cpl_matrix_new(4,8);
00694
00695 cpl_matrix_set(ccd,0,0 ,1 );
00696 cpl_matrix_set(ccd,0,1 ,2 );
00697 cpl_matrix_set(ccd,0,2 ,3 );
00698 cpl_matrix_set(ccd,0,3 ,4 );
00699 cpl_matrix_set(ccd,0,4 ,17);
00700 cpl_matrix_set(ccd,0,5 ,18);
00701 cpl_matrix_set(ccd,0,6 ,19);
00702 cpl_matrix_set(ccd,0,7 ,20);
00703
00704 cpl_matrix_set(ccd,1,0 ,5 );
00705 cpl_matrix_set(ccd,1,1 ,6 );
00706 cpl_matrix_set(ccd,1,2 ,7 );
00707 cpl_matrix_set(ccd,1,3 ,8 );
00708 cpl_matrix_set(ccd,1,4 ,21);
00709 cpl_matrix_set(ccd,1,5 ,22);
00710 cpl_matrix_set(ccd,1,6 ,23);
00711 cpl_matrix_set(ccd,1,7 ,24);
00712
00713 cpl_matrix_set(ccd,2,0 ,9);
00714 cpl_matrix_set(ccd,2,1 ,10);
00715 cpl_matrix_set(ccd,2,2 ,11);
00716 cpl_matrix_set(ccd,2,3 ,12);
00717 cpl_matrix_set(ccd,2,4 ,25);
00718 cpl_matrix_set(ccd,2,5 ,26);
00719 cpl_matrix_set(ccd,2,6 ,27);
00720 cpl_matrix_set(ccd,2,7 ,28);
00721
00722
00723 cpl_matrix_set(ccd,3,0 ,13);
00724 cpl_matrix_set(ccd,3,1 ,14);
00725 cpl_matrix_set(ccd,3,2 ,15);
00726 cpl_matrix_set(ccd,3,3 ,16);
00727 cpl_matrix_set(ccd,3,4 ,29);
00728 cpl_matrix_set(ccd,3,5 ,30);
00729 cpl_matrix_set(ccd,3,6 ,31);
00730 cpl_matrix_set(ccd,3,7 ,32);
00731
00732 return ccd;
00733 }
00734
00751 static cpl_error_code omega_shutter_basicsteps(cpl_frameset * frameset,
00752 cpl_image * mbias, cpl_imagelist * ilist, float exptime_lower,
00753 float exptime_upper, const char * direction, int extension)
00754 {
00755 char * direction_local=NULL;
00756 double local_TMOPEN=0.;
00757 float exptime_local=0;
00758 cpl_propertylist * plist=NULL;
00759 cpl_image * image_local=NULL;
00760 cpl_image * image_local_collapsed=NULL;
00761 cpl_frame * cur_frame=NULL;
00762 cpl_errorstate prestate = cpl_errorstate_get();
00763
00764 cur_frame=cpl_frameset_get_first(frameset);
00765
00766
00767 while(cur_frame)
00768 {
00769 cpl_free(direction_local); direction_local=NULL;
00770 plist=cpl_propertylist_load(cpl_frame_get_filename(cur_frame),0);
00771 local_TMOPEN=cpl_propertylist_get_double(plist,
00772 "ESO DET SHUT TMOPEN");
00773 if(cpl_error_get_code() != CPL_ERROR_NONE)
00774 {
00775 omega_shutter_basicsteps_exit("Missing keyword "
00776 "ESO DET SHUT TMOPEN in scientific header");
00777 }
00778 cpl_msg_debug(cpl_func, "ESO DET SHUT TMOPEN: %g", local_TMOPEN);
00779 if(local_TMOPEN>0.){
00780 direction_local= cpl_sprintf("up");
00781 }
00782 else {
00783 direction_local= cpl_sprintf("down");
00784 }
00785
00786 exptime_local=cpl_propertylist_get_float(plist, "EXPTIME");
00787
00788 if ((cpl_error_get_code() != CPL_ERROR_NONE) || (exptime_local <=0)){
00789 cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT);
00790 omega_shutter_basicsteps_exit("Missing keyword "
00791 "EXPTIME in scientific header or EXPTIME <= ZERO");
00792 }
00793
00794 if(strcmp(direction_local,direction)==0 && exptime_local >exptime_lower
00795 && exptime_local <=exptime_upper)
00796 {
00797 cpl_msg_debug(cpl_func, "Loop: ESO DET SHUT TMOPEN: %g", local_TMOPEN);
00798 cpl_msg_debug(cpl_func, "Loop: direction_local: %s", direction_local);
00799 cpl_msg_debug(cpl_func, "Loop: direction: %s", direction);
00800
00801 cpl_msg_info(cpl_func,"Trimming and overscan correcting");
00802
00803 image_local=TrimOscanCorrect(cur_frame, omega_shutter_config.oc,
00804 extension);
00805
00806 if(image_local==NULL){
00807 omega_shutter_basicsteps_exit("Can not trim and correct the "
00808 "overscan ");
00809 }
00810
00811
00812 cpl_msg_info(cpl_func,"Subtracting the bias");
00813 cpl_image_subtract(image_local,mbias);
00814 if (!cpl_errorstate_is_equal(prestate)){
00815 omega_shutter_basicsteps_exit("Can not subtract the bias");
00816 }
00817
00818
00819 cpl_msg_info(cpl_func,"Median collapsing in y-direction");
00820 image_local_collapsed=cpl_image_collapse_median_create(
00821 image_local, 0, 0, 0);
00822 if (!cpl_errorstate_is_equal(prestate)){
00823 omega_shutter_basicsteps_exit("Can not collapse the image in "
00824 "y-direction");
00825 }
00826
00827
00828 cpl_msg_info(cpl_func,"Normalizing the exposure time to 1 sec");
00829 cpl_image_divide_scalar(image_local_collapsed,exptime_local);
00830 if (!cpl_errorstate_is_equal(prestate)){
00831 omega_shutter_basicsteps_exit("can not normalize the exposure "
00832 "time to unity");
00833 }
00834
00835
00836 cpl_imagelist_set(ilist,image_local_collapsed,extension-1);
00837
00838
00839 cpl_image_delete(image_local); image_local=NULL;
00840
00841 }
00842 cpl_propertylist_delete(plist); plist=NULL;
00843 cpl_free(direction_local); direction_local=NULL;
00844 cur_frame=cpl_frameset_get_next(frameset);
00845 }
00846
00847
00848 if (cpl_imagelist_get_size(ilist)<1){
00849 cpl_error_set_message(cpl_func,CPL_ERROR_ILLEGAL_INPUT,"Imagelist is "
00850 "empty! Please check the input raw frames");
00851 }
00852
00853
00854 return cpl_error_set(cpl_func, cpl_error_get_code());
00855
00856 }
00864 static cpl_error_code omega_table_insert_xcoordinates(cpl_table * intable)
00865 {
00866
00867 int * ptablecol=NULL;
00868 int i = 0;
00869 cpl_errorstate prestate = cpl_errorstate_get();
00870
00871 cpl_table_new_column(intable, "x_coordinate", CPL_TYPE_INT);
00872 cpl_table_fill_column_window_int(intable, "x_coordinate", 0,
00873 cpl_table_get_nrow(intable), 0);
00874 ptablecol = cpl_table_get_data_int(intable, "x_coordinate");
00875
00876 if (!cpl_errorstate_is_equal(prestate)){
00877 return cpl_error_set(cpl_func, cpl_error_get_code());
00878 }
00879 else {
00880
00881 for(i = 0; i < cpl_table_get_nrow(intable); i++){
00882 ptablecol[i] = i + 1;
00883 }
00884 }
00885
00886 return cpl_error_set(cpl_func, cpl_error_get_code());
00887 }
00888
00889
00890 static void omega_shutter_init(void) {
00891 ps.labels = NULL;
00892 ps.mbframe = NULL;
00893 ps.domelist = NULL;
00894
00895 }
00896
00897
00898 static void omega_shutter_tidy(void) {
00899 freespace(ps.labels);
00900 freeframeset(ps.domelist);
00901
00902 }
00903
00912 static float omega_get_exptime_limit(cpl_frameset * frameset){
00913
00914 cpl_vector * exptime_vector=NULL;
00915 cpl_propertylist * plist=NULL;
00916 cpl_frame * cur_frame=NULL;
00917 int i=0;
00918 float exptime_limit=0;
00919
00920 exptime_vector=cpl_vector_new(cpl_frameset_get_size(frameset));
00921
00922 cur_frame=cpl_frameset_get_first(frameset);
00923
00924 i=0;
00925
00926 while(cur_frame)
00927 {
00928 plist=cpl_propertylist_load(cpl_frame_get_filename(cur_frame),0);
00929 if(!cpl_propertylist_has(plist, "EXPTIME"))
00930 {
00931 cpl_msg_warning(cpl_func,"Can not find EXPTIME in file %s",
00932 cpl_frame_get_filename(cur_frame));
00933 cpl_propertylist_delete(plist);
00934 cpl_vector_delete(exptime_vector);
00935 return 0.;
00936 }
00937
00938 cpl_vector_set(exptime_vector, i,
00939 cpl_propertylist_get_float(plist, "EXPTIME"));
00940 cpl_propertylist_delete(plist);
00941 i++;
00942 cur_frame=cpl_frameset_get_next(frameset);
00943 }
00944
00945 exptime_limit=(cpl_vector_get_min(exptime_vector)+
00946 cpl_vector_get_max(exptime_vector))/2.;
00947 cpl_vector_delete(exptime_vector);
00948
00949 return exptime_limit;
00950
00951 }
00952