0

I have a netcdf file containing vorticity (per sec) and winds (m/s). I want to print the dates of gridpoints that satisfy the following conditions:

1). Vorticity > 1x10^-5 per sec and winds >= 5 m/s at a gridpoint.

2). The average of vorticity and winds at the "four" (North, West, East, South) surrounding the gridpoint found in (1) should also be > 1x10^-5 and 5m/s, respectively.

I am able to just filter the gridpoints that satisfied (1), using ncap:

ncap2 -v -O -s 'where(vort > 1e-5 && winds >= 5) vort=vort; elsewhere vort=vort.get_miss();' input_test.nc output_test.nc

How do I get the dates? Also how can I implement the second condition.

Here's the screenshot of the header of the netcdf file.

enter image description here

I'll appreciate any help on this.

Lyndz
  • 347
  • 1
  • 13
  • 30
  • Without knowing the structure of the NetCDF data you have, it would be difficult to get a proper answer. I think you need to show at least the NetCDF header or some other information that shows the structure of the data. – binzo Feb 08 '22 at 23:57
  • Do you want to display the date at that time if there is at least one grid that satisfies the conditions 1) and 2)? – binzo Feb 08 '22 at 23:57
  • yes @binzo..I'll update my post – Lyndz Feb 09 '22 at 03:18

1 Answers1

2

This may be achieved by combining "cdo" and "nco".

The average value of the surrounding 4 grids needed for the second condition can be calculated by combining the shiftxy and ensmean operators of "cdo".

cdo selname,vr,wspd input_test.nc vars.nc
cdo -expr,'vr_mean=vr; wspd_mean=wspd' \
      -ensmean \
        -shiftx,1  vars.nc \
        -shiftx,-1 vars.nc \
        -shifty,1  vars.nc \
        -shifty,-1 vars.nc \
    vars_mean.nc

You can then use merge operator of "cdo" to combine the variables needed to check conditions 1) and 2) into a single NetCDF file, and use ncap2 to check the conditions as you have tried.

In the example command below, the "for" loop of "ncap2" is used to scan the time. If there is at least one grid that satisfies both conditions 1) and 2) at each time, the information for that time will be displayed.

cdo merge vars.nc vars_mean.nc vars_test.nc
ncap2 -s '*flag = (vr > 1e-5 && wspd >= 5) && (vr > 1e-5 && wspd >= 5); *nt=$time.size; for(*i=0;i<nt;i++) { if ( max(flag(i,:,:))==1 ) { print(time(i)); } }' vars_test.nc 
binzo
  • 1,527
  • 1
  • 3
  • 13