tilupy 0.1.5__py3-none-any.whl → 1.0.0__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.
Potentially problematic release.
This version of tilupy might be problematic. Click here for more details.
- tilupy/cmd.py +114 -60
- tilupy/models/shaltop/initsimus.py +161 -49
- tilupy/models/shaltop/read.py +319 -164
- tilupy/notations.py +332 -47
- tilupy/plot.py +440 -187
- tilupy/read.py +817 -235
- tilupy/utils.py +99 -71
- {tilupy-0.1.5.dist-info → tilupy-1.0.0.dist-info}/METADATA +1 -1
- {tilupy-0.1.5.dist-info → tilupy-1.0.0.dist-info}/RECORD +13 -13
- {tilupy-0.1.5.dist-info → tilupy-1.0.0.dist-info}/LICENSE +0 -0
- {tilupy-0.1.5.dist-info → tilupy-1.0.0.dist-info}/WHEEL +0 -0
- {tilupy-0.1.5.dist-info → tilupy-1.0.0.dist-info}/entry_points.txt +0 -0
- {tilupy-0.1.5.dist-info → tilupy-1.0.0.dist-info}/top_level.txt +0 -0
tilupy/notations.py
CHANGED
|
@@ -5,38 +5,321 @@ Created on Thu Jun 3 12:20:34 2021
|
|
|
5
5
|
|
|
6
6
|
@author: peruzzetto
|
|
7
7
|
"""
|
|
8
|
-
import
|
|
9
|
-
LABELS = dict(h='Thickness (m)',
|
|
10
|
-
h_max='Maximum thickness (m)',
|
|
11
|
-
u_max='Maximum velocity (m)',
|
|
12
|
-
h_final='Final thickness (m)',
|
|
13
|
-
h_initial='Initial thickness (m)',
|
|
14
|
-
u='Velocity (m s$^{-1}$)')
|
|
8
|
+
import pandas as pd
|
|
15
9
|
|
|
10
|
+
LABEL_OPTIONS = dict(language="english", label_type="symbol")
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
|
|
13
|
+
class Notation:
|
|
14
|
+
def __init__(
|
|
15
|
+
self, name, long_name=None, gender=None, symbol=None, unit=None
|
|
16
|
+
):
|
|
17
|
+
self.name = name
|
|
18
|
+
self.long_name = long_name
|
|
19
|
+
self.gender = gender
|
|
20
|
+
self.symbol = symbol
|
|
21
|
+
self.unit = unit
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def unit(self):
|
|
25
|
+
return self._unit
|
|
26
|
+
|
|
27
|
+
@unit.setter
|
|
28
|
+
def unit(self, value):
|
|
29
|
+
if value is None:
|
|
30
|
+
self._unit = None
|
|
31
|
+
else:
|
|
32
|
+
self._unit = value
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def gender(self):
|
|
36
|
+
return self._gender
|
|
37
|
+
|
|
38
|
+
@gender.setter
|
|
39
|
+
def gender(self, value):
|
|
40
|
+
if value is None:
|
|
41
|
+
self._gender = Gender()
|
|
42
|
+
elif isinstance(value, dict):
|
|
43
|
+
self._gender = Gender(**value)
|
|
44
|
+
else:
|
|
45
|
+
self._gender = value
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def long_name(self):
|
|
49
|
+
return self._long_name
|
|
50
|
+
|
|
51
|
+
@long_name.setter
|
|
52
|
+
def long_name(self, value):
|
|
53
|
+
if value is None:
|
|
54
|
+
self._long_name = LongName()
|
|
55
|
+
elif isinstance(value, dict):
|
|
56
|
+
self._long_name = LongName(**value)
|
|
57
|
+
else:
|
|
58
|
+
self._long_name = value
|
|
59
|
+
|
|
60
|
+
def get_long_name(self, language=None, gender=None):
|
|
61
|
+
if isinstance(self.long_name, str):
|
|
62
|
+
return self.long_name
|
|
63
|
+
|
|
64
|
+
if language is None:
|
|
65
|
+
language = LABEL_OPTIONS["language"]
|
|
66
|
+
|
|
67
|
+
res = getattr(self.long_name, language)
|
|
68
|
+
if gender is not None:
|
|
69
|
+
res = res[gender]
|
|
70
|
+
|
|
71
|
+
return res
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class Unit(pd.Series):
|
|
75
|
+
UNITS = ["Pa", "N", "kg", "m", "s"]
|
|
76
|
+
|
|
77
|
+
def __init__(self, series=None, **kwargs):
|
|
78
|
+
if series is not None:
|
|
79
|
+
super().__init__(series)
|
|
80
|
+
else:
|
|
81
|
+
super().__init__()
|
|
82
|
+
for key in kwargs:
|
|
83
|
+
if key not in Unit.UNITS:
|
|
84
|
+
raise ValueError("unrecognized unit")
|
|
85
|
+
self[key] = kwargs[key]
|
|
86
|
+
|
|
87
|
+
def __mul__(self, other):
|
|
88
|
+
tmp = self.add(other, fill_value=0)
|
|
89
|
+
return Unit(tmp[tmp != 0])
|
|
90
|
+
|
|
91
|
+
def get_label(self):
|
|
92
|
+
if self.empty:
|
|
93
|
+
return ""
|
|
94
|
+
|
|
95
|
+
positives = self[self >= 1].reindex(Unit.UNITS).dropna()
|
|
96
|
+
negatives = self[self < 0].reindex(Unit.UNITS).dropna()
|
|
97
|
+
text_label = [
|
|
98
|
+
index + "$^{:.0f}$".format(positives[index])
|
|
99
|
+
for index in positives.index
|
|
100
|
+
]
|
|
101
|
+
text_label += [
|
|
102
|
+
index + "$^{{{:.0f}}}$".format(negatives[index])
|
|
103
|
+
for index in negatives.index
|
|
104
|
+
]
|
|
105
|
+
text_label = " ".join(text_label)
|
|
106
|
+
text_label = text_label.replace("$^1$", "")
|
|
107
|
+
|
|
108
|
+
return text_label
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class LongName(object):
|
|
112
|
+
def __init__(self, **kwargs):
|
|
113
|
+
self.__dict__.update(kwargs)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class Gender(object):
|
|
117
|
+
def __init__(self, **kwargs):
|
|
118
|
+
self.__dict__.update(kwargs)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
NOTATIONS = dict()
|
|
122
|
+
|
|
123
|
+
NOTATIONS["x"] = Notation(
|
|
124
|
+
"x",
|
|
125
|
+
symbol="X",
|
|
126
|
+
unit=Unit(m=1),
|
|
127
|
+
long_name=LongName(english="X", french="X"),
|
|
128
|
+
gender=Gender(english=None, french="f"),
|
|
129
|
+
)
|
|
130
|
+
NOTATIONS["y"] = Notation(
|
|
131
|
+
"y",
|
|
132
|
+
symbol="Y",
|
|
133
|
+
unit=Unit(m=1),
|
|
134
|
+
long_name=LongName(english="Y", french="Y"),
|
|
135
|
+
gender=Gender(english=None, french="f"),
|
|
136
|
+
)
|
|
137
|
+
NOTATIONS["t"] = Notation(
|
|
138
|
+
"t",
|
|
139
|
+
symbol="t",
|
|
140
|
+
unit=Unit(s=1),
|
|
141
|
+
long_name=LongName(english="Time", french="Temps"),
|
|
142
|
+
gender=Gender(english=None, french="m"),
|
|
143
|
+
)
|
|
144
|
+
NOTATIONS["xy"] = Notation(
|
|
145
|
+
"xy",
|
|
146
|
+
symbol="XY",
|
|
147
|
+
unit=Unit(m=2),
|
|
148
|
+
long_name=LongName(english="Time", french="Temps"),
|
|
149
|
+
gender=Gender(english=None, french="m"),
|
|
150
|
+
)
|
|
151
|
+
NOTATIONS["h"] = Notation(
|
|
152
|
+
"h",
|
|
153
|
+
symbol="h",
|
|
154
|
+
unit=Unit(m=1),
|
|
155
|
+
long_name=LongName(english="thickness", french="épaisseur"),
|
|
156
|
+
gender=Gender(english=None, french="f"),
|
|
157
|
+
)
|
|
158
|
+
NOTATIONS["hvert"] = Notation(
|
|
159
|
+
"hvert",
|
|
160
|
+
symbol="h^v",
|
|
161
|
+
unit=Unit(m=1),
|
|
162
|
+
long_name=LongName(
|
|
163
|
+
english="vertical thickness", french="épaisseur verticale"
|
|
164
|
+
),
|
|
165
|
+
gender=Gender(english=None, french="f"),
|
|
166
|
+
)
|
|
167
|
+
NOTATIONS["u"] = Notation(
|
|
168
|
+
"u",
|
|
169
|
+
symbol="u",
|
|
170
|
+
unit=Unit(m=1, s=-1),
|
|
171
|
+
long_name=LongName(english="velocity", french="vitesse"),
|
|
172
|
+
gender=Gender(english=None, french="f"),
|
|
173
|
+
)
|
|
174
|
+
NOTATIONS["hu"] = Notation(
|
|
175
|
+
"hu",
|
|
176
|
+
symbol="hu",
|
|
177
|
+
unit=Unit(m=2, s=-1),
|
|
178
|
+
long_name=None,
|
|
179
|
+
gender=None,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
NOTATIONS["max"] = Notation(
|
|
183
|
+
"max",
|
|
184
|
+
symbol="max",
|
|
185
|
+
unit=None,
|
|
186
|
+
long_name=LongName(
|
|
187
|
+
english="maximum", french=dict(m="maximum", f="maximale")
|
|
188
|
+
),
|
|
189
|
+
gender=None,
|
|
190
|
+
)
|
|
191
|
+
NOTATIONS["int"] = Notation(
|
|
192
|
+
"int",
|
|
193
|
+
symbol="int",
|
|
194
|
+
unit=None,
|
|
195
|
+
long_name=LongName(
|
|
196
|
+
english="maximum", french=dict(m="maximum", f="maximale")
|
|
197
|
+
),
|
|
198
|
+
gender=None,
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def get_notation(name, language=None):
|
|
203
|
+
try:
|
|
204
|
+
notation = NOTATIONS[name]
|
|
205
|
+
except KeyError:
|
|
206
|
+
strings = name.split("_")
|
|
207
|
+
if len(strings) == 1:
|
|
208
|
+
notation = Notation(
|
|
209
|
+
name, symbol=name, unit=None, long_name=name, gender=None
|
|
210
|
+
)
|
|
211
|
+
else:
|
|
212
|
+
state = get_notation(strings[0])
|
|
213
|
+
operator = get_notation(strings[1])
|
|
214
|
+
if len(strings) == 3:
|
|
215
|
+
axis = strings[2]
|
|
216
|
+
else:
|
|
217
|
+
axis = None
|
|
218
|
+
notation = add_operator(
|
|
219
|
+
state, operator, axis=axis, language=language
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
return notation
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def get_operator_unit(name, axis):
|
|
226
|
+
if name == "int":
|
|
227
|
+
if axis == "t" or axis is None:
|
|
228
|
+
unit = Unit(s=1)
|
|
229
|
+
if axis in ["x", "y"]:
|
|
230
|
+
unit = Unit(m=1)
|
|
231
|
+
if axis == "xy":
|
|
232
|
+
unit = Unit(m=2)
|
|
233
|
+
else:
|
|
234
|
+
unit = Unit(pd.Series())
|
|
235
|
+
return unit
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def make_long_name(notation, operator, language=None):
|
|
239
|
+
if language is None:
|
|
240
|
+
language = LABEL_OPTIONS["language"]
|
|
241
|
+
|
|
242
|
+
str_notation = notation.get_long_name(language=language)
|
|
243
|
+
try:
|
|
244
|
+
gender = gender = getattr(notation.gender, language)
|
|
245
|
+
except AttributeError:
|
|
246
|
+
gender = None
|
|
247
|
+
str_operator = operator.get_long_name(language=language, gender=gender)
|
|
248
|
+
|
|
249
|
+
if language == "english":
|
|
250
|
+
res = str_operator + " " + str_notation
|
|
251
|
+
elif language == "french":
|
|
252
|
+
res = str_notation + " " + str_operator
|
|
253
|
+
|
|
254
|
+
return res
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def add_operator(notation, operator, axis=None, language=None):
|
|
258
|
+
if isinstance(operator, str):
|
|
259
|
+
operator = get_notation(operator)
|
|
260
|
+
|
|
261
|
+
if isinstance(notation, str):
|
|
262
|
+
notation = get_notation(notation)
|
|
263
|
+
|
|
264
|
+
operator_symbol = operator.symbol
|
|
265
|
+
if axis is not None:
|
|
266
|
+
operator_symbol += "({})".format(axis)
|
|
267
|
+
|
|
268
|
+
unit_operator = get_operator_unit(operator.name, axis)
|
|
269
|
+
|
|
270
|
+
if operator.name == "int":
|
|
271
|
+
if axis is None:
|
|
272
|
+
ll = "t" # If axis is not specified by default integration is over time
|
|
273
|
+
else:
|
|
274
|
+
ll = axis
|
|
275
|
+
symbol = "\\int_{{{}}} {}".format(ll, notation.symbol)
|
|
276
|
+
else:
|
|
277
|
+
operator_symbol = operator.symbol
|
|
278
|
+
if axis is not None:
|
|
279
|
+
operator_symbol += "({})".format(axis)
|
|
280
|
+
symbol = notation.symbol + "_{{{}}}".format(operator_symbol)
|
|
281
|
+
|
|
282
|
+
if notation.unit is None:
|
|
283
|
+
unit = None
|
|
284
|
+
else:
|
|
285
|
+
unit = notation.unit * unit_operator
|
|
286
|
+
|
|
287
|
+
res = Notation(
|
|
288
|
+
name=notation.name + "_" + operator.name,
|
|
289
|
+
symbol=symbol,
|
|
290
|
+
unit=unit,
|
|
291
|
+
long_name=make_long_name(notation, operator, language=language),
|
|
292
|
+
)
|
|
293
|
+
return res
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def get_label(notation, with_unit=True, label_type=None, language=None):
|
|
297
|
+
if isinstance(notation, str):
|
|
298
|
+
notation = get_notation(notation)
|
|
299
|
+
|
|
300
|
+
if label_type is None:
|
|
301
|
+
label_type = LABEL_OPTIONS["label_type"]
|
|
19
302
|
if language is None:
|
|
20
|
-
language =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
303
|
+
language = LABEL_OPTIONS["language"]
|
|
304
|
+
|
|
305
|
+
if label_type == "litteral":
|
|
306
|
+
label = notation.get_long_name(language=language, gender=None)
|
|
307
|
+
elif label_type == "symbol":
|
|
308
|
+
label = "$" + notation.symbol + "$"
|
|
309
|
+
|
|
310
|
+
if with_unit and notation.unit is not None:
|
|
311
|
+
unit_string = notation.unit.get_label()
|
|
312
|
+
# Add unit only if string is not empty
|
|
313
|
+
if unit_string:
|
|
314
|
+
label = label + " ({})".format(unit_string)
|
|
315
|
+
|
|
316
|
+
return label
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def set_label_options(**kwargs):
|
|
320
|
+
global LABEL_OPTIONS
|
|
321
|
+
LABEL_OPTIONS.update(**kwargs)
|
|
322
|
+
|
|
40
323
|
|
|
41
324
|
def readme_to_params(file, readme_param_match=None):
|
|
42
325
|
"""
|
|
@@ -56,7 +339,7 @@ def readme_to_params(file, readme_param_match=None):
|
|
|
56
339
|
|
|
57
340
|
"""
|
|
58
341
|
params = dict()
|
|
59
|
-
with open(file,
|
|
342
|
+
with open(file, "r") as f:
|
|
60
343
|
if readme_param_match is not None:
|
|
61
344
|
for line in f:
|
|
62
345
|
(key, val) = line.split()
|
|
@@ -70,15 +353,15 @@ def readme_to_params(file, readme_param_match=None):
|
|
|
70
353
|
return params
|
|
71
354
|
|
|
72
355
|
|
|
73
|
-
def make_rheol_string_fmt(rheoldict, law=
|
|
356
|
+
def make_rheol_string_fmt(rheoldict, law="coulomb"):
|
|
74
357
|
"""Make string from rheological parameters."""
|
|
75
|
-
text =
|
|
76
|
-
for name in [
|
|
358
|
+
text = ""
|
|
359
|
+
for name in ["delta1", "delta2", "delta3", "delta4"]:
|
|
77
360
|
if name in rheoldict:
|
|
78
|
-
new_txt = name +
|
|
361
|
+
new_txt = name + "_{:05.2f}_"
|
|
79
362
|
text += new_txt
|
|
80
|
-
if
|
|
81
|
-
new_txt = name +
|
|
363
|
+
if "ksi" in rheoldict:
|
|
364
|
+
new_txt = name + "ksi_{:06.1f}_"
|
|
82
365
|
text += new_txt
|
|
83
366
|
text = text[:-1]
|
|
84
367
|
|
|
@@ -98,17 +381,19 @@ def make_rheol_string(rheoldict, law):
|
|
|
98
381
|
texts = []
|
|
99
382
|
|
|
100
383
|
for i in range(nparams):
|
|
101
|
-
if law ==
|
|
102
|
-
txt_fmt =
|
|
103
|
-
text = txt_fmt.format(rheoldict[
|
|
104
|
-
if law ==
|
|
105
|
-
txt_fmt =
|
|
106
|
-
text = txt_fmt.format(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
384
|
+
if law == "coulomb":
|
|
385
|
+
txt_fmt = "delta1_{:05.2f}"
|
|
386
|
+
text = txt_fmt.format(rheoldict["delta1"][i]).replace(".", "p")
|
|
387
|
+
if law == "voellmy":
|
|
388
|
+
txt_fmt = "delta1_{:05.2f}_ksi_{:06.1f}"
|
|
389
|
+
text = txt_fmt.format(
|
|
390
|
+
rheoldict["delta1"][i], rheoldict["ksi"][i]
|
|
391
|
+
).replace(".", "p")
|
|
392
|
+
if law == "pouliquen_2002":
|
|
393
|
+
txt_fmt = "delta1_{:05.2f}_L_{:05.2f}"
|
|
394
|
+
text = txt_fmt.format(
|
|
395
|
+
rheoldict["delta1"][i], rheoldict["wlong"][i]
|
|
396
|
+
).replace(".", "p")
|
|
112
397
|
texts.append(text)
|
|
113
398
|
|
|
114
399
|
if nparams == 1:
|