-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RasterIO backend #1260
Merged
Merged
Add RasterIO backend #1260
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
1643ce5
rasterio checkin
067dedb
temp fixes
NicWayand 7906cfd
update rasterio reader, no lazy loading, no decoding of coords
2e1b528
keep band dim even for single band. Fix longitude typo
NicWayand 532c5d3
Fix lat/lon decoding. Remove requirment comment
8bc3da3
Attr error suppression. DataArray to Variable objects. CI requirment …
77cc0ca
remove >= requirment
776cbd9
added conda-forge channel to CI check
eb739de
add scipy requirement
3a394ae
roll back ci requirements. Rename vars
061b8fd
roll back
c0962fa
fixed coord spacing bug where x and y were +1 dim than raster. Uses n…
NicWayand 7275ffa
change test env to py36
fmaussion 51a60af
first tests
fmaussion 5155634
other tests
fmaussion 09196ee
fix test
fmaussion e2b6786
get the order right
fmaussion 228a5a3
some progress with indexing
fmaussion 4b57d1c
cosmetic changes
fmaussion 2d21b4b
Conflicts
fmaussion c2cb927
More rebase
fmaussion f86507e
looking good now. Testing
fmaussion e1a5b31
docs
fmaussion 7cb8baf
whats new
fmaussion 48c7268
fix test
fmaussion 70bd03a
reviews
fmaussion 4d49195
Merge branch 'master' into feature-rasterio
fmaussion 3f18144
docs
fmaussion 3e3e6fb
Merge remote-tracking branch 'upstream/master' into feature-rasterio
fmaussion 1ae2d9b
more reviews
fmaussion 955f6b9
chunking and caching
fmaussion 7d8fe4d
Merge remote-tracking branch 'upstream/master' into feature-rasterio
fmaussion 223ce0c
Final tweaks
fmaussion 6cf2ce9
Lock-doc tweaks
fmaussion 2cd0386
Merge branch 'master' into feature-rasterio
fmaussion 9193a2b
Add rasterio to other test suites
fmaussion 4bf4b6a
Merge remote-tracking branch 'origin/feature-rasterio' into feature-r…
fmaussion c778948
use context managers in tests for windows
fmaussion 4299957
Change example to use an accessor
fmaussion fcdd894
Reviews
fmaussion 1ca6e38
Merge branch 'master' into feature-rasterio
fmaussion d5c964e
typo
fmaussion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ dependencies: | |
- scipy | ||
- seaborn | ||
- toolz | ||
- rasterio | ||
- pip: | ||
- coveralls | ||
- pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ dependencies: | |
- scipy | ||
- seaborn | ||
- toolz | ||
- rasterio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ dependencies: | |
- scipy | ||
- seaborn | ||
- toolz | ||
- rasterio | ||
- pip: | ||
- coveralls | ||
- pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ dependencies: | |
- scipy | ||
- seaborn | ||
- toolz | ||
- rasterio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ dependencies: | |
- scipy | ||
- seaborn | ||
- toolz | ||
- rasterio | ||
- pip: | ||
- coveralls | ||
- pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
.. _recipes.rasterio: | ||
|
||
================================= | ||
Parsing rasterio's geocoordinates | ||
================================= | ||
|
||
|
||
The example illustrates how to use an accessor (see :ref:`internals.accessors`) | ||
to convert a projection's cartesian coordinates into 2D longitudes and | ||
latitudes. | ||
|
||
These new coordinates might be handy for plotting and indexing, but it should | ||
be kept in mind that a grid which is regular in projection coordinates will | ||
likely be irregular in lon/lat. It is often recommended to work in the data's | ||
original map projection. | ||
""" | ||
|
||
import os | ||
import urllib.request | ||
import numpy as np | ||
import xarray as xr | ||
import cartopy.crs as ccrs | ||
import matplotlib.pyplot as plt | ||
from rasterio.warp import transform | ||
|
||
|
||
# Define the accessor | ||
@xr.register_dataarray_accessor('rasterio') | ||
class RasterioAccessor(object): | ||
def __init__(self, xarray_obj): | ||
self._obj = xarray_obj | ||
|
||
def add_lonlat_coords(self): | ||
"""Compute the lon/lat coordinates out of the dataset's crs. | ||
|
||
This adds two non-dimension coordinates ('lon' and 'lat') to the | ||
original dataarray. | ||
""" | ||
|
||
ny, nx = len(self._obj['y']), len(self._obj['x']) | ||
x, y = np.meshgrid(self._obj['x'], self._obj['y']) | ||
|
||
# Rasterio works with 1D arrays | ||
lon, lat = transform(self._obj.crs, {'init': 'EPSG:4326'}, | ||
x.flatten(), y.flatten()) | ||
lon = np.asarray(lon).reshape((ny, nx)) | ||
lat = np.asarray(lat).reshape((ny, nx)) | ||
self._obj.coords['lon'] = (('y', 'x'), lon) | ||
self._obj.coords['lat'] = (('y', 'x'), lat) | ||
|
||
|
||
# Download the file from rasterio's repository | ||
url = 'https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif' | ||
urllib.request.urlretrieve(url, 'RGB.byte.tif') | ||
|
||
# Read the data | ||
rioda = xr.open_rasterio('RGB.byte.tif') | ||
|
||
# Compute the coordinates | ||
rioda.rasterio.add_lonlat_coords() | ||
|
||
# Compute a greyscale out of the rgb image | ||
greyscale = rioda.mean(dim='band') | ||
|
||
# Plot on a map | ||
ax = plt.subplot(projection=ccrs.PlateCarree()) | ||
greyscale.plot(ax=ax, x='lon', y='lat', transform=ccrs.PlateCarree(), | ||
cmap='Greys_r', add_colorbar=False) | ||
ax.coastlines('10m', color='r') | ||
plt.show() | ||
|
||
# Delete the file | ||
os.remove('RGB.byte.tif') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would lean towards keeping this as just a function -- it keeps the example simpler and an accessor is probably overkill for this problem.