# Zarr chunks keys in xarray

**URL:** <https://discourse.pangeo.io/t/zarr-chunks-keys-in-xarray/1840>\
**Category:** Data\
**Created:** [October 12, 2021, 9:05pm UTC](https://discourse.pangeo.io/t/zarr-chunks-keys-in-xarray/1840 "2021-10-12T21:05:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![martindurant](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pangeo.io/martindurant/32/388_2.png) [@martindurant](https://discourse.pangeo.io/u/martindurant)\
**Post date:** [October 12, 2021, 9:05pm UTC](https://discourse.pangeo.io/t/zarr-chunks-keys-in-xarray/1840/1 "2021-10-12T21:05:49Z")

</div>

Reposting from gitter, as I think it’ll get more attention here:

–

If I have a zarr-backed xarray dataset, is there a way to go from coordinate location to zarr chunk key without attempting to load the data?

Can I .map() this information, i.e., create a dataset whose value is a function of that filename, e.g., whether it exists or not?

---

<div class="post-metadata">

**Author:** ![rabernat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pangeo.io/rabernat/32/22_2.png) [@rabernat](https://discourse.pangeo.io/u/rabernat)\
**Post date:** [October 13, 2021, 12:53pm UTC](https://discourse.pangeo.io/t/zarr-chunks-keys-in-xarray/1840/2 "2021-10-13T12:53:55Z")

</div>

Rather than call `ds.sel(lon=45)` you would get the Pandas index directly, e.g. `ds.indexes['lon']` , and then use the index to map your selection to logical coordinates. From there, it’s straightforward to map array indices to chunk indices.

The Pangeo Forge (internal) ChunkGrid object could be useful there: [pangeo-forge-recipes/chunk\_grid.py at master · pangeo-forge/pangeo-forge-recipes · GitHub](https://github.com/pangeo-forge/pangeo-forge-recipes/blob/master/pangeo_forge_recipes/chunk_grid.py)
