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

Fix CRS being WKT instead of PROJ.4 #2715

Merged
merged 4 commits into from
Feb 6, 2019
Merged

Fix CRS being WKT instead of PROJ.4 #2715

merged 4 commits into from
Feb 6, 2019

Conversation

djhoese
Copy link
Contributor

@djhoese djhoese commented Jan 26, 2019

See https://github.com/mapbox/rasterio/blob/master/CHANGES.txt#L7 for the change in rasterio 1.0.14 and my conda-forge issue where I discovered this: conda-forge/gdal-feedstock#262

This was put in a bugfix (micro version number) release of rasterio which made it harder to discover. @sgillies @snowman2 I saw that you brought this up and how it affected xarray (https://rasterio.groups.io/g/dev/message/68). If this pull request is a duplicate of a fix one of you made let me know.

To xarray devs, if I need to make any other changes (whats-new?) also let me know.

  • Closes #xxxx
  • Tests added
  • Fully documented, including whats-new.rst for all changes and api.rst for new API

@sgillies
Copy link

sgillies commented Jan 26, 2019

@djhoese sorry for the inconvenience! I didn't consider the change in rasterio 1.0.14 to be an API change because the behavior of CRS.from_string(crs.to_string()) was not changed. I should have looked around for more usage like that in xarray.

@@ -282,7 +282,7 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None,
# CRS is a dict-like object specific to rasterio
# If CRS is not None, we convert it back to a PROJ4 string using
# rasterio itself
attrs['crs'] = riods.crs.to_string()
attrs['crs'] = riods.crs.to_proj4()
Copy link

@sgillies sgillies Jan 27, 2019

Choose a reason for hiding this comment

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

@djhoese I recommend the following:

Suggested change
attrs['crs'] = riods.crs.to_proj4()
attrs['crs'] = riods.crs.to_dict()

It's both forward and backward compatible. As far as I can tell from scanning the xarray source, the data array's crs attribute is rarely used, except as an argument to rasterio.transform where a dict should do just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sgillies It's not just how xarray uses the crs attribute but users. The reason I made this PR was because the xarray crs attribute changed from PROJ4 to WKT.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why does it need to be a PROJ.4 string in xarray?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, backwards compatibility. I don't think there is any other strong reason other than what the original developer chose (it is a fairly popular CRS format). If you think it should be WKT then that should probably go in its own issue.

Copy link
Member

Choose a reason for hiding this comment

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

The main reason was serialization to NetCDF: attributes can't be dict or objects, and strings are a perfect representation of the CRS. Any other idea welcome though.

djhoese added a commit to pytroll/satpy that referenced this pull request Jan 27, 2019
* Force rasterio version to fix PROJ4 to WKT change

See pydata/xarray#2715

* Try escaping quotes in travis CI

* Try single quotes in travis reqs

* Try no quotes in travis config
@fmaussion
Copy link
Member

can your merge from master? The failing tests should be solved by #2720

@pep8speaks
Copy link

pep8speaks commented Jan 28, 2019

Hello @djhoese! Thanks for updating the PR.

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

Comment last updated on February 06, 2019 at 16:49 Hours UTC

@djhoese
Copy link
Contributor Author

djhoese commented Jan 28, 2019

@fmaussion Done. And I merged @snowman2's suggestion and fixed the indent (I'm guessing github's editor made it difficult to see but it was off by one indentation).

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! Let's discuss how to deal with WKT and proj4 in a separate issue

@fmaussion
Copy link
Member

I'm going to merge this tomorrow unless there are further concerns

@dcherian
Copy link
Contributor

dcherian commented Feb 5, 2019

Does this need a whats-new entry?

@shoyer
Copy link
Member

shoyer commented Feb 6, 2019

Does this need a whats-new entry?

Yes, I would recommend that here -- especially for cases where we're changing behavior without a deprecation cycle (which is sometime the best path forward)

@djhoese
Copy link
Contributor Author

djhoese commented Feb 6, 2019

@dcherian @shoyer This PR isn't changing any functionality. It is making the same functionality available with newer versions of rasterio.

There are discussions going on regarding changing the behavior: #2723

@shoyer
Copy link
Member

shoyer commented Feb 6, 2019

This PR isn't changing any functionality. It is making the same functionality available with newer versions of rasterio.

OK, good point. I do still try to lean towards adding notes about bug fixes in "what's new" but it isn't strictly required.

@djhoese
Copy link
Contributor Author

djhoese commented Feb 6, 2019

@shoyer Added something to the whats-new. Let me know if anything needs changing.

@shoyer shoyer merged commit 0c73a38 into pydata:master Feb 6, 2019
@shoyer
Copy link
Member

shoyer commented Feb 6, 2019

thanks David, that looks great

@djhoese djhoese deleted the patch-1 branch February 6, 2019 16:57
dcherian pushed a commit to yohai/xarray that referenced this pull request Feb 14, 2019
* master:
  typo in whats_new (pydata#2763)
  Update computation.py to use Python 3 function signatures (pydata#2756)
  add h5netcdf+dask tests (pydata#2737)
  Fix name loss when masking (pydata#2749)
  fix datetime_to_numeric and Variable._to_numeric (pydata#2668)
  Fix mypy errors (pydata#2753)
  enable internal plotting with cftime datetime (pydata#2665)
  remove references to cyordereddict (pydata#2750)
  BUG: Pass kwargs to the FileManager for pynio engine (pydata#2380) (pydata#2732)
  reintroduce pynio/rasterio/iris to py36 test env (pydata#2738)
  Fix CRS being WKT instead of PROJ.4 (pydata#2715)
  Refactor (part of) dataset.py to use explicit indexes (pydata#2696)
@djhoese
Copy link
Contributor Author

djhoese commented Mar 12, 2019

@shoyer Any idea when a 0.11.4 or 0.12 will be released? I'm trying to work around some other rasterio bugs and would like to remove the restriction on the rasterio version used in my CI tests, but that requires this PR.

@shoyer
Copy link
Member

shoyer commented Mar 12, 2019 via email

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.

7 participants