ScienceNoob
ScienceNoob

Reputation: 231

Merge 70 netCDF files with xarray

I want to merge 70 netCDF files into one. For that I use the .to_netcdf() function of xarray:

    ds = xarray.open_mfdataset('*.nc')
    ds.to_netcdf('SST_2021-10_timeseries.nc')

My problem is that my jupyter notebook always hangs up because the number of files is too high. Is there a more efficient way to merge the files?

Upvotes: 1

Views: 648

Answers (1)

Robert Wilson
Robert Wilson

Reputation: 3397

An alternative would be to use nctoolkit. Commands would be as follows:

import nctoolkit as nc
ds = nc.open_data('*.nc')
ds.merge("time")
ds.to_nc('SST_2021-10_timeseries.nc')

Or you could do it on the command line with CDO:

cdo -mergetime *.nc SST_2021-10_timeseries.nc

Those options should get around any RAM issues.

Upvotes: 1

Related Questions