ref2d = model_2d(xmax, ymax, 380, 740, 0.25, 955, 0.5) data2d_tmp = ref2d.as_numpy_array() data2d[:, :] += numpy.float64(data2d_tmp) # tmp = ''' from matplotlib import pyplot as plt print("Plotting data2d") plt.imshow(data2d, interpolation="nearest") plt.show() #''' from dials.algorithms.background.inclined_background_subtractor import ( layering_and_background_plane, ) layering_and_background_plane(ref_table) from dials.algorithms.integration import flex_2d_layering_n_integrating flex_2d_layering_n_integrating(ref_table) t_intensity = ref_table["intensity.sum.value"] old_i_table = t_intensity[:] # tmp=''' print("adding noise ....") t_row = 0 for count in range(num_ref): for x_loc in range(ncol): for y_loc in range(nrow): roll_the_dice = random.randint(1, 50) if roll_the_dice <= 5:
def run(i, imp): from random import randint from dials.array_family import flex #building a reflection table num_ref = 5 ref_table = flex.reflection_table() shoebox = flex.shoebox(num_ref) ref_table['shoebox'] = shoebox intensity = flex.double(num_ref) ref_table['intensity.sum.value'] = intensity intensity_var = flex.double(num_ref) ref_table['intensity.sum.variance'] = intensity_var iterate = ref_table['shoebox'] i_to_compare = [] # bulding the shoebox with a desired content # which is a reflection with noise included n = 0 for arr in iterate: img = flex.double(flex.grid(3, 3, 3)) bkg = flex.double(flex.grid(3, 3, 3)) msk = flex.int(flex.grid(3, 3, 3)) for row in range(3): for col in range(3): for fra in range(3): img[row, col, fra] = row + col + fra + n * 9 + randint(0, i) bkg[row, col, fra] = 0.0 msk[row, col, fra] = 3 n += 1 msk[1, 1, 1] = 5 tmp_i = n * n * n * 3 i_to_compare.append(tmp_i) img[1, 1, 1] += tmp_i arr.data = img[:, :, :] arr.background = bkg[:, :, :] arr.mask = msk[:, :, :] # calling the functions that we need to test # first select the algorithm for background calculation if imp == "inclined": print "testing inclined_background_subtractor" from dials.algorithms.background.inclined_background_subtractor \ import layering_and_background_plane layering_and_background_plane(ref_table) elif imp == "flat": print "testing flat_background_subtractor" from dials.algorithms.background.flat_background_subtractor \ import layering_and_background_avg layering_and_background_avg(ref_table) elif imp == "curved": print "testing curved_background_subtractor" from dials.algorithms.background.curved_background_subtractor \ import layering_and_background_modl layering_and_background_modl(ref_table) # no matter which algorithm was used for background calculation # the integration summation must remain compatible from dials.algorithms.integration.summation2d \ import flex_2d_layering_n_integrating flex_2d_layering_n_integrating(ref_table) # comparing results result = "OK" resl_its = ref_table['intensity.sum.value'] resl_var = ref_table['intensity.sum.variance'] for n_its in range(len(resl_its)): if resl_its[n_its] <= i_to_compare[n_its] + i and \ resl_its[n_its] >= i_to_compare[n_its] - i and \ resl_var[n_its] > resl_its[n_its]: print "Ok ", n_its else: print "Wrong num", n_its print "i =", i print "resl_its[n_its] =", resl_its[n_its] print "i_to_compare[n_its] =", i_to_compare[n_its] print "resl_var[n_its] =", resl_var[n_its] result = "wrong" raise RuntimeError('wrong result') return result
r.shoebox_background = background2d rlist = ReflectionList() rlist.append(r) #from dials.algorithms.background.flat_background_subtractor \ # import layering_and_background_avg #layering_and_background_avg(rlist) #from dials.algorithms.background.curved_background_subtractor \ # import layering_and_background_modl #layering_and_background_modl(rlist) from dials.algorithms.background.inclined_background_subtractor \ import layering_and_background_plane layering_and_background_plane(rlist) from dials.algorithms.integration.summation2d \ import flex_2d_layering_n_integrating flex_2d_layering_n_integrating(rlist) for r in rlist: matrix_img = r.shoebox.as_numpy_array() print print "shoebox" print matrix_img matrix_bkg = r.shoebox_background.as_numpy_array() print print "background"
data2d_tmp = ref2d.as_numpy_array() data2d[:, :] += numpy.float64(data2d_tmp) # print "created ", len(rlist), "reflections" from matplotlib import pyplot as plt print "Plotting data2d" plt.imshow(data2d, interpolation="nearest") plt.show() from dials.algorithms.background.inclined_background_subtractor import layering_and_background_plane # layering_and_background_plane(rlist) layering_and_background_plane(ref_table) from dials.algorithms.integration import flex_2d_layering_n_integrating # flex_2d_layering_n_integrating(rlist) flex_2d_layering_n_integrating(ref_table) print "_____________________________________________________ here" t_intensity = ref_table["intensity.sum.value"] old_i_table = t_intensity[:] for tmp_i in t_intensity: print "tmp_i = ", tmp_i # tmp='''
def run(i, imp): from random import randint from dials.array_family import flex #building a reflection table num_ref = 5 ref_table = flex.reflection_table() shoebox = flex.shoebox(num_ref) ref_table['shoebox'] = shoebox intensity = flex.double(num_ref) ref_table['intensity.sum.value'] = intensity intensity_var = flex.double(num_ref) ref_table['intensity.sum.variance'] = intensity_var iterate = ref_table['shoebox'] i_to_compare = [] # bulding the shoebox with a desired content # which is a reflection with noise included n = 0 for arr in iterate: img = flex.double(flex.grid(3, 3, 3)) bkg = flex.double(flex.grid(3, 3, 3)) msk = flex.int(flex.grid(3, 3, 3)) for row in range(3): for col in range(3): for fra in range(3): img[row, col, fra] = row + col + fra + n * 9 + randint(0, i) bkg[row, col, fra] = 0.0 msk[row, col, fra] = 3 n += 1 msk[1, 1, 1] = 5 tmp_i = n * n * n * 3 i_to_compare.append(tmp_i) img[1, 1, 1] += tmp_i arr.data = img[:, :, :] arr.background = bkg[:, :, :] arr.mask = msk[:, :, :] # calling the functions that we need to test # first select the algorithm for background calculation if imp == "inclined": print("testing inclined_background_subtractor") from dials.algorithms.background.inclined_background_subtractor \ import layering_and_background_plane layering_and_background_plane(ref_table) elif imp == "flat": print("testing flat_background_subtractor") from dials.algorithms.background.flat_background_subtractor \ import layering_and_background_avg layering_and_background_avg(ref_table) elif imp == "curved": print("testing curved_background_subtractor") from dials.algorithms.background.curved_background_subtractor \ import layering_and_background_modl layering_and_background_modl(ref_table) # no matter which algorithm was used for background calculation # the integration summation must remain compatible from dials.algorithms.integration.summation2d \ import flex_2d_layering_n_integrating flex_2d_layering_n_integrating(ref_table) # comparing results result = "OK" resl_its = ref_table['intensity.sum.value'] resl_var = ref_table['intensity.sum.variance'] for n_its in range(len(resl_its)): if resl_its[n_its] <= i_to_compare[n_its] + i and \ resl_its[n_its] >= i_to_compare[n_its] - i and \ resl_var[n_its] > resl_its[n_its]: print("Ok ", n_its) else: print("Wrong num", n_its) print("i =", i) print("resl_its[n_its] =", resl_its[n_its]) print("i_to_compare[n_its] =", i_to_compare[n_its]) print("resl_var[n_its] =", resl_var[n_its]) result = "wrong" raise RuntimeError('wrong result') return result
rlist = ReflectionList() rlist.append(r) # from dials.algorithms.background.flat_background_subtractor \ # import layering_and_background_avg # layering_and_background_avg(rlist) # from dials.algorithms.background.curved_background_subtractor \ # import layering_and_background_modl # layering_and_background_modl(rlist) from dials.algorithms.background.inclined_background_subtractor import ( layering_and_background_plane, ) layering_and_background_plane(rlist) from dials.algorithms.integration.summation2d import flex_2d_layering_n_integrating flex_2d_layering_n_integrating(rlist) for r in rlist: matrix_img = r.shoebox.as_numpy_array() print() print("shoebox") print(matrix_img) matrix_bkg = r.shoebox_background.as_numpy_array() print() print("background") print(matrix_bkg)