setcurrent

setcurrent(nc, index_or_name)

On a multi-variable NetCDF sets the specified variable as the current variable. Functions and operators act on the current variable only.

Parameters
  • nc (NetCDF) – input NetCDF

  • index_or_name (number or str) – index or name of the NetCDF variable

Return type

None

A NetCDF produced by the Metview applications are uni-variable, so in their case setcurrent() need not be used. For a multi-variable NetCDF setcurrent() can be usefully combined with variables() as the example below illustrates it.

Example
import metview as mv

nc = mv.read("my_data.nc")

for v in mv.variables(nc):
    mv.setcurrent(nc, v)
    # acts on current variable only
    nc = nc - 273.16