Skip to content

Better chunking for Multifile/dask backed UGRID datasets. #232

Description

@david-sh-csiro

Summary

When opening a multifile or dask backed UGRID it will give non-performative chunking out of the box.
This results in poor performance when performing .isel with emsarrays ems.selector_for_index compared against some manually defined chunking.

Example

Performing an isel operation on a large dataset: COCOMA 2k
dataset['temp'].isel({'record': 0, 'nMesh2_face': 0 }).values

Testing was performed on a local copy of the dataset running on Ubuntu 24.04 with emsarray==1.0, xarray==2026.7.0, dask[dataframe]==2026.7.1

Auto chunking (chunks='auto')

dataset.chunks output
{'nMesh2_face': (433761,), 'nMaxMesh2_face_nodes': (8,), 'nMesh2_edge': (1303043,), 'Two': (2,), 'nMesh2_face_links': (1282151,), 'nMesh2_node': (869124,), 'record': (5, 3, 2, 5, 1, 4, 3), 'Mesh2_layers': (5, 3, 2, 5, 1, 4, 4, 1, 5, 2, 3, 5, 5, 3, 2, 4)}

Time to complete operation
2.5 to 2.6 seconds

Manual chunking (chunks='{'record': 1, "nMesh2_face": 100000}')

dataset.chunks output
{'nMesh2_face': (100000, 100000, 100000, 100000, 33761), 'nMaxMesh2_face_nodes': (8,), 'nMesh2_edge': (1303043,), 'Two': (2,), 'nMesh2_face_links': (1282151,), 'nMesh2_node': (869124,), 'record': (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 'Mesh2_layers': (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)}

Time to complete operation
~0.54 seconds

No chunking (default xarray backed)

0.28 to 0.31 seconds

Possible Solutions

Given that emsarray knows alot more about the underlying topology of a given UGRID, I'd imagine that we could devise a more optimal chunking compared to the automatic selection. It's possible this could extend to other conventions in that the current auto chunking could also be optimised.

This could be implemented as an alternate opening method, something like open_dataset_chunked that will introspect the dataset first and figure out some good chunking recommendations before providing an xarray dataset result. Or it could simply be an emsarray utility that returns an optimised chunk dictionary that xarrays.open_dataset(path,chunks=...) would accept.

EDIT: Maybe disregard, I can't reproduce any of this now for some reason, not sure whats changed in my environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions