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

Improve and simplify loading of transformation chains #243

Merged
merged 32 commits into from
Oct 7, 2024
Merged

Conversation

SimonHeybrock
Copy link
Member

@SimonHeybrock SimonHeybrock commented Sep 27, 2024

See docstring in nxtransformations.py for an explanation.

I have added class DependsOn which seems a much saner way to handle the references, instead of juggling absolute and relative paths. The subclass TransformationChain additionally hold the chain of transformations starting at the depends_on.

Fixes #234 by introducing a new mechanism that can work around the shortcomings of the default data load. See there also for larger context.

Technically this represents a breaking change, since users would have to call build() after loading groups with transformations. In practice this is however typically not accessed directly — users typically use snx.compute_positions instead of working with the raw chains.

@SimonHeybrock SimonHeybrock changed the title Add transformations module Improve and simplify loading of transformation chains Sep 30, 2024
src/scippnexus/base.py Outdated Show resolved Hide resolved
Copy link
Member

@nvaytet nvaytet left a comment

Choose a reason for hiding this comment

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

I must say I didn't follow all the code changes, but the tests look fine ;-)

"""
Represents a depends_on reference in a NeXus file.

The parent (the full path within the NeXus file) is stored, as the value may be
Copy link
Member

Choose a reason for hiding this comment

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

Are parents always guaranteed to be absolute or could they also be relative?

Copy link
Member Author

Choose a reason for hiding this comment

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

The class does not check this on init, but in our code it comes from dataset.parent.name, and in h5py name gives the full absolute path.

src/scippnexus/nxtransformations.py Outdated Show resolved Hide resolved
value: sc.Variable | sc.DataArray,
*,
transformation_type: str,
select: ScippIndex,
Copy link
Member

Choose a reason for hiding this comment

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

Was this select actually never used in the old function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, never used, because it was unclear what to do with potential time selection. Also, since the selection was already applied when loading the underlying group or dataset it made little sense, unless the plan was to apply it to the entire chain, which maybe was the original idea? So maybe it should be considered to forward select when resolving a chain? But I think such a mechanism will be useless 90% of the time, since each chain link can have different length, etc., ...

raise TransformationError('A transformation needs a vector attribute.')
return sc.vector(value=self.attrs.get('vector'))

def __getitem__(self, select: ScippIndex):
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I managed to follow where the select logic was moved. Is is simply that we are not performing any selection on a time-dependent transformation anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

It can, since it is applied when loading the NXlog, before maybe_transformation builds a transformation from it. See also above though.

src/scippnexus/nxtransformations.py Outdated Show resolved Hide resolved
@SimonHeybrock SimonHeybrock merged commit b1bf148 into main Oct 7, 2024
4 checks passed
@SimonHeybrock SimonHeybrock deleted the transforms branch October 7, 2024 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Representation of loaded transformations?
2 participants