Skip to content

Commit a915aba

Browse files
fix pylit and update changelog
1 parent d2aa357 commit a915aba

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Removed:
7171

7272
### Added
7373

74+
- `climada.entity.impact_funcs.trop_cyclone.ImpfSetTropCyclone.get_countries_per_region` function [#1034](https://github.com/CLIMADA-project/climada_python/pull/1034)
7475
- `climada.hazard.tc_tracks.TCTracks.subset_years` function [#1023](https://github.com/CLIMADA-project/climada_python/pull/1023)
7576
- `climada.hazard.tc_tracks.TCTracks.from_FAST` function, add Australia basin (AU) [#993](https://github.com/CLIMADA-project/climada_python/pull/993)
7677
- Add `osm-flex` package to CLIMADA core [#981](https://github.com/CLIMADA-project/climada_python/pull/981)

climada/entity/impact_funcs/trop_cyclone.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
LOGGER = logging.getLogger(__name__)
3636

3737

38-
class country_code(Enum):
38+
class CountryCode(Enum):
3939
"""
4040
Enum class that links ISO country codes (both iso3a and iso3n) to specific regions and
4141
associated impact function IDs.
@@ -48,7 +48,7 @@ class country_code(Enum):
4848
"""
4949

5050
# fmt: off
51-
iso3n = {
51+
ISO3N = {
5252
"NA1": [
5353
660, 28, 32, 533, 44, 52, 84, 60, 68, 132,
5454
136, 152, 170, 188, 192, 212, 214, 218, 222, 238,
@@ -88,7 +88,7 @@ class country_code(Enum):
8888
581, 732, 894, 248,
8989
],
9090
}
91-
iso3a = {
91+
ISO3A = {
9292
"NA1": [
9393
"AIA", "ATG", "ARG", "ABW", "BHS", "BRB", "BLZ", "BMU", "BOL", "CPV",
9494
"CYM", "CHL", "COL", "CRI", "CUB", "DMA", "DOM", "ECU", "SLV", "FLK",
@@ -132,7 +132,7 @@ class country_code(Enum):
132132
],
133133
}
134134
# fmt: on
135-
impf_id = {
135+
IMPF_ID = {
136136
"NA1": 1,
137137
"NA2": 2,
138138
"NI": 3,
@@ -145,7 +145,7 @@ class country_code(Enum):
145145
"ROW": 10,
146146
}
147147

148-
region_name = {
148+
REGION_NAME = {
149149
"NA1": "Caribbean and Mexico",
150150
"NA2": "USA and Canada",
151151
"NI": "North Indian",
@@ -439,22 +439,22 @@ def get_countries_per_region(region=None):
439439

440440
if region == "all":
441441
return (
442-
country_code.region_name,
443-
country_code.impf_id,
444-
country_code.iso3n,
445-
country_code.iso3a,
442+
CountryCode.REGION_NAME,
443+
CountryCode.IMPF_ID,
444+
CountryCode.ISO3N,
445+
CountryCode.ISO3A,
446446
)
447447

448448
return (
449-
country_code.region_name[region],
450-
country_code.impf_id[region],
451-
country_code.iso3n[region],
452-
country_code.iso3a[region],
449+
CountryCode.REGION_NAME[region],
450+
CountryCode.IMPF_ID[region],
451+
CountryCode.ISO3N[region],
452+
CountryCode.ISO3A[region],
453453
)
454454

455455
@staticmethod
456456
def get_regions_per_countries(
457-
countries: list = None, code_type: str = "iso3a"
457+
countries: list = None, code_type: str = "ISO3A"
458458
) -> tuple:
459459
"""Return the impact function id and the region corresponding to a list of countries,
460460
or a single country.
@@ -463,10 +463,10 @@ def get_regions_per_countries(
463463
-----------
464464
countries : list
465465
List containing the ISO code of the country, which should be either
466-
a string if the code is iso3a or an integer if iso3n. For example, for Switzerland:
467-
the iso3a code is "CHE" and the iso3n is 756.
466+
a string if the code is iso3a or an integer if ISO3N. For example, for Switzerland:
467+
the ISO3A code is "CHE" and the ISO3N is 756.
468468
code_type : str
469-
Either "iso3a" or "iso3n".
469+
Either "ISO3A" or "ISO3N".
470470
471471
Returns:
472472
--------
@@ -478,10 +478,10 @@ def get_regions_per_countries(
478478
List of the regions that match the countries.
479479
"""
480480

481-
if code_type not in {"iso3a", "iso3n"}:
481+
if code_type not in {"ISO3A", "ISO3N"}:
482482
raise ValueError("code_type must be either 'iso3a' or 'iso3n'")
483483

484-
country_dict = getattr(country_code, code_type).value
484+
country_dict = getattr(CountryCode, code_type).value
485485
# Find region
486486
regions_ids = [
487487
key
@@ -490,10 +490,8 @@ def get_regions_per_countries(
490490
if country in value
491491
]
492492
# Find impact function id
493-
impf_ids = [country_code.impf_id.value[region] for region in regions_ids]
494-
regions_name = [
495-
country_code.region_name.value[region] for region in regions_ids
496-
]
493+
impf_ids = [CountryCode.IMPF_ID.value[region] for region in regions_ids]
494+
regions_name = [CountryCode.REGION_NAME.value[region] for region in regions_ids]
497495

498496
return impf_ids, regions_ids, regions_name
499497

0 commit comments

Comments
 (0)