How can i split a netCDF file with conditions

1.1k views Asked by At

I'm working with a netCDF file with a spatially averaged wind variable, which is a function of time only.

I would like to split the file into years with east wind and years with west wind.

I thought I would do it with cdo but I don't know how to write the condition. Anything with splityear, 'u <0'?

1

There are 1 answers

2
Robert Wilson On

I do not think this is advisable, as you will split the files in to two different NetCDF files with incompatible grids. In my view this would defeat the purpose of storing the data in NetCDF files.

But, if you wish to do it, there is a way within CDO. As you haven't provided files I can outline a strategy.

First create a mask file identifying cells with u<0:

cdo -setrtomiss,-10000,0 -selname,u infile.nc mask.nc

Then apply reducegrid to the infile using this mask:

cdo -reducegrid,mask.nc infile.nc outfile.nc

That should do it for the u condition. Just test that and modify it for the other variables.