-
Notifications
You must be signed in to change notification settings - Fork 96
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
writeCDF SpatRaster names #1756
Comments
Can you include a small example that illustrates what you are seeing? |
I can upload example files, but I thought this screenshot might be enough. As you can see, the names of the TH layers (elevations) have been changed from "Elev=0", "Elev=0.2", etc to generic names after saving as a netcdf file. I know I can use the "time" variable to save unique datetime attributes for each layer, but there is no way that I can see to save unique elevation information for each layer. This information is lost when converting to a nc using writeCDF. One solution would be if writeCDF could append the original name attribute to the generic "name" being created. |
I would like a concrete example, either generated with code or with a file. We need to be sure that we talk about the same things. ncdf files have variable names, not layer names. Perhaps the issue is that terra needs to understand higher dimensions, but I am not sure what it is without a clear example, so that we have a well defined behavior, and clear expectations. |
Also, please never include screenshots in an issue (except for a plot, where relevant). You can copy and paste the exact input/output from the console instead. |
|
In this example you have variables
The layer names are derived from the variable name of the array. The NCDF CF-1standard does not support "layer names" (names for the third dimension of an x, y, z array). It would be possible to make {terra} write these and read them again. Perhaps a better approach is to automatically split SpatRasters based on their layer names. Either in writeCDF or with a function you can call before that. That could keep And you can get that with current terra by writing a SpatRaster instead of a SpatRasterDataset and using
|
Is "time" not a third dimension of an x,y,z array? How is time stored, and could it not be generic? |
time is a dimension, like x/longitude and y/latitude. There are no names associated with each step. There is not a name for each latitude step. The third dimension could also be, for example, depth and we would have the depth values (10, 20), but not names like "shallow" and "deep" |
Another thing you can do is change the label "time" to another label to get the below:
|
Thank you for your explanations. I only have one further question ... Is it possible to use depths (or angles, in my example) as the third (time) dimension in terra? Are the unique values of the 3rd dimension stored in the netcdf, or only the start value and step value? |
The unique values are stored. Right now only time is used (but that I can fix). You can use time as long as your values are integers
But it would be better to allow doing this via "depth" because it allows real numbers; allow setting the "depth-name" to e.g., "angle", and reading the file again. There could also be other options for creating the layer names. In your example you would name the third dimension "elev" and you would choose not to prepend the variable name (that should not be necessary anyway if you read the file as an SpatRasterDataset. And it should be possible to use depth and time to write four-dimensional data. |
Would the 3rd dimension always have to be an integer? Or could it be any value, as long as these values were defined in the "time" variable? For example |
With the last commit, a small step forward, depth is used if there is no time dimension; allowing the use of real numbers:
|
Great! Could each dataset within an SDS have a different third dimension?
|
depth is the generic name for the third dimension, and you can now set a specific name for that dimension, that is used when writing a ncdf file. time is the fourth dimension (or third if there is no depth dimension) and its name can be changed with zname. Some more work is needed, but I think this is moving in the right direction.
|
Thank you! |
It would be helpful to know more about what you need. Perhaps terra can
support that better. RH
…On Mon, Mar 3, 2025 at 6:47 PM Breeze-Hu ***@***.***> wrote:
I used to get confused on layer names for high dimensional data as well.
Now one of my solution is to use python xarray for data reading
open_dataset ,and then do extraction for dimension names. Then use
terra::names function for corresponding naming.
And in using terra I try to use 3D data in order to avoid my own
dimensional problems.
—
Reply to this email directly, view it on GitHub
<#1756 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACXTCNJSI3J5NMKFVPWWK632SUH55AVCNFSM6AAAAABYH5YDGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOJWGA2DANBSGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
[image: Breeze-Hu]*Breeze-Hu* left a comment (rspatial/terra#1756)
<#1756 (comment)>
I used to get confused on layer names for high dimensional data as well.
Now one of my solution is to use python xarray for data reading
open_dataset ,and then do extraction for dimension names. Then use
terra::names function for corresponding naming.
And in using terra I try to use 3D data in order to avoid my own
dimensional problems.
—
Reply to this email directly, view it on GitHub
<#1756 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACXTCNJSI3J5NMKFVPWWK632SUH55AVCNFSM6AAAAABYH5YDGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOJWGA2DANBSGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
When writing a SpatRasterDataset to a .nc file, could the writeCDF function include the original layer names within the new layer names created by the function?
For example, currently, layer names are renamed by the writeCDF function to be varname_1, varname_2, etc. Instead of using this convention, could this function rename these layers to varname_"original layername" instead, where "original_layername" is the layer's name in the SDS object? It is frustrating to have to break up an SDS into many spatRasters just so that I can save the layer names correctly in the nc file.
Or is there a way to do this with the writeCDF function that I am unaware of?
Thank you
The text was updated successfully, but these errors were encountered: