Barry
Barry

Reputation: 739

How to loop to extract certain variables from NETCDF files?

In my simple code I extract one variable named bet from the NETCDF file and then I write it out of the NETCDF file as here:

import os, glob 
print(filenamels)
for fn in filenamels:
outputFile = fn[:len(fn)-3]+'_ull_st.dat'
os.system( gdalcmd)

There are other variables feg,dis,lam, named ,in these NETCDF files and I do not want to run the code for each variable.I wonder how we can write a loop to extract these variables at once.

Upvotes: 0

Views: 439

Answers (1)

N1B4
N1B4

Reputation: 3453

ncks from the NCO package (http://nco.sourceforge.net/nco.html) is the way to go here. For example, extracting variables bet, feg, dis, lam from a file called myfile.nc and outputting them into a file called myfileout.nc would be:

ncks -v bet,feg,dis,lam myfile.nc -O myfileout.nc 

Upvotes: 1

Related Questions