-
Notifications
You must be signed in to change notification settings - Fork 41
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
enforce dimension ordering? #82
Comments
the way to do this in xarray is |
Oh right, sorry I should have been specific. Yes, I know transposing works, but you have the know the dimensions ahead of time to call transpose properly. I would hope for something that transposes but given whatever number of the 4 possible dimensions (T, Z, Y, X), puts them in the proper order. |
the challenge is that you may pass a Dataset that has an X coordinate with The current solution is ds.cf.transpose(*[dim for dim in ["T", "Z", "Y", "X"] if dim in ds.cf.get_valid_keys()]) What are you trying to do by enforcing dimension order? Maybe there's something else |
That would work if the cf xarray attributes work for a Dataarray for ROMS output. I could have that check as needed in code. I ran across this recently when I did some calculation that changed the order of dimensions in a DataArray and then I used xESMF which assumes typical ordering. So either I would like for my arrays to always be put into proper ordering with a quick command like you listed after anything I run (thinking about xroms here), or all commands to DataArrays should be able to be called by a keyword ordering instead of assuming typical array ordering (in this example that would be a change to xESMF). |
if you want
This would be desirable. We would like packages that build on xarray to not depend on dimension order. Can you open an issue at https://github.com/pangeo-data/xESMF/issues |
I'm working on integrating adding the attributes into xroms. I have another question. I had been thinking that cf-xarray
I have assigned attributes to coordinates in my ROMS output, but then the Axes are pointing to lon_rho, lat_rho, etc. I think they should point to eta_rho, xi_rho, etc, if transpose is going to work with them. However, I don't seem to be able to assign any attributes to xarray dimensions. Any ideas on this?
Ok added to my list. |
You'll have to create an actual array for
cf_xarray just has special names I agree with you: for ROMS I would set For regular grids: |
As I read this I realized you had addressed this before (#84) but it didn't stick in my head bc I hadn't run across it and thought about it yet. Thank you for your patience. I will try this. |
Just the dimension name: so For |
Sorry just saw the second cell; hmmm.... that looks wrong. |
Thanks @kthyng. I found the bug... also while trying to reproduce, I found a clear way of converting
|
As I noted elsewhere, this worked for me, thanks!
I tried out these lines and they are indeed a shorter way to convert a dimension to a coordinate and then set the attribute, so I switched over to that, thanks. So with this change, I can close this issue! I am able to use
to transpose an array from ROMS without needing to know if it actually has all the dimensions a priori. I know it is better to not require arrays to be in the correct order (will try to follow up with xESMF with about that), but it will also be helpful to have this available. Thanks again. |
Sorry to reopen this, but wouldn't this be a nice convenience function for cf-xarray to have? I was just thinking about wrapping it in xroms, but why not have this package have it? Something like:
which returns |
This comment has been minimized.
This comment has been minimized.
Maybe something like |
That would work fine for me. But, why not essentially force it with this convenience function to a specific ordering? One can always transpose to other dimension ordering if they don't want this one for some reason, but doesn't CF convention dictate this order? |
Just noticed this today, so perhaps we could have |
@dcherian I haven't gotten to integrate cf-xarray into my workflow yet, but, looking ahead, could cf-xarray be a tool for enforcing certain dimension ordering for xarray DataArrays? I find that after calculations sometimes the ordering changes and I haven't figured out a good way to automate dimensional order [time x vertical x y-coord x x-coord]. Sometimes it matters, too. Any thoughts?
The text was updated successfully, but these errors were encountered: