|
23 | 23 |
|
24 | 24 | import logging |
25 | 25 | from enum import Enum |
| 26 | +from typing import Literal, overload |
26 | 27 |
|
27 | 28 | import numpy as np |
28 | 29 | import pandas as pd |
@@ -92,7 +93,7 @@ class CountryCode(Enum): |
92 | 93 | "NAM", "NER", "NGA", "NLD", "NOR", "POL", "PRK", "PRT", "PSE", "REU", "ROU", |
93 | 94 | "RUS", "RWA", "SDN", "SEN", "SGP", "SGS", "SJM", "SLE", "SMR", "SPM", "SRB", |
94 | 95 | "SSD", "STP", "SVK", "SVN", "SWE", "SYC", "TCD", "TGO", "TUN", "TUR", "UKR", |
95 | | - "UMI", "VAT", "XKX", "ZMB", |
| 96 | + "UMI", "VAT", "XKO", "ZMB", |
96 | 97 | ], |
97 | 98 | } |
98 | 99 |
|
@@ -363,10 +364,47 @@ def calibrated_regional_vhalf( |
363 | 364 | reg_v_half[regions_short[-1]] = np.round(df_reg["v_half"].values[0], 5) |
364 | 365 | return reg_v_half |
365 | 366 |
|
| 367 | + @overload |
| 368 | + @staticmethod |
| 369 | + def get_countries_per_region( |
| 370 | + region: Literal["all"] = "all", |
| 371 | + ) -> tuple[ |
| 372 | + dict[str, str], # region_name |
| 373 | + dict[str, int], # impf_id |
| 374 | + dict[str, list[int]], # numeric |
| 375 | + dict[str, list[str]], # alpha3 |
| 376 | + ]: ... |
| 377 | + |
| 378 | + @overload |
| 379 | + @staticmethod |
| 380 | + def get_countries_per_region( |
| 381 | + region: None, |
| 382 | + ) -> tuple[ |
| 383 | + dict[str, str], dict[str, int], dict[str, list[int]], dict[str, list[str]] |
| 384 | + ]: ... |
| 385 | + |
| 386 | + @overload |
| 387 | + @staticmethod |
| 388 | + def get_countries_per_region( |
| 389 | + region: str, |
| 390 | + ) -> tuple[ |
| 391 | + str, int, list[int], list[str] # region_name # impf_id # numeric # alpha3 |
| 392 | + ]: ... |
| 393 | + |
366 | 394 | @staticmethod |
367 | 395 | def get_countries_per_region(region=None): |
368 | | - """Returns dictionaries with numerical (numeric) and alphabetical (alpha3) ISO3 codes |
369 | | - of all countries associated to a calibration region. |
| 396 | + """Returns countries within a TC calibration region and associated impact functions. |
| 397 | +
|
| 398 | + This method returns a tuple with numerical (numeric) and alphabetical (alpha3) |
| 399 | + ISO3 codes of all countries associated to a calibration region. |
| 400 | +
|
| 401 | + If no region or "all" is provided as argument, the method return a tuple of |
| 402 | + dictionaries with short name of the tropical cyclone calibration regions as |
| 403 | + keys and the values for each of those. |
| 404 | +
|
| 405 | + Notes |
| 406 | + ----- |
| 407 | +
|
370 | 408 | Only contains countries that were affected by tropical cyclones |
371 | 409 | between 1980 and 2017 according to EM-DAT. |
372 | 410 |
|
@@ -395,9 +433,12 @@ def get_countries_per_region(region=None): |
395 | 433 | return ( |
396 | 434 | CountryCode.REGION_NAME.value, |
397 | 435 | CountryCode.IMPF_ID.value, |
398 | | - coordinates.country_to_iso( |
399 | | - CountryCode.ALPHA3.value, representation="numeric" |
400 | | - ), |
| 436 | + { |
| 437 | + reg: coordinates.country_to_iso( |
| 438 | + CountryCode.ALPHA3.value[reg], representation="numeric" |
| 439 | + ) |
| 440 | + for reg in CountryCode.REGION_NAME.value |
| 441 | + }, |
401 | 442 | CountryCode.ALPHA3.value, |
402 | 443 | ) |
403 | 444 |
|
|
0 commit comments