Skip to content

Commit

Permalink
Merge pull request #1034 from mantidproject/cil_20210701
Browse files Browse the repository at this point in the history
Merge CIL recon
  • Loading branch information
samtygier-stfc authored Jul 8, 2021
2 parents 43891a2 + 5f2484b commit 599ff21
Show file tree
Hide file tree
Showing 21 changed files with 311 additions and 86 deletions.
8 changes: 6 additions & 2 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ requirements:
- pip
- setuptools=49.6.0
- sphinx=3.3.1
- numpy=1.20.*
- numpy=1.18.*
run:
- python=3.8.*
- pip
- astropy=4.2
- scipy=1.5.3
- scikit-image=0.18.*
- numpy=1.20.*
- numpy=1.18.*
- tomopy=1.9.*=cuda*
- cudatoolkit=9.2*
- cupy
Expand All @@ -35,6 +35,10 @@ requirements:
- h5py=3.1.0
- sarepy=2020.07
- psutil=5.8.*
- cil=21.2.*
- cil-astra=21.2.*
- ccpi-regulariser=20.9
- tomophantom=1.4.*

build:
number: 1
Expand Down
3 changes: 2 additions & 1 deletion docs/release_notes/next.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ New features
- #1011 : Pixel size should allow setting decimal places
- #1013 : NeXus Loading Window
- #904 : Default to using image center for ring removal COR
- #1025 : Add the Total Variation (TV) with Primal-Dual Hybrid Gradient (PDHG) from CIL

Fixes
-----
Expand Down Expand Up @@ -46,4 +47,4 @@ Developer Changes
Dependency updates
------------------

- pyqtgraph 0.12, scikit-image 0.18, tomopy 1.9, numpy 1.20
- pyqtgraph 0.12, scikit-image 0.18, tomopy 1.9, numpy 1.18
1 change: 1 addition & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ channels:
- dtasev
- astra-toolbox/label/dev
- conda-forge
- ccpi
- defaults
dependencies:
- mantidimaging
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ channels:
- dtasev
- astra-toolbox/label/dev
- conda-forge
- ccpi
- defaults
# Dependencies that can be installed with conda should be in conda/meta.yaml
dependencies:
Expand Down
9 changes: 5 additions & 4 deletions mantidimaging/core/io/loader/img_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
This module handles the loading of FIT, FITS, TIF, TIFF
"""
import os
from typing import Tuple, Optional, List, Callable, Union
from typing import Tuple, Optional, List, Callable, Union, TYPE_CHECKING

import numpy as np
import numpy.typing as npt
if TYPE_CHECKING:
import numpy.typing as npt

from mantidimaging.core.data import Images
from mantidimaging.core.io.utility import get_file_names, get_prefix
Expand All @@ -25,7 +26,7 @@ def execute(load_func: Callable[[str], np.ndarray],
dark_before_path: Optional[str],
dark_after_path: Optional[str],
img_format: str,
dtype: npt.DTypeLike,
dtype: 'npt.DTypeLike',
indices: Union[List[int], Indices, None],
progress: Optional[Progress] = None) -> Dataset:
"""
Expand Down Expand Up @@ -88,7 +89,7 @@ def __init__(self,
load_func: Callable[[str], np.ndarray],
img_format: str,
img_shape: Tuple[int, ...],
data_dtype: npt.DTypeLike,
data_dtype: 'npt.DTypeLike',
indices: Union[List[int], Indices, None],
progress: Optional[Progress] = None):
self.load_func = load_func
Expand Down
11 changes: 6 additions & 5 deletions mantidimaging/core/io/loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from dataclasses import dataclass
from logging import getLogger, Logger
from pathlib import Path
from typing import Tuple, List, Optional, Union
from typing import Tuple, List, Optional, Union, TYPE_CHECKING

import numpy as np
import numpy.typing as npt
if TYPE_CHECKING:
import numpy.typing as npt

from mantidimaging.core.data import Images
from mantidimaging.core.data.dataset import Dataset
Expand Down Expand Up @@ -88,7 +89,7 @@ class FileInformation:
def read_in_file_information(input_path: str,
in_prefix: str = '',
in_format: str = DEFAULT_IO_FILE_FORMAT,
data_dtype: npt.DTypeLike = np.float32) -> FileInformation:
data_dtype: 'npt.DTypeLike' = np.float32) -> FileInformation:
input_file_names = get_file_names(input_path, in_format, in_prefix)
dataset = load(input_path,
in_prefix=in_prefix,
Expand All @@ -110,7 +111,7 @@ def load_log(log_file: str) -> IMATLogFile:
return IMATLogFile(f.readlines(), log_file)


def load_p(parameters: ImageParameters, dtype: npt.DTypeLike, progress: Progress) -> Images:
def load_p(parameters: ImageParameters, dtype: 'npt.DTypeLike', progress: Progress) -> Images:
return load(input_path=parameters.input_path,
in_prefix=parameters.prefix,
in_format=parameters.format,
Expand All @@ -134,7 +135,7 @@ def load(input_path: Optional[str] = None,
input_path_dark_after: Optional[str] = None,
in_prefix: str = '',
in_format: str = DEFAULT_IO_FILE_FORMAT,
dtype: npt.DTypeLike = np.float32,
dtype: 'npt.DTypeLike' = np.float32,
file_names: Optional[List[str]] = None,
indices: Optional[Union[List[int], Indices]] = None,
progress: Optional[Progress] = None) -> Dataset:
Expand Down
7 changes: 4 additions & 3 deletions mantidimaging/core/io/loader/stack_loader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI
# SPDX - License - Identifier: GPL-3.0-or-later
from typing import Optional, Callable, Union, List, Tuple
from typing import Optional, Callable, Union, List, Tuple, TYPE_CHECKING

import numpy as np
import numpy.typing as npt
if TYPE_CHECKING:
import numpy.typing as npt

from mantidimaging.core.data import Images
from mantidimaging.core.parallel import utility as pu
Expand Down Expand Up @@ -36,7 +37,7 @@ def do_stack_load_seq(data: np.ndarray, new_data: np.ndarray, img_shape: Tuple[i

def execute(load_func: Callable[[str], np.ndarray],
file_name: str,
dtype: npt.DTypeLike,
dtype: 'npt.DTypeLike',
name: str,
indices: Union[List[int], Indices, None] = None,
progress: Optional[Progress] = None) -> Images:
Expand Down
9 changes: 5 additions & 4 deletions mantidimaging/core/parallel/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from logging import getLogger
from multiprocessing import Array
from multiprocessing.pool import Pool
from typing import List, Tuple, Type, Union
from typing import List, Tuple, Type, Union, TYPE_CHECKING

import numpy as np
import numpy.typing as npt
if TYPE_CHECKING:
import numpy.typing as npt

from mantidimaging.core.utility.memory_usage import system_free_memory
from mantidimaging.core.utility.progress_reporting import Progress
Expand All @@ -27,7 +28,7 @@ def enough_memory(shape, dtype):
return full_size_KB(shape=shape, axis=0, dtype=dtype) < system_free_memory().kb()


def create_array(shape: Tuple[int, ...], dtype: npt.DTypeLike = np.float32) -> np.ndarray:
def create_array(shape: Tuple[int, ...], dtype: 'npt.DTypeLike' = np.float32) -> np.ndarray:
"""
Create an array, either in a memory file (if name provided), or purely in memory (if name is None)
Expand All @@ -44,7 +45,7 @@ def create_array(shape: Tuple[int, ...], dtype: npt.DTypeLike = np.float32) -> n
return _create_shared_array(shape, dtype)


def _create_shared_array(shape, dtype: npt.DTypeLike = np.float32) -> np.ndarray:
def _create_shared_array(shape, dtype: 'npt.DTypeLike' = np.float32) -> np.ndarray:
ctype: SimpleCType = ctypes.c_float # default to numpy float32 / C type float
if dtype == np.uint8 or dtype == 'uint8':
ctype = ctypes.c_uint8
Expand Down
8 changes: 5 additions & 3 deletions mantidimaging/core/reconstruct/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI
# SPDX - License - Identifier: GPL-3.0-or-later

from typing import Union

from .astra_recon import AstraRecon
from .tomopy_recon import TomopyRecon
from .cil_recon import CILRecon
from .base_recon import BaseRecon


def get_reconstructor_for(algorithm: str) -> Union[AstraRecon, TomopyRecon]:
def get_reconstructor_for(algorithm: str) -> BaseRecon:
if algorithm == "gridrec":
return TomopyRecon()
if algorithm.startswith("CIL"):
return CILRecon()
else:
return AstraRecon()
2 changes: 1 addition & 1 deletion mantidimaging/core/reconstruct/astra_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def single_sino(sino: np.ndarray, cor: ScalarCoR, proj_angles: ProjectionAngles,
recon_params: ReconstructionParameters) -> np.ndarray:
assert sino.ndim == 2, "Sinogram must be a 2D image"

sino = BaseRecon.sino_recon_prep(sino)
sino = BaseRecon.negative_log(sino)
image_width = sino.shape[1]
vectors = vec_geom_init2d(proj_angles, 1.0, cor.to_vec(image_width).value)
vol_geom = astra.create_vol_geom((image_width, image_width))
Expand Down
10 changes: 7 additions & 3 deletions mantidimaging/core/reconstruct/base_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

class BaseRecon:
@staticmethod
def sino_recon_prep(sino: np.ndarray):
return -np.log(np.maximum(sino, MIN_PIXEL_VALUE))
def find_cor(images: Images, slice_idx: int, start_cor: float, recon_params: ReconstructionParameters) -> float:
raise NotImplementedError("Base class call")

@staticmethod
def negative_log(data: np.ndarray) -> np.ndarray:
return -np.log(np.maximum(data, MIN_PIXEL_VALUE))

@staticmethod
def single_sino(sino: np.ndarray, cor: ScalarCoR, proj_angles: ProjectionAngles,
Expand Down Expand Up @@ -53,4 +57,4 @@ def full(images: Images,

@staticmethod
def allowed_filters() -> List[str]:
raise NotImplementedError("Base class call")
return []
Loading

0 comments on commit 599ff21

Please sign in to comment.