Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xy data documentation #6736

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
22 changes: 17 additions & 5 deletions src/aiida/orm/nodes/data/array/xy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"""This module defines the classes related to Xy data. That is data that contains
collections of y-arrays bound to a single x-array, and the methods to operate
on them.

Example:
xy = XyData()
xy.set_x(np.array([1, 2, 3]), 'x', 'unit_x')
xy.set_y([np.array([1, 2, 3]), np.array([4, 5, 6])], ['y', 'z'], ['unit_y', 'unit_z'])
print(xy.get_arraynames()) # ['x_array', 'y_array_0', 'y_array_1']
print(xy.get_y()) # [('y', array([1, 2, 3]), 'unit_y'), ('z', array([4, 5, 6]), 'unit_z')]
"""

from __future__ import annotations
Expand Down Expand Up @@ -172,10 +179,15 @@
y_units = self.base.attributes.get('y_units')
except (KeyError, AttributeError):
raise NotExistent('No y units has been set yet!')
y_arrays = []

y_arrays = [self.get_array(f'y_array_{i}') for i in range(len(y_names))]
return list(zip(y_names, y_arrays, y_units))

def get_y_arraynames(self) -> list[str]:
"""Returns the user-provided names of the y-arrays."""

try:
for i in range(len(y_names)):
y_arrays += [self.get_array(f'y_array_{i}')]
y_names = self.base.attributes.get('y_names')

Check warning on line 190 in src/aiida/orm/nodes/data/array/xy.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/orm/nodes/data/array/xy.py#L190

Added line #L190 was not covered by tests
except (KeyError, AttributeError):
raise NotExistent(f'Could not retrieve array associated with y array {y_names[i]}')
return list(zip(y_names, y_arrays, y_units))
raise NotExistent('No y names have been set yet!')
return y_names

Check warning on line 193 in src/aiida/orm/nodes/data/array/xy.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/orm/nodes/data/array/xy.py#L192-L193

Added lines #L192 - L193 were not covered by tests