emodpy_malaria.weather.weather_utils module#

The module for weather utility functions.

emodpy_malaria.weather.weather_utils.invert_dict(in_dict: Dict, sort=False, single_value=False) Dict[source]#

Invert a dictionary by grouping keys by value. In the resulting dictionary keys are unique value from the original dictionary (including individual element of value lists) and values are lists of original dictionary keys. The function is used for grouping nodes by offset or weather time series hash, and determining unique series.

For example,
single_value = False (default)

{1: [11, 22], 2: [22], 3: [11]} -> {11: [1, 3], 22: [1, 2]}

single_value = True

{1: [11, 22], 2: [22], 3: [11]} -> {11: 1, 22: 1}

Parameters:
  • in_dict – Input dictionary to be inverted.

  • sort – Sort the resulting dictionary by key and value.

  • single_value – Only return a single representative “original key” (from in_dict) for each corresponding unique “original value” (from in_dict).

Returns:

Inverted dictionary where

(single_value = False): keys are “original values” and values are lists of corresponding “original keys” (single_value = True): keys are “original values” and values is a single representative “original key”.

emodpy_malaria.weather.weather_utils.hash_series(series: Iterable[float32]) int[source]#

Calculate a unique hash for each input series. Used for grouping nodes by weather time series.

Parameters:

series – The list or array of float values.

Returns:

Series hash value as int.

emodpy_malaria.weather.weather_utils.save_json(content: Dict[str, str], file_path: str | Path) NoReturn[source]#

Save dictionary to a json file.

Parameters:
  • content – Content in the form of a dictionary.

  • file_path – The path of the output weather metadata file.

  • Returns – None

emodpy_malaria.weather.weather_utils.make_path(dir_path: str | Path) NoReturn[source]#

Make path directories.

emodpy_malaria.weather.weather_utils.ymd(date_arg: datetime) str[source]#

Convert datetime into a string of format yyyymmdd.

emodpy_malaria.weather.weather_utils.parse_date(date_arg: int | str, default_month: int, default_day: int) datetime[source]#
emodpy_malaria.weather.weather_utils.validate_str_value(value: str) NoReturn[source]#

Assert a string value is not None or empty.