Skip to content
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

added some logic to deal with rasterio objects in addition to filepaths #2589

Merged
merged 8 commits into from Dec 23, 2018

Conversation

scottyhq
Copy link
Contributor

@scottyhq scottyhq commented Dec 4, 2018

…h strings

  • Closes Enabling rasterio.vrt.WarpedVRT with xr.open_rasterio #2588
  • Tests added (for all bug fixes or enhancements)
  • Fully documented, including whats-new.rst for all changes and api.rst for new API (remove if this change should not be visible to users, e.g., if it is an internal clean-up, or if this is part of a larger project that will be documented later)

@pep8speaks
Copy link

pep8speaks commented Dec 4, 2018

Hello @scottyhq! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on December 23, 2018 at 18:24 Hours UTC

@scottyhq
Copy link
Contributor Author

scottyhq commented Dec 4, 2018

Following up on dask/dask#3255 @mrocklin, @shoyer, @jhamman

Copy link
Member

@fmaussion fmaussion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I only have a few comments (I don't use these things myself), but the change seems harmless enough to me (once the tests pass ;).

Is there a way to test the functionality without actually going online?

And can you also add an entry to whatsnew.rst?

@@ -2,7 +2,8 @@
import warnings
from collections import OrderedDict
from distutils.version import LooseVersion

import rasterio
from rasterio.vrt import WarpedVRT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports of optional dependencies can unfortunately not happen at the module top level - import them only when needed in the function scope

with xr.open_rasterio(tmp_file) as actual:
assert_allclose(actual, expected)

def test_rasterio_vrt(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For network tests we have a special decorator (@network), see https://github.com/pydata/xarray/blob/55f21deff4c2b42bd6ead4dbe26a1b123337913a/xarray/tests/test_tutorial.py (although that's the only use of it as it seems?)

@scottyhq
Copy link
Contributor Author

thanks for the feedback @fmaussion, I think I've addressed your suggestions, let me know if anything else needs adjusting

@@ -123,6 +124,42 @@ def __getitem__(self, key):
key, self.shape, indexing.IndexingSupport.OUTER, self._getitem)


class RasterioVRTWrapper(RasterioArrayWrapper):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding a subclass with a lot of duplicated logic, could you add this into the base RasterioArrayWrapper class?

Something like:

def __init__(self, manager, vrt_params=None):
    ...
    riods = riods if vrt_params is None else WarpedVRT(riods, **vrt_params)

Copy link
Contributor Author

@scottyhq scottyhq Dec 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, just moved the changes to RasterioArrayWrapper

def test_rasterio_vrt_network(self):
import rasterio

url = 'https://storage.googleapis.com/\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even know this form of line-wrapping for strings was possible in Python :)

@shoyer
Copy link
Member

shoyer commented Dec 19, 2018

These tests are failing on our "py36-rasterio-0.36" build, e.g.,

    def test_rasterio_vrt(self):
        import rasterio
        # tmp_file default crs is UTM: CRS({'init': 'epsg:32618'}
        with create_tmp_geotiff() as (tmp_file, expected):
            with rasterio.open(tmp_file) as src:
>               with rasterio.vrt.WarpedVRT(src, crs='epsg:4326') as vrt:
E               AttributeError: module 'rasterio' has no attribute 'vrt'

https://travis-ci.org/pydata/xarray/builds/469845498?utm_source=github_status&utm_medium=notification

Should we increase the minimum required version of rasterio or guard these imports?

@scottyhq
Copy link
Contributor Author

I think the minimum rasterio version should be increased to 1.0. For whatever reason the conda defaults channel hasn't been updated since 0.36 (Jun 14, 2016!). There are many important changes in 1.0 and beyond, and those releases are available via both pip and conda-forge.

@jhamman
Copy link
Member

jhamman commented Dec 19, 2018

I'd be personally fine bumping our minimum version of rasterio to 1.0. There have been multiple minor releases since then so I would suggest the 1.0 version has stabilized by now.

@shoyer
Copy link
Member

shoyer commented Dec 19, 2018

OK, please update our installation page at docs/installing.rst, too. This should also definitely be mentioned in "what's new"

@mrocklin
Copy link
Contributor

For whatever reason the conda defaults channel hasn't been updated since 0.36 (Jun 14, 2016!).

@jjhelmus is there a good way to report things like this other than pinging you directly? (which I'm more than happy to continue doing :))

@jjhelmus
Copy link
Contributor

@jjhelmus is there a good way to report things like this other than pinging you directly?

Opening and issue in the anaconda-issues repository is the best option at this time for requesting a package update.

I'm looking at updating the rasterio package in defaults this week. Something should be available by the end of the week.

@mrocklin
Copy link
Contributor

mrocklin commented Dec 19, 2018 via email

@jjhelmus
Copy link
Contributor

rasterio 1.0.13 packages are now available in defaults for all supported platforms and python version.

@mrocklin
Copy link
Contributor

For whatever reason the conda defaults channel hasn't been updated since 0.36 (Jun 14, 2016!).

It looks like @jjhelmus resolved this upstream . It seems like https://github.com/ContinuumIO/anaconda-issues is a good issue tracker to know :)

@mrocklin
Copy link
Contributor

mrocklin@carbon:~$ conda search rasterio=1
Loading channels: done
# Name                  Version           Build  Channel             
rasterio                 1.0.13  py27hc38cc03_0  pkgs/main           
rasterio                 1.0.13  py36hc38cc03_0  pkgs/main           
rasterio                 1.0.13  py37hc38cc03_0  pkgs/main           

@shoyer shoyer merged commit 9352b3c into pydata:master Dec 23, 2018
dcherian pushed a commit to yohai/xarray that referenced this pull request Jan 2, 2019
* master:
  DEP: drop python 2 support and associated ci mods (pydata#2637)
  TST: silence warnings from bottleneck (pydata#2638)
  revert to dev version
  DOC: fix docstrings and doc build for 0.11.1
  Source encoding always set when opening datasets (pydata#2626)
  Add flake check to travis (pydata#2632)
  Fix dayofweek and dayofyear attributes from dates generated by cftime_range (pydata#2633)
  silence import warning (pydata#2635)
  fill_value in shift (pydata#2470)
  Flake fixed (pydata#2629)
  Allow passing of positional arguments in `apply` for Groupby objects (pydata#2413)
  Fix failure in time encoding for pandas < 0.21.1 (pydata#2630)
  Fix multiindex selection (pydata#2621)
  Close files when CachingFileManager is garbage collected (pydata#2595)
  added some logic to deal with rasterio objects in addition to filepaths (pydata#2589)
  Get 0d slices of ndarrays directly from indexing (pydata#2625)
  FIX Don't raise a deprecation warning for xarray.ufuncs.{angle,iscomplex} (pydata#2615)
  CF: also decode time bounds when available (pydata#2571)
@shoyer
Copy link
Member

shoyer commented Jul 5, 2019

test_rasterio_vrt_network is failing in continuous integration tests, now: #3083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enabling rasterio.vrt.WarpedVRT with xr.open_rasterio
7 participants