File: tiff_channels_and_files.py

package info (click to toggle)
pylibtiff 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 976 kB
  • sloc: python: 10,219; ansic: 1,064; makefile: 8
file content (64 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

from .tiff_base import TiffBase


class TiffChannelsAndFiles(TiffBase):
    """Represent a collection of TIFF files as a single TIFF source
    object.

    See also
    --------
    TiffFile, TiffFiles

    """

    def __init__(self, channels_files_map):
        """Parameters
        ----------
        channels_files_map : dict
          A dictionary of channel names and TIFF files (``TiffFiles``
          instances)
        """
        self.channels_files_map = channels_files_map

    def get_tiff_array(self, channel, sample_index=0,
                       subfile_type=0, assume_one_image_per_file=False):
        """ Return an array of images for given channel.

        Parameters
        ----------
        channel : str
          The name of a channel.
        sample_index : int
          Specify sample within a pixel.
        subfile_type : int
          Specify TIFF NewSubfileType used for collecting sample images.
        assume_one_image_per_file : bool
          When True then it is assumed that each TIFF file contains
          exactly one image and all images have the same parameters.
          This knowledge speeds up tiff_array construction as only the
          first TIFF file is opened for reading image parameters. The
          other TIFF files are opened only when particular images are
          accessed.

        Returns
        -------
        tiff_array : TiffArray
          Array of sample images. The array has rank equal to 3.
        """
        return self.channels_files_map[channel].get_tiff_array(
            sample_index=sample_index,
            subfile_type=subfile_type,
            assume_one_image_per_file=assume_one_image_per_file)

    def get_info(self):
        lst = []
        for channel, tiff in list(self.channels_files_map.items()):
            lst.append('Channel %s:' % (channel))
            lst.append('-' * len(lst[-1]))
            lst.append(tiff.get_info())
        return '\n'.join(lst)

    def close(self):
        for tiff in self.channels_files_map.values():
            tiff.close()