-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Labels
Description
Description
I'm working to generate a combined virtual dataset from grouped netCDF4 files in the NASA Earthdata Archive. To do so, I am opening each group individually for each dataset (and this works). However, when (for each group) I try to concatenate the datasets along an existing dimension, it fails on the 'root' group, even though it works on other subgroups.
The error being raised is NotImplementedError: Doesn't support slicing with (None, slice(None, None, None))
.
Related issues
I see there are other issues related to groups, but most seem to be about developing more native handling of groups in line with Datatree, so not sure if they are helpful: #84, #336, #402.
To Reproduce - Example 1
import earthaccess
import xarray as xr
from virtualizarr import open_virtual_dataset # seems to requires virtualizarr>=1.3.0 to open the root group for a single netCDF.
# 1. Authenticate for NASA Earthdata (requires a free Earthdata Login account).
earthaccess.login()
# 2. Get AWS credentials for the data archive.
fs = earthaccess.get_s3_filesystem(daac="ASDC")
reader_opts = {"storage_options": fs.storage_options}
# 3. For each of the following two netCDF links: the 'root' and 'product' groups are each opened as a virtual dataset.
data_s3links = [
's3://asdc-prod-protected/TEMPO/TEMPO_NO2_L3_V03/2025.01.11/TEMPO_NO2_L3_V03_20250111T125225Z_S002.nc',
's3://asdc-prod-protected/TEMPO/TEMPO_NO2_L3_V03/2025.01.11/TEMPO_NO2_L3_V03_20250111T133233Z_S003.nc'
]
vdataset_groups = {"": [], "product": []}
for url in data_s3links:
vdataset_groups[""].append(
open_virtual_dataset(url, group="", indexes={}, reader_options=reader_opts)
)
vdataset_groups["product"].append(
open_virtual_dataset(url, group="product", indexes={}, reader_options=reader_opts)
)
# 4. Concatenate together the two virtual datasets along the 'time' dimension.
xr_concat_kwargs = {
"coords": "minimal",
"compat": "override",
"combine_attrs": "override",
}
# *** THIS DOES NOT RAISE THE ERROR ***
vds = xr.concat(vdataset_groups["product"], dim="time", **xr_concat_kwargs)
# *** THIS RAISES THE ERROR: `NotImplementedError: Doesn't support slicing with (None, slice(None, None, None))` ***
vds = xr.concat(vdataset_groups[""], dim="time", **xr_concat_kwargs)
Error traceback
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Cell In[3], line 38
35 vds = xr.concat(vdataset_groups["product"], dim="time", **xr_concat_kwargs)
37 # THIS RAISES THE ERROR: `NotImplementedError: Doesn't support slicing with (None, slice(None, None, None))`
---> 38 vds = xr.concat(vdataset_groups[""], dim="time", **xr_concat_kwargs)
File [/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/structure/concat.py:277](https://openscapes.2i2c.cloud/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/structure/concat.py#line=276), in concat(objs, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs, create_index_for_new_dim)
264 return _dataarray_concat(
265 objs,
266 dim=dim,
(...) 274 create_index_for_new_dim=create_index_for_new_dim,
275 )
276 elif isinstance(first_obj, Dataset):
--> 277 return _dataset_concat(
278 objs,
279 dim=dim,
280 data_vars=data_vars,
281 coords=coords,
282 compat=compat,
283 positions=positions,
284 fill_value=fill_value,
285 join=join,
286 combine_attrs=combine_attrs,
287 create_index_for_new_dim=create_index_for_new_dim,
288 )
289 else:
290 raise TypeError(
291 "can only concatenate xarray Dataset and DataArray "
292 f"objects, got {type(first_obj)}"
293 )
File [/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/structure/concat.py:676](https://openscapes.2i2c.cloud/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/structure/concat.py#line=675), in _dataset_concat(datasets, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs, create_index_for_new_dim)
674 result_vars[k] = v
675 else:
--> 676 combined_var = concat_vars(
677 vars, dim_name, positions, combine_attrs=combine_attrs
678 )
679 # reindex if variable is not present in all datasets
680 if len(variable_index) < concat_index_size:
File [/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/core/variable.py:3018](https://openscapes.2i2c.cloud/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/core/variable.py#line=3017), in concat(variables, dim, positions, shortcut, combine_attrs)
2970 def concat(
2971 variables,
2972 dim="concat_dim",
(...) 2975 combine_attrs="override",
2976 ):
2977 """Concatenate variables along a new or existing dimension.
2978
2979 Parameters
(...) 3016 along the given dimension.
3017 """
-> 3018 variables = list(variables)
3019 if all(isinstance(v, IndexVariable) for v in variables):
3020 return IndexVariable.concat(variables, dim, positions, shortcut, combine_attrs)
File [/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/structure/concat.py:598](https://openscapes.2i2c.cloud/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/structure/concat.py#line=597), in _dataset_concat.<locals>.ensure_common_dims(vars, concat_dim_lengths)
596 if var.dims != common_dims:
597 common_shape = tuple(dims_sizes.get(d, dim_len) for d in common_dims)
--> 598 var = var.set_dims(common_dims, common_shape)
599 yield var
File [/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/util/deprecation_helpers.py:143](https://openscapes.2i2c.cloud/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/util/deprecation_helpers.py#line=142), in deprecate_dims.<locals>.wrapper(*args, **kwargs)
135 emit_user_level_warning(
136 f"The `{old_name}` argument has been renamed to `dim`, and will be removed "
137 "in the future. This renaming is taking place throughout xarray over the "
(...) 140 PendingDeprecationWarning,
141 )
142 kwargs["dim"] = kwargs.pop(old_name)
--> 143 return func(*args, **kwargs)
File [/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/core/variable.py:1395](https://openscapes.2i2c.cloud/srv/conda/envs/earthaccess/lib/python3.13/site-packages/xarray/core/variable.py#line=1394), in Variable.set_dims(self, dim, shape)
1388 elif shape is None or all(
1389 s == 1 for s, e in zip(shape, dim, strict=True) if e not in self_dims
1390 ):
1391 # "Trivial" broadcasting, i.e. simply inserting a new dimension
1392 # This is typically easier for duck arrays to implement
1393 # than the full "broadcast_to" semantics
1394 indexer = (None,) * (len(expanded_dims) - self.ndim) + (...,)
-> 1395 expanded_data = self.data[indexer]
1396 else: # elif shape is not None:
1397 dims_map = dict(zip(dim, shape, strict=True))
File [/srv/conda/envs/earthaccess/lib/python3.13/site-packages/virtualizarr/manifests/array.py:226](https://openscapes.2i2c.cloud/srv/conda/envs/earthaccess/lib/python3.13/site-packages/virtualizarr/manifests/array.py#line=225), in ManifestArray.__getitem__(self, key)
224 return self
225 else:
--> 226 raise NotImplementedError(f"Doesn't support slicing with {indexer}")
NotImplementedError: Doesn't support slicing with (None, slice(None, None, None))