-
Notifications
You must be signed in to change notification settings - Fork 89
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
names lost with writeCDF #1077
Comments
A netCDF file does not have layers. It has a 3rd dimension that you can name, and the layer names are derived from that. As for time information, that does not need to be (and should not, I think) be handled as layer names. So I might do
Does that work for you? |
My issue with that solution is that the SpatRaster that you read from the netcdf has different variable names from the SpatRaster that generated the netcdf. I would favour an approach where layers becomes variables in the netcdf, so that you can save and reload the same object. In other words, if my layers are called "foo" and "bar", I would like to get back "foo" and "bar" from the netcdf. I am aware that I can achieve that by creating an |
I think that what you want does not really match the netCDF format. The third dimension is normally time or something of that nature. It can also be used for different variables that can then become layers, but that is not the most common or useful use of that format. If you must use that format, you could, as you point out, use a SpatRasterDataset instead. For example like this:
I considered adding an argument "split=FALSE" to |
On this one, we might have to agree to disagree. The way I see it, when an object is saved, it should be possible to retrieve it as is, without losing information. The netCDF format is really a container, and one can have as many variables and dimensions as needed, so I am not sure I see the problem of turning layers into variables. |
@rhijmans Thinking about it, a split=TRUE could be easily fitted without too much trouble by simply imposing that the other variables have to be unset if you use split (as names and units then come from the SpatRaster itself). So, the following would allow for objects to be saved and reloaded without loss of information:
And now everything works just fine:
Acceptable? Or too messy for your taste? If acceptable, happy to make a pull request and provide appropriate guidance in the manpage. |
Thanks, I have now added argument "split=FALSE". |
When saving a SpatRaster to netCDF, layers are saved as different times, with a loss of variable names. For example:
gives FALSE, as the variable names have been replaced with the name of the file ("test_1" and "test_2"). In the netcdf, the variables have been turned into different time steps for a single variable "test" (thus messing up any real time information if present in the original SpatRaster object).
To allow saving and reloading the object as is, we would need to save each layer with a unique name in the SpatRaster object as a different variable within the netcdf file, and use time only if there are multiple layers with the same name but different times (and I guess throw an error if there are multiple instances of same name and same time, which is possible in
terra
).The text was updated successfully, but these errors were encountered: