Skip to content

Commit 2633b1e

Browse files
grinstedfmaussion
authored andcommitted
DOC: Avoid downloading .tif file (#2919)
* Avoid downloading .tif file Simplify by using that rasterio can read directly from http. This also removes imports of requests and os. * let rasterio handle the http * pep 8 * pep8
1 parent 6d93a95 commit 2633b1e

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

doc/gallery/plot_rasterio.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,16 @@
1616
original map projection (see :ref:`recipes.rasterio_rgb`).
1717
"""
1818

19-
import os
20-
import urllib.request
21-
2219
import cartopy.crs as ccrs
2320
import matplotlib.pyplot as plt
2421
import numpy as np
2522
from rasterio.warp import transform
2623

2724
import xarray as xr
2825

29-
# Download the file from rasterio's repository
30-
url = 'https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif'
31-
urllib.request.urlretrieve(url, 'RGB.byte.tif')
32-
3326
# Read the data
34-
da = xr.open_rasterio('RGB.byte.tif')
27+
url = 'https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif'
28+
da = xr.open_rasterio(url)
3529

3630
# Compute the lon/lat coordinates with rasterio.warp.transform
3731
ny, nx = len(da['y']), len(da['x'])
@@ -54,6 +48,3 @@
5448
cmap='Greys_r', add_colorbar=False)
5549
ax.coastlines('10m', color='r')
5650
plt.show()
57-
58-
# Delete the file
59-
os.remove('RGB.byte.tif')

doc/gallery/plot_rasterio_rgb.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,14 @@
1313
transformation.
1414
"""
1515

16-
import os
17-
import urllib.request
18-
1916
import cartopy.crs as ccrs
2017
import matplotlib.pyplot as plt
2118

2219
import xarray as xr
2320

24-
# Download the file from rasterio's repository
25-
url = 'https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif'
26-
urllib.request.urlretrieve(url, 'RGB.byte.tif')
27-
2821
# Read the data
29-
da = xr.open_rasterio('RGB.byte.tif')
22+
url = 'https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif'
23+
da = xr.open_rasterio(url)
3024

3125
# The data is in UTM projection. We have to set it manually until
3226
# https://github.com/SciTools/cartopy/issues/813 is implemented
@@ -37,6 +31,3 @@
3731
da.plot.imshow(ax=ax, rgb='band', transform=crs)
3832
ax.coastlines('10m', color='r')
3933
plt.show()
40-
41-
# Delete the file
42-
os.remove('RGB.byte.tif')

0 commit comments

Comments
 (0)