-
Notifications
You must be signed in to change notification settings - Fork 66
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
N + 1 sized grids for X and Y #15
Comments
This makes sense from a physical point of view. But there are two obstacles:
Have you tried just using the dataset.plot.pcolormesh method directly as is? Does the automatic inferring of intervals not work correctly? If so, you should consider opening an xarray issue. |
p.s. the relevant xarray code for inferring intervals is here: |
Thanks for the clarification.
Good to know it's an ongoing issue and that function arguments may change in the future. |
I would prefer to keep this open. While xarray handles your cartesian case fine, I don't think it will handle the llc case correctly, because the coordinates themselves are 2D arrays. For that case, we really would want to provide (Ny+1, Nx+1)-shaped arrays to pcolor. That may require a custom plotting function in xmitgcm, or it may be supported by a future version of xarray. In any case, it is a real issue. Thanks @hugke729 for your feedback! |
I am not an MITgcm user but having exactly the same issue regarding xarray. We are developing a xarray-based Python package for the Cubed-Sphere (CS) grids in GEOS-Chem and GFDL-FV3. The CS grids have similar features as the Lat-Lon-Cap (LLC) grids -- we need an additional "tile" dimension in an xarray DataSet to represent 6 tiles, pretty similar to how xmitgcm handles faces. I am very interested in implementing N+1 sized coordinates as it will benefit all kinds of quadrilateral grids. For example, if I use DataArray's plotting method on each tile (i.e. call dr.plot.pcolormesh 6 times), with cell centers being the x and y arguments, I will get ugly white lines between tiles because one row and one column are missing: If I instead use the original plt.pcolormesh() and provide cell boundaries, it looks much better: Passing cell boundaries to xarray's plottig method should be possible, because the wrapper is tiny. However, the main barrier is that DataArray (not DataSet) currently cannot contain N+1 sized coordinated variables. If you try to assign such a coordinate by dr.assign_coords(), you will get On the other hand, say you already have a DataSet containing cell bounds ("lat_b" and "lon_b") like below:
The cell bound variables will be dropped automatically when you extract a DataArray by calling
So there must be a way to preserve cell bounds. I wonder if it is possible to: PS1:
It doesn't seem necessary to support the cell bound format specified by the CF-convention . The CF-convention uses an array of size (N,2) instead of (Nx+1) for 1D grid bounds, and (Nx,Ny,4) instead of (Nx+1,Ny+1) for 2D bounds. N+1 sized grids is more elegant and also more consistent with pcolormesh as it expects (Nx+1,Ny+1) not (Nx,Ny,4). PS2: |
Hi @JiaweiZhuang--thanks for your interest. I know you have gotten some responses on the related xarray issue. I wanted to also draw your attention to xgcm: https://github.com/xgcm/xgcm. The point of xgcm is to represent and operate on Arakawa grids using xarray data structures. I am about to make a new release of xgcm which will come closer to supporting the features you need. As you pointed out, MITgcm and geos-chem have many similar issues related to these tiled grids. I will update you soon once I make this new release. |
@rabernat Thanks for pointing me to xgcm. I've just looked through its documentation and it indeed addresses xarray's limitations. Please keep me informed of the updates. |
For plotting (specifically pcolor), it's often helpful to have X and Y grids that include both end points. I think it would be convenient to have something like Xp1 and Yp1, just like there is for Zp1.
Having this baked into the Dataset would enable use of all of Dataset's plotting methods, and it would save boilerplate code for creating Xp1 and Yp1 everytime I need them.
The text was updated successfully, but these errors were encountered: