Exemplo n.º 1
0
  def from_template(template, image_range=None, check_headers=False,
                    check_format=True):
    '''Create a new sweep 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 sweeps

    '''
    import os
    from dxtbx.format.Registry import Registry
    from dxtbx.sweep_filenames import template_image_range

    if not check_format: assert not check_headers

    # Check the template is valid
    if template.count('#') < 1:
      raise ValueError("Invalid template")

    # 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 = (image_range[0] - 1, image_range[1])

    # Create the sweep file list
    filenames = SweepFileList(template_format, array_range)

    # Get the format class
    if check_format:
      format_class = Registry.find(filenames[0])
      from format.FormatMultiImage import FormatMultiImage
      if issubclass(format_class, FormatMultiImage):
        assert len(filenames) == 1
        format_instance = format_class(filenames[0])
        reader = SingleFileReader(format_instance)
      else:
        reader = MultiFileReader(format_class, filenames)
    else:
      reader = NullReader(filenames)

    # Create the sweep object
    sweep = ImageSweep(reader)

    # Check the sweep is valid
    if check_headers and not sweep.is_valid():
      raise RuntimeError('Invalid sweep of images')

    # Return the sweep
    return [sweep]
Exemplo n.º 2
0
  def _make_sweep(self, imageset, scan):
    ''' Make an image sweep. '''
    from dxtbx.sweep_filenames import template_image_range
    from dxtbx.imageset import ImageSetFactory
    from dxtbx.serialize.filename import load_path

    # Get the template format
    template = load_path(imageset['template'])

    # 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()

    # Make a sweep from the input data
    return ImageSetFactory.make_sweep(template,
      list(range(i0, i1+1)), None, check_format=self._check_format)
Exemplo n.º 3
0
  def _make_sweep(self,
                  imageset,
                  beam=None,
                  detector=None,
                  goniometer=None,
                  scan=None,
                  format_kwargs=None):
    ''' Make an image sweep. '''
    from dxtbx.sweep_filenames import template_image_range
    from dxtbx.imageset import ImageSetFactory
    from dxtbx.serialize.filename import load_path
    from dxtbx.format.FormatMultiImage import FormatMultiImage

    # Get the template format
    template = load_path(imageset['template'])

    # 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 sweep from the input data
    return ImageSetFactory.make_sweep(
      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 _make_sweep(
        self,
        imageset,
        beam=None,
        detector=None,
        goniometer=None,
        scan=None,
        format_kwargs=None,
    ):
        """ Make an image sweep. """
        # 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 sweep from the input data
        return ImageSetFactory.make_sweep(
            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,
        )
Exemplo n.º 5
0
  def _make_sweep(self, imageset, scan, format_kwargs=None):
    ''' Make an image sweep. '''
    from dxtbx.sweep_filenames import template_image_range
    from dxtbx.imageset import ImageSetFactory
    from dxtbx.serialize.filename import load_path

    # Get the template format
    template = load_path(imageset['template'])

    # 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()

    # Make a sweep from the input data
    return ImageSetFactory.make_sweep(
      template,
      list(range(i0, i1+1)),
      None,
      check_format=self._check_format,
      scan=scan,
      format_kwargs=format_kwargs)
Exemplo n.º 6
0
  def from_template(template,
                    image_range=None,
                    check_headers=False,
                    check_format=True,
                    beam=None,
                    detector=None,
                    goniometer=None,
                    scan=None):
    '''Create a new sweep 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 sweeps

    '''
    import os
    from dxtbx.format.Registry import Registry
    from dxtbx.sweep_filenames import template_image_range
    from dxtbx.format.Format import Format

    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 = (image_range[0] - 1, image_range[1])

      # Create the sweep file list
      filenames = [template_format % (i+1) for i in range(*array_range)]

    # Get the format class
    if check_format:
      format_class = Registry.find(filenames[0])
    else:
      format_class = Format

    # Create the sweep object
    sweep = format_class.get_imageset(
      filenames,
      template=template,
      as_sweep=True,
      beam=beam,
      detector=detector,
      goniometer=goniometer,
      scan=scan,
      check_format=check_format)

    # Return the sweep
    return [sweep]