We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Deprecation warnings in rescale.py
``` python
In [13]: dimensions = u.Quantity(np.array(aia.data.shape) / 2048*u.pixel)

In [14]: sp = aia.superpixel(dimensions)
d:\sunpy-master\sunpy\image\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])
d:\sunpy-master\sunpy\image\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])
d:\sunpy-master\sunpy\image\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])
d:\sunpy-master\sunpy\image\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])
d:\sunpy-master\sunpy\image\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])
d:\sunpy-master\sunpy\image\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sunpy/image/rescale.py`
Content:
```
1 """Image resampling methods"""
2 from __future__ import absolute_import, division, print_function
3 
4 import numpy as np
5 import scipy.interpolate
6 import scipy.ndimage
7 from sunpy.extern.six.moves import range
8 
9 __all__ = ['resample', 'reshape_image_to_4d_superpixel']
10 
11 def resample(orig, dimensions, method='linear', center=False, minusone=False):
12     """Returns a new `numpy.ndarray` that has been resampled up or down.
13 
14     Arbitrary resampling of source array to new dimension sizes.
15     Currently only supports maintaining the same number of dimensions.
16     To use 1-D arrays, first promote them to shape (x,1).
17 
18     Uses the same parameters and creates the same co-ordinate lookup points
19     as IDL's congrid routine (which apparently originally came from a
20     VAX/VMS routine of the same name.)
21 
22     Parameters
23     ----------
24     orig : `~numpy.ndarray`
25         Original inout array.
26     dimensions : tuple
27         Dimensions that new `~numpy.ndarray` should have.
28     method : {'neighbor' | 'nearest' | 'linear' | 'spline'}
29         Method to use for resampling interpolation.
30             * neighbor - Closest value from original data
31             * nearest and linear - Uses n x 1-D interpolations calculated by
32               `scipy.interpolate.interp1d`.
33             * spline - Uses ndimage.map_coordinates
34     center : bool
35         If True, interpolation points are at the centers of the bins,
36         otherwise points are at the front edge of the bin.
37     minusone : bool
38         For orig.shape = (i,j) & new dimensions = (x,y), if set to False
39         orig is resampled by factors of (i/x) * (j/y), otherwise orig
40         is resampled by(i-1)/(x-1) * (j-1)/(y-1)
41         This prevents extrapolation one element beyond bounds of input
42         array.
43 
44     Returns
45     -------
46     out : `~numpy.ndarray`
47         A new `~numpy.ndarray` which has been resampled to the desired
48         dimensions.
49 
50     References
51     ----------
52     | http://www.scipy.org/Cookbook/Rebinning (Original source, 2011/11/19)
53     """
54 
55     # Verify that number dimensions requested matches original shape
56     if len(dimensions) != orig.ndim:
57         raise UnequalNumDimensions("Number of dimensions must remain the same "
58                                    "when calling resample.")
59 
60     #@note: will this be okay for integer (e.g. JPEG 2000) data?
61     if orig.dtype not in [np.float64, np.float32]:
62         orig = orig.astype(np.float64)
63 
64     dimensions = np.asarray(dimensions, dtype=np.float64)
65     m1 = np.array(minusone, dtype=np.int64) # array(0) or array(1)
66     offset = np.float64(center * 0.5)       # float64(0.) or float64(0.5)
67 
68     # Resample data
69     if method == 'neighbor':
70         data = _resample_neighbor(orig, dimensions, offset, m1)
71     elif method in ['nearest','linear']:
72         data = _resample_nearest_linear(orig, dimensions, method,
73                                              offset, m1)
74     elif method == 'spline':
75         data = _resample_spline(orig, dimensions, offset, m1)
76     else:
77         raise UnrecognizedInterpolationMethod("Unrecognized interpolation "
78                                               "method requested.")
79 
80     return data
81 
82 
83 def _resample_nearest_linear(orig, dimensions, method, offset, m1):
84     """Resample Map using either linear or nearest interpolation."""
85 
86     dimlist = []
87 
88     # calculate new dims
89     for i in range(orig.ndim):
90         base = np.arange(dimensions[i])
91         dimlist.append((orig.shape[i] - m1) / (dimensions[i] - m1) *
92                        (base + offset) - offset)
93 
94     # specify old coordinates
95     old_coords = [np.arange(i, dtype=np.float) for i in orig.shape]
96 
97     # first interpolation - for ndims = any
98     mint = scipy.interpolate.interp1d(old_coords[-1], orig, bounds_error=False,
99                                       fill_value=min(old_coords[-1]), kind=method)
100 
101     new_data = mint(dimlist[-1])
102 
103     trorder = [orig.ndim - 1] + list(range(orig.ndim - 1))
104     for i in range(orig.ndim - 2, -1, -1):
105         new_data = new_data.transpose(trorder)
106 
107         mint = scipy.interpolate.interp1d(old_coords[i], new_data,
108             bounds_error=False, fill_value=min(old_coords[i]), kind=method)
109         new_data = mint(dimlist[i])
110 
111     if orig.ndim > 1:
112         # need one more transpose to return to original dimensions
113         new_data = new_data.transpose(trorder)
114 
115     return new_data
116 
117 
118 def _resample_neighbor(orig, dimensions, offset, m1):
119     """Resample Map using closest-value interpolation."""
120 
121     dimlist = []
122 
123     for i in range(orig.ndim):
124         base = np.indices(dimensions)[i]
125         dimlist.append((orig.shape[i] - m1) / (dimensions[i] - m1) *
126                        (base + offset) - offset)
127     cd = np.array(dimlist).round().astype(int)
128 
129     return orig[list(cd)]
130 
131 
132 def _resample_spline(orig, dimensions, offset, m1):
133     """Resample Map using spline-based interpolation."""
134 
135     oslices = [slice(0, j) for j in orig.shape]
136     # FIXME: not used?!
137     old_coords = np.ogrid[oslices] #pylint: disable=W0612
138     nslices = [slice(0, j) for j in list(dimensions)]
139     newcoords = np.mgrid[nslices]
140 
141     newcoords_dims = list(range(np.rank(newcoords)))
142 
143     #make first index last
144     newcoords_dims.append(newcoords_dims.pop(0))
145     newcoords_tr = newcoords.transpose(newcoords_dims) #pylint: disable=W0612
146 
147     # makes a view that affects newcoords
148     newcoords_tr += offset
149 
150     deltas = (np.asarray(orig.shape) - m1) / (dimensions - m1)
151     newcoords_tr *= deltas
152 
153     newcoords_tr -= offset
154 
155     return scipy.ndimage.map_coordinates(orig, newcoords)
156 
157 
158 def reshape_image_to_4d_superpixel(img, dimensions, offset):
159     """Re-shape the two dimension input image into a a four dimensional
160     array whose first and third dimensions express the number of original
161     pixels in the x and y directions that form one superpixel. The reshaping
162     makes it very easy to perform operations on superpixels.
163 
164     An application of this reshaping is the following.  Let's say you have an
165     array
166 
167     x = np.array([[0, 0, 0, 1, 1, 1],
168                   [0, 0, 1, 1, 0, 0],
169                   [1, 1, 0, 0, 1, 1],
170                   [0, 0, 0, 0, 1, 1],
171                   [1, 0, 1, 0, 1, 1],
172                   [0, 0, 1, 0, 0, 0]])
173 
174     and you want to sum over 2x2 non-overlapping sub-arrays.  For example, you
175     could have a noisy image and you want to increase the signal-to-noise ratio.
176     Summing over all the non-overlapping 2x2 sub-arrays will create a
177     superpixel array of the original data.  Every pixel in the superpixel array
178     is the sum of the values in a 2x2 sub-array of the original array,
179 
180     This summing can be done by reshaping the array
181 
182     y = x.reshape(3,2,3,2)
183 
184     and then summing over the 1st and third directions
185 
186     y2 = y.sum(axis=3).sum(axis=1)
187 
188     which gives the expected array.
189 
190     array([[0, 3, 2],
191            [2, 0, 4],
192            [1, 2, 2]])
193 
194     Parameters
195     ----------
196     img : `numpy.ndarray`
197         A two-dimensional `~numpy.ndarray` of the form (y, x).
198 
199     dimensions : array-like
200         A two element array-like object containing integers that describe the
201         superpixel summation in the (y, x) directions.
202 
203     offset : array-like
204         A two element array-like object containing integers that describe
205         where in the input image the array reshaping begins in the (y, x)
206         directions.
207 
208     Returns
209     -------
210     A four dimensional `~numpy.ndarray` that can be used to easily create
211     two-dimensional arrays of superpixels of the input image.
212 
213     References
214     ----------
215     Taken from
216     http://mail.scipy.org/pipermail/numpy-discussion/2010-July/051760.html
217 
218     """
219     # New dimensions of the final image
220     na = int(np.floor((img.shape[0] - offset[0]) / dimensions[0]))
221     nb = int(np.floor((img.shape[1] - offset[1]) / dimensions[1]))
222 
223     # Reshape up to a higher dimensional array which is useful for higher
224     # level operations
225     return (img[offset[0]:offset[0] + na*dimensions[0],
226                 offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])
227 
228 
229 class UnrecognizedInterpolationMethod(ValueError):
230     """Unrecognized interpolation method specified."""
231     pass
232 
233 
234 class UnequalNumDimensions(ValueError):
235     """Number of dimensions does not match input array"""
236     pass
237
```
--- 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/sunpy/image/rescale.py b/sunpy/image/rescale.py
--- a/sunpy/image/rescale.py
+++ b/sunpy/image/rescale.py
@@ -216,6 +216,9 @@
     http://mail.scipy.org/pipermail/numpy-discussion/2010-July/051760.html
 
     """
+    # make sure the input dimensions are integers
+    dimensions = [int(dim) for dim in dimensions]
+
     # New dimensions of the final image
     na = int(np.floor((img.shape[0] - offset[0]) / dimensions[0]))
     nb = int(np.floor((img.shape[1] - offset[1]) / dimensions[1]))

{"golden_diff": "diff --git a/sunpy/image/rescale.py b/sunpy/image/rescale.py\n--- a/sunpy/image/rescale.py\n+++ b/sunpy/image/rescale.py\n@@ -216,6 +216,9 @@\n     http://mail.scipy.org/pipermail/numpy-discussion/2010-July/051760.html\n \n     \"\"\"\n+    # make sure the input dimensions are integers\n+    dimensions = [int(dim) for dim in dimensions]\n+\n     # New dimensions of the final image\n     na = int(np.floor((img.shape[0] - offset[0]) / dimensions[0]))\n     nb = int(np.floor((img.shape[1] - offset[1]) / dimensions[1]))\n", "issue": "Deprecation warnings in rescale.py\n``` python\nIn [13]: dimensions = u.Quantity(np.array(aia.data.shape) / 2048*u.pixel)\n\nIn [14]: sp = aia.superpixel(dimensions)\nd:\\sunpy-master\\sunpy\\image\\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])\nd:\\sunpy-master\\sunpy\\image\\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])\nd:\\sunpy-master\\sunpy\\image\\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])\nd:\\sunpy-master\\sunpy\\image\\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])\nd:\\sunpy-master\\sunpy\\image\\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])\nd:\\sunpy-master\\sunpy\\image\\rescale.py:226: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n  offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])\n```\n\n", "before_files": [{"content": "\"\"\"Image resampling methods\"\"\"\nfrom __future__ import absolute_import, division, print_function\n\nimport numpy as np\nimport scipy.interpolate\nimport scipy.ndimage\nfrom sunpy.extern.six.moves import range\n\n__all__ = ['resample', 'reshape_image_to_4d_superpixel']\n\ndef resample(orig, dimensions, method='linear', center=False, minusone=False):\n    \"\"\"Returns a new `numpy.ndarray` that has been resampled up or down.\n\n    Arbitrary resampling of source array to new dimension sizes.\n    Currently only supports maintaining the same number of dimensions.\n    To use 1-D arrays, first promote them to shape (x,1).\n\n    Uses the same parameters and creates the same co-ordinate lookup points\n    as IDL's congrid routine (which apparently originally came from a\n    VAX/VMS routine of the same name.)\n\n    Parameters\n    ----------\n    orig : `~numpy.ndarray`\n        Original inout array.\n    dimensions : tuple\n        Dimensions that new `~numpy.ndarray` should have.\n    method : {'neighbor' | 'nearest' | 'linear' | 'spline'}\n        Method to use for resampling interpolation.\n            * neighbor - Closest value from original data\n            * nearest and linear - Uses n x 1-D interpolations calculated by\n              `scipy.interpolate.interp1d`.\n            * spline - Uses ndimage.map_coordinates\n    center : bool\n        If True, interpolation points are at the centers of the bins,\n        otherwise points are at the front edge of the bin.\n    minusone : bool\n        For orig.shape = (i,j) & new dimensions = (x,y), if set to False\n        orig is resampled by factors of (i/x) * (j/y), otherwise orig\n        is resampled by(i-1)/(x-1) * (j-1)/(y-1)\n        This prevents extrapolation one element beyond bounds of input\n        array.\n\n    Returns\n    -------\n    out : `~numpy.ndarray`\n        A new `~numpy.ndarray` which has been resampled to the desired\n        dimensions.\n\n    References\n    ----------\n    | http://www.scipy.org/Cookbook/Rebinning (Original source, 2011/11/19)\n    \"\"\"\n\n    # Verify that number dimensions requested matches original shape\n    if len(dimensions) != orig.ndim:\n        raise UnequalNumDimensions(\"Number of dimensions must remain the same \"\n                                   \"when calling resample.\")\n\n    #@note: will this be okay for integer (e.g. JPEG 2000) data?\n    if orig.dtype not in [np.float64, np.float32]:\n        orig = orig.astype(np.float64)\n\n    dimensions = np.asarray(dimensions, dtype=np.float64)\n    m1 = np.array(minusone, dtype=np.int64) # array(0) or array(1)\n    offset = np.float64(center * 0.5)       # float64(0.) or float64(0.5)\n\n    # Resample data\n    if method == 'neighbor':\n        data = _resample_neighbor(orig, dimensions, offset, m1)\n    elif method in ['nearest','linear']:\n        data = _resample_nearest_linear(orig, dimensions, method,\n                                             offset, m1)\n    elif method == 'spline':\n        data = _resample_spline(orig, dimensions, offset, m1)\n    else:\n        raise UnrecognizedInterpolationMethod(\"Unrecognized interpolation \"\n                                              \"method requested.\")\n\n    return data\n\n\ndef _resample_nearest_linear(orig, dimensions, method, offset, m1):\n    \"\"\"Resample Map using either linear or nearest interpolation.\"\"\"\n\n    dimlist = []\n\n    # calculate new dims\n    for i in range(orig.ndim):\n        base = np.arange(dimensions[i])\n        dimlist.append((orig.shape[i] - m1) / (dimensions[i] - m1) *\n                       (base + offset) - offset)\n\n    # specify old coordinates\n    old_coords = [np.arange(i, dtype=np.float) for i in orig.shape]\n\n    # first interpolation - for ndims = any\n    mint = scipy.interpolate.interp1d(old_coords[-1], orig, bounds_error=False,\n                                      fill_value=min(old_coords[-1]), kind=method)\n\n    new_data = mint(dimlist[-1])\n\n    trorder = [orig.ndim - 1] + list(range(orig.ndim - 1))\n    for i in range(orig.ndim - 2, -1, -1):\n        new_data = new_data.transpose(trorder)\n\n        mint = scipy.interpolate.interp1d(old_coords[i], new_data,\n            bounds_error=False, fill_value=min(old_coords[i]), kind=method)\n        new_data = mint(dimlist[i])\n\n    if orig.ndim > 1:\n        # need one more transpose to return to original dimensions\n        new_data = new_data.transpose(trorder)\n\n    return new_data\n\n\ndef _resample_neighbor(orig, dimensions, offset, m1):\n    \"\"\"Resample Map using closest-value interpolation.\"\"\"\n\n    dimlist = []\n\n    for i in range(orig.ndim):\n        base = np.indices(dimensions)[i]\n        dimlist.append((orig.shape[i] - m1) / (dimensions[i] - m1) *\n                       (base + offset) - offset)\n    cd = np.array(dimlist).round().astype(int)\n\n    return orig[list(cd)]\n\n\ndef _resample_spline(orig, dimensions, offset, m1):\n    \"\"\"Resample Map using spline-based interpolation.\"\"\"\n\n    oslices = [slice(0, j) for j in orig.shape]\n    # FIXME: not used?!\n    old_coords = np.ogrid[oslices] #pylint: disable=W0612\n    nslices = [slice(0, j) for j in list(dimensions)]\n    newcoords = np.mgrid[nslices]\n\n    newcoords_dims = list(range(np.rank(newcoords)))\n\n    #make first index last\n    newcoords_dims.append(newcoords_dims.pop(0))\n    newcoords_tr = newcoords.transpose(newcoords_dims) #pylint: disable=W0612\n\n    # makes a view that affects newcoords\n    newcoords_tr += offset\n\n    deltas = (np.asarray(orig.shape) - m1) / (dimensions - m1)\n    newcoords_tr *= deltas\n\n    newcoords_tr -= offset\n\n    return scipy.ndimage.map_coordinates(orig, newcoords)\n\n\ndef reshape_image_to_4d_superpixel(img, dimensions, offset):\n    \"\"\"Re-shape the two dimension input image into a a four dimensional\n    array whose first and third dimensions express the number of original\n    pixels in the x and y directions that form one superpixel. The reshaping\n    makes it very easy to perform operations on superpixels.\n\n    An application of this reshaping is the following.  Let's say you have an\n    array\n\n    x = np.array([[0, 0, 0, 1, 1, 1],\n                  [0, 0, 1, 1, 0, 0],\n                  [1, 1, 0, 0, 1, 1],\n                  [0, 0, 0, 0, 1, 1],\n                  [1, 0, 1, 0, 1, 1],\n                  [0, 0, 1, 0, 0, 0]])\n\n    and you want to sum over 2x2 non-overlapping sub-arrays.  For example, you\n    could have a noisy image and you want to increase the signal-to-noise ratio.\n    Summing over all the non-overlapping 2x2 sub-arrays will create a\n    superpixel array of the original data.  Every pixel in the superpixel array\n    is the sum of the values in a 2x2 sub-array of the original array,\n\n    This summing can be done by reshaping the array\n\n    y = x.reshape(3,2,3,2)\n\n    and then summing over the 1st and third directions\n\n    y2 = y.sum(axis=3).sum(axis=1)\n\n    which gives the expected array.\n\n    array([[0, 3, 2],\n           [2, 0, 4],\n           [1, 2, 2]])\n\n    Parameters\n    ----------\n    img : `numpy.ndarray`\n        A two-dimensional `~numpy.ndarray` of the form (y, x).\n\n    dimensions : array-like\n        A two element array-like object containing integers that describe the\n        superpixel summation in the (y, x) directions.\n\n    offset : array-like\n        A two element array-like object containing integers that describe\n        where in the input image the array reshaping begins in the (y, x)\n        directions.\n\n    Returns\n    -------\n    A four dimensional `~numpy.ndarray` that can be used to easily create\n    two-dimensional arrays of superpixels of the input image.\n\n    References\n    ----------\n    Taken from\n    http://mail.scipy.org/pipermail/numpy-discussion/2010-July/051760.html\n\n    \"\"\"\n    # New dimensions of the final image\n    na = int(np.floor((img.shape[0] - offset[0]) / dimensions[0]))\n    nb = int(np.floor((img.shape[1] - offset[1]) / dimensions[1]))\n\n    # Reshape up to a higher dimensional array which is useful for higher\n    # level operations\n    return (img[offset[0]:offset[0] + na*dimensions[0],\n                offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])\n\n\nclass UnrecognizedInterpolationMethod(ValueError):\n    \"\"\"Unrecognized interpolation method specified.\"\"\"\n    pass\n\n\nclass UnequalNumDimensions(ValueError):\n    \"\"\"Number of dimensions does not match input array\"\"\"\n    pass\n", "path": "sunpy/image/rescale.py"}], "after_files": [{"content": "\"\"\"Image resampling methods\"\"\"\nfrom __future__ import absolute_import, division, print_function\n\nimport numpy as np\nimport scipy.interpolate\nimport scipy.ndimage\nfrom sunpy.extern.six.moves import range\n\n__all__ = ['resample', 'reshape_image_to_4d_superpixel']\n\ndef resample(orig, dimensions, method='linear', center=False, minusone=False):\n    \"\"\"Returns a new `numpy.ndarray` that has been resampled up or down.\n\n    Arbitrary resampling of source array to new dimension sizes.\n    Currently only supports maintaining the same number of dimensions.\n    To use 1-D arrays, first promote them to shape (x,1).\n\n    Uses the same parameters and creates the same co-ordinate lookup points\n    as IDL's congrid routine (which apparently originally came from a\n    VAX/VMS routine of the same name.)\n\n    Parameters\n    ----------\n    orig : `~numpy.ndarray`\n        Original inout array.\n    dimensions : tuple\n        Dimensions that new `~numpy.ndarray` should have.\n    method : {'neighbor' | 'nearest' | 'linear' | 'spline'}\n        Method to use for resampling interpolation.\n            * neighbor - Closest value from original data\n            * nearest and linear - Uses n x 1-D interpolations calculated by\n              `scipy.interpolate.interp1d`.\n            * spline - Uses ndimage.map_coordinates\n    center : bool\n        If True, interpolation points are at the centers of the bins,\n        otherwise points are at the front edge of the bin.\n    minusone : bool\n        For orig.shape = (i,j) & new dimensions = (x,y), if set to False\n        orig is resampled by factors of (i/x) * (j/y), otherwise orig\n        is resampled by(i-1)/(x-1) * (j-1)/(y-1)\n        This prevents extrapolation one element beyond bounds of input\n        array.\n\n    Returns\n    -------\n    out : `~numpy.ndarray`\n        A new `~numpy.ndarray` which has been resampled to the desired\n        dimensions.\n\n    References\n    ----------\n    | http://www.scipy.org/Cookbook/Rebinning (Original source, 2011/11/19)\n    \"\"\"\n\n    # Verify that number dimensions requested matches original shape\n    if len(dimensions) != orig.ndim:\n        raise UnequalNumDimensions(\"Number of dimensions must remain the same \"\n                                   \"when calling resample.\")\n\n    #@note: will this be okay for integer (e.g. JPEG 2000) data?\n    if orig.dtype not in [np.float64, np.float32]:\n        orig = orig.astype(np.float64)\n\n    dimensions = np.asarray(dimensions, dtype=np.float64)\n    m1 = np.array(minusone, dtype=np.int64) # array(0) or array(1)\n    offset = np.float64(center * 0.5)       # float64(0.) or float64(0.5)\n\n    # Resample data\n    if method == 'neighbor':\n        data = _resample_neighbor(orig, dimensions, offset, m1)\n    elif method in ['nearest','linear']:\n        data = _resample_nearest_linear(orig, dimensions, method,\n                                             offset, m1)\n    elif method == 'spline':\n        data = _resample_spline(orig, dimensions, offset, m1)\n    else:\n        raise UnrecognizedInterpolationMethod(\"Unrecognized interpolation \"\n                                              \"method requested.\")\n\n    return data\n\n\ndef _resample_nearest_linear(orig, dimensions, method, offset, m1):\n    \"\"\"Resample Map using either linear or nearest interpolation.\"\"\"\n\n    dimlist = []\n\n    # calculate new dims\n    for i in range(orig.ndim):\n        base = np.arange(dimensions[i])\n        dimlist.append((orig.shape[i] - m1) / (dimensions[i] - m1) *\n                       (base + offset) - offset)\n\n    # specify old coordinates\n    old_coords = [np.arange(i, dtype=np.float) for i in orig.shape]\n\n    # first interpolation - for ndims = any\n    mint = scipy.interpolate.interp1d(old_coords[-1], orig, bounds_error=False,\n                                      fill_value=min(old_coords[-1]), kind=method)\n\n    new_data = mint(dimlist[-1])\n\n    trorder = [orig.ndim - 1] + list(range(orig.ndim - 1))\n    for i in range(orig.ndim - 2, -1, -1):\n        new_data = new_data.transpose(trorder)\n\n        mint = scipy.interpolate.interp1d(old_coords[i], new_data,\n            bounds_error=False, fill_value=min(old_coords[i]), kind=method)\n        new_data = mint(dimlist[i])\n\n    if orig.ndim > 1:\n        # need one more transpose to return to original dimensions\n        new_data = new_data.transpose(trorder)\n\n    return new_data\n\n\ndef _resample_neighbor(orig, dimensions, offset, m1):\n    \"\"\"Resample Map using closest-value interpolation.\"\"\"\n\n    dimlist = []\n\n    for i in range(orig.ndim):\n        base = np.indices(dimensions)[i]\n        dimlist.append((orig.shape[i] - m1) / (dimensions[i] - m1) *\n                       (base + offset) - offset)\n    cd = np.array(dimlist).round().astype(int)\n\n    return orig[list(cd)]\n\n\ndef _resample_spline(orig, dimensions, offset, m1):\n    \"\"\"Resample Map using spline-based interpolation.\"\"\"\n\n    oslices = [slice(0, j) for j in orig.shape]\n    # FIXME: not used?!\n    old_coords = np.ogrid[oslices] #pylint: disable=W0612\n    nslices = [slice(0, j) for j in list(dimensions)]\n    newcoords = np.mgrid[nslices]\n\n    newcoords_dims = list(range(np.rank(newcoords)))\n\n    #make first index last\n    newcoords_dims.append(newcoords_dims.pop(0))\n    newcoords_tr = newcoords.transpose(newcoords_dims) #pylint: disable=W0612\n\n    # makes a view that affects newcoords\n    newcoords_tr += offset\n\n    deltas = (np.asarray(orig.shape) - m1) / (dimensions - m1)\n    newcoords_tr *= deltas\n\n    newcoords_tr -= offset\n\n    return scipy.ndimage.map_coordinates(orig, newcoords)\n\n\ndef reshape_image_to_4d_superpixel(img, dimensions, offset):\n    \"\"\"Re-shape the two dimension input image into a a four dimensional\n    array whose first and third dimensions express the number of original\n    pixels in the x and y directions that form one superpixel. The reshaping\n    makes it very easy to perform operations on superpixels.\n\n    An application of this reshaping is the following.  Let's say you have an\n    array\n\n    x = np.array([[0, 0, 0, 1, 1, 1],\n                  [0, 0, 1, 1, 0, 0],\n                  [1, 1, 0, 0, 1, 1],\n                  [0, 0, 0, 0, 1, 1],\n                  [1, 0, 1, 0, 1, 1],\n                  [0, 0, 1, 0, 0, 0]])\n\n    and you want to sum over 2x2 non-overlapping sub-arrays.  For example, you\n    could have a noisy image and you want to increase the signal-to-noise ratio.\n    Summing over all the non-overlapping 2x2 sub-arrays will create a\n    superpixel array of the original data.  Every pixel in the superpixel array\n    is the sum of the values in a 2x2 sub-array of the original array,\n\n    This summing can be done by reshaping the array\n\n    y = x.reshape(3,2,3,2)\n\n    and then summing over the 1st and third directions\n\n    y2 = y.sum(axis=3).sum(axis=1)\n\n    which gives the expected array.\n\n    array([[0, 3, 2],\n           [2, 0, 4],\n           [1, 2, 2]])\n\n    Parameters\n    ----------\n    img : `numpy.ndarray`\n        A two-dimensional `~numpy.ndarray` of the form (y, x).\n\n    dimensions : array-like\n        A two element array-like object containing integers that describe the\n        superpixel summation in the (y, x) directions.\n\n    offset : array-like\n        A two element array-like object containing integers that describe\n        where in the input image the array reshaping begins in the (y, x)\n        directions.\n\n    Returns\n    -------\n    A four dimensional `~numpy.ndarray` that can be used to easily create\n    two-dimensional arrays of superpixels of the input image.\n\n    References\n    ----------\n    Taken from\n    http://mail.scipy.org/pipermail/numpy-discussion/2010-July/051760.html\n\n    \"\"\"\n    # make sure the input dimensions are integers\n    dimensions = [int(dim) for dim in dimensions]\n\n    # New dimensions of the final image\n    na = int(np.floor((img.shape[0] - offset[0]) / dimensions[0]))\n    nb = int(np.floor((img.shape[1] - offset[1]) / dimensions[1]))\n\n    # Reshape up to a higher dimensional array which is useful for higher\n    # level operations\n    return (img[offset[0]:offset[0] + na*dimensions[0],\n                offset[1]:offset[1] + nb*dimensions[1]]).reshape(na, dimensions[0], nb, dimensions[1])\n\n\nclass UnrecognizedInterpolationMethod(ValueError):\n    \"\"\"Unrecognized interpolation method specified.\"\"\"\n    pass\n\n\nclass UnequalNumDimensions(ValueError):\n    \"\"\"Number of dimensions does not match input array\"\"\"\n    pass\n", "path": "sunpy/image/rescale.py"}]}