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