floodmodeller-api 0.4.2.post1__py3-none-any.whl → 0.4.4__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.
Files changed (178) hide show
  1. floodmodeller_api/__init__.py +8 -9
  2. floodmodeller_api/_base.py +169 -176
  3. floodmodeller_api/backup.py +273 -273
  4. floodmodeller_api/dat.py +889 -831
  5. floodmodeller_api/diff.py +136 -119
  6. floodmodeller_api/ied.py +302 -306
  7. floodmodeller_api/ief.py +553 -637
  8. floodmodeller_api/ief_flags.py +253 -253
  9. floodmodeller_api/inp.py +260 -266
  10. floodmodeller_api/libs/libifcoremd.dll +0 -0
  11. floodmodeller_api/libs/libifcoremt.so.5 +0 -0
  12. floodmodeller_api/libs/libifport.so.5 +0 -0
  13. floodmodeller_api/{libmmd.dll → libs/libimf.so} +0 -0
  14. floodmodeller_api/libs/libintlc.so.5 +0 -0
  15. floodmodeller_api/libs/libmmd.dll +0 -0
  16. floodmodeller_api/libs/libsvml.so +0 -0
  17. floodmodeller_api/libs/libzzn_read.so +0 -0
  18. floodmodeller_api/libs/zzn_read.dll +0 -0
  19. floodmodeller_api/logs/__init__.py +2 -2
  20. floodmodeller_api/logs/lf.py +364 -312
  21. floodmodeller_api/logs/lf_helpers.py +354 -352
  22. floodmodeller_api/logs/lf_params.py +643 -529
  23. floodmodeller_api/mapping.py +84 -0
  24. floodmodeller_api/test/__init__.py +4 -4
  25. floodmodeller_api/test/conftest.py +16 -8
  26. floodmodeller_api/test/test_backup.py +117 -117
  27. floodmodeller_api/test/test_conveyance.py +107 -0
  28. floodmodeller_api/test/test_dat.py +222 -92
  29. floodmodeller_api/test/test_data/All Units 4_6.DAT +1081 -1081
  30. floodmodeller_api/test/test_data/All Units 4_6.feb +1081 -1081
  31. floodmodeller_api/test/test_data/BRIDGE.DAT +926 -926
  32. floodmodeller_api/test/test_data/Culvert_Inlet_Outlet.dat +36 -36
  33. floodmodeller_api/test/test_data/Culvert_Inlet_Outlet.feb +36 -36
  34. floodmodeller_api/test/test_data/DamBreakADI.xml +52 -52
  35. floodmodeller_api/test/test_data/DamBreakFAST.xml +58 -58
  36. floodmodeller_api/test/test_data/DamBreakFAST_dy.xml +53 -53
  37. floodmodeller_api/test/test_data/DamBreakTVD.xml +55 -55
  38. floodmodeller_api/test/test_data/DefenceBreach.xml +53 -53
  39. floodmodeller_api/test/test_data/DefenceBreachFAST.xml +60 -60
  40. floodmodeller_api/test/test_data/DefenceBreachFAST_dy.xml +55 -55
  41. floodmodeller_api/test/test_data/Domain1+2_QH.xml +76 -76
  42. floodmodeller_api/test/test_data/Domain1_H.xml +41 -41
  43. floodmodeller_api/test/test_data/Domain1_Q.xml +41 -41
  44. floodmodeller_api/test/test_data/Domain1_Q_FAST.xml +48 -48
  45. floodmodeller_api/test/test_data/Domain1_Q_FAST_dy.xml +48 -48
  46. floodmodeller_api/test/test_data/Domain1_Q_xml_expected.json +263 -0
  47. floodmodeller_api/test/test_data/Domain1_W.xml +41 -41
  48. floodmodeller_api/test/test_data/EX1.DAT +321 -321
  49. floodmodeller_api/test/test_data/EX1.ext +107 -107
  50. floodmodeller_api/test/test_data/EX1.feb +320 -320
  51. floodmodeller_api/test/test_data/EX1.gxy +107 -107
  52. floodmodeller_api/test/test_data/EX17.DAT +421 -422
  53. floodmodeller_api/test/test_data/EX17.ext +213 -213
  54. floodmodeller_api/test/test_data/EX17.feb +422 -422
  55. floodmodeller_api/test/test_data/EX18.DAT +375 -375
  56. floodmodeller_api/test/test_data/EX18_DAT_expected.json +3876 -0
  57. floodmodeller_api/test/test_data/EX2.DAT +302 -302
  58. floodmodeller_api/test/test_data/EX3.DAT +926 -926
  59. floodmodeller_api/test/test_data/EX3_DAT_expected.json +16235 -0
  60. floodmodeller_api/test/test_data/EX3_IEF_expected.json +61 -0
  61. floodmodeller_api/test/test_data/EX6.DAT +2084 -2084
  62. floodmodeller_api/test/test_data/EX6.ext +532 -532
  63. floodmodeller_api/test/test_data/EX6.feb +2084 -2084
  64. floodmodeller_api/test/test_data/EX6_DAT_expected.json +31647 -0
  65. floodmodeller_api/test/test_data/Event Data Example.DAT +336 -336
  66. floodmodeller_api/test/test_data/Event Data Example.ext +107 -107
  67. floodmodeller_api/test/test_data/Event Data Example.feb +336 -336
  68. floodmodeller_api/test/test_data/Linked1D2D.xml +52 -52
  69. floodmodeller_api/test/test_data/Linked1D2DFAST.xml +53 -53
  70. floodmodeller_api/test/test_data/Linked1D2DFAST_dy.xml +48 -48
  71. floodmodeller_api/test/test_data/Linked1D2D_xml_expected.json +313 -0
  72. floodmodeller_api/test/test_data/blockage.dat +50 -50
  73. floodmodeller_api/test/test_data/blockage.ext +45 -45
  74. floodmodeller_api/test/test_data/blockage.feb +9 -9
  75. floodmodeller_api/test/test_data/blockage.gxy +71 -71
  76. floodmodeller_api/test/test_data/conveyance_test.dat +165 -0
  77. floodmodeller_api/test/test_data/conveyance_test.feb +116 -0
  78. floodmodeller_api/test/test_data/conveyance_test.gxy +85 -0
  79. floodmodeller_api/test/test_data/defaultUnits.dat +127 -127
  80. floodmodeller_api/test/test_data/defaultUnits.ext +45 -45
  81. floodmodeller_api/test/test_data/defaultUnits.feb +9 -9
  82. floodmodeller_api/test/test_data/defaultUnits.fmpx +58 -58
  83. floodmodeller_api/test/test_data/defaultUnits.gxy +85 -85
  84. floodmodeller_api/test/test_data/ex3.ief +20 -20
  85. floodmodeller_api/test/test_data/ex3.lf1 +2800 -2800
  86. floodmodeller_api/test/test_data/ex4.DAT +1374 -1374
  87. floodmodeller_api/test/test_data/ex4_changed.DAT +1374 -1374
  88. floodmodeller_api/test/test_data/example1.inp +329 -329
  89. floodmodeller_api/test/test_data/example2.inp +158 -158
  90. floodmodeller_api/test/test_data/example3.inp +297 -297
  91. floodmodeller_api/test/test_data/example4.inp +388 -388
  92. floodmodeller_api/test/test_data/example5.inp +147 -147
  93. floodmodeller_api/test/test_data/example6.inp +154 -154
  94. floodmodeller_api/test/test_data/expected_conveyance.csv +60 -0
  95. floodmodeller_api/test/test_data/jump.dat +176 -176
  96. floodmodeller_api/test/test_data/network.dat +1374 -1374
  97. floodmodeller_api/test/test_data/network.ext +45 -45
  98. floodmodeller_api/test/test_data/network.exy +1 -1
  99. floodmodeller_api/test/test_data/network.feb +45 -45
  100. floodmodeller_api/test/test_data/network.ied +45 -45
  101. floodmodeller_api/test/test_data/network.ief +20 -20
  102. floodmodeller_api/test/test_data/network.inp +147 -147
  103. floodmodeller_api/test/test_data/network.pxy +57 -57
  104. floodmodeller_api/test/test_data/network.zzd +122 -122
  105. floodmodeller_api/test/test_data/network_dat_expected.json +21837 -0
  106. floodmodeller_api/test/test_data/network_from_tabularCSV.csv +87 -87
  107. floodmodeller_api/test/test_data/network_ied_expected.json +287 -0
  108. floodmodeller_api/test/test_data/rnweir.dat +9 -9
  109. floodmodeller_api/test/test_data/rnweir.ext +45 -45
  110. floodmodeller_api/test/test_data/rnweir.feb +9 -9
  111. floodmodeller_api/test/test_data/rnweir.gxy +45 -45
  112. floodmodeller_api/test/test_data/rnweir_default.dat +74 -74
  113. floodmodeller_api/test/test_data/rnweir_default.ext +45 -45
  114. floodmodeller_api/test/test_data/rnweir_default.feb +9 -9
  115. floodmodeller_api/test/test_data/rnweir_default.fmpx +58 -58
  116. floodmodeller_api/test/test_data/rnweir_default.gxy +53 -53
  117. floodmodeller_api/test/test_data/unit checks.dat +16 -16
  118. floodmodeller_api/test/test_ied.py +29 -29
  119. floodmodeller_api/test/test_ief.py +136 -24
  120. floodmodeller_api/test/test_inp.py +47 -48
  121. floodmodeller_api/test/test_json.py +114 -0
  122. floodmodeller_api/test/test_logs_lf.py +102 -51
  123. floodmodeller_api/test/test_tool.py +165 -152
  124. floodmodeller_api/test/test_toolbox_structure_log.py +234 -239
  125. floodmodeller_api/test/test_xml2d.py +151 -156
  126. floodmodeller_api/test/test_zzn.py +36 -34
  127. floodmodeller_api/to_from_json.py +230 -0
  128. floodmodeller_api/tool.py +332 -329
  129. floodmodeller_api/toolbox/__init__.py +5 -5
  130. floodmodeller_api/toolbox/example_tool.py +45 -45
  131. floodmodeller_api/toolbox/model_build/__init__.py +2 -2
  132. floodmodeller_api/toolbox/model_build/add_siltation_definition.py +100 -98
  133. floodmodeller_api/toolbox/model_build/structure_log/__init__.py +1 -1
  134. floodmodeller_api/toolbox/model_build/structure_log/structure_log.py +287 -289
  135. floodmodeller_api/toolbox/model_build/structure_log_definition.py +76 -76
  136. floodmodeller_api/units/__init__.py +10 -10
  137. floodmodeller_api/units/_base.py +214 -212
  138. floodmodeller_api/units/boundaries.py +467 -467
  139. floodmodeller_api/units/comment.py +52 -55
  140. floodmodeller_api/units/conduits.py +382 -402
  141. floodmodeller_api/units/conveyance.py +301 -0
  142. floodmodeller_api/units/helpers.py +123 -131
  143. floodmodeller_api/units/iic.py +107 -101
  144. floodmodeller_api/units/losses.py +305 -306
  145. floodmodeller_api/units/sections.py +465 -446
  146. floodmodeller_api/units/structures.py +1690 -1683
  147. floodmodeller_api/units/units.py +93 -104
  148. floodmodeller_api/units/unsupported.py +44 -44
  149. floodmodeller_api/units/variables.py +87 -89
  150. floodmodeller_api/urban1d/__init__.py +11 -11
  151. floodmodeller_api/urban1d/_base.py +188 -179
  152. floodmodeller_api/urban1d/conduits.py +93 -85
  153. floodmodeller_api/urban1d/general_parameters.py +58 -58
  154. floodmodeller_api/urban1d/junctions.py +81 -79
  155. floodmodeller_api/urban1d/losses.py +81 -74
  156. floodmodeller_api/urban1d/outfalls.py +114 -110
  157. floodmodeller_api/urban1d/raingauges.py +111 -111
  158. floodmodeller_api/urban1d/subsections.py +92 -98
  159. floodmodeller_api/urban1d/xsections.py +147 -144
  160. floodmodeller_api/util.py +119 -21
  161. floodmodeller_api/validation/parameters.py +660 -660
  162. floodmodeller_api/validation/urban_parameters.py +388 -404
  163. floodmodeller_api/validation/validation.py +110 -108
  164. floodmodeller_api/version.py +1 -1
  165. floodmodeller_api/xml2d.py +632 -673
  166. floodmodeller_api/xml2d_template.py +37 -37
  167. floodmodeller_api/zzn.py +414 -363
  168. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.4.dist-info}/LICENSE.txt +13 -13
  169. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.4.dist-info}/METADATA +85 -82
  170. floodmodeller_api-0.4.4.dist-info/RECORD +185 -0
  171. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.4.dist-info}/WHEEL +1 -1
  172. floodmodeller_api/libifcoremd.dll +0 -0
  173. floodmodeller_api/test/test_data/EX3.bmp +0 -0
  174. floodmodeller_api/test/test_data/test_output.csv +0 -87
  175. floodmodeller_api/zzn_read.dll +0 -0
  176. floodmodeller_api-0.4.2.post1.dist-info/RECORD +0 -164
  177. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.4.dist-info}/entry_points.txt +0 -0
  178. {floodmodeller_api-0.4.2.post1.dist-info → floodmodeller_api-0.4.4.dist-info}/top_level.txt +0 -0
floodmodeller_api/diff.py CHANGED
@@ -1,119 +1,136 @@
1
- """
2
- Flood Modeller Python API
3
- Copyright (C) 2023 Jacobs U.K. Limited
4
-
5
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
6
- as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
7
-
8
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10
-
11
- You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
12
-
13
- If you have any query about this program or this License, please contact us at support@floodmodeller.com or write to the following
14
- address: Jacobs UK Limited, Flood Modeller, Cottons Centre, Cottons Lane, London, SE1 2QG, United Kingdom.
15
- """
16
-
17
- import pandas as pd
18
-
19
-
20
- def check_item_with_dataframe_equal(item_a, item_b, name, diff, special_types=()): # noqa: C901
21
- result = True
22
- try:
23
- if isinstance(item_a, dict):
24
- result, diff = check_dict_with_dataframe_equal(
25
- item_a, item_b, name, diff, special_types
26
- )
27
- elif isinstance(item_a, list):
28
- result, diff = check_list_with_dataframe_equal(
29
- item_a, item_b, name, diff, special_types
30
- )
31
- elif isinstance(item_a, (pd.DataFrame, pd.Series)):
32
- if not item_a.equals(item_b):
33
- result = False
34
- if isinstance(item_a, pd.Series):
35
- item_a = pd.DataFrame(item_a).reset_index()
36
- item_b = pd.DataFrame(item_b).reset_index()
37
-
38
- df_diff = pd.concat([item_a, item_b]).drop_duplicates(keep=False)
39
- rows = df_diff.index.unique().to_list()
40
- msg = f"{len(rows)} row(s) not equal:\n"
41
- row_diffs = []
42
- for row in rows:
43
- for col in df_diff.columns:
44
- if True not in df_diff.loc[row, col].duplicated().values:
45
- vals = df_diff.loc[row, col].values
46
- row_diffs.append(
47
- f" Row: {row}, Col: '{col}' - left: {vals[0]}, right: {vals[1]}"
48
- )
49
- msg += "\n".join(row_diffs)
50
- diff.append((name, msg))
51
- elif isinstance(item_a, special_types):
52
- # item is a Unit or other fmapi class
53
- result, new_diff = item_a._get_diff(item_b)
54
- new_diff = [(f"{name}->{new_name}", new_item) for new_name, new_item in new_diff]
55
- diff.extend(new_diff)
56
- else:
57
- if not item_a == item_b:
58
- result = False
59
- diff.append((name, f"{item_a} != {item_b}"))
60
- except Exception as e:
61
- result = False
62
- diff.append((name, f"Error encountered when comparing: {e.args[0]}"))
63
-
64
- return result, diff
65
-
66
-
67
- def check_dict_with_dataframe_equal(dict_a, dict_b, name, diff, special_types):
68
- """Used to recursively check equivalence where there may be dataframe objects"""
69
- result = True
70
- try:
71
- for key, item in dict_a.items():
72
- try:
73
- _result, diff = check_item_with_dataframe_equal(
74
- item,
75
- dict_b[key],
76
- name=f"{name}->{key}",
77
- diff=diff,
78
- special_types=special_types,
79
- )
80
- if not _result:
81
- result = False
82
- except KeyError as ke:
83
- result = False
84
- diff.append((name, f"Key: '{ke.args[0]}' missing in other"))
85
- continue
86
-
87
- for key in dict_b.keys():
88
- if key not in dict_a:
89
- result = False
90
- diff.append((name, f"Key: {key} missing from first object"))
91
- except Exception:
92
- result = False
93
- diff.append((name, "Error encountered when comparing"))
94
-
95
- return result, diff
96
-
97
-
98
- def check_list_with_dataframe_equal(list_a, list_b, name, diff, special_types):
99
- result = True
100
- try:
101
- for idx, item in enumerate(list_a):
102
- _result, diff = check_item_with_dataframe_equal(
103
- item,
104
- list_b[idx],
105
- name=f"{name}->itm[{idx}]",
106
- diff=diff,
107
- special_types=special_types,
108
- )
109
- if not _result:
110
- result = False
111
-
112
- if len(list_a) != len(list_b):
113
- result = False
114
- diff.append((name, "Mismatch in list length"))
115
- except Exception:
116
- result = False
117
- diff.append((name, "Error encountered when comparing"))
118
-
119
- return result, diff
1
+ """
2
+ Flood Modeller Python API
3
+ Copyright (C) 2024 Jacobs U.K. Limited
4
+
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
6
+ as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10
+
11
+ You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
12
+
13
+ If you have any query about this program or this License, please contact us at support@floodmodeller.com or write to the following
14
+ address: Jacobs UK Limited, Flood Modeller, Cottons Centre, Cottons Lane, London, SE1 2QG, United Kingdom.
15
+ """
16
+
17
+ import pandas as pd
18
+
19
+
20
+ def check_item_with_dataframe_equal( # noqa: C901, PLR0912
21
+ item_a,
22
+ item_b,
23
+ name,
24
+ diff,
25
+ special_types=(),
26
+ ):
27
+ result = True
28
+ try:
29
+ if isinstance(item_a, dict):
30
+ result, diff = check_dict_with_dataframe_equal(
31
+ item_a,
32
+ item_b,
33
+ name,
34
+ diff,
35
+ special_types,
36
+ )
37
+ elif isinstance(item_a, list):
38
+ result, diff = check_list_with_dataframe_equal(
39
+ item_a,
40
+ item_b,
41
+ name,
42
+ diff,
43
+ special_types,
44
+ )
45
+ elif isinstance(item_a, (pd.DataFrame, pd.Series)):
46
+ if isinstance(item_a.index, pd.RangeIndex):
47
+ item_a.index = item_a.index.astype("int")
48
+ if isinstance(item_b.index, pd.RangeIndex):
49
+ item_b.index = item_b.index.astype("int")
50
+ if not item_a.equals(item_b) and len(item_a) + len(item_b) != 0:
51
+ result = False
52
+ if isinstance(item_a, pd.Series):
53
+ item_a = pd.DataFrame(item_a).reset_index()
54
+ item_b = pd.DataFrame(item_b).reset_index()
55
+
56
+ df_diff = pd.concat([item_a, item_b]).drop_duplicates(keep=False)
57
+ rows = df_diff.index.unique().to_list()
58
+ msg = f"{len(rows)} row(s) not equal:\n"
59
+ row_diffs = []
60
+ for row in rows:
61
+ for col in df_diff.columns:
62
+ if True not in df_diff.loc[row, col].duplicated().values:
63
+ vals = df_diff.loc[row, col].values
64
+ row_diffs.append(
65
+ f" Row: {row}, Col: '{col}' - left: {vals[0]}, right: {vals[1]}",
66
+ )
67
+ msg += "\n".join(row_diffs)
68
+ diff.append((name, msg))
69
+ elif isinstance(item_a, special_types):
70
+ # item is a Unit or other fmapi class
71
+ result, new_diff = item_a._get_diff(item_b)
72
+ new_diff = [(f"{name}->{new_name}", new_item) for new_name, new_item in new_diff]
73
+ diff.extend(new_diff)
74
+ elif item_a != item_b:
75
+ result = False
76
+ diff.append((name, f"{item_a} != {item_b}"))
77
+ except Exception as e:
78
+ result = False
79
+ diff.append((name, f"Error encountered when comparing: {e.args[0]}"))
80
+
81
+ return result, diff
82
+
83
+
84
+ def check_dict_with_dataframe_equal(dict_a, dict_b, name, diff, special_types):
85
+ """Used to recursively check equivalence where there may be dataframe objects"""
86
+ result = True
87
+ try:
88
+ for key, item in dict_a.items():
89
+ try:
90
+ _result, diff = check_item_with_dataframe_equal(
91
+ item,
92
+ dict_b[key],
93
+ name=f"{name}->{key}",
94
+ diff=diff,
95
+ special_types=special_types,
96
+ )
97
+ if not _result:
98
+ result = False
99
+ except KeyError as ke:
100
+ result = False
101
+ diff.append((name, f"Key: '{ke.args[0]}' missing in other"))
102
+ continue
103
+
104
+ for key in dict_b:
105
+ if key not in dict_a:
106
+ result = False
107
+ diff.append((name, f"Key: {key} missing from first object"))
108
+ except Exception:
109
+ result = False
110
+ diff.append((name, "Error encountered when comparing"))
111
+
112
+ return result, diff
113
+
114
+
115
+ def check_list_with_dataframe_equal(list_a, list_b, name, diff, special_types):
116
+ result = True
117
+ try:
118
+ for idx, item in enumerate(list_a):
119
+ _result, diff = check_item_with_dataframe_equal(
120
+ item,
121
+ list_b[idx],
122
+ name=f"{name}->itm[{idx}]",
123
+ diff=diff,
124
+ special_types=special_types,
125
+ )
126
+ if not _result:
127
+ result = False
128
+
129
+ if len(list_a) != len(list_b):
130
+ result = False
131
+ diff.append((name, "Mismatch in list length"))
132
+ except Exception:
133
+ result = False
134
+ diff.append((name, "Error encountered when comparing"))
135
+
136
+ return result, diff