Skip to content

Commit

Permalink
blackened
Browse files Browse the repository at this point in the history
  • Loading branch information
spjuhel committed Jul 4, 2024
1 parent a9a1a99 commit 6c2a75f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
19 changes: 11 additions & 8 deletions boario_tools/floods.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ def get_events_in_MRIO_regions(df, mrios_shapes, mrio_name):
scriptLogger.info("Associating events with MRIOT regions")
mrio_shapes_df = mrios_shapes.loc[mrios_shapes.mrio == mrio_name].copy()
if mrio_shapes_df.empty:
scriptLogger.error(f"...MRIOT name {mrio_name} wasn't found. Possible ones are {mrios_shapes.mrio.unique()}")
raise ValueError(f"...MRIOT name {mrio_name} wasn't found. Possible ones are {mrios_shapes.mrio.unique()}")
scriptLogger.error(
f"...MRIOT name {mrio_name} wasn't found. Possible ones are {mrios_shapes.mrio.unique()}"
)
raise ValueError(
f"...MRIOT name {mrio_name} wasn't found. Possible ones are {mrios_shapes.mrio.unique()}"
)
scriptLogger.info("...GDFying flood base")
gdf = gpd.GeoDataFrame(
df, geometry=gpd.points_from_xy(df.long, df.lat), crs="epsg:4326"
Expand Down Expand Up @@ -518,11 +522,11 @@ def get_GVA2010(region):
min_year = int(va_df.columns.get_level_values(0).min())
max_year = int(va_df.columns.get_level_values(0).max())
df["closest_MRIO_year"] = [
int(year)
if min_year <= int(year) <= max_year
else min_year
if int(year) < min_year
else max_year
(
int(year)
if min_year <= int(year) <= max_year
else min_year if int(year) < min_year else max_year
)
for year in df["year"]
]

Expand Down Expand Up @@ -596,7 +600,6 @@ def global_treatment_after_period_change(
if not match:
raise ValueError(f"{mrio_name} is not a valid mrio")


df = compute_dmg_as_gva_share(df, mrio_ref)

# scriptLogger.info("Computing direct production losses")
Expand Down
25 changes: 18 additions & 7 deletions boario_tools/mriot.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@ def parse_wiod_v2016(mrio_xlsb: str):

############################### IO, saving ###########################################
def euregio_csv_to_pkl(
mrio_csv: str, output_dir: str, year, correct_regions=True, custom_name: str|None = None
mrio_csv: str,
output_dir: str,
year,
correct_regions=True,
custom_name: str | None = None,
):
mrio_pym = build_euregio_from_csv(mrio_csv, year, correct_regions)
name = (
Expand All @@ -385,7 +389,7 @@ def eora26_zip_to_pkl(
reexport_treatment=True,
inv_treatment=True,
remove_attributes=True,
custom_name: str|None = None,
custom_name: str | None = None,
):
mrio_pym = build_eora_from_zip(
mrio_zip, reexport_treatment, inv_treatment, remove_attributes
Expand All @@ -402,9 +406,9 @@ def eora26_zip_to_pkl(
pkl.dump(mrio_pym, f)


def oecd_v2018_zip_to_pkl(mrio_zip: str, output_dir: str, year: int,
custom_name: str|None = None
):
def oecd_v2018_zip_to_pkl(
mrio_zip: str, output_dir: str, year: int, custom_name: str | None = None
):
mrio_pym = build_oecd_from_zip(mrio_zip, year)
name = (
custom_name
Expand All @@ -418,7 +422,9 @@ def oecd_v2018_zip_to_pkl(mrio_zip: str, output_dir: str, year: int,
pkl.dump(mrio_pym, f)


def wiod_v2016_xlsb2pkl(mrio_xlsb: str, output_dir: str, custom_name: str|None = None):
def wiod_v2016_xlsb2pkl(
mrio_xlsb: str, output_dir: str, custom_name: str | None = None
):
mrio_pym = parse_wiod_v2016(mrio_xlsb)
name = (
custom_name
Expand All @@ -432,7 +438,12 @@ def wiod_v2016_xlsb2pkl(mrio_xlsb: str, output_dir: str, custom_name: str|None =
pkl.dump(mrio_pym, f)


def exio3_zip_to_pkl(mrio_zip: str, output_dir: str, remove_attributes: bool = True, custom_name: str|None = None):
def exio3_zip_to_pkl(
mrio_zip: str,
output_dir: str,
remove_attributes: bool = True,
custom_name: str | None = None,
):
mrio_pym = build_exio3_from_zip(mrio_zip, remove_attributes)
name = (
custom_name
Expand Down
21 changes: 15 additions & 6 deletions boario_tools/regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@
MRIOT_YEAR_REGEX = r"(?P<mrio_year>\d{4})"
MRIOT_AGGREG_SECTORS_REGEX = r"(?P<mrio_aggreg_sectors>[a-zA-Z0-9_]+_sectors)"
MRIOT_AGGREG_REGIONS_REGEX = r"(?P<mrio_aggreg_regions>[a-zA-Z0-9_]+_regions)"
MRIOT_AGGREG_REGEX = r"""{MRIOT_AGGREG_SECTORS_REGEX}_{MRIOT_AGGREG_REGIONS_REGEX}""".format(MRIOT_AGGREG_SECTORS_REGEX=MRIOT_AGGREG_SECTORS_REGEX, MRIOT_AGGREG_REGIONS_REGEX=MRIOT_AGGREG_REGIONS_REGEX)
MRIOT_AGGREG_REGEX = (
r"""{MRIOT_AGGREG_SECTORS_REGEX}_{MRIOT_AGGREG_REGIONS_REGEX}""".format(
MRIOT_AGGREG_SECTORS_REGEX=MRIOT_AGGREG_SECTORS_REGEX,
MRIOT_AGGREG_REGIONS_REGEX=MRIOT_AGGREG_REGIONS_REGEX,
)
)

MRIOT_FULLNAME_REGEX = re.compile(r"""
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
)
""".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 6c2a75f

Please sign in to comment.