{ "name": "ValueError", "message": "The truth value of a Array is ambiguous. Use a.any() or a.all().", "stack": "--------------------------------------------------------------------------- ValueError Traceback (most recent call last) File :1 File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/ecco_v4_py/vector_calc.py:45, in UEVNfromUXVY(xfld, yfld, coords, grid) 42 grid = get_llc_grid(coords) 44 # First, interpolate velocity fields from cell edges to cell centers ---> 45 velc = grid.interp_2d_vector({'X': xfld, 'Y': yfld},boundary='fill') 47 # Compute UE VN using cos(), sin() 48 u_east = velc['X']*coords['CS'] - velc['Y']*coords['SN'] File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/grid.py:2460, in Grid.interp_2d_vector(self, vector, **kwargs) 2424 def interp_2d_vector(self, vector, **kwargs): 2425 \"\"\" 2426 Interpolate a 2D vector to the intermediate grid point. This method is 2427 only necessary for complex grid topologies. (...) 2457 are interpolated vector components along each axis 2458 \"\"\" -> 2460 return self._apply_vector_function(self.interp, vector, **kwargs) File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/grid.py:2388, in Grid._apply_vector_function(self, function, vector, **kwargs) 2385 x_axis_name, y_axis_name = list(vector) 2387 # apply for each component -> 2388 x_component = function( 2389 {x_axis_name: vector[x_axis_name]}, 2390 x_axis_name, 2391 other_component={y_axis_name: vector[y_axis_name]}, 2392 **kwargs, 2393 ) 2395 y_component = function( 2396 {y_axis_name: vector[y_axis_name]}, 2397 y_axis_name, 2398 other_component={x_axis_name: vector[x_axis_name]}, 2399 **kwargs, 2400 ) 2401 return {x_axis_name: x_component, y_axis_name: y_component} File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/grid.py:2043, in Grid.interp(self, da, axis, **kwargs) 1991 def interp(self, da, axis, **kwargs): 1992 \"\"\" 1993 Interpolate neighboring points to the intermediate grid point along 1994 this axis. (...) 2041 >>> grid.interp(da, [\"X\", \"Y\"], periodic={\"X\": True, \"Y\": False}) 2042 \"\"\" -> 2043 return self._1d_grid_ufunc_dispatch(\"interp\", da, axis, **kwargs) File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/grid.py:1838, in Grid._1d_grid_ufunc_dispatch(self, funcname, data, axis, to, keep_coords, metric_weighted, other_component, **kwargs) 1835 else: 1836 map_overlap = False -> 1838 array = grid_ufunc( 1839 self, 1840 array, 1841 axis=[(ax_name,)], 1842 keep_coords=keep_coords, 1843 dask=dask, 1844 map_overlap=map_overlap, 1845 other_component=other_component, 1846 **remaining_kwargs, 1847 ) 1849 if ax_metric_weighted: 1850 metric = self.get_metric(array, ax_metric_weighted) File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/grid_ufunc.py:460, in GridUFunc.__call__(self, grid, axis, *args, **kwargs) 458 map_overlap = kwargs.pop(\"map_overlap\", self.map_overlap) 459 pad_before_func = kwargs.pop(\"pad_before_func\", self.pad_before_func) --> 460 return apply_as_grid_ufunc( 461 self.ufunc, 462 *args, 463 axis=axis, 464 grid=grid, 465 signature=self.signature, 466 boundary_width=self.boundary_width, 467 boundary=boundary, 468 dask=dask, 469 map_overlap=map_overlap, 470 pad_before_func=pad_before_func, 471 **kwargs, 472 ) File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/grid_ufunc.py:763, in apply_as_grid_ufunc(func, axis, grid, signature, boundary_width, boundary, fill_value, keep_coords, dask, map_overlap, pad_before_func, other_component, *args, **kwargs) 760 # For most ufuncs we want to pad before applying, but for some (especially cumsum) we must apply then pad 761 # TODO could we bind a bunch of these arguments into a namedtuple/dataclass or something to save space? 762 if pad_before_func: --> 763 rechunked_padded_args = _pad_then_rechunk( 764 args, 765 grid, 766 in_core_dims, 767 boundary_width_real_axes, 768 boundary, 769 fill_value, 770 other_component, 771 ) 772 results = _apply( 773 mapped_func, 774 rechunked_padded_args, (...) 780 **kwargs, 781 ) 782 else: # pad after func File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/grid_ufunc.py:883, in _pad_then_rechunk(args, grid, in_core_dims, boundary_width_real_axes, boundary, fill_value, other_component) 873 def _pad_then_rechunk( 874 args, 875 grid, (...) 880 other_component, 881 ): --> 883 padded_args = [ 884 pad( 885 a, 886 grid=grid, 887 boundary_width=boundary_width_real_axes, 888 boundary=boundary, 889 fill_value=fill_value, 890 other_component=oc, 891 ) 892 for a, oc in zip(args, other_component) 893 ] 895 if any( 896 _has_chunked_core_dims(padded_arg, core_dims) 897 for padded_arg, core_dims in zip(padded_args, in_core_dims) 898 ): 899 # merge any lonely chunks on either end created by padding 900 rechunked_padded_args = _rechunk_to_merge_in_boundary_chunks( 901 padded_args, 902 args, 903 boundary_width_real_axes, 904 grid, 905 ) File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/grid_ufunc.py:884, in (.0) 873 def _pad_then_rechunk( 874 args, 875 grid, (...) 880 other_component, 881 ): 883 padded_args = [ --> 884 pad( 885 a, 886 grid=grid, 887 boundary_width=boundary_width_real_axes, 888 boundary=boundary, 889 fill_value=fill_value, 890 other_component=oc, 891 ) 892 for a, oc in zip(args, other_component) 893 ] 895 if any( 896 _has_chunked_core_dims(padded_arg, core_dims) 897 for padded_arg, core_dims in zip(padded_args, in_core_dims) 898 ): 899 # merge any lonely chunks on either end created by padding 900 rechunked_padded_args = _rechunk_to_merge_in_boundary_chunks( 901 padded_args, 902 args, 903 boundary_width_real_axes, 904 grid, 905 ) File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/padding.py:424, in pad(data, grid, boundary_width, boundary, fill_value, other_component) 422 # If any axis has connections we need to use the complex padding 423 if any([any(grid.axes[ax]._connections.keys()) for ax in grid.axes]): --> 424 da_padded = _pad_face_connections( 425 data, 426 grid, 427 padding_width, 428 padding, 429 fill_value, 430 other_component=other_component, 431 ) 432 else: 433 da_padded = _pad_basic(data, grid, padding_width, padding, fill_value) # type: ignore File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/padding.py:182, in _pad_face_connections(da, grid, padding_width, padding, fill_value, other_component) 178 source_da = da_partner_prepadded.isel( 179 {facedim: source_face} 180 ) 181 # adjust the dimension naming (only ever needed when swapping variables) --> 182 source_da = _maybe_rename_grid_positions( 183 grid, source_da, target_da 184 ) 186 _, source_dim = grid.axes[source_axis]._get_position_name( 187 source_da 188 ) 190 # I guess this could be more elegant. Basically I only want to replace the 191 # unpadded part of the source/target, since padding methods could be different for 192 # different axes... 193 # I am thinking about how to make this easier later File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xgcm/padding.py:28, in _maybe_rename_grid_positions(grid, arr_source, arr_target) 25 rename_dict = {} 26 for di in arr_target.dims: 27 # in case the dimension is already in the source, do nothing. ---> 28 if di not in arr_source: 29 # find associated axis 30 for axname in grid.axes: 31 all_positions = grid.axes[axname].coords.values() File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/xarray/core/dataarray.py:861, in DataArray.__contains__(self, key) 860 def __contains__(self, key: Any) -> bool: --> 861 return key in self.data File /opt/anaconda3/envs/py3_std/lib/python3.11/site-packages/dask/array/core.py:1862, in Array.__bool__(self) 1860 def __bool__(self): 1861 if self.size > 1: -> 1862 raise ValueError( 1863 f\"The truth value of a {self.__class__.__name__} is ambiguous. \" 1864 \"Use a.any() or a.all().\" 1865 ) 1866 else: 1867 return bool(self.compute()) ValueError: The truth value of a Array is ambiguous. Use a.any() or a.all()." }