Mathematical functions

abs(data)

Returns the absolute value of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

acos(data)

Returns the arc cosine of data in radians.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

asin(data)

Returns the arc sine of data in radians.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

atan(data)

Returns the arc tangent of data in radians.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

atan2(data_y, data_x)

Returns the arc tangent of data_y/data_x in radians.

Parameters
Return type

Fieldset

Missing values are retained, unaltered by the calculation.

cos(data)

Returns the cosine of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Input values must be in radians. Missing values are retained, unaltered by the calculation.

exp(data)

Returns the exponential of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

div(data_1, data_2)

Returns the integer part of the dividing data_1 by data_2.

Parameters
Return type

same type as data_1

A missing value in either data_1 or data_2 will result in a missing value in the corresponding place in the output.

int(data)

Returns the integer part of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

intbits(data, bit[, number_of_bits])

Takes the numbereger part of the values of data and extracts a specified bit (or bits).

Parameters
  • data (Geopoints or int) – input data

  • bit (number) – the bit to extract (1 is the least significant bit!)

  • number_of_bits (number) – the number of bits to extract (starting at bit)

Return type

Geopoints or number

If only bit is specified it will always be returned as 1 or 0, regardless of its position in the integer.

With number_of_bits a group of bits can be extracted. The result will be treated as if the first bit was the least significant bit of the result.

Example

These examples show how intbits work on individual numbers:

import metview as mv

# To extract the 1st, 2nd and 3rd bits from
# an int separately:

# in bit-form, this is 00000110 with the least significant
# bit at the right
n = 6

flag = mv.intbits (n, 1) # flag is now 0
flag = mv.intbits (n, 2) # flag is now 1
flag = mv.intbits (n, 3) # flag is now 1

# To extract the 1st and 2nd bits together
# to make a single int:
flag = mv.intbits (n, 1, 2) # flag is now 2

# To extract the 2nd and 3rd bits together
# to make a single int:
flag = mv.intbits (n, 2, 2) # flag is now 3

# To extract the 3rd and 4th bits together
# to make a single int:
flag = mv.intbits (n, 3, 2) # flag is now 1

The number of bits available depends on the machine architecture and Metview’s compilation options, but at the time of writing it should be 32. This function does not treat missing values differently from any other values (for efficiency with large datasets).

log(data)

Returns the natural logarithm of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

log10(data)

Returns the log base 10 of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

mod(data_1, data_2)

Returns the integer remainder of dividing data_1 by data_2.

Parameters
Return type

same type as data_1

Where the values of data_2 are larger than those of data_1, the output value is set to the integer part of data_1. A missing value in either data_1 or data_2 will result in a missing value in the corresponding place in the output. Note that only the integer parts of the inputs are considered in the calculation, meaning that a divisor of 0.5 would cause a division by zero.

neg(data)

Returns the negative of data.

Parameters

data (Fieldset) – input fieldset

Return type

Fieldset

Missing values are retained, unaltered by the calculation.

Note

The following lines of codes are equivalent:

import metview as mv
fs = mv.neg(fs)
fs = -fs
sgn(data)

Returns the sign of data: -1 for negative , 1 for positive and 0 for 0 values.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

sin(data)

Returns the sine of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Input values must be in radians. Missing values are retained, unaltered by the calculation.

sqrt(data)

Returns the square root of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Missing values are retained, unaltered by the calculation.

tan(data)

Returns the tangent of data.

Parameters

data (Fieldset, Geopoints, NetCDF, nd-array or number) – input data

Return type

same type as data

Input values must be in radians. Missing values are retained, unaltered by the calculation.