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

Encoding not preserved when creating ROI #109

Closed
jlandmann opened this issue Jul 12, 2018 · 3 comments · Fixed by #111
Closed

Encoding not preserved when creating ROI #109

jlandmann opened this issue Jul 12, 2018 · 3 comments · Fixed by #111

Comments

@jlandmann
Copy link
Contributor

The salem roi method of the xarray accessor objects is great and to my knowledge and in this user-friendliness nowhere else available.
I'm using it to clip DEMs to shapefiles and get great results. The only point I'm wondering about is if it's intentional that the encoding of the dataset/datarray and its variables is not preserved. In code language:

In[4]: data = xr.open_dataset(gdir.get_filepath('dem_ts'), group=demtype)
In[5]: data.height.encoding
Out[5]: 
{'_FillValue': nan,
 'chunksizes': None,
 'complevel': 0,
 'contiguous': True,
 'dtype': dtype('float32'),
 'fletcher32': False,
 'original_shape': (1, 1201, 3501),
 'shuffle': False,
 'source': 'some_path\\dem_ts.nc',
 'zlib': False}
In[6]: data = data.salem.roi(shape=gdir.get_filepath('outlines'))
In[7]: data.height.encoding
Out[7]: 
{}
In[8]: data.encoding
Out[8]: 
{}

The Fill_Value might interfere with the value that salem fills the mask with if other is not passed here, but in case you agree that this is not too much of a problem I guess catching the encoding before and just inserting it after making the mask could be a solution. Do you see any other problem?

@fmaussion
Copy link
Owner

Thanks for the report! I'm happy if you send a PR to correct this.

Note that you might open an issue on the xarray repo as well to ask for an option to preserve encoding with where

@jlandmann
Copy link
Contributor Author

Thanks for the answer! You are right, maybe fixing it upstream would even be a better option...I'll do that as soon as I'm home!

@fmaussion
Copy link
Owner

This is going to take a while on the xarray side, so feel free to add a hot fix to salem too.

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 a pull request may close this issue.

2 participants