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

support xarray.Dataset as input to get_cartopy and getvar #6

Open
andreas-h opened this issue Mar 9, 2017 · 5 comments
Open

support xarray.Dataset as input to get_cartopy and getvar #6

andreas-h opened this issue Mar 9, 2017 · 5 comments
Labels
enhancement New feature or request low priority Low priority item

Comments

@andreas-h
Copy link
Contributor

andreas-h commented Mar 9, 2017

it would be great if the get_cartopy and getvar functions would accept a xarray.Dataset as var input. Obviously, this can only work properly if the Dataset was loaded with a standard xarray.open_dataset call and the metadata were not modified, but still, it would be very convenient.

@andreas-h andreas-h changed the title support xarray.Dataset as input to get_cartopy support xarray.Dataset as input to get_cartopy and getvar Mar 9, 2017
@bladwig1
Copy link

bladwig1 commented Mar 9, 2017

Thank you for the feedback. I plan on improving xarray support in the future 1.1 release, so this is definitely on my to-do list. For now, a workaround for get_cartopy is to use the 'getproj' function by supplying the MAP_PROJ, TRUELAT1, TRUELAT2, MOAD_CEN_LAT, STAND_LON, POLE_LAT, POLE_LON global attributes from the WRF file as keyword arguments to getproj (note: it's case insensitive). This will return one of the Projection subclasses. You can then call the Projection.cartopy() method to get the cartopy object. As long as the projection is not a RotatedPole projection, you should have all you need.

For the RotatedPole projection, you need to use the Projection.cartopy_xlim() and Projection.cartopy_ylim() methods to set the map boundaries, since the builtin stuff with cartopy doesn't work correctly with RotatedPole (however, it might be fixed now). This requires supplying a GeoBounds argument, which is just the corner points from XLAT and XLONG.

@andreas-h
Copy link
Contributor Author

Thanks, that's great to hear!

Thanks to the xarray developer(s), it's even easier:

ds = xr.open_dataset(FILENAME)
proj = get_cartopy(ds._file_obj.ds)

Cheers!

@bladwig1
Copy link

Nice, didn't know about that. I might be able to sneak this change in now, since this requires no change to the underlying netcdf reading code. It might not get documented until version 1.1.

@bladwig1 bladwig1 added the enhancement New feature or request label Apr 6, 2017
@erogluorhan erogluorhan added the low priority Low priority item label Sep 1, 2020
@zxdawn
Copy link

zxdawn commented Mar 9, 2021

ds._file_obj.ds doesn't work for xarray new version (>=0.17.0) anymore :

lib/python3.8/site-packages/xarray/core/common.py", line 239, in __getattr__
    raise AttributeError(
AttributeError: 'Dataset' object has no attribute '_file_obj'

I guess it's related to pydata/xarray#4809.

@Murk89
Copy link

Murk89 commented Sep 13, 2021

Hi,

So is there a way to work with the get_cartopy using xarray.open_mfdataset()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low priority Low priority item
Projects
None yet
Development

No branches or pull requests

6 participants