Jeff Tilton
Jeff Tilton

Reputation: 1296

NCO combine variables into 3rd dimension

I have a netcdf file with the below variables

Each band has dimensions (x,y). I want to combine the bands into a single variable with dimensions (x,y,time).

Is that possible with NCO or another library? Python or command line.

Thanks

Upvotes: 1

Views: 268

Answers (1)

Charlie Zender
Charlie Zender

Reputation: 6352

Try NCO's ncap2. If time is size 3, and each Band is interpreted as the band at a different time, then something like this will work:

ncap2 -s 'band=Band1*time;band[:,:,1]=Band2;band[:,:,2]=Band3' in.nc out.nc

If instead the Bands are independent of time then you must add a new dimension of size 3 to accomodate the bands, e.g.,

ncap2 -s 'defdim("band",3);Band[$x,$y,$band,$time]=0;Band[:,:,0,:]=Band1;....' in.nc out.nc

Good luck!

Upvotes: 1

Related Questions