NCAR / icar

The Intermediate Complexity Atmospheric Research model (ICAR)
MIT License
72 stars 53 forks source link

Xarray Dataset.dims Future Warning #182

Closed scrasmussen closed 2 months ago

scrasmussen commented 5 months ago

Expected Behavior

No warnings produced when running aggregate_parallel_files.py

Current Behavior

The following warning is produced:

/glade/u/apps/opt/conda/envs/npl-2024a/lib/python3.11/site-packages/xarray/core/utils.py:494:
   FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension 
   names in future, in order to be more consistent with `DataArray.dims`. To access a mapping 
   from dimension names to lengths, please use `Dataset.sizes`.
  warnings.warn(

Possible Solution

Switch to Dataset.sizes like the future warning recommends. It seems to be occurring from the following section, but the warning gets cut off so it might be a different place.

        if len(dims) == 1:
            nt = d.dims[dims[0]]
            data = np.zeros((nt))
        if len(dims) == 2:
            data = np.zeros((ny + y_off, nx + x_off))
        if len(dims) == 3:
            data = np.zeros((d.dims[dims[0]], ny + y_off, nx + x_off))
        if len(dims) == 4:
            nt = d.dims[dims[0]]
            nz = d.dims[dims[1]]
            data = np.zeros((nt, nz, ny + y_off, nx + x_off))

Steps to Reproduce (for bugs)

  1. Run helpers/aggregate_parallel_files.py on ICAR output files.

Your Environment

gutmann commented 5 months ago

It looks like Dataset.sizes works the way we need, can you make the change and test it out?

scrasmussen commented 2 months ago

Closed by PR#183