Skip to content

Commit

Permalink
Fix units example
Browse files Browse the repository at this point in the history
  • Loading branch information
ksunden committed Jun 26, 2024
1 parent 47cd022 commit c2ff8af
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions data_prototype/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ def axes(self, ax):
),
FuncEdge.from_func(
"xunits",
lambda: self._axes.xunits,
lambda: self._axes.xaxis.units,
{},
{"xunits": Desc((), "units")},
),
FuncEdge.from_func(
"yunits",
lambda: self._axes.yunits,
lambda: self._axes.yaxis.units,
{},
{"yunits": Desc((), "units")},
),
Expand Down
4 changes: 2 additions & 2 deletions data_prototype/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def __init__(self, coordinates: dict[str, str] | None = None, /, **data):
self._desc = {
k: (
Desc(v.shape, coordinates.get(k, "auto"))
if isinstance(v, np.ndarray)
else Desc(())
if hasattr(v, "shape")
else Desc((), coordinates.get(k, "auto"))
)
for k, v in data.items()
}
Expand Down
2 changes: 2 additions & 0 deletions data_prototype/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def __init__(self, container, edges=None, **kwargs):

scalar = Desc((), "display") # ... this needs thinking...

print(self._graph._edges)

edges = [
CoordinateEdge.from_coords("xycoords", {"x": "auto", "y": "auto"}, "data"),
CoordinateEdge.from_coords("color", {"color": Desc(())}, "display"),
Expand Down
19 changes: 17 additions & 2 deletions examples/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from data_prototype.artist import CompatibilityAxes
from data_prototype.containers import ArrayContainer
from data_prototype.conversion_edge import FuncEdge
from data_prototype.description import Desc

from data_prototype.line import Line

Expand Down Expand Up @@ -44,9 +45,23 @@
ax.set_xlim(-0.5, 7)
ax.set_ylim(0, 5)

xconv = FuncEdge.from_func("xconv", lambda x, xunits: x.to(xunits), "units", "data")
yconv = FuncEdge.from_func("yconv", lambda y, yunits: y.to(yunits), "units", "data")
scalar = Desc((), "units")
unit_vector = Desc(("N",), "units")

xconv = FuncEdge.from_func(
"xconv",
lambda x, xunits: x.to(xunits),
{"x": unit_vector, "xunits": scalar},
{"x": Desc(("N",), "data")},
)
yconv = FuncEdge.from_func(
"yconv",
lambda y, yunits: y.to(yunits),
{"y": unit_vector, "yunits": scalar},
{"y": Desc(("N",), "data")},
)
lw = Line(cont, [xconv, yconv])

ax.add_artist(lw)
nax.xaxis.set_units(ureg.feet)
nax.yaxis.set_units(ureg.m)
Expand Down

0 comments on commit c2ff8af

Please sign in to comment.