We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove dataset's ul method
It's been deprecated since June 2016 (0.36).

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `rasterio/io.py`
Content:
```
1 """Classes capable of reading and writing datasets
2 
3 Instances of these classes are called dataset objects.
4 """
5 
6 
7 import logging
8 import math
9 import warnings
10 
11 from rasterio._base import (
12     get_dataset_driver, driver_can_create, driver_can_create_copy)
13 from rasterio._io import (
14     DatasetReaderBase, DatasetWriterBase, BufferedDatasetWriterBase,
15     MemoryFileBase)
16 from rasterio import windows
17 from rasterio.enums import Resampling
18 from rasterio.env import ensure_env
19 from rasterio.errors import RasterioDeprecationWarning
20 from rasterio.transform import guard_transform, xy, rowcol
21 
22 
23 log = logging.getLogger(__name__)
24 
25 
26 class TransformMethodsMixin(object):
27     """Mixin providing methods for calculations related
28     to transforming between rows and columns of the raster
29     array and the coordinates.
30 
31     These methods are wrappers for the functionality in
32     `rasterio.transform` module.
33 
34     A subclass with this mixin MUST provide a `transform`
35     property.
36     """
37 
38     def xy(self, row, col, offset="center"):
39         """Returns the coordinates ``(x, y)`` of a pixel at `row` and `col`.
40         The pixel's center is returned by default, but a corner can be returned
41         by setting `offset` to one of `ul, ur, ll, lr`.
42 
43         Parameters
44         ----------
45         row : int
46             Pixel row.
47         col : int
48             Pixel column.
49         offset : str, optional
50             Determines if the returned coordinates are for the center of the
51             pixel or for a corner.
52 
53         Returns
54         -------
55         tuple
56             ``(x, y)``
57         """
58         return xy(self.transform, row, col, offset=offset)
59 
60     def ul(self, row, col):
61         """Returns the coordinates (x, y) of the upper left corner of a
62         pixel at `row` and `col` in the units of the dataset's
63         coordinate reference system.
64 
65         Deprecated; Use `xy(row, col, offset='ul')` instead.
66         """
67         warnings.warn("ul method is deprecated. Use xy(row, col, offset='ul')",
68                       DeprecationWarning)
69         return xy(self.transform, row, col, offset='ul')
70 
71     def index(self, x, y, op=math.floor, precision=6):
72         """
73         Returns the (row, col) index of the pixel containing (x, y) given a
74         coordinate reference system.
75 
76         Use an epsilon, magnitude determined by the precision parameter
77         and sign determined by the op function:
78             positive for floor, negative for ceil.
79 
80         Parameters
81         ----------
82         x : float
83             x value in coordinate reference system
84         y : float
85             y value in coordinate reference system
86         op : function, optional (default: math.floor)
87             Function to convert fractional pixels to whole numbers (floor,
88             ceiling, round)
89         precision : int, optional (default: 6)
90             Decimal places of precision in indexing, as in `round()`.
91 
92         Returns
93         -------
94         tuple
95             (row index, col index)
96         """
97         return rowcol(self.transform, x, y, op=op, precision=precision)
98 
99 
100 class WindowMethodsMixin(object):
101     """Mixin providing methods for window-related calculations.
102     These methods are wrappers for the functionality in
103     `rasterio.windows` module.
104 
105     A subclass with this mixin MUST provide the following
106     properties: `transform`, `height` and `width`
107     """
108 
109     def window(self, left, bottom, right, top, precision=6, **kwargs):
110         """Get the window corresponding to the bounding coordinates.
111 
112         The resulting window is not cropped to the row and column
113         limits of the dataset.
114 
115         Parameters
116         ----------
117         left: float
118             Left (west) bounding coordinate
119         bottom: float
120             Bottom (south) bounding coordinate
121         right: float
122             Right (east) bounding coordinate
123         top: float
124             Top (north) bounding coordinate
125         precision: int, optional
126             Number of decimal points of precision when computing inverse
127             transform.
128         kwargs: mapping
129             For backwards compatibility: absorbs deprecated keyword args.
130 
131         Returns
132         -------
133         window: Window
134         """
135         if 'boundless' in kwargs:  # pragma: no branch
136             warnings.warn("boundless keyword arg should not be used",
137                           RasterioDeprecationWarning)
138 
139         transform = guard_transform(self.transform)
140         return windows.from_bounds(
141             left, bottom, right, top, transform=transform,
142             height=self.height, width=self.width, precision=precision)
143 
144     def window_transform(self, window):
145         """Get the affine transform for a dataset window.
146 
147         Parameters
148         ----------
149         window: rasterio.windows.Window
150             Dataset window
151 
152         Returns
153         -------
154         transform: Affine
155             The affine transform matrix for the given window
156         """
157 
158         transform = guard_transform(self.transform)
159         return windows.transform(window, transform)
160 
161     def window_bounds(self, window):
162         """Get the bounds of a window
163 
164         Parameters
165         ----------
166         window: rasterio.windows.Window
167             Dataset window
168 
169         Returns
170         -------
171         bounds : tuple
172             x_min, y_min, x_max, y_max for the given window
173         """
174 
175         transform = guard_transform(self.transform)
176         return windows.bounds(window, transform)
177 
178 
179 class DatasetReader(DatasetReaderBase, WindowMethodsMixin,
180                     TransformMethodsMixin):
181     """An unbuffered data and metadata reader"""
182 
183     def __repr__(self):
184         return "<{} DatasetReader name='{}' mode='{}'>".format(
185             self.closed and 'closed' or 'open', self.name, self.mode)
186 
187 
188 class DatasetWriter(DatasetWriterBase, WindowMethodsMixin,
189                     TransformMethodsMixin):
190     """An unbuffered data and metadata writer. Its methods write data
191     directly to disk.
192     """
193 
194     def __repr__(self):
195         return "<{} DatasetWriter name='{}' mode='{}'>".format(
196             self.closed and 'closed' or 'open', self.name, self.mode)
197 
198 
199 class BufferedDatasetWriter(BufferedDatasetWriterBase, WindowMethodsMixin,
200                             TransformMethodsMixin):
201     """Maintains data and metadata in a buffer, writing to disk or
202     network only when `close()` is called.
203 
204     This allows incremental updates to datasets using formats that don't
205     otherwise support updates, such as JPEG.
206     """
207 
208     def __repr__(self):
209         return "<{} BufferedDatasetWriter name='{}' mode='{}'>".format(
210             self.closed and 'closed' or 'open', self.name, self.mode)
211 
212 
213 class MemoryFile(MemoryFileBase):
214     """A BytesIO-like object, backed by an in-memory file.
215 
216     This allows formatted files to be read and written without I/O.
217 
218     A MemoryFile created with initial bytes becomes immutable. A
219     MemoryFile created without initial bytes may be written to using
220     either file-like or dataset interfaces.
221 
222     Examples
223     --------
224 
225     A GeoTIFF can be loaded in memory and accessed using the GeoTIFF
226     format driver
227 
228     >>> with open('tests/data/RGB.byte.tif', 'rb') as f, MemoryFile(f) as memfile:
229     ...     with memfile.open() as src:
230     ...         pprint.pprint(src.profile)
231     ...
232     {'count': 3,
233      'crs': CRS({'init': 'epsg:32618'}),
234      'driver': 'GTiff',
235      'dtype': 'uint8',
236      'height': 718,
237      'interleave': 'pixel',
238      'nodata': 0.0,
239      'tiled': False,
240      'transform': Affine(300.0379266750948, 0.0, 101985.0,
241            0.0, -300.041782729805, 2826915.0),
242      'width': 791}
243 
244     """
245     def __init__(self, file_or_bytes=None, filename=None, ext=''):
246         super(MemoryFile, self).__init__(
247             file_or_bytes=file_or_bytes, filename=filename, ext=ext)
248 
249     @ensure_env
250     def open(self, driver=None, width=None, height=None, count=None, crs=None,
251              transform=None, dtype=None, nodata=None, **kwargs):
252         """Open the file and return a Rasterio dataset object.
253 
254         If data has already been written, the file is opened in 'r+'
255         mode. Otherwise, the file is opened in 'w' mode.
256 
257         Parameters
258         ----------
259         Note well that there is no `path` parameter: a `MemoryFile`
260         contains a single dataset and there is no need to specify a
261         path.
262 
263         Other parameters are optional and have the same semantics as the
264         parameters of `rasterio.open()`.
265         """
266         vsi_path = self.name
267 
268         if self.closed:
269             raise IOError("I/O operation on closed file.")
270         if self.exists():
271             s = DatasetReader(vsi_path, 'r+')
272         else:
273             writer = get_writer_for_driver(driver)
274             s = writer(vsi_path, 'w', driver=driver, width=width,
275                        height=height, count=count, crs=crs,
276                        transform=transform, dtype=dtype,
277                        nodata=nodata, **kwargs)
278         s.start()
279         return s
280 
281     def __enter__(self):
282         return self
283 
284     def __exit__(self, *args, **kwargs):
285         self.close()
286 
287 
288 class ZipMemoryFile(MemoryFile):
289     """A read-only BytesIO-like object backed by an in-memory zip file.
290 
291     This allows a zip file containing formatted files to be read
292     without I/O.
293     """
294 
295     def __init__(self, file_or_bytes=None):
296         super(ZipMemoryFile, self).__init__(file_or_bytes, ext='zip')
297 
298     @ensure_env
299     def open(self, path):
300         """Open a dataset within the zipped stream.
301 
302         Parameters
303         ----------
304         path : str
305             Path to a dataset in the zip file, relative to the root of the
306             archive.
307 
308         Returns
309         -------
310         A Rasterio dataset object
311         """
312         vsi_path = '/vsizip{0}/{1}'.format(self.name, path.lstrip('/'))
313 
314         if self.closed:
315             raise IOError("I/O operation on closed file.")
316         s = DatasetReader(vsi_path, 'r')
317         s.start()
318         return s
319 
320 
321 def get_writer_for_driver(driver):
322     """Return the writer class appropriate for the specified driver."""
323     cls = None
324     if driver_can_create(driver):
325         cls = DatasetWriter
326     elif driver_can_create_copy(driver):  # pragma: no branch
327         cls = BufferedDatasetWriter
328     return cls
329 
330 
331 def get_writer_for_path(path):
332     """Return the writer class appropriate for the existing dataset."""
333     driver = get_dataset_driver(path)
334     return get_writer_for_driver(driver)
335
```
--- 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/rasterio/io.py b/rasterio/io.py
--- a/rasterio/io.py
+++ b/rasterio/io.py
@@ -57,17 +57,6 @@
         """
         return xy(self.transform, row, col, offset=offset)
 
-    def ul(self, row, col):
-        """Returns the coordinates (x, y) of the upper left corner of a
-        pixel at `row` and `col` in the units of the dataset's
-        coordinate reference system.
-
-        Deprecated; Use `xy(row, col, offset='ul')` instead.
-        """
-        warnings.warn("ul method is deprecated. Use xy(row, col, offset='ul')",
-                      DeprecationWarning)
-        return xy(self.transform, row, col, offset='ul')
-
     def index(self, x, y, op=math.floor, precision=6):
         """
         Returns the (row, col) index of the pixel containing (x, y) given a

{"golden_diff": "diff --git a/rasterio/io.py b/rasterio/io.py\n--- a/rasterio/io.py\n+++ b/rasterio/io.py\n@@ -57,17 +57,6 @@\n         \"\"\"\n         return xy(self.transform, row, col, offset=offset)\n \n-    def ul(self, row, col):\n-        \"\"\"Returns the coordinates (x, y) of the upper left corner of a\n-        pixel at `row` and `col` in the units of the dataset's\n-        coordinate reference system.\n-\n-        Deprecated; Use `xy(row, col, offset='ul')` instead.\n-        \"\"\"\n-        warnings.warn(\"ul method is deprecated. Use xy(row, col, offset='ul')\",\n-                      DeprecationWarning)\n-        return xy(self.transform, row, col, offset='ul')\n-\n     def index(self, x, y, op=math.floor, precision=6):\n         \"\"\"\n         Returns the (row, col) index of the pixel containing (x, y) given a\n", "issue": "Remove dataset's ul method\nIt's been deprecated since June 2016 (0.36).\n", "before_files": [{"content": "\"\"\"Classes capable of reading and writing datasets\n\nInstances of these classes are called dataset objects.\n\"\"\"\n\n\nimport logging\nimport math\nimport warnings\n\nfrom rasterio._base import (\n    get_dataset_driver, driver_can_create, driver_can_create_copy)\nfrom rasterio._io import (\n    DatasetReaderBase, DatasetWriterBase, BufferedDatasetWriterBase,\n    MemoryFileBase)\nfrom rasterio import windows\nfrom rasterio.enums import Resampling\nfrom rasterio.env import ensure_env\nfrom rasterio.errors import RasterioDeprecationWarning\nfrom rasterio.transform import guard_transform, xy, rowcol\n\n\nlog = logging.getLogger(__name__)\n\n\nclass TransformMethodsMixin(object):\n    \"\"\"Mixin providing methods for calculations related\n    to transforming between rows and columns of the raster\n    array and the coordinates.\n\n    These methods are wrappers for the functionality in\n    `rasterio.transform` module.\n\n    A subclass with this mixin MUST provide a `transform`\n    property.\n    \"\"\"\n\n    def xy(self, row, col, offset=\"center\"):\n        \"\"\"Returns the coordinates ``(x, y)`` of a pixel at `row` and `col`.\n        The pixel's center is returned by default, but a corner can be returned\n        by setting `offset` to one of `ul, ur, ll, lr`.\n\n        Parameters\n        ----------\n        row : int\n            Pixel row.\n        col : int\n            Pixel column.\n        offset : str, optional\n            Determines if the returned coordinates are for the center of the\n            pixel or for a corner.\n\n        Returns\n        -------\n        tuple\n            ``(x, y)``\n        \"\"\"\n        return xy(self.transform, row, col, offset=offset)\n\n    def ul(self, row, col):\n        \"\"\"Returns the coordinates (x, y) of the upper left corner of a\n        pixel at `row` and `col` in the units of the dataset's\n        coordinate reference system.\n\n        Deprecated; Use `xy(row, col, offset='ul')` instead.\n        \"\"\"\n        warnings.warn(\"ul method is deprecated. Use xy(row, col, offset='ul')\",\n                      DeprecationWarning)\n        return xy(self.transform, row, col, offset='ul')\n\n    def index(self, x, y, op=math.floor, precision=6):\n        \"\"\"\n        Returns the (row, col) index of the pixel containing (x, y) given a\n        coordinate reference system.\n\n        Use an epsilon, magnitude determined by the precision parameter\n        and sign determined by the op function:\n            positive for floor, negative for ceil.\n\n        Parameters\n        ----------\n        x : float\n            x value in coordinate reference system\n        y : float\n            y value in coordinate reference system\n        op : function, optional (default: math.floor)\n            Function to convert fractional pixels to whole numbers (floor,\n            ceiling, round)\n        precision : int, optional (default: 6)\n            Decimal places of precision in indexing, as in `round()`.\n\n        Returns\n        -------\n        tuple\n            (row index, col index)\n        \"\"\"\n        return rowcol(self.transform, x, y, op=op, precision=precision)\n\n\nclass WindowMethodsMixin(object):\n    \"\"\"Mixin providing methods for window-related calculations.\n    These methods are wrappers for the functionality in\n    `rasterio.windows` module.\n\n    A subclass with this mixin MUST provide the following\n    properties: `transform`, `height` and `width`\n    \"\"\"\n\n    def window(self, left, bottom, right, top, precision=6, **kwargs):\n        \"\"\"Get the window corresponding to the bounding coordinates.\n\n        The resulting window is not cropped to the row and column\n        limits of the dataset.\n\n        Parameters\n        ----------\n        left: float\n            Left (west) bounding coordinate\n        bottom: float\n            Bottom (south) bounding coordinate\n        right: float\n            Right (east) bounding coordinate\n        top: float\n            Top (north) bounding coordinate\n        precision: int, optional\n            Number of decimal points of precision when computing inverse\n            transform.\n        kwargs: mapping\n            For backwards compatibility: absorbs deprecated keyword args.\n\n        Returns\n        -------\n        window: Window\n        \"\"\"\n        if 'boundless' in kwargs:  # pragma: no branch\n            warnings.warn(\"boundless keyword arg should not be used\",\n                          RasterioDeprecationWarning)\n\n        transform = guard_transform(self.transform)\n        return windows.from_bounds(\n            left, bottom, right, top, transform=transform,\n            height=self.height, width=self.width, precision=precision)\n\n    def window_transform(self, window):\n        \"\"\"Get the affine transform for a dataset window.\n\n        Parameters\n        ----------\n        window: rasterio.windows.Window\n            Dataset window\n\n        Returns\n        -------\n        transform: Affine\n            The affine transform matrix for the given window\n        \"\"\"\n\n        transform = guard_transform(self.transform)\n        return windows.transform(window, transform)\n\n    def window_bounds(self, window):\n        \"\"\"Get the bounds of a window\n\n        Parameters\n        ----------\n        window: rasterio.windows.Window\n            Dataset window\n\n        Returns\n        -------\n        bounds : tuple\n            x_min, y_min, x_max, y_max for the given window\n        \"\"\"\n\n        transform = guard_transform(self.transform)\n        return windows.bounds(window, transform)\n\n\nclass DatasetReader(DatasetReaderBase, WindowMethodsMixin,\n                    TransformMethodsMixin):\n    \"\"\"An unbuffered data and metadata reader\"\"\"\n\n    def __repr__(self):\n        return \"<{} DatasetReader name='{}' mode='{}'>\".format(\n            self.closed and 'closed' or 'open', self.name, self.mode)\n\n\nclass DatasetWriter(DatasetWriterBase, WindowMethodsMixin,\n                    TransformMethodsMixin):\n    \"\"\"An unbuffered data and metadata writer. Its methods write data\n    directly to disk.\n    \"\"\"\n\n    def __repr__(self):\n        return \"<{} DatasetWriter name='{}' mode='{}'>\".format(\n            self.closed and 'closed' or 'open', self.name, self.mode)\n\n\nclass BufferedDatasetWriter(BufferedDatasetWriterBase, WindowMethodsMixin,\n                            TransformMethodsMixin):\n    \"\"\"Maintains data and metadata in a buffer, writing to disk or\n    network only when `close()` is called.\n\n    This allows incremental updates to datasets using formats that don't\n    otherwise support updates, such as JPEG.\n    \"\"\"\n\n    def __repr__(self):\n        return \"<{} BufferedDatasetWriter name='{}' mode='{}'>\".format(\n            self.closed and 'closed' or 'open', self.name, self.mode)\n\n\nclass MemoryFile(MemoryFileBase):\n    \"\"\"A BytesIO-like object, backed by an in-memory file.\n\n    This allows formatted files to be read and written without I/O.\n\n    A MemoryFile created with initial bytes becomes immutable. A\n    MemoryFile created without initial bytes may be written to using\n    either file-like or dataset interfaces.\n\n    Examples\n    --------\n\n    A GeoTIFF can be loaded in memory and accessed using the GeoTIFF\n    format driver\n\n    >>> with open('tests/data/RGB.byte.tif', 'rb') as f, MemoryFile(f) as memfile:\n    ...     with memfile.open() as src:\n    ...         pprint.pprint(src.profile)\n    ...\n    {'count': 3,\n     'crs': CRS({'init': 'epsg:32618'}),\n     'driver': 'GTiff',\n     'dtype': 'uint8',\n     'height': 718,\n     'interleave': 'pixel',\n     'nodata': 0.0,\n     'tiled': False,\n     'transform': Affine(300.0379266750948, 0.0, 101985.0,\n           0.0, -300.041782729805, 2826915.0),\n     'width': 791}\n\n    \"\"\"\n    def __init__(self, file_or_bytes=None, filename=None, ext=''):\n        super(MemoryFile, self).__init__(\n            file_or_bytes=file_or_bytes, filename=filename, ext=ext)\n\n    @ensure_env\n    def open(self, driver=None, width=None, height=None, count=None, crs=None,\n             transform=None, dtype=None, nodata=None, **kwargs):\n        \"\"\"Open the file and return a Rasterio dataset object.\n\n        If data has already been written, the file is opened in 'r+'\n        mode. Otherwise, the file is opened in 'w' mode.\n\n        Parameters\n        ----------\n        Note well that there is no `path` parameter: a `MemoryFile`\n        contains a single dataset and there is no need to specify a\n        path.\n\n        Other parameters are optional and have the same semantics as the\n        parameters of `rasterio.open()`.\n        \"\"\"\n        vsi_path = self.name\n\n        if self.closed:\n            raise IOError(\"I/O operation on closed file.\")\n        if self.exists():\n            s = DatasetReader(vsi_path, 'r+')\n        else:\n            writer = get_writer_for_driver(driver)\n            s = writer(vsi_path, 'w', driver=driver, width=width,\n                       height=height, count=count, crs=crs,\n                       transform=transform, dtype=dtype,\n                       nodata=nodata, **kwargs)\n        s.start()\n        return s\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, *args, **kwargs):\n        self.close()\n\n\nclass ZipMemoryFile(MemoryFile):\n    \"\"\"A read-only BytesIO-like object backed by an in-memory zip file.\n\n    This allows a zip file containing formatted files to be read\n    without I/O.\n    \"\"\"\n\n    def __init__(self, file_or_bytes=None):\n        super(ZipMemoryFile, self).__init__(file_or_bytes, ext='zip')\n\n    @ensure_env\n    def open(self, path):\n        \"\"\"Open a dataset within the zipped stream.\n\n        Parameters\n        ----------\n        path : str\n            Path to a dataset in the zip file, relative to the root of the\n            archive.\n\n        Returns\n        -------\n        A Rasterio dataset object\n        \"\"\"\n        vsi_path = '/vsizip{0}/{1}'.format(self.name, path.lstrip('/'))\n\n        if self.closed:\n            raise IOError(\"I/O operation on closed file.\")\n        s = DatasetReader(vsi_path, 'r')\n        s.start()\n        return s\n\n\ndef get_writer_for_driver(driver):\n    \"\"\"Return the writer class appropriate for the specified driver.\"\"\"\n    cls = None\n    if driver_can_create(driver):\n        cls = DatasetWriter\n    elif driver_can_create_copy(driver):  # pragma: no branch\n        cls = BufferedDatasetWriter\n    return cls\n\n\ndef get_writer_for_path(path):\n    \"\"\"Return the writer class appropriate for the existing dataset.\"\"\"\n    driver = get_dataset_driver(path)\n    return get_writer_for_driver(driver)\n", "path": "rasterio/io.py"}], "after_files": [{"content": "\"\"\"Classes capable of reading and writing datasets\n\nInstances of these classes are called dataset objects.\n\"\"\"\n\n\nimport logging\nimport math\nimport warnings\n\nfrom rasterio._base import (\n    get_dataset_driver, driver_can_create, driver_can_create_copy)\nfrom rasterio._io import (\n    DatasetReaderBase, DatasetWriterBase, BufferedDatasetWriterBase,\n    MemoryFileBase)\nfrom rasterio import windows\nfrom rasterio.enums import Resampling\nfrom rasterio.env import ensure_env\nfrom rasterio.errors import RasterioDeprecationWarning\nfrom rasterio.transform import guard_transform, xy, rowcol\n\n\nlog = logging.getLogger(__name__)\n\n\nclass TransformMethodsMixin(object):\n    \"\"\"Mixin providing methods for calculations related\n    to transforming between rows and columns of the raster\n    array and the coordinates.\n\n    These methods are wrappers for the functionality in\n    `rasterio.transform` module.\n\n    A subclass with this mixin MUST provide a `transform`\n    property.\n    \"\"\"\n\n    def xy(self, row, col, offset=\"center\"):\n        \"\"\"Returns the coordinates ``(x, y)`` of a pixel at `row` and `col`.\n        The pixel's center is returned by default, but a corner can be returned\n        by setting `offset` to one of `ul, ur, ll, lr`.\n\n        Parameters\n        ----------\n        row : int\n            Pixel row.\n        col : int\n            Pixel column.\n        offset : str, optional\n            Determines if the returned coordinates are for the center of the\n            pixel or for a corner.\n\n        Returns\n        -------\n        tuple\n            ``(x, y)``\n        \"\"\"\n        return xy(self.transform, row, col, offset=offset)\n\n    def index(self, x, y, op=math.floor, precision=6):\n        \"\"\"\n        Returns the (row, col) index of the pixel containing (x, y) given a\n        coordinate reference system.\n\n        Use an epsilon, magnitude determined by the precision parameter\n        and sign determined by the op function:\n            positive for floor, negative for ceil.\n\n        Parameters\n        ----------\n        x : float\n            x value in coordinate reference system\n        y : float\n            y value in coordinate reference system\n        op : function, optional (default: math.floor)\n            Function to convert fractional pixels to whole numbers (floor,\n            ceiling, round)\n        precision : int, optional (default: 6)\n            Decimal places of precision in indexing, as in `round()`.\n\n        Returns\n        -------\n        tuple\n            (row index, col index)\n        \"\"\"\n        return rowcol(self.transform, x, y, op=op, precision=precision)\n\n\nclass WindowMethodsMixin(object):\n    \"\"\"Mixin providing methods for window-related calculations.\n    These methods are wrappers for the functionality in\n    `rasterio.windows` module.\n\n    A subclass with this mixin MUST provide the following\n    properties: `transform`, `height` and `width`\n    \"\"\"\n\n    def window(self, left, bottom, right, top, precision=6, **kwargs):\n        \"\"\"Get the window corresponding to the bounding coordinates.\n\n        The resulting window is not cropped to the row and column\n        limits of the dataset.\n\n        Parameters\n        ----------\n        left: float\n            Left (west) bounding coordinate\n        bottom: float\n            Bottom (south) bounding coordinate\n        right: float\n            Right (east) bounding coordinate\n        top: float\n            Top (north) bounding coordinate\n        precision: int, optional\n            Number of decimal points of precision when computing inverse\n            transform.\n        kwargs: mapping\n            For backwards compatibility: absorbs deprecated keyword args.\n\n        Returns\n        -------\n        window: Window\n        \"\"\"\n        if 'boundless' in kwargs:  # pragma: no branch\n            warnings.warn(\"boundless keyword arg should not be used\",\n                          RasterioDeprecationWarning)\n\n        transform = guard_transform(self.transform)\n        return windows.from_bounds(\n            left, bottom, right, top, transform=transform,\n            height=self.height, width=self.width, precision=precision)\n\n    def window_transform(self, window):\n        \"\"\"Get the affine transform for a dataset window.\n\n        Parameters\n        ----------\n        window: rasterio.windows.Window\n            Dataset window\n\n        Returns\n        -------\n        transform: Affine\n            The affine transform matrix for the given window\n        \"\"\"\n\n        transform = guard_transform(self.transform)\n        return windows.transform(window, transform)\n\n    def window_bounds(self, window):\n        \"\"\"Get the bounds of a window\n\n        Parameters\n        ----------\n        window: rasterio.windows.Window\n            Dataset window\n\n        Returns\n        -------\n        bounds : tuple\n            x_min, y_min, x_max, y_max for the given window\n        \"\"\"\n\n        transform = guard_transform(self.transform)\n        return windows.bounds(window, transform)\n\n\nclass DatasetReader(DatasetReaderBase, WindowMethodsMixin,\n                    TransformMethodsMixin):\n    \"\"\"An unbuffered data and metadata reader\"\"\"\n\n    def __repr__(self):\n        return \"<{} DatasetReader name='{}' mode='{}'>\".format(\n            self.closed and 'closed' or 'open', self.name, self.mode)\n\n\nclass DatasetWriter(DatasetWriterBase, WindowMethodsMixin,\n                    TransformMethodsMixin):\n    \"\"\"An unbuffered data and metadata writer. Its methods write data\n    directly to disk.\n    \"\"\"\n\n    def __repr__(self):\n        return \"<{} DatasetWriter name='{}' mode='{}'>\".format(\n            self.closed and 'closed' or 'open', self.name, self.mode)\n\n\nclass BufferedDatasetWriter(BufferedDatasetWriterBase, WindowMethodsMixin,\n                            TransformMethodsMixin):\n    \"\"\"Maintains data and metadata in a buffer, writing to disk or\n    network only when `close()` is called.\n\n    This allows incremental updates to datasets using formats that don't\n    otherwise support updates, such as JPEG.\n    \"\"\"\n\n    def __repr__(self):\n        return \"<{} BufferedDatasetWriter name='{}' mode='{}'>\".format(\n            self.closed and 'closed' or 'open', self.name, self.mode)\n\n\nclass MemoryFile(MemoryFileBase):\n    \"\"\"A BytesIO-like object, backed by an in-memory file.\n\n    This allows formatted files to be read and written without I/O.\n\n    A MemoryFile created with initial bytes becomes immutable. A\n    MemoryFile created without initial bytes may be written to using\n    either file-like or dataset interfaces.\n\n    Examples\n    --------\n\n    A GeoTIFF can be loaded in memory and accessed using the GeoTIFF\n    format driver\n\n    >>> with open('tests/data/RGB.byte.tif', 'rb') as f, MemoryFile(f) as memfile:\n    ...     with memfile.open() as src:\n    ...         pprint.pprint(src.profile)\n    ...\n    {'count': 3,\n     'crs': CRS({'init': 'epsg:32618'}),\n     'driver': 'GTiff',\n     'dtype': 'uint8',\n     'height': 718,\n     'interleave': 'pixel',\n     'nodata': 0.0,\n     'tiled': False,\n     'transform': Affine(300.0379266750948, 0.0, 101985.0,\n           0.0, -300.041782729805, 2826915.0),\n     'width': 791}\n\n    \"\"\"\n    def __init__(self, file_or_bytes=None, filename=None, ext=''):\n        super(MemoryFile, self).__init__(\n            file_or_bytes=file_or_bytes, filename=filename, ext=ext)\n\n    @ensure_env\n    def open(self, driver=None, width=None, height=None, count=None, crs=None,\n             transform=None, dtype=None, nodata=None, **kwargs):\n        \"\"\"Open the file and return a Rasterio dataset object.\n\n        If data has already been written, the file is opened in 'r+'\n        mode. Otherwise, the file is opened in 'w' mode.\n\n        Parameters\n        ----------\n        Note well that there is no `path` parameter: a `MemoryFile`\n        contains a single dataset and there is no need to specify a\n        path.\n\n        Other parameters are optional and have the same semantics as the\n        parameters of `rasterio.open()`.\n        \"\"\"\n        vsi_path = self.name\n\n        if self.closed:\n            raise IOError(\"I/O operation on closed file.\")\n        if self.exists():\n            s = DatasetReader(vsi_path, 'r+')\n        else:\n            writer = get_writer_for_driver(driver)\n            s = writer(vsi_path, 'w', driver=driver, width=width,\n                       height=height, count=count, crs=crs,\n                       transform=transform, dtype=dtype,\n                       nodata=nodata, **kwargs)\n        s.start()\n        return s\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, *args, **kwargs):\n        self.close()\n\n\nclass ZipMemoryFile(MemoryFile):\n    \"\"\"A read-only BytesIO-like object backed by an in-memory zip file.\n\n    This allows a zip file containing formatted files to be read\n    without I/O.\n    \"\"\"\n\n    def __init__(self, file_or_bytes=None):\n        super(ZipMemoryFile, self).__init__(file_or_bytes, ext='zip')\n\n    @ensure_env\n    def open(self, path):\n        \"\"\"Open a dataset within the zipped stream.\n\n        Parameters\n        ----------\n        path : str\n            Path to a dataset in the zip file, relative to the root of the\n            archive.\n\n        Returns\n        -------\n        A Rasterio dataset object\n        \"\"\"\n        vsi_path = '/vsizip{0}/{1}'.format(self.name, path.lstrip('/'))\n\n        if self.closed:\n            raise IOError(\"I/O operation on closed file.\")\n        s = DatasetReader(vsi_path, 'r')\n        s.start()\n        return s\n\n\ndef get_writer_for_driver(driver):\n    \"\"\"Return the writer class appropriate for the specified driver.\"\"\"\n    cls = None\n    if driver_can_create(driver):\n        cls = DatasetWriter\n    elif driver_can_create_copy(driver):  # pragma: no branch\n        cls = BufferedDatasetWriter\n    return cls\n\n\ndef get_writer_for_path(path):\n    \"\"\"Return the writer class appropriate for the existing dataset.\"\"\"\n    driver = get_dataset_driver(path)\n    return get_writer_for_driver(driver)\n", "path": "rasterio/io.py"}]}