1

I am using TIGRE (an open source toolbox for reconstruction provided by CERN). The original code was written for python 3.7 and is struggling to run correctly on 3.9.

This is the original code and the error it produces.

#%% Initialize
import tigre
import numpy as np
from tigre.utilities import sample_loader
from tigre.utilities import CTnoise
import tigre.algorithms as algs

#%% Geometry
geo = tigre.geometry_default(high_resolution=False)

#%% Load data and generate projections
# define angles
angles = np.linspace(0, 2 * np.pi, 100)
# Load thorax phatom data
head = sample_loader.load_head_phantom(geo.nVoxel)
# generate projections
projections = tigre.Ax(head, geo, angles)
# add noise
noise_projections = CTnoise.add(projections, Poisson=1e5, Gaussian=np.array([0, 10]))

#%% Reconstruct image using OS-SART and FDK

# FDK
imgFDK = algs.fdk(noise_projections, geo, angles)
# OS-SART

niter = 50
imgOSSART = algs.ossart(noise_projections, geo, angles, niter)

imgOSSART.save

#%% Show the results
tigre.plotimg(np.concatenate([imgFDK, imgOSSART], axis=1), dim="z")

Error:

  File ~\TIGRE\Python\demos\d04_SimpleReconstruction.py:54 in <module>
    imgOSSART.save

AttributeError: 'numpy.ndarray' object has no attribute 'save'

When I remove the imgOSSART.save, the program runs but returns an empty figure:

<Figure size 432x288 with 0 Axes>
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\animation.py:889: UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you have outputted the Animation using `plt.show()` or `anim.save()`.
  warnings.warn(

Does anyone know a way to tackle this or to get python 3.7?

flawr
  • 10,814
  • 3
  • 41
  • 71
phoenix156
  • 13
  • 2
  • Well, getting Python 3.7 is easy with something like miniconda. Install Miniconda3 (if you don't already have it) and create an environment with `conda create --name py37env python==3.7`. Better yet, create a specific environment just for this project, with a name more specific to the project. – joanis Aug 06 '22 at 12:34
  • Where did this code come from? Did you write it yourself? Or did you copy paste it from somewhere? Double check that you have the most recent version of the source. – Code-Apprentice Aug 06 '22 at 13:06
  • 2
    Happy to see someone use my tool :) Feel free to ask in the Github Issues/Discussion too. – Ander Biguri Aug 09 '22 at 11:07

1 Answers1

3

In numpy ndarrays are saved using the numpy.save function. So, try something like this instead

np.save('imgOSSART.npy', imgOSSART)

However, I don't think this solves the problem.


The code snippet seems to be from here, which does not include np.save.

To save the animation as a gif, you can try adding savegif parameter

tigre.plotimg(
   np.concatenate([imgFDK, imgOSSART], axis=1), 
   dim="z", 
   savegif='filename.gif'
)
Mansur
  • 182
  • 2
  • 8