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

Add dimensionality information to Specs #89

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

DiamondJoseph
Copy link
Contributor

- Closes #88
- Add axes, shape and snaked information in (usually) non-points-calculating method.
- Deprecate Spec.axes: did not respect Frame information
- Deprecate Spec.shape: Called calculate() and discarded information
Comment on lines +520 to +543
class DimensionInfo(Generic[Axis]):
def __init__(
self,
axes: Tuple[Tuple[Axis, ...]],
shape: Tuple[int, ...],
snaked: Tuple[bool, ...] = None,
):
self._axes = axes
self._shape = shape
self._snaked = snaked or (False,) * len(shape)

@property
def axes(self) -> Tuple[Tuple[Axis, ...]]:
return self._axes

@property
def shape(self) -> Tuple[int, ...]:
return self._shape

@property
def snaked(self) -> Tuple[bool, ...]:
return self._snaked


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Achieves the same thing and more inkeeping with the rest of the codebase

Suggested change
class DimensionInfo(Generic[Axis]):
def __init__(
self,
axes: Tuple[Tuple[Axis, ...]],
shape: Tuple[int, ...],
snaked: Tuple[bool, ...] = None,
):
self._axes = axes
self._shape = shape
self._snaked = snaked or (False,) * len(shape)
@property
def axes(self) -> Tuple[Tuple[Axis, ...]]:
return self._axes
@property
def shape(self) -> Tuple[int, ...]:
return self._shape
@property
def snaked(self) -> Tuple[bool, ...]:
return self._snaked
@dataclass(frozen=True)
class DimensionInfo:
axes: Tuple[Tuple[Axis, ...]]
shape: Tuple[int, ...]
snaked: Tuple[bool, ...]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also would prefer Dimensions to DimensionInfo, because that's also a similar naming convention to other classes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not in keeping with the other classes in this file, which is why I didn't make a dataclass. it may be a holdover from worse dataclass Generic handling? I'll see how it behaves and maybe make a PR to move Frame etc. over to be dataclasses: the specs are dataclasses but the Frames etc. are not.

RE: Dimensions vs DimensionInfo: Dimension has meaning from SPG that is already present in some of the docs. This object is not a Dimension or collection of Dimensions, it describes some Dimensions.
Each component of axes/shape/snaked refers to the behaviour of a single Dimension. DimensionsInfo for maybe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also suggest Dimensionality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dimensionality I like

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, none of the other classes in core are dataclasses, but they do all contain a lot of logic, so I think that's correct. This almost purely holds data.
From discussion with Tom, he's leaning towards suggesting that there be no default for snaked and that be dealt with downstream. That would then make this a pure data class.

@@ -60,7 +63,14 @@ def axes(self) -> List[Axis]:

Ordered from slowest moving to fastest moving.
"""
raise NotImplementedError(self)
warn(
"axes() is deprecated, call dimension_info()",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this should be deprecated. I think there are still valid reasons to just say "I want a list of all axes that may be involved in this scan" without caring about/having to unpack the dimensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUI Tom requested deprecating axes(), shape(), will have to check when he's back.
The handling to get from the info is there, so it's easy to leave them both in and not worry about it again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted with Tom, happy to deprecate for now and and add a .flat_axes() to Dimensionality if a need arises

src/scanspec/specs.py Show resolved Hide resolved
):
self._axes = axes
self._shape = shape
self._snaked = snaked or (False,) * len(shape)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if this would help, but is it easier to make snaked an enum of yes, no and unknown?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snaked is False until an inner Dimension when it's True. Maybe it should be the outermost Dimension that is Snaked instead, or a dimension index?

src/scanspec/specs.py Show resolved Hide resolved
self,
axes: Tuple[Tuple[Axis, ...]],
shape: Tuple[int, ...],
snaked: Tuple[bool, ...] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
snaked: Tuple[bool, ...] = None,
snaked: Optional[Tuple[bool, ...]] = None,

@coretl
Copy link
Contributor

coretl commented Apr 24, 2024

What's the status of this now?

@callumforrester
Copy link
Contributor

@coretl Suggest putting #88 into a sprint and getting this PR taken over/finished

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specs should be able to get their dimensionality information
3 participants