Skip to content

Commit 7205ee7

Browse files
update strings and func name
1 parent 4c08a08 commit 7205ee7

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

climada/entity/impact_funcs/test/test_tc.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,39 +169,41 @@ def test_get_countries_per_region(self):
169169
self.assertListEqual(out[3], ["CAN", "USA"])
170170

171171
def test_get_region_per_countries(self):
172-
"""Test static get_regions_per_countries()"""
172+
"""Test get_impf_id_regions_per_countries()"""
173173
ifs = ImpfSetTropCyclone()
174-
out = ifs.get_regions_per_countries(countries=["CHE"], code_type="ISO3A")
174+
out = ifs.get_impf_id_regions_per_countries(
175+
countries=["CHE"], code_type="ISO3A"
176+
)
175177
self.assertEqual(out[0][0], 10)
176178
self.assertEqual(out[1][0], "ROW")
177179
self.assertEqual(out[2][0], "Rest of The World")
178-
out = ifs.get_regions_per_countries(countries=[756], code_type="ISO3N")
180+
out = ifs.get_impf_id_regions_per_countries(countries=[756], code_type="ISO3N")
179181
self.assertEqual(out[0][0], 10)
180182
self.assertEqual(out[1][0], "ROW")
181183
self.assertEqual(out[2][0], "Rest of The World")
182184
with self.assertRaises(ValueError) as context:
183-
ImpfSetTropCyclone.get_regions_per_countries(
185+
ImpfSetTropCyclone.get_impf_id_regions_per_countries(
184186
countries=["SWE"], code_type="invalid_code"
185187
)
186188
self.assertEqual(
187189
str(context.exception), "code_type must be either 'iso3a' or 'iso3n'"
188190
)
189191
with self.assertRaises(ValueError) as context:
190-
ImpfSetTropCyclone.get_regions_per_countries(
192+
ImpfSetTropCyclone.get_impf_id_regions_per_countries(
191193
countries=["SWE", 840], code_type="ISO3A"
192194
)
193195
self.assertEqual(
194196
str(context.exception), "All elements in the list must be of the same type."
195197
)
196198
with self.assertRaises(ValueError) as context:
197-
ImpfSetTropCyclone.get_regions_per_countries(
199+
ImpfSetTropCyclone.get_impf_id_regions_per_countries(
198200
countries=[840, 124], code_type="ISO3A"
199201
)
200202
self.assertEqual(
201203
str(context.exception), "ISO3A code type cannot have integer values."
202204
)
203205
with self.assertRaises(ValueError) as context:
204-
ImpfSetTropCyclone.get_regions_per_countries(
206+
ImpfSetTropCyclone.get_impf_id_regions_per_countries(
205207
countries=["MEX"], code_type="ISO3N"
206208
)
207209
self.assertEqual(

climada/entity/impact_funcs/trop_cyclone.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CountryCode(Enum):
5050
A mapping of region names to corresponding impact function IDs.
5151
REGION_NAME: dict
5252
A mapping of region names to their descriptive names.
53-
""""
53+
"""
5454

5555
# fmt: off
5656
ISO3N = {
@@ -458,7 +458,7 @@ def get_countries_per_region(region=None):
458458
)
459459

460460
@staticmethod
461-
def get_regions_per_countries(
461+
def get_impf_id_regions_per_countries(
462462
countries: list = None, code_type: str = "ISO3A"
463463
) -> tuple:
464464
"""Return the impact function id and the region corresponding to a list of countries,
@@ -467,20 +467,24 @@ def get_regions_per_countries(
467467
Parameters:
468468
-----------
469469
countries : list
470-
List containing the ISO code of the country, which should be either
471-
a string if the code is iso3a or an integer if ISO3N. For example, for Switzerland:
472-
the ISO3A code is "CHE" and the ISO3N is 756.
470+
List containing the ISO codes of the country, which should be either
471+
in string format if the code is "ISO3A" or an integer if "ISO3N", see code_type below.
473472
code_type : str
474-
Either "ISO3A" or "ISO3N".
473+
Either "ISO3A" or "ISO3N". "ISO3A" stands for "ISO 3166-1 alpha-3" which is a
474+
three-letter country code, "ISO3N" stands for "ISO 3166-1 numeric" which is a
475+
three-digit country code, the numeric version of "ISO3A". For example, for Switzerland:
476+
the "ISO3A" code is "CHE" and the "ISO3N" is 756.
475477
476478
Returns:
477479
--------
478480
impf_ids : list
479481
List of impact function ids matching the countries.
480482
regions_ids : list
481-
List of the regions that match the countries.
483+
List of the region ids. Regions are a container of countries as defined in:
484+
https://nhess.copernicus.org/articles/21/393/2021/nhess-21-393-2021.pdf, and implemented
485+
in the CountryCode Enum Class. Example: "NA1", "NA2", ...
482486
regions_names : list
483-
List of the regions that match the countries.
487+
List of the regions names. Example: "Caribbean and Mexico", "USA and Canada", ...
484488
"""
485489

486490
if code_type not in {"ISO3A", "ISO3N"}:

0 commit comments

Comments
 (0)