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 unitwhereSEPis a separator character. You can also pass two values in one string by separate them with a char frommulti_value_sep, The returned array will a tuple that contains the arrays.Warning
If an element of
dataisn’t a string, it will result in anp.naninto the converted array.Parameters
- data
np.array The array of strings to convert.
- separators
tuple, 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_sep
tuple, 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_char
tuple, 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
- out
list 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.]))
- data