feat: Add ND2File.binary_data
property - extract binary layers from file
#108
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.
figured out how to decode the binary data in an nd2 file
Info below also present in the readme for anyone who stumbles on this PR:
The
ND2File.binary_data
property returns annd2.BinaryLayers
object representing all of thebinary masks in the nd2 file.
A
nd2.BinaryLayers
object is a sequence of individualnd2.BinaryLayer
objects (one for each binary layer found in the file). Each
BinaryLayer
inthe sequence is a named tuple that has, among other things, a
name
attribute,and a
data
attribute that is list of numpy arrays (one for each frame in theexperiment) or
None
if the binary layer had no data in that frame.The most common use case will be to cast either the entire
BinaryLayers
objector an individual
BinaryLayer
to anumpy.ndarray
:For example, if the data in the nd2 file has shape
(nT, nZ, nC, nY, nX)
, andthere are 4 binary layers, then the output of
np.asarray(nd2file.binary_data)
willhave shape
(4, nT, nZ, nY, nX)
. (Note that thenC
dimension is not presentin the output array, and the binary layers are always in the first axis).
You can also cast an individual
BinaryLayer
to a numpy array: