Skip to content

How to ignore non-existing dims given in chunks? #3633

Closed

Description

@willirath

Is there a way of over-specifying chunks upon opening a dataset without throwing an error?

Currently, giving chunk sizes along dimensions that are not present in the dataset fails with a ValueError:

da = xr.DataArray(np.arange(10), dims=("x", ), name="example_data")
da.to_dataset().to_netcdf("example.nc")
ds = xr.open_dataset("example.nc", chunks={"x": 5, "y": 1})

Activity

  1. dcherian commented on Dec 17, 2019

    @dcherian
    Contributor

    I don't think so. You can do chunks=5 which will chunk along all dimensions.

  2. TomNicholas commented on Dec 28, 2019

    @TomNicholas
    Member

    @willirath if the problem is that you don't know the dimensions of the dataset until after you've opened it, you could always open first then chunk afterwards, I think the result is the same:

    chunks = {'x': 5}
    
    ds = xr.open_dataset("example.nc")
    
    if 'y' in ds.dims:
        chunks['y'] = 1
    
    ds = ds.chunk(chunks=chunks)
  3. locked and limited conversation to collaborators on Aug 2, 2023
  4. converted this issue into a discussion #8043 on Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions