XGCM: Your friend and helper for naughty grids

XGCM: Your friend and helper for naughty grids

I am seeing many fantastic science projects emerging for the hackathon (so many I am already dreading to decide in a few days).

I would like to add a project that is technical and likely related to many of the other projects in one way or the other.
Many of the projects propose using a combination of xarray and xgcm. The latter is the focus of this project and a centralized project around xgcm would assure that the functionality of this package would be optimally promoted and used but more crucially, that it evolves with the demand of the science done at the hackathon.

I am proposing to centralize efforts around promoting, improving and testing xgcm here

Scientific Motivation

One of the major challenges of a project like CMIP6 is that the various models provided have different grid architectures, both in the horizontal and vertical. In order to analyze the output between different models we require tools that can calculate properties on the native grid of the model and avoid interpolation and associated errors. The syntax of these tools should be as „agnostic“ as possible so that common operations like a gradient or divergence operator can be applied with a simple syntax akin to an analytical equation. The proposed tools would detect if e.g. the velocities are located on a B or C-grid and then execute the numerical calculations as close to the internal model code as possible.

xgcm currently has the ability to do the fundamental operations like interpolating and differencing on a finite grid, but the user has to remember the appropriate grid architecture and grid metrics (e.g. cell distances, areas, volumes). We need some higher-level functions to make xgcm even more useful.

I would propose the implementation of common vector calculus operators like grad, div, curl into the xgcm module. The recent addition of automatic grid metric handling builds the foundation for these operators and this workshop presents a fantastic opportunity to develop these new function on top while simultaneously testing them with a variety of model outputs.

Functionality for (very related) vertical grid transformation has happened mostly at Plotting ocean variables in density coordinates (using xhistogram), but this could be a fit for this more technical project too.

A note on the scope of xgcm

The goal of xgcm is to provide a generalized tool that is applicable on any logically rectangular grid (sorry no unstructured grids yet…). Functionality in xgcm should be kept to a very small set of essential functions. In that sense, we discourage building many specialized functions, like e.g. Okubo-Weiss Parameters or Shear and Strain fields and functionality that works only on your favorite model. These can be hosted in other packages building on xgcm functionality (here is an example of how I did this with MOM5 specific analysis tools; WARNING: This is not a pretty and/or well documented packaged yet).

Proposed Hacking

Since this project straddles so many others I am unsure what the best way to organize would be. But I would envision something like this:

  1. An introduction to xgcm and what it can currently do at the beginning stage of the hackathon.

  2. Getting feedback from the projects on what is working, and what is not.

  3. Implement new functionality or resolve issues that were brought up.

  4. Start at 2. again and repeat throughout the workshop.

I am very keen to get some feedback on this structure from people who have more experience in these kinds of events.

Anticipated Data Needs

For testing and using xgcm properly, we need the static grid information of each model:

  • Grid metrics: distances, areas for each logical cell (e.g. tracer, north, northeast, west or equivalent)

Anticipated Software Tools

This is focused on xgcm as a tool but we might implement other tools like xhistogram if we decide to implement a vertical coordinate transform as part of xgcm.

Desired Collaborators

I wish for as many people as possible to get involved, use the tools and give feedback. This gathering really is a unique opportunity to improve these tools at a fast speed and get broad feedback. So literally anyone is more than welcome!

We should probably include at least @rabernat to approve PRs :smile:

A plead: :alarm_clock: Get involved before the Hackathon!

I think most folks (including myself) want to focus on the science during the hackathon, so I am very determined to bring a good chunk of the functionality to xgcm before next week. Please get involved by trying xgcm out and raise or comment on issues.


Great proposal @jbusecke! This will be so helpful for the CMIP ensemble. I’ll see how far I can get before the hackathon!

1 Like

Thanks @yassir.eddebbar, I will try to put some example notebooks using the cutting edge features together in the coming days.
In the meantime some older examples can be found here and here.

Cross post from slack:
Hey folks, I have a very brief tutorial on how to compute the SST gradient magnitude with xgcm for all available models on their native grid in one go except the AWI unstructured one…. here.

The notebook is super long because I had to recreate grid metrics and also homogenize the naming of all models (we should generalize this for the whole group maybe?).

The xgcm part itself is super quick (3 cells incl. plotting).NOTE: This will not run in the binder because it is based on the newest functionality of xgcm (waiting for approval of @rabernat ).

Soon this should work and I will interface with @jhamman to hopefully make this available to everyone at the time of the hackathon. I will also try to add some more examples (streamfunction, curl etc) but ran out of steam yesterday night

Julius, these examples are amazing! Thanks so long to spend the time going through all the different models!

Thanks, Ryan. If you have any time at all it would be phenomenal if you could check xgcm #162! That will enable all the goodies! Ill try to get more things into the examples and move the renaming functionality to a different package.

Quick update: I have updated the preprocessing and we now get properly staggered grids with tracer u and v variables and grid locations.
I have added the computation of surface vorticity to the examples.

Here is a simple function I wrote along the same lines to relabel pop output to work with xgcm:

@jbusecke, thanks for the efforts on XGCM, looks fab.

As noted over on that twitter website I’m trying to carve out some time to shift my workflow to use XGCM.

My main dataset is MOM ocean model based with a mixture of B-grid (temp,salt,u,v, etc) and C-grid (model derived transports on the cell faces) variables.

Before I plunge into XGCM can you clarify if it’s C-grid specific? I assume I can get B-grid variables into your grid objects?

Thanks again for sharing the code and the luv.

1 Like

I should really RTFM! (or at least the whole thread) as @jbusecke seems to point to an example that includes B-grid models above.

1 Like

Hehe, no problem. Yes theoretically we support all Arakawa grid types. I have worked with A/B/C grids so far. Let me know how it goes. If anything comes up, try to raise an issue over at github. I am afraid I dont check discourse often enough…

1 Like