def with_individual_given_intensity(self, N, In, Ba, Bb, Bc, Bd): """Generate reflections with given intensity and background.""" from dials.algorithms.simulation import simulate_reciprocal_space_gaussian from dials.algorithms.simulation.generate_test_reflections import ( random_background_plane2, ) from dials.util.command_line import ProgressBar # Check the lengths assert N == len(In) assert N == len(Ba) assert N == len(Bb) assert N == len(Bc) assert N == len(Bd) # Generate some predictions refl = self.generate_predictions(N) # Calculate the signal progress = ProgressBar( title=f"Calculating signal for {len(refl)} reflections") s1 = refl["s1"] phi = refl["xyzcal.mm"].parts()[2] bbox = refl["bbox"] shoebox = refl["shoebox"] m = int(len(refl) / 100) I_exp = flex.double(len(refl), 0) for i in range(len(refl)): if In[i] > 0: data = shoebox[i].data.as_double() I_exp[i] = simulate_reciprocal_space_gaussian( self.experiment.beam, self.experiment.detector, self.experiment.goniometer, self.experiment.scan, self.sigma_b, self.sigma_m, s1[i], phi[i], bbox[i], In[i], data, shoebox[i].mask, ) shoebox[i].data = data.as_float() if i % m == 0: progress.update(100.0 * float(i) / len(refl)) progress.finished( f"Calculated signal impacts for {len(refl)} reflections") # Calculate the background progress = ProgressBar( title=f"Calculating background for {len(refl)} reflections") for l in range(len(refl)): background = flex.float(flex.grid(shoebox[l].size()), 0.0) random_background_plane2(background, Ba[l], Bb[l], Bc[l], Bd[l]) shoebox[l].data += background shoebox[l].background = background if l % m == 0: progress.update(100.0 * float(l) / len(refl)) progress.update(100.0 * float(l) / len(refl)) progress.finished(f"Calculated background for {len(refl)} reflections") ## Calculate the expected intensity by monte-carlo integration # progress = ProgressBar(title='Integrating expected signal for %d reflections' % len(refl)) # s1 = refl['s1'] # phi = refl['xyzcal.mm'].parts()[2] # bbox = refl['bbox'] # shoebox = refl['shoebox'] # I_exp = flex.double(len(refl), 0) # m = int(len(refl) / 100) # for i in range(len(refl)): # if In[i] > 0: # I_exp[i] = integrate_reciprocal_space_gaussian( # self.experiment.beam, # self.experiment.detector, # self.experiment.goniometer, # self.experiment.scan, # self.sigma_b, # self.sigma_m, # s1[i], # phi[i], # bbox[i], # 10000, # shoebox[i].mask) / 10000.0 # if i % m == 0: # progress.update(100.0 * float(i) / len(refl)) # progress.finished('Integrated expected signal impacts for %d reflections' % len(refl)) # Save the expected intensity and background refl["intensity.sim"] = In refl["background.sim.a"] = Ba refl["background.sim.b"] = Bb refl["background.sim.c"] = Bc refl["background.sim.d"] = Bd refl["intensity.exp"] = I_exp # Return the reflections return refl
def with_individual_given_intensity(self, N, I, Ba, Bb, Bc, Bd): """ Generate reflections with given intensity and background. """ from dials.array_family import flex from dials.util.command_line import ProgressBar from dials.algorithms.simulation import simulate_reciprocal_space_gaussian from dials.algorithms.simulation.generate_test_reflections import random_background_plane2 # Check the lengths assert N == len(I) assert N == len(Ba) assert N == len(Bb) assert N == len(Bc) assert N == len(Bd) # Generate some predictions refl = self.generate_predictions(N) # Calculate the signal progress = ProgressBar(title="Calculating signal for %d reflections" % len(refl)) s1 = refl["s1"] phi = refl["xyzcal.mm"].parts()[2] bbox = refl["bbox"] shoebox = refl["shoebox"] m = int(len(refl) / 100) I_exp = flex.double(len(refl), 0) for i in range(len(refl)): if I[i] > 0: data = shoebox[i].data.as_double() I_exp[i] = simulate_reciprocal_space_gaussian( self.experiment.beam, self.experiment.detector, self.experiment.goniometer, self.experiment.scan, self.sigma_b, self.sigma_m, s1[i], phi[i], bbox[i], I[i], data, shoebox[i].mask, ) shoebox[i].data = data.as_float() if i % m == 0: progress.update(100.0 * float(i) / len(refl)) progress.finished("Calculated signal impacts for %d reflections" % len(refl)) # Calculate the background progress = ProgressBar(title="Calculating background for %d reflections" % len(refl)) for l in range(len(refl)): background = flex.float(flex.grid(shoebox[l].size()), 0.0) random_background_plane2(background, Ba[l], Bb[l], Bc[l], Bd[l]) shoebox[l].data += background shoebox[l].background = background if l % m == 0: progress.update(100.0 * float(l) / len(refl)) progress.update(100.0 * float(l) / len(refl)) progress.finished("Calculated background for %d reflections" % len(refl)) ## Calculate the expected intensity by monte-carlo integration # progress = ProgressBar(title='Integrating expected signal for %d reflections' % len(refl)) # s1 = refl['s1'] # phi = refl['xyzcal.mm'].parts()[2] # bbox = refl['bbox'] # shoebox = refl['shoebox'] # I_exp = flex.double(len(refl), 0) # m = int(len(refl) / 100) # for i in range(len(refl)): # if I[i] > 0: # I_exp[i] = integrate_reciprocal_space_gaussian( # self.experiment.beam, # self.experiment.detector, # self.experiment.goniometer, # self.experiment.scan, # self.sigma_b, # self.sigma_m, # s1[i], # phi[i], # bbox[i], # 10000, # shoebox[i].mask) / 10000.0 # if i % m == 0: # progress.update(100.0 * float(i) / len(refl)) # progress.finished('Integrated expected signal impacts for %d reflections' % len(refl)) # Save the expected intensity and background refl["intensity.sim"] = I refl["background.sim.a"] = Ba refl["background.sim.b"] = Bb refl["background.sim.c"] = Bc refl["background.sim.d"] = Bd refl["intensity.exp"] = I_exp # Return the reflections return refl