From 11953f538faee55317f147feb96e8d56f585a786 Mon Sep 17 00:00:00 2001 From: Jean-Paul Travert <jean-paul.travert@edf.fr> Date: Mon, 12 Jun 2023 11:58:16 +0000 Subject: [PATCH] [scripts] Fix of URL of Corine Land Cover database and add of year 2018 data --- NEWS.txt | 3 +++ ...r_table_12.txt => def_strickler_table.txt} | 0 scripts/python3/pretel/clc.py | 21 ++++++++++++------- scripts/python3/run_telfile.py | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) rename notebooks/data/{def_strickler_table_12.txt => def_strickler_table.txt} (100%) diff --git a/NEWS.txt b/NEWS.txt index fd4c43c5e2..af3529f4d2 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,6 +1,9 @@ Latest developments on main =========================== +Python: Fix url of Corine Land Cover (CLC) database and possibility to use +latest CLC data from 2018 (as default now) instead of 2012. + The SISYPHE module has been removed from the system. GAIA: the following keywords are deleted since not used: diff --git a/notebooks/data/def_strickler_table_12.txt b/notebooks/data/def_strickler_table.txt similarity index 100% rename from notebooks/data/def_strickler_table_12.txt rename to notebooks/data/def_strickler_table.txt diff --git a/scripts/python3/pretel/clc.py b/scripts/python3/pretel/clc.py index f03c598df0..3911ceb005 100644 --- a/scripts/python3/pretel/clc.py +++ b/scripts/python3/pretel/clc.py @@ -75,7 +75,7 @@ def wfs2xml(xml_file, year, bbox): from owslib.wfs import WebFeatureService - wfs11 = WebFeatureService('http://wxs.ign.fr/corinelandcover/geoportail/' + + wfs11 = WebFeatureService('http://wxs.ign.fr/clc/geoportail/' + 'wfs?service=WFS&request=GetCapabilities') response = wfs11.getfeature(typename=[typename], bbox=bbox) @@ -95,8 +95,10 @@ def get_typename(year): """ if year == 2012: typename = "LANDCOVER.CLC12_FR:clc12_fr" + elif year == 2018: + typename = "LANDCOVER.CLC18_FR:clc18_fr" else: - raise Exception("Unknown year: {}\nYear handled: 2012".format(year)) + raise Exception(f'Unknown year: {year}\nHandled years: 2012 and 2018') return typename @@ -122,8 +124,10 @@ def build_clc_struct(xml_file, year): for zone_elem in zone: # Here we are in a new strickler zone # print(zone_elem.tag) - if zone_elem.tag == \ - '{https://datastore.wxs.ign.fr/datastore/'+tag+'}code_12': + if re.match( + r'{https://datastore.wxs.ign.fr/datastore/' + tag + + r'}code_\d+', zone_elem.tag + ): # Saving code for that zone code = zone_elem.text if code not in struct: @@ -158,9 +162,9 @@ def read_corresp_table(year, table_name=None): @param year (int) Year to extract @parma table (str) Overwrites the table used """ - if year == 2012: + if year == 2012 or year==2018: tab_file = path.join(environ['HOMETEL'], 'notebooks', 'data', - 'def_strickler_table_12.txt') + 'def_strickler_table.txt') else: raise Exception("Year not handled") @@ -171,7 +175,10 @@ def read_corresp_table(year, table_name=None): with open(tab_file, 'r') as f: f.readline() for line in f.readlines(): - match = re.match(r'"(?P<name>[^"]+)"\s+(?P<value>[^ ]+)\s+(?P<ref>[^ ]+)\s+(?P<code>[^ ]+)', line) + match = re.match( + r'"(?P<name>[^"]+)"\s+(?P<value>[^ ]+)\s+(?P<ref>[^ ]+)\s+(?P<code>[^ ]+)', + line + ) corresp[int(match.group('code'))] = {\ 'name':match.group('name'), 'ref':match.group('ref'), diff --git a/scripts/python3/run_telfile.py b/scripts/python3/run_telfile.py index 567c3a61ce..2e3bcc9ab6 100755 --- a/scripts/python3/run_telfile.py +++ b/scripts/python3/run_telfile.py @@ -96,8 +96,8 @@ def clc_parser(subparser): "-v", dest="varname", default="FRICTION", help="Name of the variable containing Corinne Land Cover data " "(default: FRICTION)") - parser.add_argument("--year", default=2012, - choices=[2012], + parser.add_argument("--year",default=2018,type=int, + choices=[2012,2018], help="Year to extract data from") parser.add_argument("-o", dest="res_file", metavar="Telemac File", help="Output file if not given will write in mesh_file") -- GitLab