def generate_predictions(self, N): """Generate some reflections.""" from dials.algorithms import filtering from dials.algorithms.profile_model.gaussian_rs import MaskCalculator3D from dials.algorithms.profile_model.gaussian_rs import Model as ProfileModel from dials.algorithms.shoebox import MaskCode from dials.util.command_line import Command # Set the profile model self.experiment.profile = ProfileModel(None, self.n_sigma, self.sigma_b, self.sigma_m) # Generate a list of reflections refl = flex.reflection_table.from_predictions(self.experiment) refl["id"] = flex.int(len(refl), 0) # Filter by zeta zeta = 0.05 Command.start(f"Filtering by zeta >= {zeta:f}") mask = filtering.by_zeta(self.experiment.goniometer, self.experiment.beam, refl["s1"], zeta) refl.del_selected(~mask) Command.end(f"Filtered {len(refl)} reflections by zeta >= {zeta:f}") # Compute the bounding box refl.compute_bbox([self.experiment]) index = [] image_size = self.experiment.detector[0].get_image_size() array_range = self.experiment.scan.get_array_range() bbox = refl["bbox"] for i in range(len(refl)): x0, x1, y0, y1, z0, z1 = bbox[i] if (x0 < 0 or x1 > image_size[0] or y0 < 0 or y1 > image_size[1] or z0 < array_range[0] or z1 > array_range[1]): index.append(i) refl.del_selected(flex.size_t(index)) # Sample if specified index = random.sample(range(len(refl)), N) refl = refl.select(flex.size_t(index)) # Compute the bounding box # Create a load of shoeboxes Command.start(f"Creating shoeboxes for {len(refl)} reflections") refl["shoebox"] = flex.shoebox(refl["panel"], refl["bbox"]) refl["shoebox"].allocate_with_value(MaskCode.Valid) Command.end(f"Created shoeboxes for {len(refl)} reflections") # Get the function object to mask the foreground Command.start(f"Masking Foreground for {len(refl)} reflections") mask_foreground = MaskCalculator3D( self.experiment.beam, self.experiment.detector, self.experiment.goniometer, self.experiment.scan, self.n_sigma * self.sigma_b, self.n_sigma * self.sigma_m, ) # Mask the foreground mask_foreground(refl["shoebox"], refl["s1"], refl["xyzcal.px"].parts()[2], refl["panel"]) Command.end(f"Masked foreground for {len(refl)} reflections") # Return the reflections return refl
def generate_predictions(self, N): """ Generate some reflections. """ from dials.algorithms.profile_model.gaussian_rs import MaskCalculator3D from dials.array_family import flex from dials.util.command_line import Command from dials.algorithms import filtering from dials.algorithms.shoebox import MaskCode from dials.algorithms.profile_model.gaussian_rs import Model as ProfileModel import random # Set the profile model self.experiment.profile = ProfileModel(None, self.n_sigma, self.sigma_b, self.sigma_m) # Generate a list of reflections refl = flex.reflection_table.from_predictions(self.experiment) refl["id"] = flex.int(len(refl), 0) # Filter by zeta zeta = 0.05 Command.start("Filtering by zeta >= %f" % zeta) mask = filtering.by_zeta(self.experiment.goniometer, self.experiment.beam, refl["s1"], zeta) refl.del_selected(mask != True) Command.end("Filtered %d reflections by zeta >= %f" % (len(refl), zeta)) # Compute the bounding box refl.compute_bbox([self.experiment]) index = [] image_size = self.experiment.detector[0].get_image_size() array_range = self.experiment.scan.get_array_range() bbox = refl["bbox"] for i in range(len(refl)): x0, x1, y0, y1, z0, z1 = bbox[i] if ( x0 < 0 or x1 > image_size[0] or y0 < 0 or y1 > image_size[1] or z0 < array_range[0] or z1 > array_range[1] ): index.append(i) refl.del_selected(flex.size_t(index)) # Sample if specified index = random.sample(range(len(refl)), N) refl = refl.select(flex.size_t(index)) # Compute the bounding box # Create a load of shoeboxes Command.start("Creating shoeboxes for %d reflections" % len(refl)) refl["shoebox"] = flex.shoebox(refl["panel"], refl["bbox"]) refl["shoebox"].allocate_with_value(MaskCode.Valid) Command.end("Created shoeboxes for %d reflections" % len(refl)) # Get the function object to mask the foreground Command.start("Masking Foreground for %d reflections" % len(refl)) mask_foreground = MaskCalculator3D( self.experiment.beam, self.experiment.detector, self.experiment.goniometer, self.experiment.scan, self.n_sigma * self.sigma_b, self.n_sigma * self.sigma_m, ) # Mask the foreground mask_foreground(refl["shoebox"], refl["s1"], refl["xyzcal.px"].parts()[2], refl["panel"]) Command.end("Masked foreground for %d reflections" % len(refl)) # Return the reflections return refl