ipyrowtable 0.1.1__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.
ipyrowtable/units.py ADDED
@@ -0,0 +1,71 @@
1
+ """Unit systems: how each physical quantity is displayed.
2
+
3
+ Values are always stored (and passed to your compute function) in *base* units, whatever
4
+ units your compute function works in. A UnitSystem only changes what is shown:
5
+
6
+ display = base * scale + offset
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from dataclasses import dataclass, field
12
+
13
+ import numpy as np
14
+
15
+ __all__ = ["Unit", "UnitSystem"]
16
+
17
+
18
+ @dataclass(frozen=True)
19
+ class Unit:
20
+ """How one quantity is displayed: ``display = base * scale + offset``.
21
+
22
+ Examples
23
+ --------
24
+ >>> Unit("mm", 1000.0) # base unit metres
25
+ >>> Unit("°F", 1.8, 32.0) # base unit °C
26
+ """
27
+
28
+ label: str
29
+ scale: float = 1.0
30
+ offset: float = 0.0
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class UnitSystem:
35
+ """A named set of display units, one per quantity name.
36
+
37
+ Quantity names are free-form strings you choose ("length", "temperature", "flow", ...).
38
+ Quantities the system doesn't list are shown in base units with no label.
39
+
40
+ Examples
41
+ --------
42
+ >>> SI = UnitSystem("SI", {"length": Unit("mm", 1000.0), "temperature": Unit("°C")})
43
+ >>> SI.to_display("length", 0.01)
44
+ 10.0
45
+ """
46
+
47
+ name: str
48
+ units: dict = field(default_factory=dict)
49
+
50
+ def label(self, quantity: str | None) -> str:
51
+ """The unit label for a quantity, or "" if the system doesn't list it."""
52
+ unit = self.units.get(quantity)
53
+ return unit.label if unit else ""
54
+
55
+ def to_display(self, quantity, value):
56
+ """Convert a base value (scalar or array) to display units."""
57
+ unit = self.units.get(quantity)
58
+ if unit is None:
59
+ return value
60
+ return _scalar(np.asarray(value, dtype=float) * unit.scale + unit.offset)
61
+
62
+ def to_base(self, quantity, value):
63
+ """Convert a display value (scalar or array) to base units."""
64
+ unit = self.units.get(quantity)
65
+ if unit is None:
66
+ return value
67
+ return _scalar((np.asarray(value, dtype=float) - unit.offset) / unit.scale)
68
+
69
+
70
+ def _scalar(a):
71
+ return float(a) if np.ndim(a) == 0 else a
@@ -0,0 +1,303 @@
1
+ Metadata-Version: 2.5
2
+ Name: ipyrowtable
3
+ Version: 0.1.1
4
+ Summary: Editable ipywidgets tables of elements in series, with live computed columns, unit toggles and plots.
5
+ Author-email: jborlik@gmail.com
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: engineering,heat transfer,ipywidgets,jupyter,table,units,widgets
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Framework :: Jupyter
11
+ Classifier: Framework :: Jupyter :: JupyterLab
12
+ Classifier: Framework :: Jupyter :: JupyterLab :: 4
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Scientific/Engineering
24
+ Classifier: Topic :: Scientific/Engineering :: Physics
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: ipywidgets>=8.1
27
+ Requires-Dist: numpy>=1.23
28
+ Provides-Extra: dev
29
+ Requires-Dist: build; extra == 'dev'
30
+ Requires-Dist: hypothesis>=6.100; extra == 'dev'
31
+ Requires-Dist: ipykernel>=6.29; extra == 'dev'
32
+ Requires-Dist: jupyterlab>=4; extra == 'dev'
33
+ Requires-Dist: matplotlib>=3.6; extra == 'dev'
34
+ Requires-Dist: nbclient>=0.10; extra == 'dev'
35
+ Requires-Dist: nbformat>=5.9; extra == 'dev'
36
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
37
+ Requires-Dist: pytest>=8.0; extra == 'dev'
38
+ Requires-Dist: ruff; extra == 'dev'
39
+ Requires-Dist: twine>=6.1; extra == 'dev'
40
+ Provides-Extra: plot
41
+ Requires-Dist: matplotlib>=3.6; extra == 'plot'
42
+ Provides-Extra: test
43
+ Requires-Dist: hypothesis>=6.100; extra == 'test'
44
+ Requires-Dist: ipykernel>=6.29; extra == 'test'
45
+ Requires-Dist: matplotlib>=3.6; extra == 'test'
46
+ Requires-Dist: nbclient>=0.10; extra == 'test'
47
+ Requires-Dist: nbformat>=5.9; extra == 'test'
48
+ Requires-Dist: pytest-cov>=5.0; extra == 'test'
49
+ Requires-Dist: pytest>=8.0; extra == 'test'
50
+ Provides-Extra: ui
51
+ Requires-Dist: hypothesis>=6.100; extra == 'ui'
52
+ Requires-Dist: ipykernel>=6.29; extra == 'ui'
53
+ Requires-Dist: matplotlib>=3.6; extra == 'ui'
54
+ Requires-Dist: nbclient>=0.10; extra == 'ui'
55
+ Requires-Dist: nbformat>=5.9; extra == 'ui'
56
+ Requires-Dist: pytest-cov>=5.0; extra == 'ui'
57
+ Requires-Dist: pytest-ipywidgets>=1.40; extra == 'ui'
58
+ Requires-Dist: pytest>=8.0; extra == 'ui'
59
+ Description-Content-Type: text/markdown
60
+
61
+ # ipyrowtable
62
+
63
+ Editable [ipywidgets](https://ipywidgets.readthedocs.io) tables for problems made of elements
64
+ in series: wall layers, pipe segments, cable runs, process stages. You describe the columns
65
+ and write a `compute` function; ipyrowtable gives a table where Jupyter users add and remove
66
+ rows, edit inputs, see computed results update immediately, and easily use the configured inputs
67
+ in downstream cells.
68
+
69
+ ![A layer table with an SI / Imperial toggle and a live temperature profile](https://raw.githubusercontent.com/jborlik/ipyrowtable/refs/heads/master/docs/screenshot.png)
70
+
71
+ What sets it apart from a general-purpose data grid:
72
+
73
+ - **Every cell is a real widget.** Dropdowns, number boxes and text boxes in the table itself,
74
+ with add and remove buttons per row.
75
+ - **Values between rows.** A `NodeColumn` holds the n + 1 values at the joints of n elements
76
+ (interface temperatures, joint pressures, node voltages), with editable boundary
77
+ conditions at either end.
78
+ - **Unit systems.** A toggle switches everything shown between, say, SI and Imperial. Values
79
+ are stored in your base units, so switching never changes the physics or drifts.
80
+ - **Live plots.** `LiveFigure` keeps a matplotlib figure in step with the table.
81
+ - **Saved between sessions.** A table can keep its inputs across kernel restarts, making it a
82
+ friendlier alternative to a hard-coded dict of inputs.
83
+
84
+ It suits small, carefully entered inputs: tens of rows, not thousands. For large data, use a
85
+ grid such as [ipydatagrid](https://github.com/jupyter-widgets/ipydatagrid) or Panel's
86
+ [Tabulator](https://panel.holoviz.org/reference/widgets/Tabulator.html).
87
+
88
+ ## Install
89
+
90
+ ```bash
91
+ pip install ipyrowtable # the table
92
+ pip install "ipyrowtable[plot]" # plus matplotlib, for LiveFigure and the conduction example
93
+ ```
94
+
95
+ Needs Python 3.10+ and ipywidgets 8.1+. It uses only standard widgets, with no custom JavaScript,
96
+ so it works wherever ipywidgets does: JupyterLab, Jupyter Notebook, VS Code, Voilà.
97
+
98
+ ## Try it
99
+
100
+ A complete application ships with the package: steady conduction through a plane composite
101
+ wall, with an SI / Imperial toggle and a temperature-profile plot.
102
+
103
+ ```python
104
+ from ipyrowtable.examples.conduction import layer_stack_app
105
+
106
+ layer_stack_app(layers=[("Gypsum board", 12.7), ("Fiberglass insulation", 89), ("Brick", 90)],
107
+ T_top=21, T_bottom=-10)
108
+ ```
109
+
110
+ ## Quick start
111
+
112
+ Voltage along a cable run. Each row is a segment; the voltage at each joint is computed from
113
+ the source voltage (an editable boundary value) and the load current (a parameter that
114
+ applies to the whole run).
115
+
116
+ ```python
117
+ import numpy as np
118
+ from ipyrowtable import ChoiceColumn, NodeColumn, NumberColumn, OutputColumn, RowTable
119
+
120
+ OHM_PER_M = {"14 AWG": 0.008286, "12 AWG": 0.005211, "10 AWG": 0.003277} # copper, 20 °C
121
+
122
+ def voltage_drop(inputs):
123
+ ohm_per_m = np.array([OHM_PER_M[g] for g in inputs.column("gauge")])
124
+ drop = 2 * inputs.params["current"] * ohm_per_m * inputs.column("length") # out and back
125
+ V_source = inputs.edges["voltage"][0]
126
+ return {"drop": drop, "voltage": V_source - np.concatenate(([0.0], np.cumsum(drop)))}
127
+
128
+ cable = RowTable(
129
+ columns=[
130
+ ChoiceColumn("gauge", "Wire", options=OHM_PER_M),
131
+ NumberColumn("length", "Length (m)", default=10.0, min=0),
132
+ OutputColumn("drop", "Drop (V)"),
133
+ NodeColumn("voltage", "Voltage (V)", inputs="first", first_default=120.0),
134
+ ],
135
+ compute=voltage_drop,
136
+ parameters=[NumberColumn("current", "Current (A)", default=15.0)],
137
+ leading_label="— source —",
138
+ item_name="segment",
139
+ )
140
+ cable
141
+ ```
142
+
143
+ `cable.results["voltage"]` holds the latest values, and `cable.results.records()` gives one
144
+ dict per row, ready for `pandas.DataFrame`.
145
+
146
+ ## Concepts
147
+
148
+ ### Columns
149
+
150
+ | Column | Kind | Per row |
151
+ |---|---|---|
152
+ | `ChoiceColumn` | input | a dropdown; options can carry data, like a material's conductivity |
153
+ | `NumberColumn` | input | a number, optionally unit-aware (`quantity=`) and bounded (`min=`, `max=`) |
154
+ | `TextColumn` | input | free text, such as a name or tag |
155
+ | `OutputColumn` | output | one computed value |
156
+ | `NodeColumn` | output | the value at the row's bottom or outlet face; the value at the top or inlet goes in a leading row |
157
+
158
+ Headers can include units: `"Thickness ({unit})"` shows the column's own unit, and
159
+ `"k in {conductivity}"` shows any other quantity's unit.
160
+
161
+ Input columns can also be **parameters**, shown above the table for values that apply to the
162
+ whole problem. To add a new input type, subclass `InputColumn` and implement `create_widget`.
163
+ The *03_extending* notebook adds a whole-number column this way.
164
+
165
+ ### Values between rows
166
+
167
+ A `NodeColumn` holds **n + 1** values for **n** rows. Use `inputs=` to say which ends are
168
+ editable:
169
+
170
+ - `("first", "last")` for both ends, like the two surface temperatures of a wall
171
+ - `"first"` for the inlet only, like a supply pressure
172
+ - `"last"` for the outlet only
173
+ - `()` for neither
174
+
175
+ Your compute function receives the boundary values as `inputs.edges[key]` and returns all
176
+ n + 1 values, including the ends.
177
+
178
+ ### Units
179
+
180
+ ```python
181
+ from ipyrowtable import Unit, UnitSystem
182
+
183
+ SI = UnitSystem("SI", {"length": Unit("mm", 1000.0), "temperature": Unit("°C")})
184
+ IMPERIAL = UnitSystem("Imperial", {"length": Unit("in", 1 / 0.0254),
185
+ "temperature": Unit("°F", 1.8, 32.0)})
186
+ ```
187
+
188
+ A `Unit` converts with `display = base × scale + offset`. Your compute function always works
189
+ in base units (metres and °C here). Pass `unit_systems=[SI, IMPERIAL]` to get a toggle.
190
+ Defaults can be given per system, such as `default={"SI": 10, "Imperial": 0.5}`, so new rows
191
+ start at round numbers in whichever units are showing.
192
+
193
+ ### The compute function and results
194
+
195
+ `compute(inputs)` receives:
196
+
197
+ - `inputs.rows`: a list of dicts, one per row
198
+ - `inputs.column(key)`: one column as an array
199
+ - `inputs.edges`: the NodeColumn boundary values
200
+ - `inputs.params`: the parameters
201
+
202
+ All of them are in base units. It returns `{column key: values}`, and any extra keys (totals,
203
+ fluxes) are kept too. If it raises `ValueError("message")`, the message appears in place of
204
+ the results.
205
+
206
+ After every change:
207
+
208
+ - `table.results[key]` gives values in base units, and `table.results.display(key)` gives
209
+ them in the units shown.
210
+ - `table.results.records()` gives one dict per row.
211
+ - `table.on_update(callback)` runs your code with the results, or with `None` while the
212
+ inputs are invalid.
213
+ - `table.error` says what went wrong, if anything did.
214
+
215
+ ### Saving inputs between sessions
216
+
217
+ ```python
218
+ cable = RowTable(..., rows=[...], persist="feeder")
219
+ ```
220
+
221
+ With a `persist` key, the table saves its inputs whenever they change and restores them when
222
+ a table with the same key is created again, for example after a kernel restart. The inputs
223
+ are the rows, boundary values, parameters, and the unit system that was showing.
224
+
225
+ `rows`, `edges`, `params` and `units` then become the *initial* values. They're used:
226
+
227
+ - when nothing has been saved yet;
228
+ - when the saved inputs can't be used, for example because an option no longer exists (the
229
+ table says why, and keeps the old file as a `.bak` copy before replacing it);
230
+ - by the **Reset** button, which asks for a second click first.
231
+
232
+ Where the inputs go:
233
+
234
+ - By default, into `<notebook name>.ipyrowtable.json` next to the notebook. If the notebook
235
+ can't be identified, they go into `ipyrowtable.json` in the working folder. The note under
236
+ the table names the file.
237
+ - `persist_file=` picks a different file. One file can hold many tables, each under its own
238
+ key.
239
+ - Values are stored as plain JSON in base units, so it doesn't matter which unit system was
240
+ showing.
241
+
242
+ They go in a file rather than the notebook's metadata because the kernel can't write
243
+ notebook metadata.
244
+
245
+ To always start from the initial values, leave out `persist`. The environment variable
246
+ `IPYROWTABLE_PERSIST=off` turns saving off for every table, which is useful for batch runs
247
+ that must start from known inputs. `table.get_inputs()` and `table.set_inputs(snapshot)` let
248
+ you keep and load snapshots yourself, such as several named designs.
249
+
250
+ ### Plots
251
+
252
+ ```python
253
+ from ipyrowtable import LiveFigure, side_by_side
254
+
255
+ def draw(fig, results):
256
+ ax = fig.add_subplot()
257
+ ax.plot(results["voltage"], marker="o")
258
+
259
+ side_by_side(cable, LiveFigure(cable, draw=draw))
260
+ ```
261
+
262
+ ### Styling
263
+
264
+ Every part carries a CSS class you can style:
265
+
266
+ - `ipyrowtable-grid`, `ipyrowtable-add`, `ipyrowtable-reset`, `ipyrowtable-message`,
267
+ `ipyrowtable-persist`
268
+ - `ipyrowtable-<key>` on each column's cells
269
+
270
+ ## Examples
271
+
272
+ The [`examples/`](examples) folder has four notebooks:
273
+
274
+ 1. **01_getting_started**: a first table, values between rows, a live plot, driving a table
275
+ from code.
276
+ 2. **02_plane_wall_conduction**: the conduction app: units, reading results, plugging in your
277
+ own solver.
278
+ 3. **03_extending**: pipes in series (Darcy–Weisbach). Covers your own unit systems, a custom
279
+ column type, parameters, `on_update`, and styling.
280
+ 4. **04_saving_inputs**: keeping a table's inputs between sessions: initial values, the
281
+ saved file, named snapshots, resetting, and turning saving off.
282
+
283
+ ## FAQ
284
+
285
+ ### In VS Code, a table shows "Failed to load model class …" instead of rendering
286
+
287
+ This can happen the first time a notebook runs in VS Code's Jupyter extension, when a table is
288
+ created in one cell and displayed in a later one. It comes from how VS Code loads its widget
289
+ support: widgets created before VS Code has finished loading it can fail to render. It isn't
290
+ caused by ipyrowtable, which uses only standard ipywidgets. Seen with the Jupyter extension
291
+ 2025.9.1 on Windows.
292
+
293
+ - **To fix it:** re-run the cell that creates the table, then the cell that displays it.
294
+
295
+
296
+ ## Development
297
+
298
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, the test suite (including real-browser tests)
299
+ and releasing.
300
+
301
+ ## License
302
+
303
+ MIT
@@ -0,0 +1,14 @@
1
+ ipyrowtable/__init__.py,sha256=LBn4Oh188VN8LGMd9nEZLNgJbbVjBe1rPH7WC30qbvA,1423
2
+ ipyrowtable/columns.py,sha256=PVIojelSKv5VO2wnHxzCKia_oPxN2yjo3s2epFOE04Q,10171
3
+ ipyrowtable/figure.py,sha256=qcRFE8Qxt8nQPQ9jef28p7JcXvzZkOKEeqd2hl9ida0,2437
4
+ ipyrowtable/formatting.py,sha256=Nu8WEkGCePilA4GtKCaWbK1FhnZbbEi_SCX8eBqA0B8,1152
5
+ ipyrowtable/layout.py,sha256=HgOxPBK4ANdTnNjgTN6ehM-47_MAd882vxRGTgphWoE,462
6
+ ipyrowtable/persistence.py,sha256=-PP3rPrXCPiT-_uCS_K3ejPfHlLaNBeVek44DG-xeGo,5913
7
+ ipyrowtable/table.py,sha256=6uvpiZcSjO0_dcKO28YJsXtVO9mHq3MLiHA2uge5F_s,32998
8
+ ipyrowtable/units.py,sha256=ZRJGnBa3LdHf3MMFJz_rbVH8MhC0my77T_QdvDSZoEs,2089
9
+ ipyrowtable/examples/__init__.py,sha256=u0E1-h3-RPIdl4Z3joa0zfavmJ4D75FaVqgUjWEFWfA,155
10
+ ipyrowtable/examples/conduction.py,sha256=p_32YqQBejqIgyGvkvqaupesuzpzGB7YGy-bEituHCk,13822
11
+ ipyrowtable-0.1.1.dist-info/METADATA,sha256=iJ2NE8mcxffD_LpiOYLH_gLAIDjeIeOhDzf5LjgzANk,12382
12
+ ipyrowtable-0.1.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
13
+ ipyrowtable-0.1.1.dist-info/licenses/LICENSE,sha256=GeRO50G1gUVz1TTTJw3v6q_A2O34gBbMZT8H_ec-btI,1080
14
+ ipyrowtable-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The ipyrowtable authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.