Skip to content

Improve and simplify loading of transformation chains - #243

Merged
SimonHeybrock merged 32 commits into
mainfrom
transforms
Oct 7, 2024
Merged

SimonHeybrock merged 32 commits into
mainfrom
transforms

Conversation

@SimonHeybrock

@SimonHeybrock SimonHeybrock commented Sep 27, 2024 •

Copy link
Copy Markdown
Member

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
Comment thread src/scippnexus/base.py Outdated
@SimonHeybrock
SimonHeybrock marked this pull request as ready for review October 1, 2024 07:10
@nvaytet nvaytet self-assigned this Oct 4, 2024

@nvaytet nvaytet left a comment

Copy link
Copy Markdown
Member

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 ;-)

Comment thread src/scippnexus/field.py
"""
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/scippnexus/nxtransformations.py Outdated
value: sc.Variable | sc.DataArray,
*,
transformation_type: str,
select: ScippIndex,

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/scippnexus/nxtransformations.py Outdated
@SimonHeybrock
SimonHeybrock merged commit b1bf148 into main Oct 7, 2024
@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

None yet

Development

Successfully merging this pull request may close these issues.

Representation of loaded transformations?

2 participants