# Coarsening 3D hdf5 data

**URL:** <https://forum.hdfgroup.org/t/coarsening-3d-hdf5-data/13019>\
**Category:** h5py\
**Created:** [February 5, 2025, 4:03pm UTC](https://forum.hdfgroup.org/t/coarsening-3d-hdf5-data/13019 "2025-02-05T16:03:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ameliadrew94](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@ameliadrew94](https://forum.hdfgroup.org/u/ameliadrew94)\
**Post date:** [February 5, 2025, 4:03pm UTC](https://forum.hdfgroup.org/t/coarsening-3d-hdf5-data/13019/1 "2025-02-05T16:03:08Z")

</div>

Is it possible to use h5py or any other method to reduce the resolution of a 3D hdf5 dataset? Eg. if I have field values for a 512^3 grid and I want to remove points to give a 256^3 grid with double the lattice spacing.

---

<div class="post-metadata">

**Author:** ![dave.allured](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@dave.allured](https://forum.hdfgroup.org/u/dave.allured)\
**Post date:** [February 5, 2025, 6:44pm UTC](https://forum.hdfgroup.org/t/coarsening-3d-hdf5-data/13019/2 "2025-02-05T18:44:48Z")

</div>

This is called regridding. For this I like packages NCL, ESMF, CDO, and NCO. These are all Netcdf-oriented tools, but Netcdf-4 is just HDF5 under the hood. So all of these should work for HDF5 with a little coaxing. I am sure there are other regridders out there.

---

<div class="post-metadata">

**Author:** ![thomas1](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/thomas1/32/1733_2.png) [@thomas1](https://forum.hdfgroup.org/u/thomas1)\
**Post date:** [February 6, 2025, 12:02pm UTC](https://forum.hdfgroup.org/t/coarsening-3d-hdf5-data/13019/3 "2025-02-06T12:02:31Z")

</div>

If all you want is to read every Nth point along one or more axes, you can do that with h5py without any extra tools, using the same syntax as slicing a Numpy array. E.g. for your example of a 3D dataset and taking every second point on each dimension:

```python
dset[::2, ::2, ::2]

```

That will give you a Numpy array with the data. You can then save that, in a new file or another dataset in the same file, if you need to.

This only reads a subset of the data that’s already there, though. If you want the values in your coarser grid to be the average of several values from the finer grid, you’ll need to read all the data and do some more work on it.
