Opened 2 years ago

Closed 2 years ago

#9420 closed defect (fixed)

Showing single plane of .nii file gives traceback

Reported by: chimerax-bug-report@… Owned by: Zach Pearson
Priority: moderate Milestone:
Component: DICOM Version:
Keywords: Cc: Tom Goddard
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

The following bug report has been submitted:
Platform:        macOS-10.15.7-x86_64-i386-64bit
ChimeraX Version: 1.6.1 (2023-05-09 17:57:07 UTC)
Description
Showing single plane of .nii file gives a traceback.  Probably the file reader for nii is not providing a numpy array with the right shape.  Submitted by Tom G from Selina's computer.

Log:
UCSF ChimeraX version: 1.6.1 (2023-05-09)  
© 2016-2023 Regents of the University of California. All rights reserved.  
How to cite UCSF ChimeraX  

> open /Users/macbook/Downloads/Lung_005_0000.nii format nifti

Opened Lung_005_0000.nii as #1, grid size 178,512,512, pixel 0.977,0.977,5,
shown at level 377, step 2, values float64  

> open /Users/macbook/Downloads/Lung_005_gt.nii

Opened Lung_005_gt.nii as #2, grid size 512,512,178, pixel 1, shown at level
5e-05, step 2, values float64  

> volume showOutlineBox true

> open /Users/macbook/Downloads/Lung_005_Model_102_2d.nii

Opened Lung_005_Model_102_2d.nii as #3, grid size 178,512,512, pixel
0.977,0.977,5, shown at level 5e-05, step 2, values float64  

> hide #!2 models

> open /Users/macbook/Downloads/Lung_005_Model_102_3d_ful.nii

Opened Lung_005_Model_102_3d_ful.nii as #4, grid size 178,512,512, pixel
0.977,0.977,5, shown at level 5e-05, step 2, values float64  

> hide #!3 models

> hide #!4 models

> show #!3 models

> hide #!3 models

> show #!4 models

> show #!3 models

> volume #!1,3-4 region all imageMode "full region"

> volume unzone #!1,3-4

> mousemode rightMode "crop volume"

> hide #!3 models

> hide #!4 models

> show #!3 models

> show #!4 models

> hide #!3 models

> volume #1 style image region 0,0,254,177,511,254 step 1

An error occurred in drawing the scene. Redrawing graphics is now stopped to
avoid a continuous stream of error messages. To restart graphics use the
command "graphics restart" after changing the settings that caused the error.  
  
cannot select an axis to squeeze out which has size not equal to one  
  
Traceback (most recent call last):  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/core/updateloop.py", line 73, in draw_new_frame  
view.draw(check_for_changes = False)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/graphics/view.py", line 177, in draw  
self._draw_scene(camera, drawings)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/graphics/view.py", line 254, in _draw_scene  
draw_transparent(r, transparent_drawings)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/graphics/drawing.py", line 1547, in draw_transparent  
r.draw_transparent(  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/graphics/opengl.py", line 1252, in draw_transparent  
draw()  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/graphics/drawing.py", line 1549, in <lambda>  
lambda: _draw_multiple(drawings, r, Drawing.TRANSPARENT_DRAW_PASS))  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/graphics/drawing.py", line 1555, in _draw_multiple  
d.draw(renderer, draw_pass)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 783, in draw  
pd = self._update_planes(renderer)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 551, in _update_planes  
pd = self._update_2d_texture_planes(view_dir)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 559, in _update_2d_texture_planes  
pd = self._texture_2d_planes(axis)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 585, in _texture_2d_planes  
pd = self._make_planes(axis)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 713, in _make_planes  
d = Texture2dPlanes(self, axis)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 984, in __init__  
self._update_textures(planes)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 1056, in _update_textures  
textures = [self._plane_texture(k, axis) for k,axis in planes]  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 1056, in <listcomp>  
textures = [self._plane_texture(k, axis) for k,axis in planes]  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 1063, in _plane_texture  
self._fill_plane_texture(k, axis, t)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 1082, in _fill_plane_texture  
data = ir._color_plane(plane, axis)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 234, in _color_plane  
m = self._matrix_plane(plane, axis)  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/chimerax/map/image3d.py", line 211, in _matrix_plane  
p = squeeze(m, 2-axis) # Reduce from 3d array to 2d.  
File "<__array_function__ internals>", line 180, in squeeze  
File
"/Applications/ChimeraX-1.6.1.app/Contents/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/numpy/core/fromnumeric.py", line 1545, in squeeze  
return squeeze(axis=axis)  
ValueError: cannot select an axis to squeeze out which has size not equal to
one  
  

> volume #1

> graphics reset

Expected a keyword  




OpenGL version: 4.1 INTEL-14.7.28
OpenGL renderer: Intel(R) Iris(TM) Plus Graphics OpenGL Engine
OpenGL vendor: Intel Inc.

Python: 3.9.11
Locale: UTF-8
Qt version: PyQt6 6.4.2, Qt 6.4.2
Qt runtime version: 6.4.3
Qt platform: cocoa
Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro16,2
      Processor Name: Quad-Core Intel Core i5
      Processor Speed: 2 GHz
      Number of Processors: 1
      Total Number of Cores: 4
      L2 Cache (per Core): 512 KB
      L3 Cache: 6 MB
      Hyper-Threading Technology: Enabled
      Memory: 16 GB
      Boot ROM Version: 1731.140.2.0.0 (iBridge: 19.16.16064.0.0,0)

Software:

    System Software Overview:

      System Version: macOS 10.15.7 (19H2026)
      Kernel Version: Darwin 19.6.0
      Time since boot: 11 days 6:12

Graphics/Displays:

    Intel Iris Plus Graphics:

      Chipset Model: Intel Iris Plus Graphics
      Type: GPU
      Bus: Built-In
      VRAM (Dynamic, Max): 1536 MB
      Vendor: Intel
      Device ID: 0x8a53
      Revision ID: 0x0007
      Metal: Supported, feature set macOS GPUFamily2 v1
      Displays:
        Color LCD:
          Display Type: Built-In Retina LCD
          Resolution: 2560 x 1600 Retina
          Framebuffer Depth: 30-Bit Color (ARGB2101010)
          Main Display: Yes
          Mirror: Off
          Online: Yes
          Automatically Adjust Brightness: No
          Connection Type: Internal


Installed Packages:
    alabaster: 0.7.13
    appdirs: 1.4.4
    appnope: 0.1.3
    asttokens: 2.2.1
    Babel: 2.12.1
    backcall: 0.2.0
    beautifulsoup4: 4.11.2
    blockdiag: 3.0.0
    build: 0.10.0
    certifi: 2021.10.8
    cftime: 1.6.2
    charset-normalizer: 3.1.0
    ChimeraX-AddCharge: 1.5.9.1
    ChimeraX-AddH: 2.2.5
    ChimeraX-AlignmentAlgorithms: 2.0.1
    ChimeraX-AlignmentHdrs: 3.3.1
    ChimeraX-AlignmentMatrices: 2.1
    ChimeraX-Alignments: 2.9.3
    ChimeraX-AlphaFold: 1.0
    ChimeraX-AltlocExplorer: 1.0.3
    ChimeraX-AmberInfo: 1.0
    ChimeraX-Arrays: 1.1
    ChimeraX-Atomic: 1.43.10
    ChimeraX-AtomicLibrary: 10.0.6
    ChimeraX-AtomSearch: 2.0.1
    ChimeraX-AxesPlanes: 2.3.2
    ChimeraX-BasicActions: 1.1.2
    ChimeraX-BILD: 1.0
    ChimeraX-BlastProtein: 2.1.2
    ChimeraX-BondRot: 2.0.1
    ChimeraX-BugReporter: 1.0.1
    ChimeraX-BuildStructure: 2.8
    ChimeraX-Bumps: 1.0
    ChimeraX-BundleBuilder: 1.2.2
    ChimeraX-ButtonPanel: 1.0.1
    ChimeraX-CageBuilder: 1.0.1
    ChimeraX-CellPack: 1.0
    ChimeraX-Centroids: 1.3.2
    ChimeraX-ChangeChains: 1.0.2
    ChimeraX-CheckWaters: 1.3.1
    ChimeraX-ChemGroup: 2.0.1
    ChimeraX-Clashes: 2.2.4
    ChimeraX-ColorActions: 1.0.3
    ChimeraX-ColorGlobe: 1.0
    ChimeraX-ColorKey: 1.5.3
    ChimeraX-CommandLine: 1.2.5
    ChimeraX-ConnectStructure: 2.0.1
    ChimeraX-Contacts: 1.0.1
    ChimeraX-Core: 1.6.1
    ChimeraX-CoreFormats: 1.1
    ChimeraX-coulombic: 1.4.2
    ChimeraX-Crosslinks: 1.0
    ChimeraX-Crystal: 1.0
    ChimeraX-CrystalContacts: 1.0.1
    ChimeraX-DataFormats: 1.2.3
    ChimeraX-Dicom: 1.2
    ChimeraX-DistMonitor: 1.4
    ChimeraX-DockPrep: 1.1.1
    ChimeraX-Dssp: 2.0
    ChimeraX-EMDB-SFF: 1.0
    ChimeraX-ESMFold: 1.0
    ChimeraX-FileHistory: 1.0.1
    ChimeraX-FunctionKey: 1.0.1
    ChimeraX-Geometry: 1.3
    ChimeraX-gltf: 1.0
    ChimeraX-Graphics: 1.1.1
    ChimeraX-Hbonds: 2.4
    ChimeraX-Help: 1.2.1
    ChimeraX-HKCage: 1.3
    ChimeraX-IHM: 1.1
    ChimeraX-ImageFormats: 1.2
    ChimeraX-IMOD: 1.0
    ChimeraX-IO: 1.0.1
    ChimeraX-ItemsInspection: 1.0.1
    ChimeraX-Label: 1.1.7
    ChimeraX-ListInfo: 1.1.1
    ChimeraX-Log: 1.1.5
    ChimeraX-LookingGlass: 1.1
    ChimeraX-Maestro: 1.8.2
    ChimeraX-Map: 1.1.4
    ChimeraX-MapData: 2.0
    ChimeraX-MapEraser: 1.0.1
    ChimeraX-MapFilter: 2.0.1
    ChimeraX-MapFit: 2.0
    ChimeraX-MapSeries: 2.1.1
    ChimeraX-Markers: 1.0.1
    ChimeraX-Mask: 1.0.2
    ChimeraX-MatchMaker: 2.0.12
    ChimeraX-MDcrds: 2.6
    ChimeraX-MedicalToolbar: 1.0.2
    ChimeraX-Meeting: 1.0.1
    ChimeraX-MLP: 1.1.1
    ChimeraX-mmCIF: 2.12
    ChimeraX-MMTF: 2.2
    ChimeraX-Modeller: 1.5.9
    ChimeraX-ModelPanel: 1.3.7
    ChimeraX-ModelSeries: 1.0.1
    ChimeraX-Mol2: 2.0
    ChimeraX-Mole: 1.0
    ChimeraX-Morph: 1.0.2
    ChimeraX-MouseModes: 1.2
    ChimeraX-Movie: 1.0
    ChimeraX-Neuron: 1.0
    ChimeraX-Nifti: 1.0
    ChimeraX-NRRD: 1.0
    ChimeraX-Nucleotides: 2.0.3
    ChimeraX-OpenCommand: 1.10.1
    ChimeraX-PDB: 2.7.2
    ChimeraX-PDBBio: 1.0
    ChimeraX-PDBLibrary: 1.0.2
    ChimeraX-PDBMatrices: 1.0
    ChimeraX-PickBlobs: 1.0.1
    ChimeraX-Positions: 1.0
    ChimeraX-PresetMgr: 1.1
    ChimeraX-PubChem: 2.1
    ChimeraX-ReadPbonds: 1.0.1
    ChimeraX-Registration: 1.1.1
    ChimeraX-RemoteControl: 1.0
    ChimeraX-RenderByAttr: 1.1
    ChimeraX-RenumberResidues: 1.1
    ChimeraX-ResidueFit: 1.0.1
    ChimeraX-RestServer: 1.1
    ChimeraX-RNALayout: 1.0
    ChimeraX-RotamerLibMgr: 3.0
    ChimeraX-RotamerLibsDunbrack: 2.0
    ChimeraX-RotamerLibsDynameomics: 2.0
    ChimeraX-RotamerLibsRichardson: 2.0
    ChimeraX-SaveCommand: 1.5.1
    ChimeraX-SchemeMgr: 1.0
    ChimeraX-SDF: 2.0.1
    ChimeraX-Segger: 1.0
    ChimeraX-Segment: 1.0.1
    ChimeraX-SelInspector: 1.0
    ChimeraX-SeqView: 2.8.3
    ChimeraX-Shape: 1.0.1
    ChimeraX-Shell: 1.0.1
    ChimeraX-Shortcuts: 1.1.1
    ChimeraX-ShowSequences: 1.0.1
    ChimeraX-SideView: 1.0.1
    ChimeraX-Smiles: 2.1
    ChimeraX-SmoothLines: 1.0
    ChimeraX-SpaceNavigator: 1.0
    ChimeraX-StdCommands: 1.10.3
    ChimeraX-STL: 1.0.1
    ChimeraX-Storm: 1.0
    ChimeraX-StructMeasure: 1.1.2
    ChimeraX-Struts: 1.0.1
    ChimeraX-Surface: 1.0.1
    ChimeraX-SwapAA: 2.0.1
    ChimeraX-SwapRes: 2.2.1
    ChimeraX-TapeMeasure: 1.0
    ChimeraX-Test: 1.0
    ChimeraX-Toolbar: 1.1.2
    ChimeraX-ToolshedUtils: 1.2.1
    ChimeraX-Topography: 1.0
    ChimeraX-Tug: 1.0.1
    ChimeraX-UI: 1.28.4
    ChimeraX-uniprot: 2.2.2
    ChimeraX-UnitCell: 1.0.1
    ChimeraX-ViewDockX: 1.2
    ChimeraX-VIPERdb: 1.0
    ChimeraX-Vive: 1.1
    ChimeraX-VolumeMenu: 1.0.1
    ChimeraX-VTK: 1.0
    ChimeraX-WavefrontOBJ: 1.0
    ChimeraX-WebCam: 1.0.2
    ChimeraX-WebServices: 1.1.1
    ChimeraX-Zone: 1.0.1
    colorama: 0.4.6
    comm: 0.1.3
    contourpy: 1.0.7
    cxservices: 1.2.2
    cycler: 0.11.0
    Cython: 0.29.33
    debugpy: 1.6.7
    decorator: 5.1.1
    docutils: 0.19
    executing: 1.2.0
    filelock: 3.9.0
    fonttools: 4.39.3
    funcparserlib: 1.0.1
    grako: 3.16.5
    h5py: 3.8.0
    html2text: 2020.1.16
    idna: 3.4
    ihm: 0.35
    imagecodecs: 2022.2.22
    imagesize: 1.4.1
    importlib-metadata: 6.6.0
    ipykernel: 6.21.1
    ipython: 8.10.0
    ipython-genutils: 0.2.0
    ipywidgets: 8.0.6
    jedi: 0.18.2
    Jinja2: 3.1.2
    jupyter-client: 8.0.2
    jupyter-core: 5.3.0
    jupyterlab-widgets: 3.0.7
    kiwisolver: 1.4.4
    line-profiler: 4.0.2
    lxml: 4.9.2
    lz4: 4.3.2
    MarkupSafe: 2.1.2
    matplotlib: 3.6.3
    matplotlib-inline: 0.1.6
    msgpack: 1.0.4
    nest-asyncio: 1.5.6
    netCDF4: 1.6.2
    networkx: 2.8.8
    nibabel: 5.0.1
    nptyping: 2.5.0
    numexpr: 2.8.4
    numpy: 1.23.5
    openvr: 1.23.701
    packaging: 21.3
    ParmEd: 3.4.3
    parso: 0.8.3
    pep517: 0.13.0
    pexpect: 4.8.0
    pickleshare: 0.7.5
    Pillow: 9.3.0
    pip: 23.0
    pkginfo: 1.9.6
    platformdirs: 3.5.0
    prompt-toolkit: 3.0.38
    psutil: 5.9.4
    ptyprocess: 0.7.0
    pure-eval: 0.2.2
    pycollada: 0.7.2
    pydicom: 2.3.0
    Pygments: 2.14.0
    pynrrd: 1.0.0
    PyOpenGL: 3.1.5
    PyOpenGL-accelerate: 3.1.5
    pyparsing: 3.0.9
    pyproject-hooks: 1.0.0
    PyQt6-commercial: 6.4.2
    PyQt6-Qt6: 6.4.3
    PyQt6-sip: 13.4.1
    PyQt6-WebEngine-commercial: 6.4.0
    PyQt6-WebEngine-Qt6: 6.4.3
    python-dateutil: 2.8.2
    pytz: 2023.3
    pyzmq: 25.0.2
    qtconsole: 5.4.0
    QtPy: 2.3.1
    RandomWords: 0.4.0
    requests: 2.28.2
    scipy: 1.9.3
    setuptools: 67.4.0
    setuptools-scm: 7.0.5
    sfftk-rw: 0.7.3
    six: 1.16.0
    snowballstemmer: 2.2.0
    sortedcontainers: 2.4.0
    soupsieve: 2.4.1
    sphinx: 6.1.3
    sphinx-autodoc-typehints: 1.22
    sphinxcontrib-applehelp: 1.0.4
    sphinxcontrib-blockdiag: 3.0.0
    sphinxcontrib-devhelp: 1.0.2
    sphinxcontrib-htmlhelp: 2.0.1
    sphinxcontrib-jsmath: 1.0.1
    sphinxcontrib-qthelp: 1.0.3
    sphinxcontrib-serializinghtml: 1.1.5
    stack-data: 0.6.2
    tables: 3.7.0
    tcia-utils: 1.2.0
    tifffile: 2022.10.10
    tinyarray: 1.2.4
    tomli: 2.0.1
    tornado: 6.3.1
    traitlets: 5.9.0
    typing-extensions: 4.5.0
    tzdata: 2023.3
    urllib3: 1.26.15
    wcwidth: 0.2.6
    webcolors: 1.12
    wheel: 0.38.4
    wheel-filename: 1.4.1
    widgetsnbextension: 4.0.7
    zipp: 3.15.0

Change History (7)

comment:1 by Zach Pearson, 2 years ago

Component: UnassignedDICOM
Owner: set to Zach Pearson
Platform: all
Priority: normalmoderate
Project: ChimeraX
Status: newassigned
Summary: ChimeraX bug report submissionShowing single plane of .nii file

comment:2 by Zach Pearson, 2 years ago

Summary: Showing single plane of .nii fileShowing single plane of .nii file gives traceback

comment:3 by Zach Pearson, 2 years ago

Cc: Tom Goddard added

Well, I'm baffled.

NIfTI images are stored slowest-axis first (so an X dimensional array of Y-by-Z images) but as far as I can tell ChimeraX expects image arrays to be fastest-axis first (a Z-dimensional away of X-by-Y images), so when we read in a NIfTI image we can reverse the tuple we get for the image shape (178x512x512 -> 512x512x178) and transpose the image array.

But this results in a completely blown out image and the error persists. DICOM provides a hint: we give DicomGrid a size that's (X,Y,Z) but if you check the shape of the output of DicomGrid.read_matrix it's (Z,Y,X). Aha! OK. Let's reverse the size tuple and not touch the image array. The image is no longer blown out of proportion but the bounding box is as before and the error persists.

So let's not reverse the tuple but do transpose the array. Realistic bounding box, way disproportionate image, error persists.

I give up, let's do neither. Realistic bounding box, realistically proportioned surface... and the error is still there!

comment:4 by Zach Pearson, 2 years ago

I think I got the axis orderings backwards in the above comment but the point is I tried every possible pair.

comment:5 by Tom Goddard, 2 years ago

In ChimeraX volume data a map with x,y,z axes sizes 100,200,300 as reported in the Log or in the Volume Viewer panel means that the numpy array of values will have shape (300,200,100).  In other words the first axis controls which z plane you are looking at.    That means in the GridData.read_matrix() routine if it is asking you for a chunk of the data of size 50,60,70 grid points in i,j,k then the routine must return a numpy array of shape (70,60,50).  The i,j,k grid indices correspond to the x,y,z axes.

comment:6 by Zach Pearson, 2 years ago

OH

OK. Will be fixed in tomorrow's build. This bug was a two-for-one -- the better way was to transpose the image array and that fixed NIfTI's not showing the correct slices in the correct segmentation windows, too.

Reversed which indices were used in which axis for read_matrix (and also made it respect ijk_size... d'oh) and the error went away.

comment:7 by Zach Pearson, 2 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.