def _make_sequence( self, imageset, beam=None, detector=None, goniometer=None, scan=None, format_kwargs=None, ): """Make an image sequence.""" # Get the template format template = resolve_path(imageset["template"], directory=self._directory) # Get the number of images (if no scan is given we'll try # to find all the images matching the template if scan is None: i0, i1 = template_image_range(template) else: i0, i1 = scan.get_image_range() format_class = None if self._check_format is False: if "single_file_indices" in imageset: format_class = FormatMultiImage # Make a sequence from the input data return ImageSetFactory.make_sequence( template, list(range(i0, i1 + 1)), format_class=format_class, check_format=self._check_format, beam=beam, detector=detector, goniometer=goniometer, scan=scan, format_kwargs=format_kwargs, )
def from_template( template, image_range=None, check_headers=False, check_format=True, beam=None, detector=None, goniometer=None, scan=None, ): """Create a new sequence from a template. Params: template The template argument image_range The image range check_headers Check the headers to ensure all images are valid Returns: A list of sequences """ if not check_format: assert not check_headers # Check the template is valid if template.count("#") == 0: if "master" not in template: raise ValueError("Invalid template") filenames = [template] else: # Get the template format pfx = template.split("#")[0] sfx = template.split("#")[-1] template_format = "%s%%0%dd%s" % (pfx, template.count("#"), sfx) # Get the template image range if image_range is None: image_range = template_image_range(template) # Set the image range array_range = range(image_range[0] - 1, image_range[1]) # Create the sequence file list filenames = [template_format % (i + 1) for i in array_range] # Import here as Format and Imageset have cyclic dependencies from dxtbx.format.Format import Format # Get the format class if check_format: format_class = dxtbx.format.Registry.get_format_class_for_file( filenames[0]) else: format_class = Format # Create the sequence object sequence = format_class.get_imageset( filenames, template=template, as_sequence=True, beam=beam, detector=detector, goniometer=goniometer, scan=scan, check_format=check_format, ) # Return the sequence return [sequence]
def from_template( template, image_range=None, check_headers=False, check_format=True, beam=None, detector=None, goniometer=None, scan=None, ): """Create a new sequence from a template. Params: template The template argument image_range The image range check_headers Check the headers to ensure all images are valid Returns: A list of sequences """ if not check_format: assert not check_headers # Check the template is valid if "#" in template: # Get the template image range if image_range is None: image_range = template_image_range(template) # Set the image range indices = range(image_range[0], image_range[1] + 1) filenames = _expand_template(template, indices) else: if "master" not in template: raise ValueError("Invalid template") filenames = [template] # Import here as Format and Imageset have cyclic dependencies from dxtbx.format.Format import Format # Get the format class if check_format: format_class = dxtbx.format.Registry.get_format_class_for_file( filenames[0]) else: format_class = Format # Create the sequence object sequence = format_class.get_imageset( filenames, template=template, as_sequence=True, beam=beam, detector=detector, goniometer=goniometer, scan=scan, check_format=check_format, ) return [sequence]