Coarsening 3D hdf5 data

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.

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.

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:

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.

1 Like