Modifying a coordinate #6311
Replies: 2 comments
-
After trying to dig up in the code with the debugger, I looked closer at the solution with Look at this test made with SOI.nc from ucar. time is a int32, I cast it to a int64 and it works. Casting back to int32, it does not work anymore.
The result is:
I tried again with a CMEMS file. Time coordinates is a datetime64[ns], with
We can see that time is modified when it is a datetime64[ns] but not when it is an int32. |
Beta Was this translation helpful? Give feedback.
-
I tried every numpy dtypes with the dataset example from the doc. A few values of a coords can't be changed if its type size is less than 64 bits. Unicode strings coordinates can't be changed.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
Sorry for not being able to totally respect #5404 about creating the data within the example since I don't know how to create two datasets that give the results exposed below except one.
We find a strange behavior while working with this file from ucar and another file that has been produced by a coworker. This has been tested with these versions : 0.16.1, 0.20.1 and 0.21.1.
The other file gives:
With another file downloaded from CMEMS, we also observe no modification of time.
But after modifying it with cdo remapbil, we get:
Otherwise, casting the time coordinate seems to make the job:
With the dataset example from xarray doc and time adapted:
To sum up, for some files we can change some values of its coordinates with
.values[a:b]
but for others, we can't. Altering (like a cast) the all coordinate changes its behavior regarding.values[a:b]
. For any other variables, I got [1 1 1].Is this a known issue? It seems to exist many ways to change a coordinate. If I understand correctly a coordinate is handled by a PandasIndex that is immutable. Thus using
.values
should not be allowed and besides it raises the question ofassign_coords
usage since we can just dods['mycoord'].values = np.array([....])
like for every variables. What do you think about it? Is it possible that a netcdf file has some kind of a memory lock for the coordinates?I take the freedom to use this discussion to ask you if it exists an ULM diagram or other kinds of graphs to see xarray internal architecture. I am really interested to better understand how it works.
Thank you very much !
Beta Was this translation helpful? Give feedback.
All reactions