meteociel.utils.conv

meteociel.utils.conv(data: array, separators: tuple = (), multi_value_sep: tuple = (), strip_char: tuple = ())

Convert the given array of strings into an array of floats. The input strings should be formatted as follow: value SEP unit where SEP is a separator character. You can also pass two values in one string by separate them with a char from multi_value_sep, The returned array will a tuple that contains the arrays.

Warning

If an element of data isn’t a string, it will result in a np.nan into the converted array.

Parameters

datanp.array

The array of strings to convert.

separatorstuple, optionnal

By default only spaces are managed. A tuple of strings that allows to split strings beetween value and units. Spaces are automatically managed so no need to add them.

multi_value_septuple, optionnal

By default, this feature is disabled, to enable it, pass a tuple of characters. A tuple of strings that allows to split strings that contain two couples (value, unit).

strip_chartuple, optionnal

By default, this feature is disabled. A tuple of characters that will be deleted when trying to convert a string into a float.

Returns

outlist

The converted array of floats.

Exemples

>>> import numpy as np
>>> from meteociel import utils
>>> utils.conv(np.array(["1 m", "2 m", "3 m"]))
[1.0, 2.0, 3.0]
>>> utils.conv(
...     np.array(["40° / 5 km/h", "50° / 10 km/h", "45° / 7 km/h"]),
...     separators=("°", ),
...     multi_value_sep=(" / ", )
... )
(array([40., 50., 45.]), array([ 5., 10.,  7.]))