aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am6
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/scaling_check.c (renamed from tests/linear_scale_check.c)83
3 files changed, 70 insertions, 21 deletions
diff --git a/Makefile.am b/Makefile.am
index 94ec2d6f..f5d38c2a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,7 @@ noinst_PROGRAMS = tests/list_check tests/integration_check \
tests/cell_check tests/ring_check \
tests/prof2d_check tests/ambi_check \
tests/prediction_gradient_check \
- tests/linear_scale_check
+ tests/scaling_check
MERGE_CHECKS = tests/first_merge_check tests/second_merge_check \
tests/third_merge_check tests/fourth_merge_check
@@ -26,7 +26,7 @@ TESTS = tests/list_check $(MERGE_CHECKS) $(PARTIAL_CHECKS) \
tests/integration_check \
tests/symmetry_check tests/centering_check tests/transformation_check \
tests/cell_check tests/ring_check tests/prof2d_check tests/ambi_check \
- tests/prediction_gradient_check tests/linear_scale_check
+ tests/prediction_gradient_check tests/scaling_check
EXTRA_DIST += $(MERGE_CHECKS) $(PARTIAL_CHECKS)
EXTRA_DIST += relnotes-0.6.3 announcement-0.6.3
@@ -123,7 +123,7 @@ tests_ring_check_SOURCES = tests/ring_check.c
tests_cell_check_SOURCES = tests/cell_check.c
-tests_linear_scale_check_SOURCES = tests/linear_scale_check.c src/scaling.c \
+tests_scaling_check_SOURCES = tests/scaling_check.c src/scaling.c \
src/merge.c
INCLUDES = -I$(top_srcdir)/libcrystfel/src -I$(top_srcdir)/data
diff --git a/tests/.gitignore b/tests/.gitignore
index 083e0eaa..cac64f7b 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -13,4 +13,4 @@ ring_check
prof2d_check
ambi_check
prediction_gradient_check
-linear_scale_check
+scaling_check
diff --git a/tests/linear_scale_check.c b/tests/scaling_check.c
index 7c9e0a9f..96df9cf0 100644
--- a/tests/linear_scale_check.c
+++ b/tests/scaling_check.c
@@ -1,7 +1,7 @@
/*
- * linear_scale_check.c
+ * scaling_check.c
*
- * Check that linear scaling works
+ * Check that scaling works
*
* Copyright © 2017-2018 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
@@ -35,14 +35,14 @@
#include <stdio.h>
#include <reflist.h>
+#include <cell-utils.h>
#include "../src/scaling.h"
-int main(int argc, char *argv[])
+int test_scaling(double G, double B, int scaleflags, int do_partials,
+ gsl_rng *rng)
{
- int fail = 0;
int i;
- gsl_rng *rng;
Crystal *cr;
RefList *list1;
RefList *list2;
@@ -52,38 +52,87 @@ int main(int argc, char *argv[])
list1 = reflist_new();
list2 = reflist_new();
- rng = gsl_rng_alloc(gsl_rng_mt19937);
+ cell = cell_new();
+ cell_set_parameters(cell, 50e-10, 50e-10, 50e-10,
+ deg2rad(90), deg2rad(90), deg2rad(90));
for ( i=0; i<50; i++ ) {
+
signed int h, k, l;
Reflection *refl1;
Reflection *refl2;
- double intens;
+ double intens, p, s, L;
+
h = gsl_rng_uniform_int(rng, 20) - gsl_rng_uniform_int(rng, 40);
k = gsl_rng_uniform_int(rng, 20) - gsl_rng_uniform_int(rng, 40);
l = gsl_rng_uniform_int(rng, 20) - gsl_rng_uniform_int(rng, 40);
+
refl1 = add_refl(list1, h, k, l);
refl2 = add_refl(list2, h, k, l);
intens = gsl_rng_uniform(rng); /* [0,1) */
- set_intensity(refl1, intens);
- set_partiality(refl1, 1.0);
- set_lorentz(refl1, 1.0);
- set_intensity(refl2, intens*2.0);
+ p = do_partials ? gsl_rng_uniform(rng) : 1.0;
+ L = gsl_rng_uniform(rng);
+
+ s = resolution(cell, h, k, l);
+
+ /* Reference */
+ set_intensity(refl2, intens);
set_partiality(refl2, 1.0);
set_lorentz(refl2, 1.0);
set_redundancy(refl2, 2);
+
+ /* Crystal */
+ set_intensity(refl1, intens * G * exp(-B*s*s) * p / L);
+ set_partiality(refl1, p);
+ set_lorentz(refl1, L);
+
}
cr = crystal_new();
- cell = cell_new();
- cell_set_parameters(cell, 50e-10, 50e-10, 50e-10,
- deg2rad(90), deg2rad(90), deg2rad(90));
crystal_set_reflections(cr, list1);
crystal_set_cell(cr, cell);
- r = scale_one_crystal(cr, list2, SCALE_NO_B);
- STATUS("Scaling result: %i, G = %f, B = %e\n", r,
- crystal_get_osf(cr), crystal_get_Bfac(cr));
+ crystal_set_osf(cr, 999.0);
+ crystal_set_Bfac(cr, 999.0);
+
+ r = scale_one_crystal(cr, list2, scaleflags | SCALE_VERBOSE_ERRORS);
+ STATUS("Scaling result: %i, G = %8.4f, B = %8.4f A^2\n", r,
+ crystal_get_osf(cr), crystal_get_Bfac(cr)*1e20);
+
+ if ( fabs(G - crystal_get_osf(cr)) > 0.001 ) r = 1;
+ if ( fabs(B - crystal_get_Bfac(cr)) > 0.001e-20 ) r = 1;
+
+ reflist_free(list1);
+ reflist_free(list2);
+ cell_free(cell);
+ crystal_free(cr);
+
+ if ( r ) {
+ STATUS(" (should be: G = %8.4f, B = %8.4f A^2), %s partials\n",
+ G, B*1e20, do_partials ? "with" : "no");
+ }
+
+ return r;
+}
+
+
+int main(int argc, char *argv[])
+{
+ int fail = 0;
+ gsl_rng *rng;
+
+ rng = gsl_rng_alloc(gsl_rng_mt19937);
+
+ fail += test_scaling(2.0, 0.0, SCALE_NO_B, 0, rng);
+ fail += test_scaling(2.0, 0.0, SCALE_NONE, 0, rng);
+ fail += test_scaling(2.0, 10.0e-20, SCALE_NONE, 0, rng);
+ fail += test_scaling(5.0, 30.0e-20, SCALE_NONE, 0, rng);
+ fail += test_scaling(2.0, 0.0, SCALE_NO_B, 1, rng);
+ fail += test_scaling(2.0, 0.0, SCALE_NONE, 1, rng);
+ fail += test_scaling(2.0, 10.0e-20, SCALE_NONE, 1, rng);
+ fail += test_scaling(5.0, 30.0e-20, SCALE_NONE, 1, rng);
+
+ gsl_rng_free(rng);
return fail;
}