aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-08-05 13:40:54 +0200
committerThomas White <taw@physics.org>2020-08-05 14:45:44 +0200
commit95b167d7c9df4fd21e69853a664f02eb7bfe8901 (patch)
tree30c464866ff5075541470c954c643ac792a9db3f /tests
parenta7ce7d83d70e747446cb54581216f440b9677954 (diff)
Restore HDF5 output in polarisation_check
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/meson.build7
-rw-r--r--tests/polarisation_check.c81
-rw-r--r--tests/polarisation_check.geom15
4 files changed, 56 insertions, 50 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 373187c9..f28b0cb9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -90,7 +90,8 @@ add_test(cellcompare_check cellcompare_check)
add_executable(polarisation_check polarisation_check.c)
target_include_directories(polarisation_check PRIVATE ${COMMON_INCLUDES})
target_link_libraries(polarisation_check ${COMMON_LIBRARIES})
-add_test(polarisation_check polarisation_check)
+add_test(NAME polarisation_check
+ COMMAND polarisation_check ${CMAKE_CURRENT_SOURCE_DIR}/polarisation_check.geom)
add_executable(evparse1 evparse1.c)
target_include_directories(evparse1 PRIVATE ${COMMON_INCLUDES})
diff --git a/tests/meson.build b/tests/meson.build
index 5b368f9b..968bc39f 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -35,7 +35,6 @@ simple_tests = ['ambi_check',
'rational_check',
'spectrum_check',
'cellcompare_check',
- 'polarisation_check',
'evparse1',
'evparse2',
'evparse3',
@@ -74,6 +73,12 @@ exe = executable('gpu_sim_check',
geom = files('gpu_sim_check.geom')
test('gpu_sim_check', exe, args: [geom])
+exe = executable('polarisation_check',
+ ['polarisation_check.c'],
+ dependencies : [libcrystfeldep, mdep, gsldep])
+geom = files('polarisation_check.geom')
+test('polarisation_check', exe, args: [geom])
+
# Event enumeration tests
ev_enum_tests = ['ev_enum1',
diff --git a/tests/polarisation_check.c b/tests/polarisation_check.c
index 1ebc41b7..60c3770c 100644
--- a/tests/polarisation_check.c
+++ b/tests/polarisation_check.c
@@ -38,12 +38,11 @@
int main(int argc, char *argv[])
{
- struct image image;
+ DataTemplate *dtempl;
+ struct image *image;
FILE *fh;
unsigned long int seed;
int fail = 0;
- const int w = 1024;
- const int h = 1024;
RefList *list;
RefListIterator *iter;
Reflection *refl;
@@ -53,9 +52,13 @@ int main(int argc, char *argv[])
struct polarisation p;
int i;
double *map;
- double *nmap;
+ int *nmap;
const int ntrial = 1000;
+ /* NB must match polarisation_check.geom */
+ const int w = 512;
+ const int h = 512;
+
rng = gsl_rng_alloc(gsl_rng_mt19937);
fh = fopen("/dev/urandom", "r");
@@ -66,36 +69,11 @@ int main(int argc, char *argv[])
}
fclose(fh);
- image.lambda = ph_eV_to_lambda(9000.0);
- image.bw = 0.000001;
- image.div = 0.0;
- image.spectrum = spectrum_generate_gaussian(image.lambda, image.bw);
-
- image.detgeom = calloc(1, sizeof(struct detgeom));
- image.detgeom->n_panels = 1;
- image.detgeom->panels = calloc(1, sizeof(struct detgeom_panel));
-
- image.dp = calloc(1, sizeof(float *));
- image.bad = calloc(1, sizeof(int *));
-
- image.detgeom->panels[0].w = w;
- image.detgeom->panels[0].h = h;
- image.detgeom->panels[0].fsx = 1.0;
- image.detgeom->panels[0].fsy = 0.0;
- image.detgeom->panels[0].ssx = 0.0;
- image.detgeom->panels[0].ssy = 1.0;
- image.detgeom->panels[0].cnx = -w/2;
- image.detgeom->panels[0].cny = -h/2;
- image.detgeom->panels[0].cnz = 50.0e-3 / 10e-6;
- image.detgeom->panels[0].pixel_pitch = 10e-6;
- image.detgeom->panels[0].adu_per_photon = 1.0;
- image.detgeom->panels[0].max_adu = +INFINITY; /* No cutoff */
-
- image.dp[0] = malloc(w*h*sizeof(float));
- memset(image.dp[0], 0, w*h*sizeof(float));
- image.bad[0] = malloc(w*h*sizeof(int));
- memset(image.bad[0], 0, w*h*sizeof(int));
- image.sat = NULL;
+ dtempl = data_template_new_from_file(argv[1]);
+ if ( dtempl == NULL ) return 1;
+
+ image = image_create_for_simulation(dtempl);
+ if ( image == NULL ) return 1;
cell = cell_new();
cell_set_lattice_type(cell, L_CUBIC);
@@ -106,17 +84,17 @@ int main(int argc, char *argv[])
cr = crystal_new();
crystal_set_profile_radius(cr, 0.001e9);
crystal_set_mosaicity(cr, 0.0); /* radians */
- crystal_set_image(cr, &image);
+ crystal_set_image(cr, image);
crystal_set_cell(cr, cell);
- image.n_crystals = 1;
- image.crystals = &cr;
+ image->n_crystals = 1;
+ image->crystals = &cr;
map = malloc(w*h*sizeof(double));
- nmap = malloc(w*h*sizeof(double));
+ nmap = malloc(w*h*sizeof(int));
for ( i=0; i<w*h; i++ ) {
map[i] = 0.0;
- nmap[i] = 0.0;
+ nmap[i] = 0;
}
for ( i=0; i<ntrial; i++ ) {
@@ -125,8 +103,8 @@ int main(int argc, char *argv[])
ncell = cell_rotate(cell, random_quaternion(rng));
crystal_set_cell(cr, ncell);
- list = predict_to_res(cr, detgeom_max_resolution(image.detgeom,
- image.lambda));
+ list = predict_to_res(cr, detgeom_max_resolution(image->detgeom,
+ image->lambda));
crystal_set_reflections(cr, list);
for ( refl = first_refl(list, &iter);
@@ -138,6 +116,7 @@ int main(int argc, char *argv[])
p.angle = deg2rad(105.0);
p.fraction = 1.0;
+ p.disable = 0;
polarisation_correction(list, ncell, p);
for ( refl = first_refl(list, &iter);
@@ -152,25 +131,31 @@ int main(int argc, char *argv[])
/* Intensity in reflist is corrected,
* but we want "un-correction" */
map[nfs + nss*w] += 1.0/get_intensity(refl);
- nmap[nfs + nss*w] += 1.0;
+ nmap[nfs + nss*w] += 1;
}
cell_free(ncell);
reflist_free(list);
+ crystal_set_cell(cr, NULL);
+ crystal_set_reflections(cr, NULL);
+
progress_bar(i+1, ntrial, "Calculating");
}
for ( i=0; i<w*h; i++ ) {
- image.dp[0][i] = 1000.0 * map[i] / nmap[i];
- if ( isnan(image.dp[0][i]) ) image.dp[0][i] = 0.0;
+ if ( nmap[i] > 0 ) {
+ image->dp[0][i] = 1000.0 * map[i] / nmap[i];
+ }
}
- //hdf5_write_image("test.h5", &image, "/data/data");
+ image_write(image, dtempl, "test.h5");
+
+ image->crystals = NULL;
+ image->n_crystals = 0;
- detgeom_free(image.detgeom);
- free(image.dp[0]);
- free(image.dp);
+ data_template_free(dtempl);
+ image_free(image);
gsl_rng_free(rng);
if ( fail ) return 1;
diff --git a/tests/polarisation_check.geom b/tests/polarisation_check.geom
new file mode 100644
index 00000000..13ae073b
--- /dev/null
+++ b/tests/polarisation_check.geom
@@ -0,0 +1,15 @@
+photon_energy = 9 keV
+bandwidth = 0.0001
+
+panel0/min_fs = 0
+panel0/max_fs = 511
+panel0/min_ss = 0
+panel0/max_ss = 511
+panel0/corner_x = -256.0
+panel0/corner_y = -256.0
+panel0/clen = 20 mm
+panel0/res = 9090.91
+panel0/adu_per_photon = 1
+panel0/data = /data/panel0
+panel0/fs = x
+panel0/ss = y \ No newline at end of file