Skip to content

Commit dfb77a1

Browse files
committed
delay TIGRE imports
1 parent 56d7468 commit dfb77a1

3 files changed

Lines changed: 27 additions & 22 deletions

File tree

Wrappers/Python/cil/plugins/tigre/FBP.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
from cil.framework.labels import AcquisitionDimension, ImageDimension
2525
from cil.plugins.tigre import CIL2TIGREGeometry
2626

27-
try:
28-
from tigre.algorithms import fdk, fbp
29-
except ModuleNotFoundError:
30-
raise ModuleNotFoundError("This plugin requires the additional package TIGRE\n" +
31-
"Please install it via conda as tigre from the ccpi channel")
32-
3327
class FBP(DataProcessor):
3428

3529
'''FBP Filtered Back Projection is a reconstructor for 2D and 3D parallel and cone-beam geometries.
@@ -82,7 +76,7 @@ def check_input(self, dataset):
8276

8377
AcquisitionDimension.check_order_for_engine('tigre', dataset.geometry)
8478
return True
85-
79+
8680
def _set_up(self):
8781
"""
8882
Configure processor attributes that require the data to setup
@@ -91,7 +85,12 @@ def _set_up(self):
9185
self._shape_out = self.image_geometry.shape
9286

9387
def process(self, out=None):
94-
88+
try:
89+
from tigre.algorithms import fdk, fbp
90+
except ModuleNotFoundError:
91+
raise ModuleNotFoundError(
92+
"This plugin requires the additional package TIGRE\n"
93+
"Please install it via conda as tigre from the ccpi channel")
9594
if self.tigre_geom.is2D:
9695
data_temp = np.expand_dims(self.get_input().as_array(), axis=1)
9796

Wrappers/Python/cil/plugins/tigre/Geometry.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
try:
2323
from tigre.utilities.geometry import Geometry
2424
except ModuleNotFoundError:
25-
raise ModuleNotFoundError("This plugin requires the additional package TIGRE\n" +
26-
"Please install it via conda as tigre from the ccpi channel")
25+
Geometry = object
2726

2827
class CIL2TIGREGeometry(object):
2928
@staticmethod
@@ -50,10 +49,12 @@ def getTIGREGeometry(ig, ag):
5049
return tg, angles
5150

5251
class TIGREGeometry(Geometry):
53-
5452
def __init__(self, ig, ag):
55-
56-
Geometry.__init__(self)
53+
if Geometry is object:
54+
raise ModuleNotFoundError(
55+
"This plugin requires the additional package TIGRE\n"
56+
"Please install it via conda as tigre from the ccpi channel")
57+
super().__init__()
5758

5859
if ag.geom_type not in ['cone', 'parallel']:
5960
raise ValueError(f"CIL cannot use TIGRE to process geometries of type {ag.geom_type}.")

Wrappers/Python/cil/plugins/tigre/ProjectionOperator.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626

2727
log = logging.getLogger(__name__)
2828

29-
try:
30-
from _Atb import _Atb_ext as Atb
31-
from _Ax import _Ax_ext as Ax
32-
33-
except ModuleNotFoundError:
34-
raise ModuleNotFoundError(
35-
"This plugin requires the additional package TIGRE\n" +
36-
"Please install it via conda as tigre from the ccpi channel")
37-
3829
try:
3930
from tigre.utilities.gpu import GpuIds
4031
has_gpu_sel = True
@@ -176,6 +167,13 @@ def __init__(self,
176167
self.gpuids = GpuIds()
177168

178169
def __call_Ax(self, data):
170+
try:
171+
from _Ax import _Ax_ext as Ax
172+
except ModuleNotFoundError:
173+
raise ModuleNotFoundError(
174+
"This plugin requires the additional package TIGRE\n"
175+
"Please install it via conda as tigre from the ccpi channel")
176+
179177
if has_gpu_sel:
180178
return Ax(data, self.tigre_geom, self.tigre_geom.angles,
181179
self.method['direct'], self.tigre_geom.mode, self.gpuids)
@@ -207,6 +205,13 @@ def direct(self, x, out=None):
207205
return out
208206

209207
def __call_Atb(self, data):
208+
try:
209+
from _Atb import _Atb_ext as Atb
210+
except ModuleNotFoundError:
211+
raise ModuleNotFoundError(
212+
"This plugin requires the additional package TIGRE\n"
213+
"Please install it via conda as tigre from the ccpi channel")
214+
210215
if has_gpu_sel:
211216
return Atb(data, self.tigre_geom, self.tigre_geom.angles,
212217
self.method['adjoint'], self.tigre_geom.mode,

0 commit comments

Comments
 (0)