Repository : ssh://g18-sc-serv-04.diamond.ac.uk/dials
On branch : master
commit ff694ccea66a1ce6c4075ea09b67e7523bf4ab64
Author: James Beilsten-Edmands <[log in to unmask]>
Date: Thu Jul 26 11:06:57 2018 +0100
Guard against zero division errors due to small g-values in scaling
Very small or zero g values can cause ZeroDivision errors, so
check if this causes wg^2 to be zero and if so then mark these
as outliers to allow the calculation to continue.
Weights should still never be zero so keep the weights assertion.
ff694ccea66a1ce6c4075ea09b67e7523bf4ab64
algorithms/scaling/outlier_rejection.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/algorithms/scaling/outlier_rejection.py b/algorithms/scaling/outlier_rejection.py
index 8962535b..fa379f5c 100644
--- a/algorithms/scaling/outlier_rejection.py
+++ b/algorithms/scaling/outlier_rejection.py
@@ -204,14 +204,21 @@ def round_of_outlier_rejection(self, reflection_tables):
sel = nh > 2 #could be > 1 if we want to calculate z_score for groups of 2
wg2sum_others_sel = wg2sum_others.select(sel)
wgIsum_others_sel = wgIsum_others.select(sel)
+
+ # guard against zero divison errors - can happen due to rounding errors
+ # or bad data giving g values are very small
+ zero_sel = (wg2sum_others_sel == 0.0)
+ # set as one for now, then mark as outlier below. This will only affect if
+ # g is near zero, if w is zero then throw an assertionerror.
+ wg2sum_others_sel.set_selected(zero_sel, 1.0)
g_sel = g.select(sel)
I_sel = I.select(sel)
w_sel = w.select(sel)
assert w_sel.all_gt(0) # guard against division by zero
- assert wg2sum_others_sel.all_gt(0) # guard against division by zero
norm_dev = (I_sel - (g_sel * wgIsum_others_sel/wg2sum_others_sel))/(
((1.0/w_sel)+((g_sel/wg2sum_others_sel)**2))**0.5)
+ norm_dev.set_selected(zero_sel, 1000) # to trigger rejection
z_score = flex.abs(norm_dev)
# Want an array same size as Ih table.
all_z_scores = flex.double(Ih_table.size, 0.0)
To unsubscribe from the DIALS-COMMIT list, click the following link:
https://www.jiscmail.ac.uk/cgi-bin/webadmin?SUBED1=DIALS-COMMIT&A=1