We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
 remove unused dtype argument in IO plugins
## Description

See #3918

* Add deprecation cycle to these functions.
* Add a bullet in TODO.txt. Indicate #3918 as a way to clean the code in the future.





--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `skimage/io/_plugins/gdal_plugin.py`
Content:
```
1 __all__ = ['imread']
2 
3 try:
4     import osgeo.gdal as gdal
5 except ImportError:
6     raise ImportError("The GDAL Library could not be found. "
7                       "Please refer to http://www.gdal.org/ "
8                       "for further instructions.")
9 
10 
11 def imread(fname, dtype=None):
12     """Load an image from file.
13 
14     """
15     ds = gdal.Open(fname)
16 
17     return ds.ReadAsArray().astype(dtype)
18
```

Path: `skimage/io/_plugins/fits_plugin.py`
Content:
```
1 __all__ = ['imread', 'imread_collection']
2 
3 import skimage.io as io
4 
5 try:
6     from astropy.io import fits as pyfits
7 except ImportError:
8     try:
9         import pyfits
10     except ImportError:
11         raise ImportError(
12             "PyFITS could not be found. Please refer to\n"
13             "http://www.stsci.edu/resources/software_hardware/pyfits\n"
14             "for further instructions.")
15 
16 
17 def imread(fname, dtype=None):
18     """Load an image from a FITS file.
19 
20     Parameters
21     ----------
22     fname : string
23         Image file name, e.g. ``test.fits``.
24     dtype : dtype, optional
25         For FITS, this argument is ignored because Stefan is planning on
26         removing the dtype argument from imread anyway.
27 
28     Returns
29     -------
30     img_array : ndarray
31         Unlike plugins such as PIL, where different color bands/channels are
32         stored in the third dimension, FITS images are greyscale-only and can
33         be N-dimensional, so an array of the native FITS dimensionality is
34         returned, without color channels.
35 
36         Currently if no image is found in the file, None will be returned
37 
38     Notes
39     -----
40 
41     Currently FITS ``imread()`` always returns the first image extension when
42     given a Multi-Extension FITS file; use ``imread_collection()`` (which does
43     lazy loading) to get all the extensions at once.
44 
45     """
46 
47     hdulist = pyfits.open(fname)
48 
49     # Iterate over FITS image extensions, ignoring any other extension types
50     # such as binary tables, and get the first image data array:
51     img_array = None
52     for hdu in hdulist:
53         if isinstance(hdu, pyfits.ImageHDU) or \
54            isinstance(hdu, pyfits.PrimaryHDU):
55             if hdu.data is not None:
56                 img_array = hdu.data
57                 break
58     hdulist.close()
59 
60     return img_array
61 
62 
63 def imread_collection(load_pattern, conserve_memory=True):
64     """Load a collection of images from one or more FITS files
65 
66        Parameters
67        ----------
68        load_pattern : str or list
69            List of extensions to load. Filename globbing is currently
70            unsupported.
71        converve_memory : bool
72            If True, never keep more than one in memory at a specific
73            time. Otherwise, images will be cached once they are loaded.
74 
75        Returns
76        -------
77 
78        ic : ImageCollection
79            Collection of images.
80 
81     """
82 
83     intype = type(load_pattern)
84     if intype is not list and intype is not str:
85         raise TypeError("Input must be a filename or list of filenames")
86 
87     # Ensure we have a list, otherwise we'll end up iterating over the string:
88     if intype is not list:
89         load_pattern = [load_pattern]
90 
91     # Generate a list of filename/extension pairs by opening the list of
92     # files and finding the image extensions in each one:
93     ext_list = []
94     for filename in load_pattern:
95         hdulist = pyfits.open(filename)
96         for n, hdu in zip(range(len(hdulist)), hdulist):
97             if isinstance(hdu, pyfits.ImageHDU) or \
98                isinstance(hdu, pyfits.PrimaryHDU):
99                 # Ignore (primary) header units with no data (use '.size'
100                 # rather than '.data' to avoid actually loading the image):
101                 try:
102                     data_size = hdu.size()
103                 except TypeError:  # (size changed to int in PyFITS 3.1)
104                     data_size = hdu.size
105                 if data_size > 0:
106                     ext_list.append((filename, n))
107         hdulist.close()
108 
109     return io.ImageCollection(ext_list, load_func=FITSFactory,
110                               conserve_memory=conserve_memory)
111 
112 
113 def FITSFactory(image_ext):
114     """Load an image extension from a FITS file and return a NumPy array
115 
116     Parameters
117     ----------
118 
119     image_ext : tuple
120         FITS extension to load, in the format ``(filename, ext_num)``.
121         The FITS ``(extname, extver)`` format is unsupported, since this
122         function is not called directly by the user and
123         ``imread_collection()`` does the work of figuring out which
124         extensions need loading.
125 
126     """
127 
128     # Expect a length-2 tuple with a filename as the first element:
129     if not isinstance(image_ext, tuple):
130         raise TypeError("Expected a tuple")
131 
132     if len(image_ext) != 2:
133         raise ValueError("Expected a tuple of length 2")
134 
135     filename = image_ext[0]
136     extnum = image_ext[1]
137 
138     if type(filename) is not str or type(extnum) is not int:
139         raise ValueError("Expected a (filename, extension) tuple")
140 
141     hdulist = pyfits.open(filename)
142 
143     data = hdulist[extnum].data
144 
145     hdulist.close()
146 
147     if data is None:
148         raise RuntimeError(
149             "Extension %d of %s has no data" % (extnum, filename))
150 
151     return data
152
```

Path: `skimage/io/_plugins/tifffile_plugin.py`
Content:
```
1 try:
2     from tifffile import TiffFile, imsave, parse_kwargs
3 except ImportError:
4     from ...external.tifffile import TiffFile, imsave, parse_kwargs
5 
6 
7 def imread(fname, dtype=None, **kwargs):
8     """Load a tiff image from file.
9 
10     Parameters
11     ----------
12     fname : str or file
13        File name or file-like-object.
14     dtype : numpy dtype object or string specifier
15        Specifies data type of array elements (Not currently used).
16     kwargs : keyword pairs, optional
17         Additional keyword arguments to pass through (see ``tifffile``'s
18         ``imread`` function).
19 
20     Notes
21     -----
22     Provided by Christophe Golhke's tifffile.py [1]_, and supports many
23     advanced image types including multi-page and floating point.
24 
25     References
26     ----------
27     .. [1] http://www.lfd.uci.edu/~gohlke/code/tifffile.py
28 
29     """
30 
31     if 'img_num' in kwargs:
32         kwargs['key'] = kwargs.pop('img_num')
33 
34     # parse_kwargs will extract keyword arguments intended for the TiffFile 
35     # class and remove them from the kwargs dictionary in-place
36     tiff_keys = ['multifile', 'multifile_close', 'pages', 'fastij', 'is_ome']
37     kwargs_tiff = parse_kwargs(kwargs, *tiff_keys)
38 
39     # read and return tiff as numpy array
40     with TiffFile(fname, **kwargs_tiff) as tif:
41         return tif.asarray(**kwargs)
42
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/skimage/io/_plugins/fits_plugin.py b/skimage/io/_plugins/fits_plugin.py
--- a/skimage/io/_plugins/fits_plugin.py
+++ b/skimage/io/_plugins/fits_plugin.py
@@ -1,6 +1,7 @@
 __all__ = ['imread', 'imread_collection']
 
 import skimage.io as io
+from warnings import warn
 
 try:
     from astropy.io import fits as pyfits
@@ -22,8 +23,8 @@
     fname : string
         Image file name, e.g. ``test.fits``.
     dtype : dtype, optional
-        For FITS, this argument is ignored because Stefan is planning on
-        removing the dtype argument from imread anyway.
+        Was always silently ignored.
+        Will be removed from version 0.17.
 
     Returns
     -------
@@ -43,6 +44,11 @@
     lazy loading) to get all the extensions at once.
 
     """
+    if 'dtype' is not None:
+        warn('The dtype argument was always silently ignored. It will be '
+             'removed from scikit-image version 0.17. To avoid this '
+             'warning, do not specify it in your function call.',
+             UserWarning, stacklevel=2)
 
     hdulist = pyfits.open(fname)
 
diff --git a/skimage/io/_plugins/gdal_plugin.py b/skimage/io/_plugins/gdal_plugin.py
--- a/skimage/io/_plugins/gdal_plugin.py
+++ b/skimage/io/_plugins/gdal_plugin.py
@@ -1,5 +1,7 @@
 __all__ = ['imread']
 
+from warnings import warn
+
 try:
     import osgeo.gdal as gdal
 except ImportError:
@@ -12,6 +14,12 @@
     """Load an image from file.
 
     """
+    if 'dtype' is not None:
+        warn('The dtype argument was always silently ignored. It will be '
+             'removed from scikit-image version 0.17. To avoid this '
+             'warning, do not specify it in your function call.',
+             UserWarning, stacklevel=2)
+
     ds = gdal.Open(fname)
 
     return ds.ReadAsArray().astype(dtype)
diff --git a/skimage/io/_plugins/tifffile_plugin.py b/skimage/io/_plugins/tifffile_plugin.py
--- a/skimage/io/_plugins/tifffile_plugin.py
+++ b/skimage/io/_plugins/tifffile_plugin.py
@@ -1,3 +1,5 @@
+from warnings import warn
+
 try:
     from tifffile import TiffFile, imsave, parse_kwargs
 except ImportError:
@@ -12,7 +14,8 @@
     fname : str or file
        File name or file-like-object.
     dtype : numpy dtype object or string specifier
-       Specifies data type of array elements (Not currently used).
+       Specifies data type of array elements.
+       Will be removed from version 0.17.
     kwargs : keyword pairs, optional
         Additional keyword arguments to pass through (see ``tifffile``'s
         ``imread`` function).
@@ -27,11 +30,16 @@
     .. [1] http://www.lfd.uci.edu/~gohlke/code/tifffile.py
 
     """
+    if 'dtype' is not None:
+        warn('The dtype argument was always silently ignored. It will be '
+             'removed from scikit-image version 0.17. To avoid this '
+             'warning, do not specify it in your function call.',
+             UserWarning, stacklevel=2)
 
     if 'img_num' in kwargs:
         kwargs['key'] = kwargs.pop('img_num')
 
-    # parse_kwargs will extract keyword arguments intended for the TiffFile 
+    # parse_kwargs will extract keyword arguments intended for the TiffFile
     # class and remove them from the kwargs dictionary in-place
     tiff_keys = ['multifile', 'multifile_close', 'pages', 'fastij', 'is_ome']
     kwargs_tiff = parse_kwargs(kwargs, *tiff_keys)

{"golden_diff": "diff --git a/skimage/io/_plugins/fits_plugin.py b/skimage/io/_plugins/fits_plugin.py\n--- a/skimage/io/_plugins/fits_plugin.py\n+++ b/skimage/io/_plugins/fits_plugin.py\n@@ -1,6 +1,7 @@\n __all__ = ['imread', 'imread_collection']\n \n import skimage.io as io\n+from warnings import warn\n \n try:\n     from astropy.io import fits as pyfits\n@@ -22,8 +23,8 @@\n     fname : string\n         Image file name, e.g. ``test.fits``.\n     dtype : dtype, optional\n-        For FITS, this argument is ignored because Stefan is planning on\n-        removing the dtype argument from imread anyway.\n+        Was always silently ignored.\n+        Will be removed from version 0.17.\n \n     Returns\n     -------\n@@ -43,6 +44,11 @@\n     lazy loading) to get all the extensions at once.\n \n     \"\"\"\n+    if 'dtype' is not None:\n+        warn('The dtype argument was always silently ignored. It will be '\n+             'removed from scikit-image version 0.17. To avoid this '\n+             'warning, do not specify it in your function call.',\n+             UserWarning, stacklevel=2)\n \n     hdulist = pyfits.open(fname)\n \ndiff --git a/skimage/io/_plugins/gdal_plugin.py b/skimage/io/_plugins/gdal_plugin.py\n--- a/skimage/io/_plugins/gdal_plugin.py\n+++ b/skimage/io/_plugins/gdal_plugin.py\n@@ -1,5 +1,7 @@\n __all__ = ['imread']\n \n+from warnings import warn\n+\n try:\n     import osgeo.gdal as gdal\n except ImportError:\n@@ -12,6 +14,12 @@\n     \"\"\"Load an image from file.\n \n     \"\"\"\n+    if 'dtype' is not None:\n+        warn('The dtype argument was always silently ignored. It will be '\n+             'removed from scikit-image version 0.17. To avoid this '\n+             'warning, do not specify it in your function call.',\n+             UserWarning, stacklevel=2)\n+\n     ds = gdal.Open(fname)\n \n     return ds.ReadAsArray().astype(dtype)\ndiff --git a/skimage/io/_plugins/tifffile_plugin.py b/skimage/io/_plugins/tifffile_plugin.py\n--- a/skimage/io/_plugins/tifffile_plugin.py\n+++ b/skimage/io/_plugins/tifffile_plugin.py\n@@ -1,3 +1,5 @@\n+from warnings import warn\n+\n try:\n     from tifffile import TiffFile, imsave, parse_kwargs\n except ImportError:\n@@ -12,7 +14,8 @@\n     fname : str or file\n        File name or file-like-object.\n     dtype : numpy dtype object or string specifier\n-       Specifies data type of array elements (Not currently used).\n+       Specifies data type of array elements.\n+       Will be removed from version 0.17.\n     kwargs : keyword pairs, optional\n         Additional keyword arguments to pass through (see ``tifffile``'s\n         ``imread`` function).\n@@ -27,11 +30,16 @@\n     .. [1] http://www.lfd.uci.edu/~gohlke/code/tifffile.py\n \n     \"\"\"\n+    if 'dtype' is not None:\n+        warn('The dtype argument was always silently ignored. It will be '\n+             'removed from scikit-image version 0.17. To avoid this '\n+             'warning, do not specify it in your function call.',\n+             UserWarning, stacklevel=2)\n \n     if 'img_num' in kwargs:\n         kwargs['key'] = kwargs.pop('img_num')\n \n-    # parse_kwargs will extract keyword arguments intended for the TiffFile \n+    # parse_kwargs will extract keyword arguments intended for the TiffFile\n     # class and remove them from the kwargs dictionary in-place\n     tiff_keys = ['multifile', 'multifile_close', 'pages', 'fastij', 'is_ome']\n     kwargs_tiff = parse_kwargs(kwargs, *tiff_keys)\n", "issue": " remove unused dtype argument in IO plugins\n## Description\r\n\r\nSee #3918\r\n\r\n* Add deprecation cycle to these functions.\r\n* Add a bullet in TODO.txt. Indicate #3918 as a way to clean the code in the future.\r\n\r\n\r\n\r\n\n", "before_files": [{"content": "__all__ = ['imread']\n\ntry:\n    import osgeo.gdal as gdal\nexcept ImportError:\n    raise ImportError(\"The GDAL Library could not be found. \"\n                      \"Please refer to http://www.gdal.org/ \"\n                      \"for further instructions.\")\n\n\ndef imread(fname, dtype=None):\n    \"\"\"Load an image from file.\n\n    \"\"\"\n    ds = gdal.Open(fname)\n\n    return ds.ReadAsArray().astype(dtype)\n", "path": "skimage/io/_plugins/gdal_plugin.py"}, {"content": "__all__ = ['imread', 'imread_collection']\n\nimport skimage.io as io\n\ntry:\n    from astropy.io import fits as pyfits\nexcept ImportError:\n    try:\n        import pyfits\n    except ImportError:\n        raise ImportError(\n            \"PyFITS could not be found. Please refer to\\n\"\n            \"http://www.stsci.edu/resources/software_hardware/pyfits\\n\"\n            \"for further instructions.\")\n\n\ndef imread(fname, dtype=None):\n    \"\"\"Load an image from a FITS file.\n\n    Parameters\n    ----------\n    fname : string\n        Image file name, e.g. ``test.fits``.\n    dtype : dtype, optional\n        For FITS, this argument is ignored because Stefan is planning on\n        removing the dtype argument from imread anyway.\n\n    Returns\n    -------\n    img_array : ndarray\n        Unlike plugins such as PIL, where different color bands/channels are\n        stored in the third dimension, FITS images are greyscale-only and can\n        be N-dimensional, so an array of the native FITS dimensionality is\n        returned, without color channels.\n\n        Currently if no image is found in the file, None will be returned\n\n    Notes\n    -----\n\n    Currently FITS ``imread()`` always returns the first image extension when\n    given a Multi-Extension FITS file; use ``imread_collection()`` (which does\n    lazy loading) to get all the extensions at once.\n\n    \"\"\"\n\n    hdulist = pyfits.open(fname)\n\n    # Iterate over FITS image extensions, ignoring any other extension types\n    # such as binary tables, and get the first image data array:\n    img_array = None\n    for hdu in hdulist:\n        if isinstance(hdu, pyfits.ImageHDU) or \\\n           isinstance(hdu, pyfits.PrimaryHDU):\n            if hdu.data is not None:\n                img_array = hdu.data\n                break\n    hdulist.close()\n\n    return img_array\n\n\ndef imread_collection(load_pattern, conserve_memory=True):\n    \"\"\"Load a collection of images from one or more FITS files\n\n       Parameters\n       ----------\n       load_pattern : str or list\n           List of extensions to load. Filename globbing is currently\n           unsupported.\n       converve_memory : bool\n           If True, never keep more than one in memory at a specific\n           time. Otherwise, images will be cached once they are loaded.\n\n       Returns\n       -------\n\n       ic : ImageCollection\n           Collection of images.\n\n    \"\"\"\n\n    intype = type(load_pattern)\n    if intype is not list and intype is not str:\n        raise TypeError(\"Input must be a filename or list of filenames\")\n\n    # Ensure we have a list, otherwise we'll end up iterating over the string:\n    if intype is not list:\n        load_pattern = [load_pattern]\n\n    # Generate a list of filename/extension pairs by opening the list of\n    # files and finding the image extensions in each one:\n    ext_list = []\n    for filename in load_pattern:\n        hdulist = pyfits.open(filename)\n        for n, hdu in zip(range(len(hdulist)), hdulist):\n            if isinstance(hdu, pyfits.ImageHDU) or \\\n               isinstance(hdu, pyfits.PrimaryHDU):\n                # Ignore (primary) header units with no data (use '.size'\n                # rather than '.data' to avoid actually loading the image):\n                try:\n                    data_size = hdu.size()\n                except TypeError:  # (size changed to int in PyFITS 3.1)\n                    data_size = hdu.size\n                if data_size > 0:\n                    ext_list.append((filename, n))\n        hdulist.close()\n\n    return io.ImageCollection(ext_list, load_func=FITSFactory,\n                              conserve_memory=conserve_memory)\n\n\ndef FITSFactory(image_ext):\n    \"\"\"Load an image extension from a FITS file and return a NumPy array\n\n    Parameters\n    ----------\n\n    image_ext : tuple\n        FITS extension to load, in the format ``(filename, ext_num)``.\n        The FITS ``(extname, extver)`` format is unsupported, since this\n        function is not called directly by the user and\n        ``imread_collection()`` does the work of figuring out which\n        extensions need loading.\n\n    \"\"\"\n\n    # Expect a length-2 tuple with a filename as the first element:\n    if not isinstance(image_ext, tuple):\n        raise TypeError(\"Expected a tuple\")\n\n    if len(image_ext) != 2:\n        raise ValueError(\"Expected a tuple of length 2\")\n\n    filename = image_ext[0]\n    extnum = image_ext[1]\n\n    if type(filename) is not str or type(extnum) is not int:\n        raise ValueError(\"Expected a (filename, extension) tuple\")\n\n    hdulist = pyfits.open(filename)\n\n    data = hdulist[extnum].data\n\n    hdulist.close()\n\n    if data is None:\n        raise RuntimeError(\n            \"Extension %d of %s has no data\" % (extnum, filename))\n\n    return data\n", "path": "skimage/io/_plugins/fits_plugin.py"}, {"content": "try:\n    from tifffile import TiffFile, imsave, parse_kwargs\nexcept ImportError:\n    from ...external.tifffile import TiffFile, imsave, parse_kwargs\n\n\ndef imread(fname, dtype=None, **kwargs):\n    \"\"\"Load a tiff image from file.\n\n    Parameters\n    ----------\n    fname : str or file\n       File name or file-like-object.\n    dtype : numpy dtype object or string specifier\n       Specifies data type of array elements (Not currently used).\n    kwargs : keyword pairs, optional\n        Additional keyword arguments to pass through (see ``tifffile``'s\n        ``imread`` function).\n\n    Notes\n    -----\n    Provided by Christophe Golhke's tifffile.py [1]_, and supports many\n    advanced image types including multi-page and floating point.\n\n    References\n    ----------\n    .. [1] http://www.lfd.uci.edu/~gohlke/code/tifffile.py\n\n    \"\"\"\n\n    if 'img_num' in kwargs:\n        kwargs['key'] = kwargs.pop('img_num')\n\n    # parse_kwargs will extract keyword arguments intended for the TiffFile \n    # class and remove them from the kwargs dictionary in-place\n    tiff_keys = ['multifile', 'multifile_close', 'pages', 'fastij', 'is_ome']\n    kwargs_tiff = parse_kwargs(kwargs, *tiff_keys)\n\n    # read and return tiff as numpy array\n    with TiffFile(fname, **kwargs_tiff) as tif:\n        return tif.asarray(**kwargs)\n", "path": "skimage/io/_plugins/tifffile_plugin.py"}], "after_files": [{"content": "__all__ = ['imread']\n\nfrom warnings import warn\n\ntry:\n    import osgeo.gdal as gdal\nexcept ImportError:\n    raise ImportError(\"The GDAL Library could not be found. \"\n                      \"Please refer to http://www.gdal.org/ \"\n                      \"for further instructions.\")\n\n\ndef imread(fname, dtype=None):\n    \"\"\"Load an image from file.\n\n    \"\"\"\n    if 'dtype' is not None:\n        warn('The dtype argument was always silently ignored. It will be '\n             'removed from scikit-image version 0.17. To avoid this '\n             'warning, do not specify it in your function call.',\n             UserWarning, stacklevel=2)\n\n    ds = gdal.Open(fname)\n\n    return ds.ReadAsArray().astype(dtype)\n", "path": "skimage/io/_plugins/gdal_plugin.py"}, {"content": "__all__ = ['imread', 'imread_collection']\n\nimport skimage.io as io\nfrom warnings import warn\n\ntry:\n    from astropy.io import fits as pyfits\nexcept ImportError:\n    try:\n        import pyfits\n    except ImportError:\n        raise ImportError(\n            \"PyFITS could not be found. Please refer to\\n\"\n            \"http://www.stsci.edu/resources/software_hardware/pyfits\\n\"\n            \"for further instructions.\")\n\n\ndef imread(fname, dtype=None):\n    \"\"\"Load an image from a FITS file.\n\n    Parameters\n    ----------\n    fname : string\n        Image file name, e.g. ``test.fits``.\n    dtype : dtype, optional\n        Was always silently ignored.\n        Will be removed from version 0.17.\n\n    Returns\n    -------\n    img_array : ndarray\n        Unlike plugins such as PIL, where different color bands/channels are\n        stored in the third dimension, FITS images are greyscale-only and can\n        be N-dimensional, so an array of the native FITS dimensionality is\n        returned, without color channels.\n\n        Currently if no image is found in the file, None will be returned\n\n    Notes\n    -----\n\n    Currently FITS ``imread()`` always returns the first image extension when\n    given a Multi-Extension FITS file; use ``imread_collection()`` (which does\n    lazy loading) to get all the extensions at once.\n\n    \"\"\"\n    if 'dtype' is not None:\n        warn('The dtype argument was always silently ignored. It will be '\n             'removed from scikit-image version 0.17. To avoid this '\n             'warning, do not specify it in your function call.',\n             UserWarning, stacklevel=2)\n\n    hdulist = pyfits.open(fname)\n\n    # Iterate over FITS image extensions, ignoring any other extension types\n    # such as binary tables, and get the first image data array:\n    img_array = None\n    for hdu in hdulist:\n        if isinstance(hdu, pyfits.ImageHDU) or \\\n           isinstance(hdu, pyfits.PrimaryHDU):\n            if hdu.data is not None:\n                img_array = hdu.data\n                break\n    hdulist.close()\n\n    return img_array\n\n\ndef imread_collection(load_pattern, conserve_memory=True):\n    \"\"\"Load a collection of images from one or more FITS files\n\n       Parameters\n       ----------\n       load_pattern : str or list\n           List of extensions to load. Filename globbing is currently\n           unsupported.\n       converve_memory : bool\n           If True, never keep more than one in memory at a specific\n           time. Otherwise, images will be cached once they are loaded.\n\n       Returns\n       -------\n\n       ic : ImageCollection\n           Collection of images.\n\n    \"\"\"\n\n    intype = type(load_pattern)\n    if intype is not list and intype is not str:\n        raise TypeError(\"Input must be a filename or list of filenames\")\n\n    # Ensure we have a list, otherwise we'll end up iterating over the string:\n    if intype is not list:\n        load_pattern = [load_pattern]\n\n    # Generate a list of filename/extension pairs by opening the list of\n    # files and finding the image extensions in each one:\n    ext_list = []\n    for filename in load_pattern:\n        hdulist = pyfits.open(filename)\n        for n, hdu in zip(range(len(hdulist)), hdulist):\n            if isinstance(hdu, pyfits.ImageHDU) or \\\n               isinstance(hdu, pyfits.PrimaryHDU):\n                # Ignore (primary) header units with no data (use '.size'\n                # rather than '.data' to avoid actually loading the image):\n                try:\n                    data_size = hdu.size()\n                except TypeError:  # (size changed to int in PyFITS 3.1)\n                    data_size = hdu.size\n                if data_size > 0:\n                    ext_list.append((filename, n))\n        hdulist.close()\n\n    return io.ImageCollection(ext_list, load_func=FITSFactory,\n                              conserve_memory=conserve_memory)\n\n\ndef FITSFactory(image_ext):\n    \"\"\"Load an image extension from a FITS file and return a NumPy array\n\n    Parameters\n    ----------\n\n    image_ext : tuple\n        FITS extension to load, in the format ``(filename, ext_num)``.\n        The FITS ``(extname, extver)`` format is unsupported, since this\n        function is not called directly by the user and\n        ``imread_collection()`` does the work of figuring out which\n        extensions need loading.\n\n    \"\"\"\n\n    # Expect a length-2 tuple with a filename as the first element:\n    if not isinstance(image_ext, tuple):\n        raise TypeError(\"Expected a tuple\")\n\n    if len(image_ext) != 2:\n        raise ValueError(\"Expected a tuple of length 2\")\n\n    filename = image_ext[0]\n    extnum = image_ext[1]\n\n    if type(filename) is not str or type(extnum) is not int:\n        raise ValueError(\"Expected a (filename, extension) tuple\")\n\n    hdulist = pyfits.open(filename)\n\n    data = hdulist[extnum].data\n\n    hdulist.close()\n\n    if data is None:\n        raise RuntimeError(\n            \"Extension %d of %s has no data\" % (extnum, filename))\n\n    return data\n", "path": "skimage/io/_plugins/fits_plugin.py"}, {"content": "from warnings import warn\n\ntry:\n    from tifffile import TiffFile, imsave, parse_kwargs\nexcept ImportError:\n    from ...external.tifffile import TiffFile, imsave, parse_kwargs\n\n\ndef imread(fname, dtype=None, **kwargs):\n    \"\"\"Load a tiff image from file.\n\n    Parameters\n    ----------\n    fname : str or file\n       File name or file-like-object.\n    dtype : numpy dtype object or string specifier\n       Specifies data type of array elements.\n       Will be removed from version 0.17.\n    kwargs : keyword pairs, optional\n        Additional keyword arguments to pass through (see ``tifffile``'s\n        ``imread`` function).\n\n    Notes\n    -----\n    Provided by Christophe Golhke's tifffile.py [1]_, and supports many\n    advanced image types including multi-page and floating point.\n\n    References\n    ----------\n    .. [1] http://www.lfd.uci.edu/~gohlke/code/tifffile.py\n\n    \"\"\"\n    if 'dtype' is not None:\n        warn('The dtype argument was always silently ignored. It will be '\n             'removed from scikit-image version 0.17. To avoid this '\n             'warning, do not specify it in your function call.',\n             UserWarning, stacklevel=2)\n\n    if 'img_num' in kwargs:\n        kwargs['key'] = kwargs.pop('img_num')\n\n    # parse_kwargs will extract keyword arguments intended for the TiffFile\n    # class and remove them from the kwargs dictionary in-place\n    tiff_keys = ['multifile', 'multifile_close', 'pages', 'fastij', 'is_ome']\n    kwargs_tiff = parse_kwargs(kwargs, *tiff_keys)\n\n    # read and return tiff as numpy array\n    with TiffFile(fname, **kwargs_tiff) as tif:\n        return tif.asarray(**kwargs)\n", "path": "skimage/io/_plugins/tifffile_plugin.py"}]}