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 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030
00036
00039
00040
00041
00042
00043
00044
00045 #include <xsh_error.h>
00046 #include <xsh_msg.h>
00047 #include <xsh_dfs.h>
00048 #include <xsh_pfits.h>
00049 #include <xsh_utils_image.h>
00050 #include <tests.h>
00051
00052 #include <cpl.h>
00053 #include <math.h>
00054
00055
00056
00057
00058 #define MODULE_ID "XSH_IFU_TRACE_SLICES"
00059
00060 #define SYNTAX "Computes the ifu slices positio \n"\
00061 "use : ./test_xsh_ifu_trace_slices IFU_FLAT.fits SLIT_FLATS.fits ORDER_TAB_CENTR\n"
00062
00063
00064
00065
00066
00073
00074 int main( int argc, char** argv)
00075 {
00076 char *ifu_flat_name = NULL;
00077 char *slit_flat_name = NULL;
00078
00079
00080 cpl_image* lx_ima=NULL;
00081 cpl_image* ly_ima=NULL;
00082 cpl_image* scharr_x_ima=NULL;
00083 cpl_image* scharr_y_ima=NULL;
00084 cpl_image* ifu_flat_ima=NULL;
00085 cpl_image* slit_flat_ima=NULL;
00086 cpl_image* ratio_ima=NULL;
00087 int j=0;
00088 int sx=0;
00089 int sy=0;
00090 double max=0;
00091
00092 TESTS_INIT( MODULE_ID);
00093 cpl_msg_set_level( CPL_MSG_DEBUG);
00094 xsh_debug_level_set( XSH_DEBUG_LEVEL_MEDIUM) ;
00095
00096
00097 if (argc > 1){
00098 ifu_flat_name = argv[1];
00099 slit_flat_name = argv[2];
00100 }
00101 else{
00102 printf(SYNTAX);
00103 return 0;
00104 }
00105
00106 XSH_ASSURE_NOT_NULL( ifu_flat_name);
00107 XSH_ASSURE_NOT_NULL( slit_flat_name);
00108
00109 check(ifu_flat_ima=cpl_image_load(ifu_flat_name,CPL_TYPE_FLOAT,0,0));
00110 check(slit_flat_ima=cpl_image_load(slit_flat_name,CPL_TYPE_FLOAT,0,0));
00111 sx=cpl_image_get_size_x(ifu_flat_ima);
00112 sy=cpl_image_get_size_y(ifu_flat_ima);
00113
00114 check(lx_ima=xsh_sobel_lx(ifu_flat_ima));
00115 check(ly_ima=xsh_sobel_ly(ifu_flat_ima));
00116 check(cpl_image_save(lx_ima,"lx.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00117 check(cpl_image_save(ly_ima,"ly.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00118
00119
00120 check(scharr_x_ima=xsh_scharr_x(ifu_flat_ima));
00121 check(scharr_y_ima=xsh_scharr_y(ifu_flat_ima));
00122
00123 check(cpl_image_save(scharr_x_ima,"scharr_x.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00124 check(cpl_image_save(scharr_y_ima,"scharr_y.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00125
00126
00127
00128
00129
00130
00131
00132
00133 check(max=cpl_image_get_max(scharr_x_ima));
00134 check(cpl_image_divide_scalar(scharr_x_ima,max));
00135
00136
00137
00138
00139
00140
00141
00142
00143 check(max=cpl_image_get_max(scharr_y_ima));
00144 check(cpl_image_divide_scalar(scharr_y_ima,max));
00145
00146
00147 check(cpl_image_save(scharr_x_ima,"scharr_x_n.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00148 check(cpl_image_save(scharr_y_ima,"scharr_y_n.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00149
00150
00151 check(cpl_image_divide(ifu_flat_ima,slit_flat_ima));
00152 xsh_free_image(&lx_ima);
00153 xsh_free_image(&ly_ima);
00154
00155 check(lx_ima=xsh_sobel_lx(ifu_flat_ima));
00156 check(ly_ima=xsh_sobel_ly(ifu_flat_ima));
00157
00158 xsh_free_image(&scharr_x_ima);
00159 xsh_free_image(&scharr_y_ima);
00160 check(scharr_x_ima=xsh_scharr_x(ifu_flat_ima));
00161 check(scharr_y_ima=xsh_scharr_y(ifu_flat_ima));
00162
00163
00164
00165 check(cpl_image_save(lx_ima,"lx_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00166 check(cpl_image_save(ly_ima,"ly_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00167 check(cpl_image_save(scharr_x_ima,"scharr_x_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00168 check(cpl_image_save(scharr_y_ima,"scharr_y_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00169
00170 check(cpl_image_save(ifu_flat_ima,"ifu_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00171
00172 cleanup:
00173 xsh_free_image(&ifu_flat_ima);
00174 xsh_free_image(&slit_flat_ima);
00175 xsh_free_image(&ratio_ima);
00176 xsh_free_image(&lx_ima);
00177 xsh_free_image(&ly_ima);
00178 xsh_free_image(&scharr_x_ima);
00179 xsh_free_image(&scharr_y_ima);
00180
00181
00182 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00183 xsh_error_dump(CPL_MSG_ERROR);
00184 return 1;
00185 } else {
00186 return 0;
00187 }
00188
00189 }
00190