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