prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Use astropy instead of pyfits to read FITS images
  pyfits is not currently installable on 3.5, and it looks like AstroPy is more actively maintained.
  
  --- 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/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
  ```
  --- 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()
  
  ```
  
golden_diff: 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
  @@ -3,15 +3,12 @@
   import skimage.io as io
   
   try:
  -    from astropy.io import fits as pyfits
  +    from astropy.io import fits
   except ImportError:
  -    try:
  -        import pyfits
  -    except ImportError:
  -        raise ImportError(
  -            "PyFITS could not be found. Please refer to\n"
  -            "http://www.stsci.edu/resources/software_hardware/pyfits\n"
  -            "for further instructions.")
  +    raise ImportError(
  +        "Astropy could not be found. It is needed to read FITS files.\n"
  +        "Please refer to http://www.astropy.org for installation\n"
  +        "instructions.")
   
   
   def imread(fname, dtype=None):
  @@ -44,14 +41,14 @@
   
       """
   
  -    hdulist = pyfits.open(fname)
  +    hdulist = fits.open(fname)
   
       # Iterate over FITS image extensions, ignoring any other extension types
       # such as binary tables, and get the first image data array:
       img_array = None
       for hdu in hdulist:
  -        if isinstance(hdu, pyfits.ImageHDU) or \
  -           isinstance(hdu, pyfits.PrimaryHDU):
  +        if isinstance(hdu, fits.ImageHDU) or \
  +           isinstance(hdu, fits.PrimaryHDU):
               if hdu.data is not None:
                   img_array = hdu.data
                   break
  @@ -92,16 +89,16 @@
       # files and finding the image extensions in each one:
       ext_list = []
       for filename in load_pattern:
  -        hdulist = pyfits.open(filename)
  +        hdulist = fits.open(filename)
           for n, hdu in zip(range(len(hdulist)), hdulist):
  -            if isinstance(hdu, pyfits.ImageHDU) or \
  -               isinstance(hdu, pyfits.PrimaryHDU):
  +            if isinstance(hdu, fits.ImageHDU) or \
  +               isinstance(hdu, fits.PrimaryHDU):
                   # Ignore (primary) header units with no data (use '.size'
                   # rather than '.data' to avoid actually loading the image):
                   try:
  +                    data_size = hdu.size  # size is int in Astropy 3.1.2
  +                except TypeError:
                       data_size = hdu.size()
  -                except TypeError:  # (size changed to int in PyFITS 3.1)
  -                    data_size = hdu.size
                   if data_size > 0:
                       ext_list.append((filename, n))
           hdulist.close()
  @@ -138,7 +135,7 @@
       if type(filename) is not str or type(extnum) is not int:
           raise ValueError("Expected a (filename, extension) tuple")
   
  -    hdulist = pyfits.open(filename)
  +    hdulist = fits.open(filename)
   
       data = hdulist[extnum].data
  
verification_info: {"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@@ -3,15 +3,12 @@\n import skimage.io as io\n \n try:\n-    from astropy.io import fits as pyfits\n+    from astropy.io import fits\n except 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+    raise ImportError(\n+        \"Astropy could not be found. It is needed to read FITS files.\\n\"\n+        \"Please refer to http://www.astropy.org for installation\\n\"\n+        \"instructions.\")\n \n \n def imread(fname, dtype=None):\n@@ -44,14 +41,14 @@\n \n     \"\"\"\n \n-    hdulist = pyfits.open(fname)\n+    hdulist = fits.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 isinstance(hdu, fits.ImageHDU) or \\\n+           isinstance(hdu, fits.PrimaryHDU):\n             if hdu.data is not None:\n                 img_array = hdu.data\n                 break\n@@ -92,16 +89,16 @@\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+        hdulist = fits.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+            if isinstance(hdu, fits.ImageHDU) or \\\n+               isinstance(hdu, fits.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  # size is int in Astropy 3.1.2\n+                except TypeError:\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@@ -138,7 +135,7 @@\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+    hdulist = fits.open(filename)\n \n     data = hdulist[extnum].data\n", "issue": "Use astropy instead of pyfits to read FITS images\npyfits is not currently installable on 3.5, and it looks like AstroPy is more actively maintained.\n", "before_files": [{"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"}], "after_files": [{"content": "__all__ = ['imread', 'imread_collection']\n\nimport skimage.io as io\n\ntry:\n    from astropy.io import fits\nexcept ImportError:\n    raise ImportError(\n        \"Astropy could not be found. It is needed to read FITS files.\\n\"\n        \"Please refer to http://www.astropy.org for installation\\n\"\n        \"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 = fits.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, fits.ImageHDU) or \\\n           isinstance(hdu, fits.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 = fits.open(filename)\n        for n, hdu in zip(range(len(hdulist)), hdulist):\n            if isinstance(hdu, fits.ImageHDU) or \\\n               isinstance(hdu, fits.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  # size is int in Astropy 3.1.2\n                except TypeError:\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 = fits.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"}]}