Reputation: 11
I would like to merge two netcdf files. The problem is that all the variables from the first file are contained in the second file (with different data) and the second file has some extra variables. So, I would like to get a netcdf file having all the variables of the second file with the data of the first one (when defined). Thank you all.
Upvotes: 1
Views: 1401
Reputation: 3417
You should be able to handle this easily using nctoolkit (https://nctoolkit.readthedocs.io/en/latest/), as follows:
import nctoolkit as nc
# read in the files
ds = nc.open_data("infile1.nc")
ds2 = nc.open_data("infile2.nc")
# remove the 1st netcdf files variables from the second's
ds2.drop(ds.variables)
# merge the files
ds.append(ds2)
ds.merge()
# save the files as a netcdf file
ds.to_nc("merged.nc")
Upvotes: 1