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

All multiple nodata values to be passed to reproject #720

Open
andypbarrett opened this issue Dec 15, 2023 · 3 comments
Open

All multiple nodata values to be passed to reproject #720

andypbarrett opened this issue Dec 15, 2023 · 3 comments
Labels
proposal Idea for a new feature.

Comments

@andypbarrett
Copy link

For datasets with several data variables of different datatypes, it would be helpful to set a nodata value for each data variable.

Current Behavior
The nodata keyword argument for rio.reproject accepts a single value. If nodata == None, then a default value is used based on data type.

Suggested Behavior
Allow nodata to accept a scalar or a dict, where the dict is {'var1': nodata_value_var1, 'var2': nodata_value_var2}.

The for-loop in rioxarray.raster_dataset.reproject would then check for a nodata value for the data variable.

for var in self.vars:
    <snip>
    if isinstance(nodata, dict):
         nodata_val = nodata.get(var)
    else:
        nodata_val = nodata
    x_dim, y_dim = _get_spatial_dims(self._obj, var)
    resampled_dataset[var] = (
                    self._obj[var]
                    .rio.set_spatial_dims(x_dim=x_dim, y_dim=y_dim, inplace=True)
                    .rio.reproject(
                        dst_crs,
                        resolution=resolution,
                        shape=shape,
                        transform=transform,
                        resampling=resampling,
                        nodata=nodata_val,
                        **kwargs,
                    )
    <snip>
@andypbarrett andypbarrett added the proposal Idea for a new feature. label Dec 15, 2023
@snowman2
Copy link
Member

This is the recommended approach for setting the nodata values: https://corteva.github.io/rioxarray/stable/getting_started/nodata_management.html

@andypbarrett
Copy link
Author

Thank you @snowman2 . I take your point. Ideally, data files will have the nodata values set correctly. This is not always the case. While using one of the recommended methods is preferable, it adds an extra layer to simple workflows.

As reproject allows nodata to be set as a keyword anyway, then it would be useful if the nodata keyword covered the case where a dataset has variables with different nodata values.

Happy to submit a PR.

@snowman2
Copy link
Member

A PR would be welcome!

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

No branches or pull requests

2 participants