Why convert NC to HDF5?
Some scientific pipelines and tools accept HDF5 but lack a dedicated netCDF driver. Converting produces a plain HDF5 file that any HDF5-aware reader such as h5py or HDFView can open without needing the netCDF library.
How to convert NC to HDF5
nccopy FREE
Run nccopy -k netCDF-4 input.nc output.nc to convert a classic netCDF file to netCDF-4/HDF5 format; rename the output to .hdf5 if your downstream tool requires that extension.
Python (netCDF4 + h5py) OPEN-SOURCE
Install with pip install netCDF4 h5py, read the .nc file with netCDF4.Dataset(), then write each variable to an HDF5 file using h5py.File() and create_dataset().
About these formats
An .nc file is a netCDF (Network Common Data Form) file - a binary format for multidimensional scientific data such as climate, weather, and ocean datasets from NOAA, NASA, and Copernicus.…
Open .NC details →A .HDF5 file is associated with HDF5, a misc file.
Open .HDF5 details →Quality & what to watch
- netCDF-4 is built directly on HDF5 - if
ncdump -k yourfile.ncreportsnetCDF-4, you can rename the file to.hdf5and open it with h5py or HDFView without any conversion. - Classic netCDF files start with the bytes
CDF(hex43 44 46) and are not HDF5 - these requirenccopyor a Python rewrite to convert. - The reverse is not true: plain HDF5 files are not valid netCDF, so renaming
.hdf5to.ncwill not work without restructuring the internal layout to match netCDF conventions.
Frequently asked questions
How do I know if my NC file is already HDF5?
ncdump -k yourfile.nc; if it returns netCDF-4, the file is HDF5 internally. You can also check whether the first two bytes are 89 48 (the HDF5 signature).Will h5py be able to read the converted file directly?
nccopy, the file is a valid HDF5 container; variable names and data are intact, though the internal structure follows netCDF naming conventions.Is metadata preserved during conversion?
nccopy. When using h5py directly, you must copy attributes manually, as h5py does not transfer netCDF metadata automatically.