netCDF4 multi-file dataset

37 Views Asked by At

I'm using netCDF4 in Python to handle .netcdf files. For example, say I have two files representing measurements from the same locations in different years, which both have dimensions: longitude(5), latitude(5), time(365). I should be able to combine them into one netCDF4 dataset with dimensions longitude(5), latitude(5), time(730), since the spatial coordinates are identical. What's the best way to do this?

1

There are 1 best solutions below

0
Robert Wilson On

There are different options available in Python. One is my package nctoolkit.

You could merge two files and save them as a new file as follows:

import nctoolkit as nc
# open a multi-file dataset
ds = nc.open_data(["foo1.nc", "foo2.nc"])
# merge along the time coordinates
ds.merge("time")
# save the merged dataset to a file
ds.to_nc("foo_bar.nc")