Yoni Verhaegen
Yoni Verhaegen

Reputation: 123

How to merge 2 separate netcdf files into 1 and add a time dimension

I have two NetCDF files of the Greenland ice sheet velocities, one from 2015 and one from 2016. These files contain grided data where the velocity is plotted with x,y coordinates. However, no time dimension is included. How can I merge these two files into 1, where the final file has a time dimension? So in stead of two separate x,y,z grids, I would like to have one x,y,z,t data structure, where time = 2.

Thanks!

Upvotes: 1

Views: 2132

Answers (2)

Charlie Zender
Charlie Zender

Reputation: 6352

If the files contain the same variables and are the same size, try ncecat

ncecat -u time file1.nc file2.nc out.nc

Upvotes: 3

ClimateUnboxed
ClimateUnboxed

Reputation: 8107

You can add a time dimension to a file with ncap2:

ncap2 -s 'defdim("time",1);time[time]=74875.0;time@long_name="Time"; etc.etc.etc.' -O ~/nco/data/in.nc ~/foo.nc

I suggest reading this thread for more details: https://sourceforge.net/p/nco/discussion/9830/thread/cee4e1ad/

After you have done that you can merge them together either using the ncrcat command (see https://linux.die.net/man/1/ncrcat) or also with cdo

cdo mergetime file1.nc file2.nc combined_file.nc 

Upvotes: 2

Related Questions