Closed BornKrefeld closed 4 months ago
Hi @BornKrefeld, as you found in your traceback, nd2.ND2File
indeed does not have a channel
attribute (see the readme or the docs for attributes available on the ND2File object). There are a number of ways to get this though.
option 1: turn your data into a numpy array and then extract the channel axis:
import nd2
import numpy as np
with nd2.ND2File('24_02_22_ecoliatcc25922_growthonchip_4chips_xy001.nd2') as f:
data = f.asarray() # turn data into n-dimensional array
c_axis = list(f.sizes).index('C') # get the channel axis
for c_idx in range(f.sizes['C']):
channel_data = np.take(data, c_idx, axis=c_axis) # iterate over channel axis
# save your channel_data
alternatively, you can use the xarray/dask support
import nd2
ary = nd2.imread('24_02_22_ecoliatcc25922_growthonchip_4chips_xy001.nd2', xarray=True, dask=True)
for c_idx in range(ary.sizes['C']):
channel_data = ary.isel(C=c_idx)
# save your channel_data
How I can select a single channel from an nd2 file and save it to a numpy array
Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.
I was not able to select the data. Storage of the whole nd2 to numpy was possible
What I Did
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.