xgcm: General Circulation Model Postprocessing with xarray
Binder Examples
Link
Provider
Description
mybinder.org
Basic self-contained example
Pangeo Binder
More complex examples integrated with other Pangeo tools (dask, zarr, etc.)
Description
xgcm is a python package for working with the datasets produced by numerical
General Circulation Models
(GCMs) and similar gridded datasets that are amenable to
finite volume analysis.
In these datasets, different variables are located at different positions with
respect to a volume or area element (e.g. cell center, cell face, etc.)
xgcm solves the problem of how to interpolate and difference these variables
from one position to another.
xgcm consumes and produces xarray data structures, which are coordinate and
metadata-rich representations of multidimensional array data. xarray is ideal
for analyzing GCM data in many ways, providing convenient indexing and grouping,
coordinate-aware data transformations, and (via dask) parallel,
out-of-core array computation. On top of this, xgcm adds an understanding of
the finite volume Arakawa Grids commonly used in ocean and atmospheric
models and differential and integral operators suited to these grids.
xgcm was motivated by the rapid growth in the numerical resolution of
ocean, atmosphere, and climate models. While highly parallel supercomputers can
now easily generate tera- and petascale datasets, common post-processing
workflows struggle with these volumes. Furthermore, we believe that a flexible,
evolving, open-source, python-based framework for GCM analysis will enhance
the productivity of the field as a whole, accelerating the rate of discovery in
climate science. xgcm is part of the Pangeo initiative.
Getting Started
To learn how to install and use xgcm for your dataset, visit the xgcm documentation.
Currently we have too much whitespace in our thumbnail. I could just cut it (but that would contribute to the weird jagged layout of pangeo gallery. Not a priority, just pinning this here.
First of all, thanks for making these tutorials! They've really helped me master xgcm, which I use almost daily now.
I spotted a mistake in the MITgcm example. The computation of the divergence is incorrect. The right MITgcm discrete form is found here. The difference is that there should be no multiplication by ds.drF (which in the link you currently include is present to correctly represent the z-derivative of the vertical velocity in the continuity equation), and that there should be an additional division by ds.hFacC. This also means that you may want to rename u/v_transport, since you don't need the transport after all.
I figured it's easiest for me to open an issue over a PR, since I don't know your specific workflow/integration for getting these examples on the xgcm website.
Maybe mention that even if these are 2 different git repositories, they use the same conda environment, which instructions are found in the xgcm contributors guide.
That was this point that was not clear for me.
I think it would be nice to give some more examples how to transform datasets between coordinates. Especially demonstrating this with gridded observational datasets seems to something people are interested in.
I'm trying to follow along from some of these sample notebooks but can't figure out the environment. I'm on sciserver. I have installed xgcm (it does appear in !conda list).
Can y'all help interpret this?
Traceback:
TypingErrorTraceback (most recent call last)
in
----> 1 from xgcm import Grid
2 from xgcm.autogenerate import generate_grid_ds
~/miniconda3/envs/py37/lib/python3.7/site-packages/xgcm/init.py in
4 version = "unknown"
5
----> 6 from .autogenerate import generate_grid_ds
7 from .grid import Axis, Grid
~/miniconda3/envs/py37/lib/python3.7/site-packages/xgcm/autogenerate.py in
1 import xarray as xr
2
----> 3 from xgcm.grid import Axis, raw_interp_function
4
5
~/miniconda3/envs/py37/lib/python3.7/site-packages/xgcm/grid.py in
15 import numba
16
---> 17 from .transform import conservative_interpolation, linear_interpolation
18 except ImportError:
19 numba = None
~/miniconda3/envs/py37/lib/python3.7/site-packages/numba/compiler.py in _compile_bytecode(self)
901 """
902 assert self.func_ir is None
--> 903 return self._compile_core()
904
905 def _compile_ir(self):
~/miniconda3/envs/py37/lib/python3.7/site-packages/numba/compiler.py in _compile_core(self)
888 self.define_pipelines(pm)
889 pm.finalize()
--> 890 res = pm.run(self.status)
891 if res is not None:
892 # Early pipeline completion
~/miniconda3/envs/py37/lib/python3.7/site-packages/numba/compiler_lock.py in _acquire_compile_lock(*args, **kwargs)
30 def _acquire_compile_lock(*args, **kwargs):
31 with self:
---> 32 return func(*args, **kwargs)
33 return _acquire_compile_lock
34
~/miniconda3/envs/py37/lib/python3.7/site-packages/numba/compiler.py in run(self, status)
264 # No more fallback pipelines?
265 if is_final_pipeline:
--> 266 raise patched_exception
267 # Go to next fallback pipeline
268 else:
~/miniconda3/envs/py37/lib/python3.7/site-packages/numba/typeinfer.py in propagate(self, raise_errors)
925 if errors:
926 if raise_errors:
--> 927 raise errors[0]
928 else:
929 return errors
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function interp at 0x7f44f9406cb0>) with argument(s) of type(s): (array(float32, 1d, A), array(float32, 1d, A), array(float32, 1d, A))
parameterized
In definition 0:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function np_interp_impl_inner_factory..impl at 0x7f44f60215f0>) with argument(s) of type(s): (array(float32, 1d, A), array(float32, 1d, A), array(float32, 1d, A), dtype(float64))
parameterized
In definition 0:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Cannot unify array(float32, 1d, C) and array(float64, 1d, C) for 'slopes', defined at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2120)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2120:
def impl(x, xp, fp, dtype):
[1] During: typing of assignment at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2122)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2122:
def impl(x, xp, fp, dtype):
raised from /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/typeinfer.py:927
In definition 1:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Cannot unify array(float32, 1d, C) and array(float64, 1d, C) for 'slopes', defined at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2120)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2120:
def impl(x, xp, fp, dtype):
[1] During: typing of assignment at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2122)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2122:
def impl(x, xp, fp, dtype):
raised from /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/typeinfer.py:927
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<function np_interp_impl_inner_factory..impl at 0x7f44f60215f0>)
[2] During: typing of call at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2237)
raised from /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/typeinfer.py:927
In definition 1:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function np_interp_impl_inner_factory..impl at 0x7f44f60215f0>) with argument(s) of type(s): (array(float32, 1d, A), array(float32, 1d, A), array(float32, 1d, A), dtype(float64))
parameterized
In definition 0:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Cannot unify array(float32, 1d, C) and array(float64, 1d, C) for 'slopes', defined at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2120)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2120:
def impl(x, xp, fp, dtype):
[1] During: typing of assignment at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2122)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2122:
def impl(x, xp, fp, dtype):
raised from /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/typeinfer.py:927
In definition 1:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Cannot unify array(float32, 1d, C) and array(float64, 1d, C) for 'slopes', defined at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2120)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2120:
def impl(x, xp, fp, dtype):
[1] During: typing of assignment at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2122)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py", line 2122:
def impl(x, xp, fp, dtype):
raised from /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/typeinfer.py:927
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<function np_interp_impl_inner_factory..impl at 0x7f44f60215f0>)
[2] During: typing of call at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/targets/arraymath.py (2237)
raised from /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/numba/typeinfer.py:927
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<function interp at 0x7f44f9406cb0>)
[2] During: typing of call at /home/idies/miniconda3/envs/py37/lib/python3.7/site-packages/xgcm/transform.py (31)
File "../../../../miniconda3/envs/py37/lib/python3.7/site-packages/xgcm/transform.py", line 31:
def _interp_1d_linear(
I wanted to rework the NEMO example (fix the typos, and reshape some stuff now that I am more confident with xgcm) and I am wondering, what environment should I use? Previously I used the environment.yml provided in xgcm (for readthedocs), is it still the same case now?
I feel lost between all the environments + the pangeo gallery.
Thanks!