John
John

Reputation: 4981

Split Netcdf variable and re-write the file

I have a netcdf file that contains air quality data. There are 4 dimensions:

time : 24 hours (midnight to midnight) 
level : 1 to 8 (this is the height in meters (0, 50, 250, 500, 1000, 2000, 3000, 5000 m)) 
latitude : 1 to 400
longitude : 1 to 700

I want to make a new netcdf file retaining only level 1, deleting the other levels, as I only need the surface.

How can I do that ?

I tried to do this with nccopy command line but it reproduces the dataset. I don't know how can I delete the other levels.

Upvotes: 0

Views: 1806

Answers (2)

ClimateUnboxed
ClimateUnboxed

Reputation: 8077

You can do this in cdo using

cdo sellevel,lev in.nc out.nc

Selects all fields with levels as required in a user given list, or

cdo sellevidx,idx in.nc out.nc

allows you to select by level index instead. Further details here:

https://code.mpimet.mpg.de/projects/cdo/embedded/index.html#x1-1360002.3.3

Upvotes: 0

Charlie Zender
Charlie Zender

Reputation: 6322

You can hyperslab with NCO, e.g.,

ncks -d level,0 in.nc out.nc

If you don't have NCO yet, but you do have conda, install NCO with

conda install -c conda-forge nco

Upvotes: 2

Related Questions