Skip to content

Commit

Permalink
added regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuhel committed Mar 20, 2024
1 parent f389fef commit ca70289
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 2 additions & 5 deletions boario_tools/floods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from pathlib import Path
from boario_tools.regex_patterns import MRIOT_FULLNAME_REGEX
import pyarrow.feather as feather
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -590,15 +591,11 @@ def global_treatment_after_period_change(
df, mrio_name, mrio_ref, output_dir, period_name
):
output_dir = Path(output_dir)
mrio_re = re.compile(
r"^(?P<mrio_basename>[a-zA-Z0-9]+)(?:_(?P<mrio_subname>full|\d+_sectors))?$"
)
mrio_re = MRIOT_FULLNAME_REGEX
match = mrio_re.match(mrio_name)
if not match:
raise ValueError(f"{mrio_name} is not a valid mrio")

# mrio_basename = match['mrio_basename']
# mrio_subname = "full" if match['mrio_subname'] is None else match["mrio_subname"]

df = compute_dmg_as_gva_share(df, mrio_ref)

Expand Down
20 changes: 20 additions & 0 deletions boario_tools/regex_patterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import re

ORDER_TYPE_REGEX = r"(?P<order>alt|noalt)"
PSI_REGEX = r"(?P<psi>(?:1|0)\.\d+)"
BASE_ALPHA_REGEX = r"(?P<base_alpha>\d(?:\.\d+)?)"
MAX_ALPHA_REGEX = r"(?P<max_alpha>\d(?:\.\d+)?)"
TAU_ALPHA_REGEX = r"(?P<tau_alpha>\d+)"

MRIOT_BASENAME_REGEX = r"(?P<mrio_basename>icio2021|euregio|exiobase3_ixi|eora26)"
MRIOT_YEAR_REGEX = r"(?P<mrio_year>\d{4})"
MRIOT_AGGREG_REGEX = r"(?P<mrio_aggreg>full|\d+_sectors|common_aggreg)"
MRIOT_FULLNAME_REGEX = re.compile(r"""
{MRIOT_BASENAME_REGEX} # MRIOT basename
_ #
{MRIOT_YEAR_REGEX} # MRIOT year
_ #
{MRIOT_AGGREG_REGEX} # Aggregation specification
""".format(MRIOT_BASENAME_REGEX=MRIOT_BASENAME_REGEX,
MRIOT_YEAR_REGEX=MRIOT_YEAR_REGEX,
MRIOT_AGGREG_REGEX=MRIOT_AGGREG_REGEX),re.VERBOSE)

0 comments on commit ca70289

Please sign in to comment.