question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LLC90 grid and face connections

See original GitHub issue

Hello,

I am trying to differentiate some ECCO fields on the LLC90 grid using xgcm, and having some issues working with subsets of the grid (see https://ecco.jpl.nasa.gov/products/latest/user-guide/ for a brief overview of the grid).

Using all 13 faces, this can be done easily with the following code:

# define the connectivity between faces
face_connections = {'face':
                    {0: {'X':  ((12, 'Y', False), (3, 'X', False)),
                         'Y':  (None,             (1, 'Y', False))},
                     1: {'X':  ((11, 'Y', False), (4, 'X', False)),
                         'Y':  ((0, 'Y', False),  (2, 'Y', False))},
                     2: {'X':  ((10, 'Y', False), (5, 'X', False)),
                         'Y':  ((1, 'Y', False),  (6, 'X', False))},
                     3: {'X':  ((0, 'X', False),  (9, 'Y', False)),
                         'Y':  (None,             (4, 'Y', False))},
                     4: {'X':  ((1, 'X', False),  (8, 'Y', False)),
                         'Y':  ((3, 'Y', False),  (5, 'Y', False))},
                     5: {'X':  ((2, 'X', False),  (7, 'Y', False)),
                         'Y':  ((4, 'Y', False),  (6, 'Y', False))},
                     6: {'X':  ((2, 'Y', False),  (7, 'X', False)),
                         'Y':  ((5, 'Y', False),  (10, 'X', False))},
                     7: {'X':  ((6, 'X', False),  (8, 'X', False)),
                         'Y':  ((5, 'X', False),  (10, 'Y', False))},
                     8: {'X':  ((7, 'X', False),  (9, 'X', False)),
                         'Y':  ((4, 'X', False),  (11, 'Y', False))},
                     9: {'X':  ((8, 'X', False),  None),
                         'Y':  ((3, 'X', False),  (12, 'Y', False))},
                     10: {'X': ((6, 'Y', False),  (11, 'X', False)),
                          'Y': ((7, 'Y', False),  (2, 'X', False))},
                     11: {'X': ((10, 'X', False), (12, 'X', False)),
                          'Y': ((8, 'Y', False),  (1, 'X', False))},
                     12: {'X': ((11, 'X', False), None),
                          'Y': ((9, 'Y', False),  (0, 'X', False))}}}

grid = xgcm.Grid(ds.isel(face=facen), periodic=False, face_connections=face_connections)
div = grid.diff_2d_vector({'X': u, 'Y': v}, boundary='fill')

Where this fails is when working with only a subset of the 13 faces. For example, if I am interested in the North Atlantic, I would use only faces 3 and 11. The face connections dictionary that I would supply to the differentiation function (see https://buildmedia.readthedocs.org/media/pdf/xgcm/latest/xgcm.pdf) should look like this then:

face_connections = {'face': 
                         {2: {'X': ((10, 'Y', False), None),
                              'Y': (None, None)},
                          10: {'X': (None, None),
                               'Y': (None, (2, 'X', False))}}}

Using this, I can create the xgcm grid succesfully:

grid = xgcm.Grid(ds.isel(face=facen), periodic=False, face_connections=face_connections_test)
grid
<xgcm.Grid>
T Axis (not periodic):
  * center   time --> inner
  * inner    time_snp --> center
Y Axis (not periodic):
  * center   j --> left
  * left     j_g --> center
Z Axis (not periodic):
  * center   k --> left
  * left     k_l --> center
  * outer    k_p1 --> center
  * right    k_u --> center
X Axis (not periodic):
  * center   i --> left
  * left     i_g --> center

However, I get the following error when I differentiate:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-149-34d1b34b72ee> in <module>
      3 #               grid.diff(ADVy_TH_anom, 'Y', boundary='fill'))/vol
      4 
----> 5 adv_hDivH = grid.diff_2d_vector({'X': ADVx_TH_anom, 'Y': ADVy_TH_anom}, boundary='fill')
      6 adv_hConvH = -(adv_hDivH['X'] + adv_hDivH['Y'])/vol
      7 

/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in diff_2d_vector(self, vector, **kwargs)
    955         """
    956 
--> 957         return self._apply_vector_function(Axis.diff, vector, **kwargs)
    958 
    959 

/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in _apply_vector_function(self, function, vector, **kwargs)
    841                                     vector_partner={y_axis_name:
    842                                                     vector[y_axis_name]},
--> 843                                     **kwargs)
    844 
    845         y_component = function(y_axis, vector[y_axis_name],

/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in diff(self, da, to, boundary, fill_value, boundary_discontinuity, vector_partner)
    506                                           boundary, fill_value,
    507                                           boundary_discontinuity,
--> 508                                           vector_partner)
    509 
    510     @docstrings.dedent

/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in _neighbor_binary_func(self, da, f, to, boundary, fill_value, boundary_discontinuity, vector_partner)
    219                                                   boundary_discontinuity,
    220                                                   vector_partner=
--> 221                                                   vector_partner)
    222         # wrap in a new xarray wrapper
    223         da_new = self._wrap_and_replace_coords(da, data_new, to)

/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in _neighbor_binary_func_raw(self, da, f, to, boundary, fill_value, boundary_discontinuity, vector_partner, position_check)
    243 
    244         # apply the function
--> 245         data_new = f(data_left, data_right)
    246 
    247         return data_new

/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in raw_diff_function(data_left, data_right)
   1003 
   1004 def raw_diff_function(data_left, data_right):
-> 1005     return data_right - data_left
   1006 
   1007 def raw_min_function(data_left, data_right):

/srv/conda/envs/notebook/lib/python3.6/site-packages/dask/array/core.py in __sub__(self, other)
   1735 
   1736     def __sub__(self, other):
-> 1737         return elemwise(operator.sub, self, other)
   1738 
   1739     def __rsub__(self, other):

/srv/conda/envs/notebook/lib/python3.6/site-packages/dask/array/core.py in elemwise(op, *args, **kwargs)
   3638     shapes = [s if isinstance(s, Iterable) else () for s in shapes]
   3639     out_ndim = len(
-> 3640         broadcast_shapes(*shapes)
   3641     )  # Raises ValueError if dimensions mismatch
   3642     expr_inds = tuple(range(out_ndim))[::-1]

/srv/conda/envs/notebook/lib/python3.6/site-packages/dask/array/core.py in broadcast_shapes(*shapes)
   3599             raise ValueError(
   3600                 "operands could not be broadcast together with "
-> 3601                 "shapes {0}".format(" ".join(map(str, shapes)))
   3602             )
   3603         out.append(dim)

ValueError: operands could not be broadcast together with shapes (288, 50, 2, 90, 89) (288, 50, 2, 90, 90)

The input shapes for both arrays are (288,50,2,90,90), so I’m not sure what’s going on. Am I missing something here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yangleircommented, Feb 5, 2022

Thanks @jbusecke , manually setting works.

0reactions
jbuseckecommented, Feb 4, 2022

Hi @yangleir it seems like xgcm is not able to detect the axes and coordinates from the metadata of the dataset. Have you tried to set these manually (example here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

LLC90 grid and face connections · Issue #684 · pangeo-data ...
I am trying to differentiate some ECCO fields on the LLC90 grid using xgcm, and having some issues working with subsets of the...
Read more >
ECCO Ocean Velocity - Daily Mean llc90 Grid (Version 4 ...
This dataset provides daily-averaged ocean velocity on the native Lat-Lon-Cap 90 (LLC90) model grid from the ECCO Version 4 Release 4 (V4r4) ocean...
Read more >
Use case: reading the full grid from MITgcm input files - xmitgcm
Example 1: LLC90¶ · [1]:. #We're going to download a sample grid from figshare ! · [2]:. import xmitgcm · [3]:. # We...
Read more >
Articles - GMD - Copernicus.org
We use a suite of experiments to explore the sensitivity of coastal plume regions to runoff forcing, model grid resolution, and grid type....
Read more >
ECCO Version 4 Python Tutorial Documentation
Here are some links to help you learn more about Python. ... Note: Each tile in the llc90 grid used by ECCO v4...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found