EEZ: Update EEZ to v12, auto-download and remove from databundle (#1188)
* eez: update to version 12, autodownload, remove pycountry * eez: do not simplify as it distorts topology * remove missed merge conflicts
This commit is contained in:
parent
c907d59253
commit
fb41016c60
@ -53,7 +53,6 @@ extensions = [
|
||||
autodoc_mock_imports = [
|
||||
"atlite",
|
||||
"snakemake",
|
||||
"pycountry",
|
||||
"rioxarray",
|
||||
"country_converter",
|
||||
"tabula",
|
||||
|
@ -17,7 +17,6 @@ tabula-py
|
||||
|
||||
# cartopy
|
||||
scikit-learn
|
||||
pycountry
|
||||
pyyaml
|
||||
seaborn
|
||||
memory_profiler
|
||||
|
@ -18,7 +18,6 @@ dependencies:
|
||||
# Dependencies of the workflow itself
|
||||
- xlrd
|
||||
- openpyxl!=3.1.1
|
||||
- pycountry
|
||||
- seaborn
|
||||
- snakemake-minimal>=8.14
|
||||
- memory_profiler
|
||||
|
@ -92,7 +92,7 @@ rule build_shapes:
|
||||
countries=config_provider("countries"),
|
||||
input:
|
||||
naturalearth=ancient("data/naturalearth/ne_10m_admin_0_countries_deu.shp"),
|
||||
eez=ancient("data/bundle/eez/World_EEZ_v8_2014.shp"),
|
||||
eez=ancient("data/eez/World_EEZ_v12_20231025_gpkg/eez_v12.gpkg"),
|
||||
nuts3=ancient("data/bundle/NUTS_2013_60M_SH/data/NUTS_RG_60M_2013.shp"),
|
||||
nuts3pop=ancient("data/bundle/nama_10r_3popgdp.tsv.gz"),
|
||||
nuts3gdp=ancient("data/bundle/nama_10r_3gdp.tsv.gz"),
|
||||
|
@ -16,7 +16,6 @@ if config["enable"]["retrieve"] is False:
|
||||
if config["enable"]["retrieve"] and config["enable"].get("retrieve_databundle", True):
|
||||
datafiles = [
|
||||
"je-e-21.03.02.xls",
|
||||
"eez/World_EEZ_v8_2014.shp",
|
||||
"NUTS_2013_60M_SH/data/NUTS_RG_60M_2013.shp",
|
||||
"nama_10r_3popgdp.tsv.gz",
|
||||
"nama_10r_3gdp.tsv.gz",
|
||||
@ -215,6 +214,41 @@ if config["enable"]["retrieve"]:
|
||||
move(input[0], output[0])
|
||||
|
||||
|
||||
if config["enable"]["retrieve"]:
|
||||
|
||||
rule retrieve_eez:
|
||||
params:
|
||||
zip="data/eez/World_EEZ_v12_20231025_gpkg.zip",
|
||||
output:
|
||||
gpkg="data/eez/World_EEZ_v12_20231025_gpkg/eez_v12.gpkg",
|
||||
run:
|
||||
import os
|
||||
import requests
|
||||
from uuid import uuid4
|
||||
|
||||
name = str(uuid4())[:8]
|
||||
org = str(uuid4())[:8]
|
||||
|
||||
response = requests.post(
|
||||
"https://www.marineregions.org/download_file.php",
|
||||
params={"name": "World_EEZ_v12_20231025_gpkg.zip"},
|
||||
data={
|
||||
"name": name,
|
||||
"organisation": org,
|
||||
"email": f"{name}@{org}.org",
|
||||
"country": "Germany",
|
||||
"user_category": "academia",
|
||||
"purpose_category": "Research",
|
||||
"agree": "1",
|
||||
},
|
||||
)
|
||||
|
||||
with open(params["zip"], "wb") as f:
|
||||
f.write(response.content)
|
||||
output_folder = Path(params["zip"]).parent
|
||||
unpack_archive(params["zip"], output_folder)
|
||||
os.remove(params["zip"])
|
||||
|
||||
if config["enable"]["retrieve"]:
|
||||
|
||||
# Download directly from naciscdn.org which is a redirect from naturalearth.com
|
||||
|
@ -26,7 +26,7 @@ Inputs
|
||||
.. image:: img/countries.png
|
||||
:scale: 33 %
|
||||
|
||||
- ``data/bundle/eez/World_EEZ_v8_2014.shp``: World `exclusive economic zones <https://en.wikipedia.org/wiki/Exclusive_economic_zone>`_ (EEZ)
|
||||
- ``data/eez/World_EEZ_v12_20231025_gpkg/eez_v12.gpkg ``: World `exclusive economic zones <https://en.wikipedia.org/wiki/Exclusive_economic_zone>`_ (EEZ)
|
||||
|
||||
.. image:: img/eez.png
|
||||
:scale: 33 %
|
||||
@ -76,19 +76,13 @@ from operator import attrgetter
|
||||
import geopandas as gpd
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pycountry as pyc
|
||||
import country_converter as coco
|
||||
from _helpers import configure_logging, set_scenario_config
|
||||
from shapely.geometry import MultiPolygon, Polygon
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_country(target, **keys):
|
||||
assert len(keys) == 1
|
||||
try:
|
||||
return getattr(pyc.countries.get(**keys), target)
|
||||
except (KeyError, AttributeError):
|
||||
return np.nan
|
||||
cc = coco.CountryConverter()
|
||||
|
||||
|
||||
def _simplify_polys(polys, minarea=0.1, tolerance=None, filterremote=True):
|
||||
@ -135,22 +129,15 @@ def countries(naturalearth, country_list):
|
||||
return s
|
||||
|
||||
|
||||
def eez(country_shapes, eez, country_list):
|
||||
def eez(eez, country_list):
|
||||
df = gpd.read_file(eez)
|
||||
df = df.loc[
|
||||
df["ISO_3digit"].isin(
|
||||
[_get_country("alpha_3", alpha_2=c) for c in country_list]
|
||||
)
|
||||
]
|
||||
df["name"] = df["ISO_3digit"].map(lambda c: _get_country("alpha_2", alpha_3=c))
|
||||
iso3_list = cc.convert(country_list, src="ISO2", to="ISO3")
|
||||
df = df.query("ISO_TER1 in @iso3_list and POL_TYPE == '200NM'").copy()
|
||||
df["name"] = cc.convert(df.ISO_TER1, src="ISO3", to="ISO2")
|
||||
s = df.set_index("name").geometry.map(
|
||||
lambda s: _simplify_polys(s, filterremote=False)
|
||||
)
|
||||
s = gpd.GeoSeries(
|
||||
{k: v for k, v in s.items() if v.distance(country_shapes[k]) < 1e-3},
|
||||
crs=df.crs,
|
||||
)
|
||||
s = s.to_frame("geometry")
|
||||
s = s.to_frame("geometry").set_crs(df.crs)
|
||||
s.index.name = "name"
|
||||
return s
|
||||
|
||||
@ -262,9 +249,7 @@ if __name__ == "__main__":
|
||||
country_shapes = countries(snakemake.input.naturalearth, snakemake.params.countries)
|
||||
country_shapes.reset_index().to_file(snakemake.output.country_shapes)
|
||||
|
||||
offshore_shapes = eez(
|
||||
country_shapes, snakemake.input.eez, snakemake.params.countries
|
||||
)
|
||||
offshore_shapes = eez(snakemake.input.eez, snakemake.params.countries)
|
||||
offshore_shapes.reset_index().to_file(snakemake.output.offshore_shapes)
|
||||
|
||||
europe_shape = gpd.GeoDataFrame(
|
||||
|
Loading…
Reference in New Issue
Block a user