floodmodeller-api 0.4.4.post1__py3-none-any.whl → 0.5.0.post1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- floodmodeller_api/__init__.py +1 -0
- floodmodeller_api/dat.py +117 -96
- floodmodeller_api/hydrology_plus/__init__.py +2 -0
- floodmodeller_api/hydrology_plus/helper.py +23 -0
- floodmodeller_api/hydrology_plus/hydrology_plus_export.py +333 -0
- floodmodeller_api/ied.py +93 -90
- floodmodeller_api/ief.py +233 -50
- floodmodeller_api/ief_flags.py +1 -0
- floodmodeller_api/logs/lf.py +5 -1
- floodmodeller_api/mapping.py +2 -0
- floodmodeller_api/test/test_conveyance.py +23 -32
- floodmodeller_api/test/test_data/7082.ief +28 -0
- floodmodeller_api/test/test_data/BaseModel_2D_Q100.ief +28 -0
- floodmodeller_api/test/test_data/Baseline_unchecked.csv +77 -0
- floodmodeller_api/test/test_data/Constant QT.ief +19 -0
- floodmodeller_api/test/test_data/Domain1_Q_xml_expected.json +7 -7
- floodmodeller_api/test/test_data/EX18_DAT_expected.json +54 -38
- floodmodeller_api/test/test_data/EX3_DAT_expected.json +246 -166
- floodmodeller_api/test/test_data/EX3_IEF_expected.json +25 -20
- floodmodeller_api/test/test_data/EX6_DAT_expected.json +522 -350
- floodmodeller_api/test/test_data/FEH boundary.ief +23 -0
- floodmodeller_api/test/test_data/Linked1D2D_xml_expected.json +7 -7
- floodmodeller_api/test/test_data/P3Panels_UNsteady.ief +25 -0
- floodmodeller_api/test/test_data/QT in dat file.ief +20 -0
- floodmodeller_api/test/test_data/T10.ief +25 -0
- floodmodeller_api/test/test_data/T2.ief +25 -0
- floodmodeller_api/test/test_data/T5.ief +25 -0
- floodmodeller_api/test/test_data/df_flows_hplus.csv +56 -0
- floodmodeller_api/test/test_data/event_hplus.csv +56 -0
- floodmodeller_api/test/test_data/ex4.ief +20 -0
- floodmodeller_api/test/test_data/ex6.ief +21 -0
- floodmodeller_api/test/test_data/example_h+_export.csv +77 -0
- floodmodeller_api/test/test_data/hplus_export_example_1.csv +72 -0
- floodmodeller_api/test/test_data/hplus_export_example_10.csv +77 -0
- floodmodeller_api/test/test_data/hplus_export_example_2.csv +79 -0
- floodmodeller_api/test/test_data/hplus_export_example_3.csv +77 -0
- floodmodeller_api/test/test_data/hplus_export_example_4.csv +131 -0
- floodmodeller_api/test/test_data/hplus_export_example_5.csv +77 -0
- floodmodeller_api/test/test_data/hplus_export_example_6.csv +131 -0
- floodmodeller_api/test/test_data/hplus_export_example_7.csv +131 -0
- floodmodeller_api/test/test_data/hplus_export_example_8.csv +131 -0
- floodmodeller_api/test/test_data/hplus_export_example_9.csv +131 -0
- floodmodeller_api/test/test_data/network_dat_expected.json +312 -210
- floodmodeller_api/test/test_data/network_ied_expected.json +6 -6
- floodmodeller_api/test/test_data/network_with_comments.ied +55 -0
- floodmodeller_api/test/test_flowtimeprofile.py +133 -0
- floodmodeller_api/test/test_hydrology_plus_export.py +210 -0
- floodmodeller_api/test/test_ied.py +12 -0
- floodmodeller_api/test/test_ief.py +49 -9
- floodmodeller_api/test/test_json.py +6 -1
- floodmodeller_api/test/test_read_file.py +27 -0
- floodmodeller_api/test/test_river.py +246 -0
- floodmodeller_api/to_from_json.py +7 -1
- floodmodeller_api/tool.py +6 -10
- floodmodeller_api/units/__init__.py +11 -1
- floodmodeller_api/units/conveyance.py +103 -212
- floodmodeller_api/units/sections.py +120 -39
- floodmodeller_api/util.py +2 -0
- floodmodeller_api/version.py +1 -1
- floodmodeller_api/xml2d.py +20 -13
- floodmodeller_api/xsd_backup.xml +738 -0
- {floodmodeller_api-0.4.4.post1.dist-info → floodmodeller_api-0.5.0.post1.dist-info}/METADATA +2 -1
- {floodmodeller_api-0.4.4.post1.dist-info → floodmodeller_api-0.5.0.post1.dist-info}/RECORD +67 -33
- {floodmodeller_api-0.4.4.post1.dist-info → floodmodeller_api-0.5.0.post1.dist-info}/WHEEL +1 -1
- {floodmodeller_api-0.4.4.post1.dist-info → floodmodeller_api-0.5.0.post1.dist-info}/LICENSE.txt +0 -0
- {floodmodeller_api-0.4.4.post1.dist-info → floodmodeller_api-0.5.0.post1.dist-info}/entry_points.txt +0 -0
- {floodmodeller_api-0.4.4.post1.dist-info → floodmodeller_api-0.5.0.post1.dist-info}/top_level.txt +0 -0
floodmodeller_api/xml2d.py
CHANGED
|
@@ -24,6 +24,7 @@ from pathlib import Path
|
|
|
24
24
|
from subprocess import DEVNULL, Popen
|
|
25
25
|
from typing import Callable
|
|
26
26
|
|
|
27
|
+
import requests
|
|
27
28
|
from lxml import etree
|
|
28
29
|
from tqdm import trange
|
|
29
30
|
|
|
@@ -57,7 +58,7 @@ class XML2D(FMFile):
|
|
|
57
58
|
xml_filepath (str, optional): Full filepath to xml file.
|
|
58
59
|
|
|
59
60
|
Output:
|
|
60
|
-
Initiates '
|
|
61
|
+
Initiates 'XML2D' class object
|
|
61
62
|
|
|
62
63
|
Raises:
|
|
63
64
|
TypeError: Raised if xml_filepath does not point to a .xml file
|
|
@@ -66,7 +67,8 @@ class XML2D(FMFile):
|
|
|
66
67
|
|
|
67
68
|
_filetype: str = "XML2D"
|
|
68
69
|
_suffix: str = ".xml"
|
|
69
|
-
_xsd_loc: str = "
|
|
70
|
+
_xsd_loc: str = "https://schema.floodmodeller.com/7.1/2d.xsd"
|
|
71
|
+
_w3_schema: str = "{http://www.w3.org/2001/XMLSchema}"
|
|
70
72
|
OLD_FILE = 5
|
|
71
73
|
GOOD_EXIT_CODE = 100
|
|
72
74
|
|
|
@@ -88,8 +90,13 @@ class XML2D(FMFile):
|
|
|
88
90
|
self._xmltree = etree.parse(io.StringIO(xml2d_template))
|
|
89
91
|
else:
|
|
90
92
|
self._xmltree = etree.parse(self._filepath)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
try:
|
|
94
|
+
xsd_bin = requests.get(self._xsd_loc).content
|
|
95
|
+
self._xsd = etree.parse(io.BytesIO(xsd_bin))
|
|
96
|
+
self._xsdschema = etree.XMLSchema(self._xsd)
|
|
97
|
+
except Exception:
|
|
98
|
+
self._xsd = etree.parse(Path(__file__).parent / "xsd_backup.xml")
|
|
99
|
+
self._xsdschema = etree.XMLSchema(self._xsd)
|
|
93
100
|
self._get_multi_value_keys()
|
|
94
101
|
|
|
95
102
|
self._create_dict()
|
|
@@ -175,18 +182,18 @@ class XML2D(FMFile):
|
|
|
175
182
|
# find element in schema
|
|
176
183
|
parent_name = parent.tag.replace(self._ns, "")
|
|
177
184
|
schema_elem = self._xsd.find(
|
|
178
|
-
f".//{
|
|
185
|
+
f".//{self._w3_schema}*[@name='{parent_name}']",
|
|
179
186
|
)
|
|
180
187
|
if "type" in schema_elem.attrib:
|
|
181
188
|
schema_elem = self._xsd.find(
|
|
182
|
-
f".//{
|
|
189
|
+
f".//{self._w3_schema}*[@name='{schema_elem.attrib['type']}']",
|
|
183
190
|
)
|
|
184
191
|
else:
|
|
185
|
-
schema_elem = schema_elem.find("{
|
|
192
|
+
schema_elem = schema_elem.find(f"{self._w3_schema}complexType")
|
|
186
193
|
if schema_elem is None:
|
|
187
194
|
return parent.getchildren()
|
|
188
195
|
|
|
189
|
-
seq = schema_elem.find("{
|
|
196
|
+
seq = schema_elem.find(f"{self._w3_schema}sequence")
|
|
190
197
|
if seq is None:
|
|
191
198
|
return parent.getchildren()
|
|
192
199
|
|
|
@@ -311,7 +318,7 @@ class XML2D(FMFile):
|
|
|
311
318
|
# Check schema to see if we should use parent.set for attribute
|
|
312
319
|
# or etree.subelement() and set text
|
|
313
320
|
schema_elem = self._xsd.findall(
|
|
314
|
-
f".//{
|
|
321
|
+
f".//{self._w3_schema}*[@name='{add_key}']",
|
|
315
322
|
)
|
|
316
323
|
if len(schema_elem) == 1:
|
|
317
324
|
schema_elem = schema_elem[0]
|
|
@@ -319,14 +326,14 @@ class XML2D(FMFile):
|
|
|
319
326
|
# This is just here for when there's multiple schema elements with same
|
|
320
327
|
# name, e.g. 'frequency'
|
|
321
328
|
parent_schema_elem = self._xsd.find(
|
|
322
|
-
f".//{
|
|
329
|
+
f".//{self._w3_schema}*[@name='{parent.tag.replace(self._ns, '')}']",
|
|
323
330
|
)
|
|
324
331
|
if "type" in parent_schema_elem.attrib:
|
|
325
332
|
parent_schema_elem = self._xsd.find(
|
|
326
|
-
f".//{
|
|
333
|
+
f".//{self._w3_schema}*[@name='{parent_schema_elem.attrib['type']}']",
|
|
327
334
|
)
|
|
328
335
|
schema_elem = parent_schema_elem.find(
|
|
329
|
-
f".//{
|
|
336
|
+
f".//{self._w3_schema}*[@name='{add_key}']",
|
|
330
337
|
)
|
|
331
338
|
|
|
332
339
|
if schema_elem.tag.endswith("attribute"):
|
|
@@ -403,7 +410,7 @@ class XML2D(FMFile):
|
|
|
403
410
|
def _get_multi_value_keys(self):
|
|
404
411
|
self._multi_value_keys = []
|
|
405
412
|
root = self._xsd.getroot()
|
|
406
|
-
for elem in root.findall(".//{
|
|
413
|
+
for elem in root.findall(f".//{self._w3_schema}element"):
|
|
407
414
|
if elem.attrib.get("maxOccurs") not in (None, "0", "1"):
|
|
408
415
|
self._multi_value_keys.append(elem.attrib["name"])
|
|
409
416
|
self._multi_value_keys = set(self._multi_value_keys)
|