Vertical methods#

nctoolkit features built in methods for handling files with multiple vertical levels. They work for datasets with fixed vertical levels, for example ocean data with z-levels, as well as files with varying vertical levels such as terrain following coordinates.

The vertical methods available will be illustrated using depth-resolved ocean temperatures from NOAA’s World Ocean Atlas for January to a depth of 500 metres. The vertical_interp method requires a levels argument, which is sea-depth in this case.

[1]:
import nctoolkit as nc
nc.deep_clean()
ds = nc.open_thredds("https://data.nodc.noaa.gov/thredds/dodsC/ncei/woa/temperature/A5B7/1.00/woa18_A5B7_t01_01.nc")
ds.subset(variables="t_an")
ds.run()
nctoolkit is using the latest version of Climate Data Operators version: 2.0.5

We can see right awy that there are 57 vertical levels, going as deep as 1500 metres.

[2]:
len(ds.levels)
min(ds.levels)
max(ds.levels)
[2]:
57
[2]:
0.0
[2]:
1500.0

Calculating simple vertical statistics#

If we want to calculate the mean temperature across all vertical levels, we can do the following. Note: that you must specify the fixed arg, which tells nctoolkit whether the vertical levels are consistent in this space. In this case they are. Note: this method will account for cell thickness when calculating the mean.

[3]:
ds_mean = ds.copy()
ds_mean.vertical_mean(fixed = True)
ds_mean.plot()
[3]:

You can calculate the vertical maximum in a similar way:

[4]:
ds_max = ds.copy()
ds_max.vertical_max()
ds_max.plot()
[4]:

Likewise, you can calculate the vertical minimum as follows:

[5]:
ds_min = ds.copy()
ds_min.vertical_min()
ds_min.plot()
[5]:

Vertical interpolation#

If you want to carry out vertical interpolation, you can use the vertical_interp method. This requires the target levels, and users must specifify whether the vertical levels are fixed in space. In this case, we could interpolate to a single depth of 1000m as follows:

[6]:
ds_interp = ds.copy()
ds_interp.vertical_interp(levels = [1000], fixed = True)
ds_interp.plot()
[6]:

Selecting the top and bottom levels#

You can easily select the top and bottom vertical level using the top and bottom method.

So, if you wanted to select the sea-surface, you would do the following:

[7]:
ds_top = ds.copy()
ds_top.top()
ds_top.plot()
[7]:

Additional vertical methods#

Other vertical methods available are: vertical_min, vertical_range, vertical_cumsum, and invert_levels.

If you are working with ocean data and you want to calculate an integrated water column total, you can use the vertical_integration method, which will sum up the water column values accounting for the thickness of each vertical cell.