Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autoarray/structures/vectors/irregular.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def __array_finalize__(self, obj):
if hasattr(obj, "grid"):
self.grid = obj.grid

@property
def values(self) -> np.ndarray:
"""
The raw underlying ndarray of (y, x) vector components, with shape [total_vectors, 2].
"""
return self.array

@property
def slim(self) -> np.ndarray:
"""
Expand Down
17 changes: 17 additions & 0 deletions test_autoarray/structures/vectors/test_vectors_irregular.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,20 @@ def test__vectors_within_radius():

with pytest.raises(exc.VectorYXException):
vectors.vectors_within_radius(radius=0.0, centre=(0.0, 0.0))


def test__json_round_trip(tmp_path):
from autoconf.dictable import output_to_json, from_json

vectors = aa.VectorYX2DIrregular(
values=[(0.1, 0.2), (0.3, 0.4)],
grid=[(0.0, 0.0), (1.0, 1.0)],
)

file_path = tmp_path / "vectors.json"
output_to_json(obj=vectors, file_path=file_path)
loaded = from_json(file_path=file_path)

assert isinstance(loaded, aa.VectorYX2DIrregular)
assert np.allclose(loaded.array, vectors.array)
assert np.allclose(loaded.grid.array, vectors.grid.array)
Loading