Problem

If we want to divide two fields or Fieldsets the denominator cannot contain zeros otherwise the computations fail with a floating points exception.

Solution

The solution is to turn all the zeros in question to missing values, which are then automatically skipped in all the arithmetic operations in Metview. We can do this by using the bitmap function:

import metview as mv

# read grib data into Fieldset objects
fs_1 = mv.read("my_data_1.grib")
fs_2 = mv.read("my_data_2.grib")

# turn zero values to missing values in fs_2
fs_2 = mv.bitmap(fs_2, 0)

# it is now safe to perform the division. The result will contain missing
# values in all the points where either fs_1 or fs_2 is zero
r = fs_1/fs_2