napari: Segmentation fault wen trying to start Napari viewer from script
🐛 Bug
When I try to start the Napari Viewer (latest version) from a script on Ubunto 18.04.3 LTS I recently got: Segmentation fault
To Reproduce
The relevant lines of code are here and I think the error occue
def show_napari(array, metadata,
blending='additive',
gamma=0.45,
verbose=True):
with napari.gui_qt():
# create scalefcator with all ones
scalefactors = [1] * len(array.shape)
# initialize the napari viewer
viewer = napari.Viewer()
if metadata['ImageType'] == 'ometiff':
# find position of dimensions
posZ = metadata['DimOrder BF Array'].find('Z')
posC = metadata['DimOrder BF Array'].find('C')
posT = metadata['DimOrder BF Array'].find('T')
# get the scalefactors from the metadata
scalef = get_scalefactor(metadata)
# modify the tuple for the scales for napari
scalefactors[posZ] = scalef['zx']
if verbose:
print('Dim PosT : ', posT)
print('Dim PosC : ', posC)
print('Dim PosZ : ', posZ)
print('Scale Factors : ', scalefactors)
# add all channels as layers
for ch in range(metadata['SizeC']):
try:
# get the channel name
chname = metadata['Channels'][ch]
except:
# or use CH1 etc. as string for the name
chname = 'CH' + str(ch + 1)
# cutout channel
channel = array.take(ch, axis=posC)
print('Shape Channel : ', ch, channel.shape)
# actually show the image array
print('Scaling Factors: ', scalefactors)
# get min-max values for initial scaling
clim = [channel.min(), np.round(channel.max() * 0.85)]
if verbose:
print('Scaling: ', clim)
viewer.add_image(channel,
name=chname,
scale=scalefactors,
contrast_limits=clim,
blending=blending,
gamma=gamma)
if metadata['ImageType'] == 'czi':
# find position of dimensions
posZ = metadata['Axes'].find('Z')
posC = metadata['Axes'].find('C')
posT = metadata['Axes'].find('T')
# get the scalefactors from the metadata
scalef = get_scalefactor(metadata)
# modify the tuple for the scales for napari
scalefactors[posZ] = scalef['zx']
if verbose:
print('Dim PosT : ', posT)
print('Dim PosZ : ', posZ)
print('Dim PosC : ', posC)
print('Scale Factors : ', scalefactors)
if metadata['SizeC'] > 1:
# add all channels as layers
for ch in range(metadata['SizeC']):
try:
# get the channel name
chname = metadata['Channels'][ch]
except:
# or use CH1 etc. as string for the name
chname = 'CH' + str(ch + 1)
# cut out channel
channel = array.take(ch, axis=posC)
print('Shape Channel : ', ch, channel.shape)
# actually show the image array
print('Adding Channel: ', chname)
print('Scaling Factors: ', scalefactors)
# get min-max values for initial scaling
clim = [channel.min(), np.round(channel.max() * 0.85)]
if verbose:
print('Scaling: ', clim)
viewer.add_image(channel,
name=chname,
scale=scalefactors,
contrast_limits=clim,
blending=blending,
gamma=gamma)
if metadata['SizeC'] == 1:
ch = 0
# just add one channel as a layer
try:
# get the channel name
chname = metadata['Channels'][ch]
except:
# or use CH1 etc. as string for the name
chname = 'CH' + str(ch + 1)
# actually show the image array
print('Adding Channel: ', chname)
print('Scaling Factors: ', scalefactors)
# get min-max values for initial scaling
clim = [channel.min(), np.round(channel.max() * 0.85)]
if verbose:
print('Scaling: ', clim)
viewer.add_image(array,
name=chname,
scale=scalefactors,
contrast_limits=clim,
blending=blending,
gamma=gamma)
This is the output when I call the script:
Expected behavior
No Segmentation fault
Environment
I used the latest version (24.11.2019) of Napari from GitHub and installed it via
pip install -e .
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 29 (22 by maintainers)
Hi guys, I also tried the same on my windows 10 machine and there the code works fine. You can try to reproduce it by using this script:
Read_OMETIFF_or_CZI.py
The images can be also found on the little repository On the Ubuntu system napari also stopped working when used from a jupyter notebook (kernel dies), which is probably the same issue. Again on my windows 10 system it also works fine from the notebook.
Instally vispy by using
pip install -e .
did not change the behavior. It still does not work.This might relate to #576 which has been fixed on the latest version of vispy on GitHub (which they havn’t released yet), so if you install vispy from GitHub and
pip install -e .
I’m curious if the error still persists. They should be releasing pretty soon, so we can get this fix to everyone.Both the latest napari on pypi and the napari on master should behave the same way with respect to #576