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

icvert variable converted to float when saving to NetCDF #128

Closed
tomvansteijn opened this issue Nov 9, 2022 · 4 comments
Closed

icvert variable converted to float when saving to NetCDF #128

tomvansteijn opened this issue Nov 9, 2022 · 4 comments
Assignees

Comments

@tomvansteijn
Copy link

The icvert variable in the nlmod model dataset is converted to float when saving to NetCDF. The variable has the attribute "_FillValue" set to -1. This attribute is lost when saving to NetCDF. The changes can cause problems when writing the DISV package.

Is this a NetCDF issue? Or is it caused by missing values in the icvert variable for certain coordinate combinations?

@OnnoEbbens
Copy link
Collaborator

It has to do with how NetCDF stores missing values in an integer array. For more information see this issue: #91

Did you encounter problems when writing the DISV?

@rubencalje
Copy link
Collaborator

So the saved NetCDF-file does contain integer values for the variable icvert, but when you read the NetCDF again using xarray, the integer values are converted to floats, and the values equal to _FillValue are set to NaN. To make sure this does not happen, read the NetCDF-file with the parameter mask_and_scale set to False. Like:

ds = xr.open_dataset(fname, mask_and_scale=False)

@tomvansteijn
Copy link
Author

Thanks for the clarification @rubencalje. I meant to provide a working example but I haven't got to it yet. I trust this will solve the issue I had. Indeed the _FillValue was set to NaN, and NaN's were written to the DISV package files, with a Modflow error as a result. Good to include this solution (about the mask_and_scale flag) in the docs if you haven't already.

@OnnoEbbens
Copy link
Collaborator

Fixed by #238

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

No branches or pull requests

3 participants