feature(spm): Add trace/retrace reading for the .spm reader - #196
Open
derollins wants to merge 4 commits into
Open
feature(spm): Add trace/retrace reading for the .spm reader#196derollins wants to merge 4 commits into
derollins wants to merge 4 commits into
Conversation
load_spm previously selected channels by name only, silently returning
the forward (trace) image and providing no way to load retrace. It also
only exposed available channels via an error message, not as data.
- Add spm_channel_list() to enumerate a file's channels with direction,
keyed as '<name> trace' / '<name> retrace', reading only the parsed
header (no pixel decode).
- Thread the direction through to pySPM's get_channel(backward=...) so
retrace images actually load.
- For backward compatability accept bare names ('Height Sensor'), explicit direction ('Height
Sensor retrace'), and any case; bare names default to trace (or
retrace if that is the only direction present) and log which was used.
Backwards compatible: existing bare-name calls return trace as before.
… direction channel loading and channel list creation.
…the general loader.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
.spmfile reader opens channels by name however if there is both a trace and retrace channel within the file then only the trace channel is accessible. Trace and retrace are both meaningful and both can be important for analysis so it is important to be able to access both scan directions.This PR makes both trace and retrace accessible for
.spmfiles and exposes them with a newspm_channel_list()function.Summary
channelparameter still accepts a bare channel name as before ('Height Sensor' or 'Adhesion' etc.) and like before will open the trace channel, or if the trace channel is not available a retrace channel if available - this ensures backward compatibility,channelparameter also accepts an explicit direction ('Height Sensor trace' or 'Height Sensor retrace') which opens the trace or retrace channel respectively,spm_channel_list()returns the available channels for a file (with trace/retrace directions), used internally to check channel presence and produce the informative errors. It may also be useful for building interactive channel pickers (e.g. the napari plugin).Changes
load_spm()now usesspm_channel_list()to build a list of available channels and matches the requested channel against it. Matching is case-insensitive. Because Bruker channel names contain spaces (e.g. 'Height Sensor'), the direction is a suffix on the full name ('Height Sensor retrace').pySPM(backwardparameter) so retrace images actually load; previously the direction was never forwarded and only trace was returned.pySPM's "channel not found" exception and re-raised it. The requested channel is now checked against the channel list up front, and aValueError(listing the available channels) is raised beforepySPMis called. As a result, any otherpySPMerrors now propagate directly rather than being caught and re-raised, this should help with debugging.Backwards compatibility
Existing calls are unaffected, a bare channel name still returns the trace image preferentially as it always did. The new behaviour is opt-in via the direction suffix.
Tests
sample_0.spm.pySPMwith the correct backward flag, including case-insensitive requests and the bare-name-defaults-to-trace case.spm_channel_list()returns the expected channels with correct directions..spmtests updated for the new channel-list format. Full test suite passes.One limitation:
sample_0.spmdoesn't contain a single channel present in both directions, so a direct "same channel, trace and retrace differ" test isn't possible against it. Direction handling is instead verified by checking the flag passed through topySPM. This would require adding an extra file to the test resources, I'm sure I could find something suitable if you think this is important to have although it would increase the repo size.