{"action":"opened","issue":{"url":"https://api.github.com/repos/pangeo-data/pangeo/issues/684","repository_url":"https://api.github.com/repos/pangeo-data/pangeo","labels_url":"https://api.github.com/repos/pangeo-data/pangeo/issues/684/labels{/name}","comments_url":"https://api.github.com/repos/pangeo-data/pangeo/issues/684/comments","events_url":"https://api.github.com/repos/pangeo-data/pangeo/issues/684/events","html_url":"https://github.com/pangeo-data/pangeo/issues/684","id":476325499,"node_id":"MDU6SXNzdWU0NzYzMjU0OTk=","number":684,"title":"LLC90 grid and face connections","user":{"login":"cpatrizio88","id":1316945,"node_id":"MDQ6VXNlcjEzMTY5NDU=","avatar_url":"https://avatars1.githubusercontent.com/u/1316945?v=4","gravatar_id":"","url":"https://api.github.com/users/cpatrizio88","html_url":"https://github.com/cpatrizio88","followers_url":"https://api.github.com/users/cpatrizio88/followers","following_url":"https://api.github.com/users/cpatrizio88/following{/other_user}","gists_url":"https://api.github.com/users/cpatrizio88/gists{/gist_id}","starred_url":"https://api.github.com/users/cpatrizio88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpatrizio88/subscriptions","organizations_url":"https://api.github.com/users/cpatrizio88/orgs","repos_url":"https://api.github.com/users/cpatrizio88/repos","events_url":"https://api.github.com/users/cpatrizio88/events{/privacy}","received_events_url":"https://api.github.com/users/cpatrizio88/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-08-02T19:31:22Z","updated_at":"2019-08-02T19:31:22Z","closed_at":null,"author_association":"NONE","body":"Hello,\r\n\r\nI'm not sure if this is the appropriate place to post this, so please bare with me! 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). \r\n\r\nUsing all 13 faces, this can be done easily with the following code: \r\n\r\n```\r\n# define the connectivity between faces\r\nface_connections = {'face':\r\n                    {0: {'X':  ((12, 'Y', False), (3, 'X', False)),\r\n                         'Y':  (None,             (1, 'Y', False))},\r\n                     1: {'X':  ((11, 'Y', False), (4, 'X', False)),\r\n                         'Y':  ((0, 'Y', False),  (2, 'Y', False))},\r\n                     2: {'X':  ((10, 'Y', False), (5, 'X', False)),\r\n                         'Y':  ((1, 'Y', False),  (6, 'X', False))},\r\n                     3: {'X':  ((0, 'X', False),  (9, 'Y', False)),\r\n                         'Y':  (None,             (4, 'Y', False))},\r\n                     4: {'X':  ((1, 'X', False),  (8, 'Y', False)),\r\n                         'Y':  ((3, 'Y', False),  (5, 'Y', False))},\r\n                     5: {'X':  ((2, 'X', False),  (7, 'Y', False)),\r\n                         'Y':  ((4, 'Y', False),  (6, 'Y', False))},\r\n                     6: {'X':  ((2, 'Y', False),  (7, 'X', False)),\r\n                         'Y':  ((5, 'Y', False),  (10, 'X', False))},\r\n                     7: {'X':  ((6, 'X', False),  (8, 'X', False)),\r\n                         'Y':  ((5, 'X', False),  (10, 'Y', False))},\r\n                     8: {'X':  ((7, 'X', False),  (9, 'X', False)),\r\n                         'Y':  ((4, 'X', False),  (11, 'Y', False))},\r\n                     9: {'X':  ((8, 'X', False),  None),\r\n                         'Y':  ((3, 'X', False),  (12, 'Y', False))},\r\n                     10: {'X': ((6, 'Y', False),  (11, 'X', False)),\r\n                          'Y': ((7, 'Y', False),  (2, 'X', False))},\r\n                     11: {'X': ((10, 'X', False), (12, 'X', False)),\r\n                          'Y': ((8, 'Y', False),  (1, 'X', False))},\r\n                     12: {'X': ((11, 'X', False), None),\r\n                          'Y': ((9, 'Y', False),  (0, 'X', False))}}}\r\n\r\ngrid = xgcm.Grid(ds.isel(face=facen), periodic=False, face_connections=face_connections)\r\ndiv = grid.diff_2d_vector({'X': u, 'Y': v}, boundary='fill')\r\n```\r\nWhere 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: \r\n\r\n```\r\nface_connections = {'face': \r\n                         {2: {'X': ((10, 'Y', False), None),\r\n                              'Y': (None, None)},\r\n                          10: {'X': (None, None),\r\n                               'Y': (None, (2, 'X', False))}}}\r\n```\r\nUsing this, I can create the xgcm grid succesfully:\r\n\r\n```\r\ngrid = xgcm.Grid(ds.isel(face=facen), periodic=False, face_connections=face_connections_test)\r\ngrid\r\n<xgcm.Grid>\r\nT Axis (not periodic):\r\n  * center   time --> inner\r\n  * inner    time_snp --> center\r\nY Axis (not periodic):\r\n  * center   j --> left\r\n  * left     j_g --> center\r\nZ Axis (not periodic):\r\n  * center   k --> left\r\n  * left     k_l --> center\r\n  * outer    k_p1 --> center\r\n  * right    k_u --> center\r\nX Axis (not periodic):\r\n  * center   i --> left\r\n  * left     i_g --> center\r\n```\r\n\r\nHowever, I get the following error when I differentiate: \r\n\r\n```\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-149-34d1b34b72ee> in <module>\r\n      3 #               grid.diff(ADVy_TH_anom, 'Y', boundary='fill'))/vol\r\n      4 \r\n----> 5 adv_hDivH = grid.diff_2d_vector({'X': ADVx_TH_anom, 'Y': ADVy_TH_anom}, boundary='fill')\r\n      6 adv_hConvH = -(adv_hDivH['X'] + adv_hDivH['Y'])/vol\r\n      7 \r\n\r\n/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in diff_2d_vector(self, vector, **kwargs)\r\n    955         \"\"\"\r\n    956 \r\n--> 957         return self._apply_vector_function(Axis.diff, vector, **kwargs)\r\n    958 \r\n    959 \r\n\r\n/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in _apply_vector_function(self, function, vector, **kwargs)\r\n    841                                     vector_partner={y_axis_name:\r\n    842                                                     vector[y_axis_name]},\r\n--> 843                                     **kwargs)\r\n    844 \r\n    845         y_component = function(y_axis, vector[y_axis_name],\r\n\r\n/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in diff(self, da, to, boundary, fill_value, boundary_discontinuity, vector_partner)\r\n    506                                           boundary, fill_value,\r\n    507                                           boundary_discontinuity,\r\n--> 508                                           vector_partner)\r\n    509 \r\n    510     @docstrings.dedent\r\n\r\n/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)\r\n    219                                                   boundary_discontinuity,\r\n    220                                                   vector_partner=\r\n--> 221                                                   vector_partner)\r\n    222         # wrap in a new xarray wrapper\r\n    223         da_new = self._wrap_and_replace_coords(da, data_new, to)\r\n\r\n/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)\r\n    243 \r\n    244         # apply the function\r\n--> 245         data_new = f(data_left, data_right)\r\n    246 \r\n    247         return data_new\r\n\r\n/srv/conda/envs/notebook/lib/python3.6/site-packages/xgcm/grid.py in raw_diff_function(data_left, data_right)\r\n   1003 \r\n   1004 def raw_diff_function(data_left, data_right):\r\n-> 1005     return data_right - data_left\r\n   1006 \r\n   1007 def raw_min_function(data_left, data_right):\r\n\r\n/srv/conda/envs/notebook/lib/python3.6/site-packages/dask/array/core.py in __sub__(self, other)\r\n   1735 \r\n   1736     def __sub__(self, other):\r\n-> 1737         return elemwise(operator.sub, self, other)\r\n   1738 \r\n   1739     def __rsub__(self, other):\r\n\r\n/srv/conda/envs/notebook/lib/python3.6/site-packages/dask/array/core.py in elemwise(op, *args, **kwargs)\r\n   3638     shapes = [s if isinstance(s, Iterable) else () for s in shapes]\r\n   3639     out_ndim = len(\r\n-> 3640         broadcast_shapes(*shapes)\r\n   3641     )  # Raises ValueError if dimensions mismatch\r\n   3642     expr_inds = tuple(range(out_ndim))[::-1]\r\n\r\n/srv/conda/envs/notebook/lib/python3.6/site-packages/dask/array/core.py in broadcast_shapes(*shapes)\r\n   3599             raise ValueError(\r\n   3600                 \"operands could not be broadcast together with \"\r\n-> 3601                 \"shapes {0}\".format(\" \".join(map(str, shapes)))\r\n   3602             )\r\n   3603         out.append(dim)\r\n\r\nValueError: operands could not be broadcast together with shapes (288, 50, 2, 90, 89) (288, 50, 2, 90, 90)\r\n```\r\n\r\nThe 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? \r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"cpatrizio88"}}