Skip to content

Commit

Permalink
fixup! fixup! RFC: refactor Plotable around typed data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Dec 6, 2024
1 parent ffbe62a commit fbaf844
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
22 changes: 11 additions & 11 deletions nonos/api/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class Plotable:
def __init__(
self,
*,
abscissa: NamedArray,
ordinate: NamedArray,
field: Optional[NamedArray] = None,
abscissa: tuple[str, np.ndarray],
ordinate: tuple[str, np.ndarray],
field: Optional[tuple[str, np.ndarray]] = None,
) -> None:
self.abscissa = abscissa
self.ordinate = ordinate
self.field = field
self.abscissa = NamedArray(*abscissa)
self.ordinate = NamedArray(*ordinate)
self.field = None if field is None else NamedArray(*field)
if ndim := self.data.ndim > 2:
raise TypeError(
f"Plotable doesn't support data with dimensionality>2, got {ndim}"
Expand Down Expand Up @@ -563,8 +563,8 @@ def map(
data_view = self.data.view()

return Plotable(
abscissa=NamedArray(abscissa_key, abscissa_value),
ordinate=NamedArray(data_key, data_view.squeeze()),
abscissa=(abscissa_key, abscissa_value),
ordinate=(data_key, data_view.squeeze()),
)

elif dimension == 2:
Expand Down Expand Up @@ -611,9 +611,9 @@ def rotate_axes(arr, shift: int):
data_view = data_view.T

return Plotable(
abscissa=NamedArray(abscissa_key, abscissa_value),
ordinate=NamedArray(ordinate_key, ordinate_value),
field=NamedArray(data_key, data_view),
abscissa=(abscissa_key, abscissa_value),
ordinate=(ordinate_key, ordinate_value),
field=(data_key, data_view),
)
else:
raise RuntimeError
Expand Down
17 changes: 7 additions & 10 deletions nonos/api/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from lick.lick import lick_box

from nonos.api.analysis import Coordinates, GasField, NamedArray, Plotable
from nonos.api.analysis import Coordinates, GasField, Plotable
from nonos.loaders import Recipe, loader_from, recipe_from

if TYPE_CHECKING:
Expand Down Expand Up @@ -136,34 +136,31 @@ def plot(
color_streamlines: str = "black",
):
im = Plotable(
field=NamedArray("background", self.F),
abscissa=NamedArray("x", self.X),
ordinate=NamedArray("y", self.Y),
abscissa=("x", self.X),
ordinate=("y", self.Y),
field=("background", self.F),
).plot(
fig,
ax,
vmin=vmin,
vmax=vmax,
log=log,
cmap=cmap,
filename=None,
dpi=500,
title=title,
shading="nearest",
rasterized=True,
)
Plotable(
field=NamedArray("lick", self.lick),
abscissa=NamedArray("x", self.X),
ordinate=NamedArray("y", self.Y),
abscissa=("x", self.X),
ordinate=("y", self.Y),
field=("lick", self.lick),
).plot(
fig,
ax,
log=False,
cmap="binary_r",
filename=None,
dpi=500,
title=None,
alpha=alpha,
shading="nearest",
rasterized=True,
Expand Down

0 comments on commit fbaf844

Please sign in to comment.