Skip to content

Commit

Permalink
Add NUTS regions according to config
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-almeida committed Sep 18, 2024
1 parent 1f23e3f commit a031018
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nomenclature/codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ def from_directory(
except AttributeError:
code_list.append(RegionCode(name=c.name, hierarchy="Country"))

# adding nuts regions
if config.definitions.region.nuts:
for level, countries in config.definitions.region.nuts.items():
for n in nomenclature.nuts.get(
level=int(level[-1]), country_code=countries
):
code_list.append(
RegionCode(name=n.code, hierarchy="NUTS 2021-2024")
)

# importing from an external repository
for repo in config.definitions.region.repositories:
repo_path = config.repositories[repo].local_path / "definitions" / "region"
Expand Down
11 changes: 11 additions & 0 deletions nomenclature/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def repository_dimension_path(self) -> str:

class RegionCodeListConfig(CodeListConfig):
country: bool = False
nuts: dict[str, list[str]] = None

@field_validator("nuts")
@classmethod
def check_nuts(cls, v: dict[str, list[str]] | None) -> dict[str, list[str]] | None:
if v and not all(k in ["nuts-1", "nuts-2", "nuts-3"] for k in v.keys()):
raise ValueError(
"Invalid fields for `nuts` in configuration. "
"NUTS level must be 1, 2 and/or 3."
)
return v


class Repository(BaseModel):
Expand Down

0 comments on commit a031018

Please sign in to comment.