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 sx=0;
00088 int sy=0;
00089 double max=0;
00090
00091 TESTS_INIT( MODULE_ID);
00092 cpl_msg_set_level( CPL_MSG_DEBUG);
00093 xsh_debug_level_set( XSH_DEBUG_LEVEL_MEDIUM) ;
00094
00095
00096 if (argc > 1){
00097 ifu_flat_name = argv[1];
00098 slit_flat_name = argv[2];
00099 }
00100 else{
00101 printf(SYNTAX);
00102 return 0;
00103 }
00104
00105 XSH_ASSURE_NOT_NULL( ifu_flat_name);
00106 XSH_ASSURE_NOT_NULL( slit_flat_name);
00107
00108 check(ifu_flat_ima=cpl_image_load(ifu_flat_name,CPL_TYPE_FLOAT,0,0));
00109 check(slit_flat_ima=cpl_image_load(slit_flat_name,CPL_TYPE_FLOAT,0,0));
00110 sx=cpl_image_get_size_x(ifu_flat_ima);
00111 sy=cpl_image_get_size_y(ifu_flat_ima);
00112
00113 check(lx_ima=xsh_sobel_lx(ifu_flat_ima));
00114 check(ly_ima=xsh_sobel_ly(ifu_flat_ima));
00115 check(cpl_image_save(lx_ima,"lx.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00116 check(cpl_image_save(ly_ima,"ly.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00117
00118
00119 check(scharr_x_ima=xsh_scharr_x(ifu_flat_ima));
00120 check(scharr_y_ima=xsh_scharr_y(ifu_flat_ima));
00121
00122 check(cpl_image_save(scharr_x_ima,"scharr_x.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00123 check(cpl_image_save(scharr_y_ima,"scharr_y.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00124
00125
00126
00127
00128
00129
00130
00131
00132 check(max=cpl_image_get_max(scharr_x_ima));
00133 check(cpl_image_divide_scalar(scharr_x_ima,max));
00134
00135
00136
00137
00138
00139
00140
00141
00142 check(max=cpl_image_get_max(scharr_y_ima));
00143 check(cpl_image_divide_scalar(scharr_y_ima,max));
00144
00145
00146 check(cpl_image_save(scharr_x_ima,"scharr_x_n.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00147 check(cpl_image_save(scharr_y_ima,"scharr_y_n.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00148
00149
00150 check(cpl_image_divide(ifu_flat_ima,slit_flat_ima));
00151 xsh_free_image(&lx_ima);
00152 xsh_free_image(&ly_ima);
00153
00154 check(lx_ima=xsh_sobel_lx(ifu_flat_ima));
00155 check(ly_ima=xsh_sobel_ly(ifu_flat_ima));
00156
00157 xsh_free_image(&scharr_x_ima);
00158 xsh_free_image(&scharr_y_ima);
00159 check(scharr_x_ima=xsh_scharr_x(ifu_flat_ima));
00160 check(scharr_y_ima=xsh_scharr_y(ifu_flat_ima));
00161
00162
00163
00164 check(cpl_image_save(lx_ima,"lx_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00165 check(cpl_image_save(ly_ima,"ly_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00166 check(cpl_image_save(scharr_x_ima,"scharr_x_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00167 check(cpl_image_save(scharr_y_ima,"scharr_y_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00168
00169 check(cpl_image_save(ifu_flat_ima,"ifu_norm.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT));
00170
00171 cleanup:
00172 xsh_free_image(&ifu_flat_ima);
00173 xsh_free_image(&slit_flat_ima);
00174 xsh_free_image(&ratio_ima);
00175 xsh_free_image(&lx_ima);
00176 xsh_free_image(&ly_ima);
00177 xsh_free_image(&scharr_x_ima);
00178 xsh_free_image(&scharr_y_ima);
00179
00180
00181 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00182 xsh_error_dump(CPL_MSG_ERROR);
00183 return 1;
00184 } else {
00185 return 0;
00186 }
00187
00188 }
00189