-
Notifications
You must be signed in to change notification settings - Fork 95
Add very minimal xarray plugin for engine="rasterio"
#281
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
1834d61
Add minimal xarray plugin for `engine="gdal"`
alexamici eca38dc
Dask and distributed switched from `master` to `main`
alexamici 1d34780
Add a test intended to work with xarray `master`
alexamici 1370432
Code style
alexamici d5e5601
Test xarray plugin integration for newer versions
alexamici 12eb9e1
Move `spatial_ref` out of coords to make it CF-compliant
alexamici 848cbd4
Code style (flake8)
alexamici 6928b5e
Test with and without guessing the extension
alexamici 13362fc
Add CAN_OPEN_EXT set of extensions and keep bands as dimension
alexamici d39034f
Enable all `open_rasterio` in `open_dataset` as `backend_kwargs` and …
alexamici 12f88a2
Quick & dirty implementation of `decode_coords="all"`
alexamici 0b2cc76
Code style
alexamici da1f0a1
Fix typo
alexamici 07cc1be
Minimal xarray plugin to enable `xr.open_dataset("cog.tif", engine="r…
alexamici 581997e
Code style
alexamici 073db2f
Added entry in the history
alexamici 1e139a5
Implement PR feedback by @snowman2
alexamici 274a112
Merge branch 'master' into xarray-plugin
alexamici 36961c7
rebase and integrate with `grid_mapping` in `encoding`
alexamici 730d19b
Try add minimal user documentation
alexamici 951c4d9
version added
alexamici 511d99e
Code style
alexamici 25ab9bd
Add open_kwargs to backend
alexamici cf3c3f9
Apply suggestions from code review
alexamici b66db56
Merge remote-tracking branch 'origin/xarray-plugin' into xarray-plugin
alexamici 37adc6e
Add a comment on xarray miversion
alexamici a1c8dfc
Implement feedback
alexamici 18d7bd8
Declare minimal xarray version.
alexamici 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 hidden or 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 hidden or 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,20 @@ | ||
| import os.path | ||
|
|
||
| import xarray as xr | ||
|
|
||
| from . import _io | ||
|
|
||
|
|
||
| class GdalBackend(xr.backends.common.BackendEntrypoint): | ||
| def open_dataset(self, filename_or_obj, drop_variables=None): | ||
| ds = _io.open_rasterio(filename_or_obj).to_dataset("band") | ||
| ds = ds.rename({idx: f"band{idx}" for idx in ds.data_vars}) | ||
| ds = ds.reset_coords("spatial_ref") | ||
| return ds | ||
|
|
||
| def guess_can_open(self, filename_or_obj): | ||
| try: | ||
| _, ext = os.path.splitext(filename_or_obj) | ||
| except TypeError: | ||
| return False | ||
| return ext in {".tif", ".geotif", ".tiff", ".geotiff"} | ||
snowman2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
snowman2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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 hidden or 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,21 @@ | ||
| import os.path | ||
|
|
||
| import pytest | ||
|
|
||
| from test.conftest import TEST_INPUT_DATA_DIR | ||
|
|
||
| xr = pytest.importorskip("xarray", minversion="0.17.1.dev0") | ||
snowman2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def test_xarray_open_dataset(): | ||
snowman2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cog_file = os.path.join(TEST_INPUT_DATA_DIR, "cog.tif") | ||
|
|
||
| ds = xr.open_dataset(cog_file, engine="gdal") | ||
|
|
||
| assert isinstance(ds, xr.Dataset) | ||
| assert "band1" in ds.data_vars | ||
| assert ds.data_vars["band1"].shape == (500, 500) | ||
|
|
||
| ds = xr.open_dataset(cog_file) | ||
|
|
||
| assert isinstance(ds, xr.Dataset) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.