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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifdef HAVE_CONFIG_H
00050 # include <config.h>
00051 #endif
00052
00053 #include <uves_cd_align_impl.h>
00054 #include <uves_utils_wrappers.h>
00055 #include <uves_error.h>
00056 #include <irplib_test.h>
00057
00058 #include <cpl.h>
00059
00060 #include <float.h>
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00074
00077
00086
00087 static double eval_gauss(double x, double my, double sigma, double norm, double back)
00088 {
00089 double result;
00090 double a[5];
00091 double xa[1];
00092
00093 xa[0] = x;
00094
00095 a[0] = my;
00096 a[1] = sigma;
00097 a[2] = norm;
00098 a[3] = back;
00099 a[4] = 0.01;
00100
00101
00102 assure( uves_moffat(xa, a, &result) == 0,
00103 CPL_ERROR_ILLEGAL_OUTPUT,
00104 "Moffat evalutation failed");
00105
00106 cleanup:
00107 return result;
00108 }
00109
00110
00111
00115
00116 static void
00117 test_process(void)
00118 {
00119 const int nx = 100;
00120 const int ny = 100;
00121 const double maxrow = 61.1;
00122 const double sigma = 2;
00123 const double norm = 6000;
00124 const double background = 200;
00125 cpl_image *im[2] = {NULL, NULL};
00126 cpl_table *cd_align = NULL;
00127 double shift;
00128
00129
00130 im[0] = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
00131 im[1] = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
00132
00133 assure_mem( im[0] );
00134 assure_mem( im[1] );
00135
00136
00137
00138 for (shift = -20; shift < 5; shift = (shift < -5) ? shift/1.5 : shift + 0.7)
00139 {
00140 int x, y;
00141 for (y = 1; y <= ny; y++)
00142 {
00143 for (x = 1; x <= nx; x++)
00144 {
00145 cpl_image_set(im[0], x, y,
00146 eval_gauss(y, maxrow, sigma, norm, background));
00147 cpl_image_set(im[1], x, y,
00148 eval_gauss(y, maxrow+shift, sigma, norm, background));
00149 }
00150 }
00151
00152
00153 {
00154 int steps = 10;
00155 int xborder = 0;
00156 int window = 20;
00157
00158 bool DEBUG = false;
00159 enum uves_chip chip = UVES_CHIP_BLUE;
00160
00161 uves_free_table(&cd_align);
00162 check( cd_align = uves_cd_align_process(
00163 im[0],
00164 im[1],
00165 NULL, NULL,
00166 steps, xborder, window, DEBUG, chip),
00167 "Processing failed");
00168 }
00169
00170
00171 assure_nomsg( cpl_table_has_column(cd_align, "X" ), CPL_ERROR_ILLEGAL_OUTPUT);
00172 assure_nomsg( cpl_table_has_column(cd_align, "YCEN1"), CPL_ERROR_ILLEGAL_OUTPUT);
00173 assure_nomsg( cpl_table_has_column(cd_align, "YCEN2"), CPL_ERROR_ILLEGAL_OUTPUT);
00174 assure_nomsg( cpl_table_has_column(cd_align, "SIGMA1"), CPL_ERROR_ILLEGAL_OUTPUT);
00175 assure_nomsg( cpl_table_has_column(cd_align, "SIGMA2"), CPL_ERROR_ILLEGAL_OUTPUT);
00176 assure_nomsg( cpl_table_has_column(cd_align, "BACK1"), CPL_ERROR_ILLEGAL_OUTPUT);
00177 assure_nomsg( cpl_table_has_column(cd_align, "BACK2"), CPL_ERROR_ILLEGAL_OUTPUT);
00178 assure_nomsg( cpl_table_has_column(cd_align, "NORM1"), CPL_ERROR_ILLEGAL_OUTPUT);
00179 assure_nomsg( cpl_table_has_column(cd_align, "NORM2"), CPL_ERROR_ILLEGAL_OUTPUT);
00180 assure_nomsg( cpl_table_has_column(cd_align, "YDIFF"), CPL_ERROR_ILLEGAL_OUTPUT);
00181
00182 uves_msg("Shift: %f pixels. Measured shift: %f pixels",
00183 shift, cpl_table_get_column_mean(cd_align, "YDIFF"));
00184
00185 {
00186 double abs_tolerance = 0.1;
00187
00188 irplib_test_rel(cpl_table_get_column_mean(cd_align, "YDIFF"),
00189 shift, abs_tolerance);
00190 }
00191
00192 }
00193
00194 cleanup:
00195 uves_free_image(&im[0]);
00196 uves_free_image(&im[1]);
00197 uves_free_table(&cd_align);
00198
00199 return;
00200 }
00201
00202
00206
00207
00208 int main(void)
00209 {
00210
00211 IRPLIB_TEST_INIT;
00212
00213 check( test_process(),
00214 "Test of CD align failed");
00215
00216 cleanup:
00217 IRPLIB_TEST_END;
00218 }
00219
00220