dgpost 2.2.2__tar.gz → 2.3__tar.gz

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 (64) hide show
  1. {dgpost-2.2.2/src/dgpost.egg-info → dgpost-2.3}/PKG-INFO +1 -1
  2. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/main.py +0 -1
  3. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/catalysis.py +12 -3
  4. dgpost-2.3/src/dgpost/transform/complex.py +108 -0
  5. dgpost-2.3/src/dgpost/transform/mixtures.py +93 -0
  6. dgpost-2.3/src/dgpost/transform/table.py +523 -0
  7. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/helpers.py +39 -1
  8. {dgpost-2.2.2 → dgpost-2.3/src/dgpost.egg-info}/PKG-INFO +1 -1
  9. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost.egg-info/SOURCES.txt +5 -0
  10. {dgpost-2.2.2 → dgpost-2.3}/tests/test_catalysis_atbal.py +11 -0
  11. {dgpost-2.2.2 → dgpost-2.3}/tests/test_catalysis_conversion.py +29 -0
  12. dgpost-2.3/tests/test_complex.py +89 -0
  13. {dgpost-2.2.2 → dgpost-2.3}/tests/test_extract.py +13 -0
  14. dgpost-2.3/tests/test_mixtures_flowtofraction.py +23 -0
  15. dgpost-2.3/tests/test_table_apply_linear.py +193 -0
  16. dgpost-2.2.2/src/dgpost/transform/table.py +0 -250
  17. {dgpost-2.2.2 → dgpost-2.3}/LICENSE +0 -0
  18. {dgpost-2.2.2 → dgpost-2.3}/README.md +0 -0
  19. {dgpost-2.2.2 → dgpost-2.3}/pyproject.toml +0 -0
  20. {dgpost-2.2.2 → dgpost-2.3}/setup.cfg +0 -0
  21. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/__init__.py +0 -0
  22. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/__init__.py +0 -0
  23. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/chromatography.py +0 -0
  24. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/circuit_utils/__init__.py +0 -0
  25. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/circuit_utils/circuit_components.py +0 -0
  26. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/circuit_utils/circuit_parser.py +0 -0
  27. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/electrochemistry.py +0 -0
  28. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/impedance.py +0 -0
  29. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/rates.py +0 -0
  30. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/transform/reflection.py +0 -0
  31. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/__init__.py +0 -0
  32. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/extract.py +0 -0
  33. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/load.py +0 -0
  34. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/parse.py +0 -0
  35. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/pivot.py +0 -0
  36. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/plot.py +0 -0
  37. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/save.py +0 -0
  38. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost/utils/transform.py +0 -0
  39. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost.egg-info/dependency_links.txt +0 -0
  40. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost.egg-info/entry_points.txt +0 -0
  41. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost.egg-info/requires.txt +0 -0
  42. {dgpost-2.2.2 → dgpost-2.3}/src/dgpost.egg-info/top_level.txt +0 -0
  43. {dgpost-2.2.2 → dgpost-2.3}/tests/test_catalysis_selectivity.py +0 -0
  44. {dgpost-2.2.2 → dgpost-2.3}/tests/test_catalysis_yield.py +0 -0
  45. {dgpost-2.2.2 → dgpost-2.3}/tests/test_chromatography.py +0 -0
  46. {dgpost-2.2.2 → dgpost-2.3}/tests/test_electrochemistry_charge.py +0 -0
  47. {dgpost-2.2.2 → dgpost-2.3}/tests/test_electrochemistry_current.py +0 -0
  48. {dgpost-2.2.2 → dgpost-2.3}/tests/test_electrochemistry_fe.py +0 -0
  49. {dgpost-2.2.2 → dgpost-2.3}/tests/test_electrochemistry_nernst.py +0 -0
  50. {dgpost-2.2.2 → dgpost-2.3}/tests/test_impedance.py +0 -0
  51. {dgpost-2.2.2 → dgpost-2.3}/tests/test_load.py +0 -0
  52. {dgpost-2.2.2 → dgpost-2.3}/tests/test_main.py +0 -0
  53. {dgpost-2.2.2 → dgpost-2.3}/tests/test_parse.py +0 -0
  54. {dgpost-2.2.2 → dgpost-2.3}/tests/test_pivot.py +0 -0
  55. {dgpost-2.2.2 → dgpost-2.3}/tests/test_plot.py +0 -0
  56. {dgpost-2.2.2 → dgpost-2.3}/tests/test_rates_batchtomolar.py +0 -0
  57. {dgpost-2.2.2 → dgpost-2.3}/tests/test_rates_flowtomolar.py +0 -0
  58. {dgpost-2.2.2 → dgpost-2.3}/tests/test_realworld.py +0 -0
  59. {dgpost-2.2.2 → dgpost-2.3}/tests/test_reflection.py +0 -0
  60. {dgpost-2.2.2 → dgpost-2.3}/tests/test_roundtrip.py +0 -0
  61. {dgpost-2.2.2 → dgpost-2.3}/tests/test_save.py +0 -0
  62. {dgpost-2.2.2 → dgpost-2.3}/tests/test_table_combine_columns.py +0 -0
  63. {dgpost-2.2.2 → dgpost-2.3}/tests/test_table_combine_namespaces.py +0 -0
  64. {dgpost-2.2.2 → dgpost-2.3}/tests/test_table_set_uncertainty.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dgpost
3
- Version: 2.2.2
3
+ Version: 2.3
4
4
  Summary: datagram post-processing toolkit
5
5
  Author: Ueli Sauter
6
6
  Author-email: Peter Kraus <peter.kraus@tu-berlin.de>
@@ -97,7 +97,6 @@ def run(path: str, patch: str = None) -> tuple[dict, dict]:
97
97
  if saveas in tables:
98
98
  temp = combine_tables(tables[saveas], newdf)
99
99
  temp.attrs = tables[saveas].attrs
100
- temp.attrs["units"].update(newdf.attrs["units"])
101
100
  tables[saveas] = temp
102
101
  else:
103
102
  tables[saveas] = newdf
@@ -208,7 +208,8 @@ def conversion(
208
208
  standard,
209
209
  )
210
210
  sd = smiles[name_to_chem(standard).smiles]
211
- exp = inp[sd["inp"]] / out[sd["out"]]
211
+ temp = np.where(out[sd["out"]] > 0, out[sd["out"]], np.nan)
212
+ exp = inp[sd["inp"]] / temp
212
213
 
213
214
  # reactant-based conversion
214
215
  if type == "reactant":
@@ -216,7 +217,8 @@ def conversion(
216
217
  assert "out" in fd, f"Feedstock '{feedstock}' not in outlet."
217
218
  logger.debug("Calculating reactant-based conversion.")
218
219
  dfsm = inp[fd["inp"]] - out[fd["out"]] * exp
219
- Xr = dfsm / inp[fd["inp"]]
220
+ f_in = np.where(inp[fd["inp"]] > 0, inp[fd["inp"]], np.nan)
221
+ Xr = dfsm / f_in
220
222
  tag = f"{'Xr' if output is None else output}->{feedstock}"
221
223
  ret = {tag: Xr}
222
224
 
@@ -224,6 +226,7 @@ def conversion(
224
226
  else:
225
227
  assert "inp" in fd, f"Feedstock '{feedstock}' not in inlet."
226
228
  f_in = inp[fd["inp"]] * element_from_formula(fform, element)
229
+ f_in = np.where(f_in > 0, f_in, np.nan)
227
230
  nat_out = f_in * 0.0
228
231
 
229
232
  if "out" in fd:
@@ -241,6 +244,7 @@ def conversion(
241
244
  nat_out += dnat
242
245
  if type == "product":
243
246
  logger.debug("Calculating product-based conversion using reactant outlet.")
247
+ nat_out = np.where(nat_out > 0, nat_out, np.nan)
244
248
  Xp = (nat_out - f_out) / nat_out
245
249
  prefix = f"Xp_{element}" if output is None else output
246
250
  elif type == "mixed":
@@ -342,6 +346,8 @@ def selectivity(
342
346
  nat_out = dnat
343
347
  else:
344
348
  nat_out += dnat
349
+
350
+ nat_out = np.where(nat_out > 0, nat_out, np.nan)
345
351
  ret = {}
346
352
  for k, v in smiles.items():
347
353
  if k != fsmi and "out" in v:
@@ -523,7 +529,8 @@ def atom_balance(
523
529
 
524
530
  if rin is None:
525
531
  sd = smiles[name_to_chem(standard).smiles]
526
- exp = inp[sd["inp"]] / out[sd["out"]]
532
+ temp = np.where(out[sd["out"]] > 0, out[sd["out"]], np.nan)
533
+ exp = inp[sd["inp"]] / temp
527
534
  else:
528
535
  exp = 1.0
529
536
 
@@ -537,6 +544,8 @@ def atom_balance(
537
544
  if "out" in v:
538
545
  dout = exp * out[v["out"]] * element_from_formula(formula, element)
539
546
  nat_out = dout if nat_out is None else nat_out + dout
547
+
548
+ nat_in = np.where(nat_in > 0, nat_in, np.nan)
540
549
  dnat = nat_in - nat_out
541
550
  atbal = 1 - dnat / nat_in
542
551
  tag = f"atbal_{element}" if output is None else output
@@ -0,0 +1,108 @@
1
+ """
2
+ .. codeauthor::
3
+ Peter Kraus
4
+
5
+ Provides convenience functions for converting complex numbers between rectangular and
6
+ polar forms.
7
+
8
+ .. rubric:: Functions
9
+
10
+ .. autosummary::
11
+
12
+ to_rectangular
13
+ to_polar
14
+
15
+
16
+ """
17
+
18
+ import pint
19
+ import numpy as np
20
+ from uncertainties import unumpy as unp
21
+ from dgpost.utils.helpers import load_data
22
+
23
+
24
+ @load_data(
25
+ ("mag", None, list),
26
+ ("arg", "radians", list),
27
+ )
28
+ def to_rectangular(
29
+ mag: pint.Quantity,
30
+ arg: pint.Quantity,
31
+ output: str = None,
32
+ ) -> pint.Quantity:
33
+ """
34
+ Convert the provided complex number in polar form :math:`(r, θ)` to rectangular
35
+ (or Cartesian) form :math:`(x, y)`.
36
+
37
+ Parameters
38
+ ----------
39
+ mag
40
+ The magnitude :math:`r`.
41
+
42
+ arg
43
+ The argument (or angle) :math:`θ`. By default in radians.
44
+
45
+ output
46
+ Name of the output namespace. Defaults to ``None``, which means ``x`` and ``y``
47
+ will be returned.
48
+
49
+ Returns
50
+ -------
51
+ dict(output, x) : dict[str, pint.Quantity]
52
+ Returns the Cartesian x-coordinate.
53
+
54
+ dict(output, y) : dict[str, pint.Quantity]
55
+ Returns the Cartesian y-coordinate.
56
+
57
+ """
58
+ arg_rad = arg.to("radians")
59
+ y = mag * unp.sin(arg_rad)
60
+ x = mag * unp.cos(arg_rad)
61
+ pretag = "" if output is None else f"{output}->"
62
+ return {f"{pretag}x": x, f"{pretag}y": y}
63
+
64
+
65
+ @load_data(
66
+ ("x", None, list),
67
+ ("y", None, list),
68
+ )
69
+ def to_polar(
70
+ x: pint.Quantity,
71
+ y: pint.Quantity,
72
+ output: str = None,
73
+ ) -> pint.Quantity:
74
+ """
75
+ Convert the provided complex number in rectangular form :math:`(x, y)` to polar
76
+ form :math:`(r, θ)`.
77
+
78
+ Returns
79
+
80
+ Parameters
81
+ ----------
82
+ x
83
+ The Cartesian x-coordinate of the complex number.
84
+
85
+ y
86
+ The Cartesian y-coordinate of the complex number.
87
+
88
+ output
89
+ Name of the output namespace. Defaults to ``None``, which means ``mag`` and
90
+ ``arg`` will be returned.
91
+
92
+ Returns
93
+ -------
94
+ dict(output, mag) : dict[str, pint.Quantity]
95
+ Returns the magnitude (r) of the complex number.
96
+
97
+ dict(output, arg) : dict[str, pint.Quantity]
98
+ Returns the argument (θ) of the complex number, in radians.
99
+
100
+ """
101
+ print(f"{x=}")
102
+ x = np.asarray(x)
103
+ y = np.asarray(y)
104
+ print(f"{x=}")
105
+ mag = pint.Quantity(unp.sqrt(x**2 + y**2), "dimensionless")
106
+ arg = pint.Quantity(unp.arctan2(y, x), "radians")
107
+ pretag = "" if output is None else f"{output}->"
108
+ return {f"{pretag}mag": mag, f"{pretag}arg": arg}
@@ -0,0 +1,93 @@
1
+ """
2
+ .. codeauthor::
3
+ Peter Kraus
4
+
5
+ Includes functions to convert namespaces containing mixtures of chemicals between
6
+ various representations, such as mole fractions etc.
7
+
8
+ .. rubric:: Functions
9
+
10
+ .. autosummary::
11
+
12
+ flows_to_fractions
13
+ fractions_to_flows
14
+
15
+ """
16
+
17
+ import pint
18
+ import numpy as np
19
+
20
+ from dgpost.utils.helpers import load_data, fill_nans
21
+
22
+ ureg = pint.get_application_registry()
23
+
24
+
25
+ @load_data(
26
+ ("total", "m³/s"),
27
+ ("vdot", "m³/s", dict),
28
+ )
29
+ def flows_to_fractions(
30
+ total: pint.Quantity,
31
+ vdot: dict[str, pint.Quantity] = None,
32
+ output: str = "x",
33
+ _inp: dict = {},
34
+ ) -> dict[str, pint.Quantity]:
35
+ """
36
+ Calculates the volume fractions of components in the provided namespace ``vdot``,
37
+ given the total flow in ``total``.
38
+
39
+ Parameters
40
+ ----------
41
+ total
42
+ The total flow, by default in m³/s. Negative or zero values are ignored.
43
+
44
+ vdot
45
+ The dictionary containing flows of all species/components. By default in m³/s.
46
+
47
+ output
48
+ Prefix of the output namespace. Defaults to "x" for mole fraction.
49
+
50
+ """
51
+ ret = {}
52
+ temp = np.where(total > 0, total, np.nan)
53
+ for k, v in vdot.items():
54
+ if _inp["total"] == f"{_inp['vdot']}->{k}":
55
+ continue
56
+ ret[f"{output}->{k}"] = v / temp
57
+ return ret
58
+
59
+
60
+ @load_data(
61
+ ("total", "m³/s"),
62
+ ("x", None, dict),
63
+ )
64
+ def fractions_to_flows(
65
+ total: pint.Quantity,
66
+ x: dict[str, pint.Quantity] = None,
67
+ fillnan: bool = True,
68
+ output: str = "vdot",
69
+ _inp: dict = {},
70
+ ) -> dict[str, pint.Quantity]:
71
+ """
72
+ Calculates the partial flow rates in the mixture given mole fractions in the provided
73
+ namespace ``x`` and the total flow in ``total``.
74
+
75
+ Parameters
76
+ ----------
77
+ total
78
+ The total flow, by default in m³/s. Negative or zero values are ignored.
79
+
80
+ x
81
+ The dictionary containing mole fractions of all species/components.
82
+
83
+ output
84
+ Prefix of the output namespace. Defaults to "vdot" for flow rates.
85
+
86
+ """
87
+ ret = {}
88
+ temp = np.where(total > 0, total, np.nan)
89
+ for k, v in x.items():
90
+ if fillnan:
91
+ v = fill_nans(v, fillmag=0.0)
92
+ ret[f"{output}->{k}"] = v * temp
93
+ return ret