cf-python
cf-python copied to clipboard
I am always struggling with dimensions, axes, and coordinates in cf-python - it seems that ChatGPT does too!
I want to find which axis in the field is associated with time, but I also want to know where it is in the chunk shape matrix.
Concrete example: I know I can do this: t_axis = t = ff.coordinate('T')
, but I don't know (programmatically) where that might be in an array shape of (720, 1920, 2560). (The answer is 0, but it could be 1 or 2).
I see that t_axis.identity()
gives me time
. Good. As it happens, I asked ChatGPT how to do this: "I am using cf-python to read some netcdf data. How do I find out which axis of the data is the time axis (if there is a time axis)" and ChatGPT suggested that
I "Iterate through the field constructs to identify which one represents the time axis.".
Great. I thought, given the above. ChatGPT even gave me this bit of code:
time_axes = field.domain_axes(todict=True)
for key, domain_axis in time_axes.items():
if 'T' in domain_axis.identity():
print(f"Field: {field.identity()}")
print(f"Time Axis: {key}, {domain_axis}")
That looked like it should work. But I didn't notice the difference between a domain axis and a coordinate (and neither did ChatGPT), which I expect explains that this is what the identities returned in that loop actually are: ncdim%time, ncdim%latitude, ncdim%longitude
.
So that didn't work. At this point I am thinking, this is too hard.
Yuck. I think civilians find these distinctions impossible to work with.