Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor framework #1692

Merged
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
d21f9be
Make config file to store important strings.
manchester-jhellier Feb 8, 2024
31078a4
Switch stuff in framework.py to use constants rather than refer to cl…
manchester-jhellier Feb 8, 2024
fee1ac4
Add license and fix import issue.
manchester-jhellier Feb 8, 2024
ead2e4b
Attempt to replace AcquisitionGeometry and ImageGeometry member calls…
manchester-jhellier Feb 8, 2024
16255c1
Pull static methods out of DataOrder and make them plain functions.
manchester-jhellier Feb 9, 2024
0693987
Make AcquisitionGeometry inherit from a blank base class.
manchester-jhellier Feb 9, 2024
156b146
Switch get_order_for_engine's check to look for BaseAcquisitionGeomet…
manchester-jhellier Feb 9, 2024
41c71ab
Move BaseAcquisitionGeometry to a new file.
manchester-jhellier Feb 9, 2024
68916b6
Move DataOrder and associated functions to label.py.
manchester-jhellier Feb 9, 2024
1b5e762
Destroy DataOrder.
manchester-jhellier Feb 9, 2024
b3671e2
Adjust whitespace.
manchester-jhellier Feb 9, 2024
16f0cc3
Move cilacc out of framework.py .
manchester-jhellier Feb 9, 2024
aeb9985
Move DataContainer and ImageGeometry into separate file (still coupled).
manchester-jhellier Feb 9, 2024
b71c063
Move Partitioner and AcquisitionData to new files.
manchester-jhellier Feb 10, 2024
3b2a528
Move AcquisitionGeometry to a new file.
manchester-jhellier Feb 10, 2024
054b2e0
Move a bunch of stuff relating to SystemConfiguration into a new file.
manchester-jhellier Feb 10, 2024
d9d0bd8
Rename framework.py to processors.py to better reflect its new purpose.
manchester-jhellier Feb 10, 2024
cd145c0
Bugfix (bad import).
manchester-jhellier Feb 10, 2024
1d55792
Rename AquisitionData.py file to acquisition_data.py to avoid import …
manchester-jhellier Feb 10, 2024
f561cd0
Rename BlockDataContainer.py file to block_data_container.py to avoid…
manchester-jhellier Feb 10, 2024
d049b9b
Rename Partitioner.py file to partitioner.py to avoid import ambiguity.
manchester-jhellier Feb 10, 2024
82c059a
Rename BlockGeometry.py file to block_geometry.py to avoid import amb…
manchester-jhellier Feb 10, 2024
f289e6e
Rename DataContainer.py file to data_container.py to avoid import amb…
manchester-jhellier Feb 10, 2024
9423e47
Amend licenses in files considerably changed by refactoring process.
manchester-jhellier Feb 10, 2024
a906387
Fix import issues with SIRF tests, and refactor imports.
manchester-jhellier Feb 14, 2024
945e823
Revert test_SIRF.py back to the master edition (less stuff affected t…
manchester-jhellier Feb 14, 2024
96c2670
backward-compat: DataOrder.get_order_for_engine
casperdcl Mar 27, 2024
2db4e2c
backward-compat: AcquisitionGeometry & ImageGeometry properties
casperdcl Mar 27, 2024
f3f2b17
fix mypy
casperdcl Mar 27, 2024
ee7545a
Merge remote-tracking branch 'upstream/master' into DataOrder-rebase
casperdcl Apr 9, 2024
fcb3858
fix merge conflicts
casperdcl Apr 9, 2024
e516c7f
Update Wrappers/Python/cil/framework/data_container.py
lauramurgatroyd Apr 16, 2024
3d0b8b3
Merge branch 'master' into DataOrder-rebase
casperdcl Aug 12, 2024
daae9d2
manual merge resolution
casperdcl Aug 12, 2024
81e9bab
fix missing refactor
casperdcl Aug 12, 2024
f712ea4
move {Image,Vector}{Data,Geometry}
casperdcl Aug 14, 2024
18e2609
add geometry_labels
casperdcl Aug 14, 2024
477bfe8
misc review comments
casperdcl Aug 14, 2024
5457830
fix merge
casperdcl Aug 14, 2024
f6bafe6
Update label to use enums and separate functionality
gfardell Aug 14, 2024
0a5e43c
geometry property returns value
gfardell Aug 15, 2024
74595af
angle property returns value
gfardell Aug 15, 2024
9382f1c
Remove redundant enum checks
gfardell Aug 15, 2024
fe6803e
rename label.py
gfardell Aug 15, 2024
f8cb315
rename DimensionLabels classes for consistency
gfardell Aug 15, 2024
e1977c2
simplified enum methods by overwriting default eq and contains
gfardell Aug 15, 2024
d8539d8
fix case error
gfardell Aug 15, 2024
32a5f2b
added unit tests for labels.py
gfardell Aug 15, 2024
e82d134
renamed to AcquisitionTypes and AcquisitionDimensions for consistency
gfardell Aug 15, 2024
025c739
added doc strings
gfardell Aug 15, 2024
35f2dff
updated changelog
gfardell Aug 15, 2024
a6683a9
Simplification of enum useage
gfardell Aug 16, 2024
36fb87a
doc string updates on reorder
gfardell Aug 16, 2024
894c369
super update
gfardell Aug 16, 2024
a5da5de
data order simplification
gfardell Aug 16, 2024
5c40579
update unittests
gfardell Aug 16, 2024
6300f65
Update CHANGELOG.md
gfardell Aug 16, 2024
a534c67
drop default reorder(order=None)
casperdcl Aug 19, 2024
55dc29b
add labels.StrEnum
casperdcl Aug 19, 2024
714434b
fix tests
casperdcl Aug 19, 2024
441135d
Merge remote-tracking branch 'upstream/master' into DataOrder-rebase
casperdcl Aug 19, 2024
73cbdfa
use more tuples
casperdcl Aug 19, 2024
96ec5ab
combine Acquisition{Types,Dimensions}(StrEnum) => AcquisitionType(Flag)
casperdcl Aug 19, 2024
cdb4b9b
missing reorder()
casperdcl Aug 21, 2024
28255ec
explicit labels import
casperdcl Aug 21, 2024
d8ff528
fix docstring
casperdcl Aug 21, 2024
e885f2d
better OOP
casperdcl Aug 21, 2024
11ab748
AcquisitionType.validate
casperdcl Aug 21, 2024
4320645
raise error on invalid dimensions
casperdcl Aug 21, 2024
8bb8821
rename labels
casperdcl Aug 21, 2024
818a1a4
Merge remote-tracking branch 'upstream/master' into DataOrder-rebase
casperdcl Aug 21, 2024
96e3429
update docstrings
casperdcl Aug 21, 2024
2a5c0f7
Update labels docs
hrobarts Aug 21, 2024
edb7953
Update changelog, add contributors to notice
hrobarts Aug 21, 2024
56f8979
Update docs
hrobarts Aug 22, 2024
df53ee7
Merge branch 'master' into DataOrder-rebase
hrobarts Aug 22, 2024
78b2fbb
Merge branch 'master' of github.com:TomographicImaging/CIL into DataO…
hrobarts Aug 22, 2024
23e59b6
fix AcquisitionType.dimension comparison to '2D'/'3D'
casperdcl Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
- Added SVRG and LSVRG stochastic functions (#1625)
- Added SAG and SAGA stochastic functions (#1624)
- Allow `SumFunction` with 1 item (#1857)
- Added `labels` module with `ImageDimension`, `AcquisitionDimension`, `AcquisitionType`, `AngleUnit`, `FillType` (#1692)
- Enhancements:
- Use ravel instead of flat in KullbackLeibler numba backend (#1874)
- Upgrade Python wrapper (#1873, #1875)
- Internal refactor: Replaced string-based label checks with enum-based checks for improved type safety and consistency (#1692)
- Internal refactor: Separate framework into multiple files (#1692)
- Bug fixes:
- `ImageData` removes dimensions of size 1 from the input array. This fixes an issue where single slice reconstructions from 3D data would fail due to shape mismatches (#1885)
- Make Binner accept accelerated=False (#1887)
Expand Down Expand Up @@ -37,9 +40,6 @@
- Merged the files `BlockGeometry.py` and `BlockDataContainer.py` in `framework` to one file `block.py`. Please use `from cil.framework import BlockGeometry, BlockDataContainer` as before (#1799)
- Bug fix in `FGP_TV` function to set the default behaviour not to enforce non-negativity (#1826).




* 24.0.0
- Update to new CCPi-Regularisation toolkit v24.0.0. This is a backward incompatible release of the toolkit.
- CIL plugin support for TIGRE version v2.6
Expand Down
2 changes: 2 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Ashley Gillman (2024) -12
Zeljko Kereta (2024) - 5
Evgueni Ovtchinnikov (2024) -1
Georg Schramm (2024) - 13
Joshua Hellier (2024) - 3
Nicholas Whyatt (2024) - 1

CIL Advisory Board:
Llion Evans - 9
Expand Down
28 changes: 11 additions & 17 deletions Wrappers/Python/cil/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@
# Authors:
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt

import numpy
import sys
from datetime import timedelta, datetime
import warnings
from functools import reduce
from .framework import cilacc
from .framework import DataContainer
from .framework import ImageData, AcquisitionData
from .framework import ImageGeometry, AcquisitionGeometry
from .framework import VectorData, VectorGeometry
from .framework import find_key, message
from .framework import DataProcessor, Processor
from .framework import AX, PixelByPixelDataProcessor, CastDataContainer
from .block import BlockDataContainer
from .block import BlockGeometry
from .framework import DataOrder
from .framework import Partitioner
from .cilacc import cilacc
gfardell marked this conversation as resolved.
Show resolved Hide resolved
from .acquisition_data import AcquisitionData
from .acquisition_geometry import AcquisitionGeometry, SystemConfiguration
from .data_container import DataContainer
from .image_data import ImageData
from .image_geometry import ImageGeometry
from .vector_data import VectorData
from .vector_geometry import VectorGeometry
from .processors import DataProcessor, Processor, AX, PixelByPixelDataProcessor, CastDataContainer
from .block import BlockDataContainer, BlockGeometry
from .partitioner import Partitioner
120 changes: 120 additions & 0 deletions Wrappers/Python/cil/framework/acquisition_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Copyright 2018 United Kingdom Research and Innovation
# Copyright 2018 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Authors:
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt
import numpy

from .labels import AcquisitionDimension, Backend
from .data_container import DataContainer
from .partitioner import Partitioner


class AcquisitionData(DataContainer, Partitioner):
'''DataContainer for holding 2D or 3D sinogram'''
__container_priority__ = 1

@property
def geometry(self):
return self._geometry

@geometry.setter
def geometry(self, val):
self._geometry = val

@property
def dimension_labels(self):
return self.geometry.dimension_labels

@dimension_labels.setter
def dimension_labels(self, val):
if val is not None:
raise ValueError("Unable to set the dimension_labels directly. Use geometry.set_labels() instead")

def __init__(self,
array = None,
deep_copy=True,
geometry = None,
**kwargs):

dtype = kwargs.get('dtype', numpy.float32)

if geometry is None:
raise AttributeError("AcquisitionData requires a geometry")

labels = kwargs.get('dimension_labels', None)
if labels is not None and labels != geometry.dimension_labels:
raise ValueError("Deprecated: 'dimension_labels' cannot be set with 'allocate()'. Use 'geometry.set_labels()' to modify the geometry before using allocate.")

if array is None:
array = numpy.empty(geometry.shape, dtype=dtype)
elif issubclass(type(array) , DataContainer):
array = array.as_array()
elif issubclass(type(array) , numpy.ndarray):
# remove singleton dimensions
array = numpy.squeeze(array)
else:
raise TypeError('array must be a CIL type DataContainer or numpy.ndarray got {}'.format(type(array)))

if array.shape != geometry.shape:
raise ValueError('Shape mismatch got {} expected {}'.format(array.shape, geometry.shape))

super(AcquisitionData, self).__init__(array, deep_copy, geometry=geometry,**kwargs)


def get_slice(self,channel=None, angle=None, vertical=None, horizontal=None, force=False):
'''Returns a new dataset of a single slice in the requested direction.'''
try:
geometry_new = self.geometry.get_slice(channel=channel, angle=angle, vertical=vertical, horizontal=horizontal)
except ValueError:
if force:
geometry_new = None
else:
raise ValueError ("Unable to return slice of requested AcquisitionData. Use 'force=True' to return DataContainer instead.")

#get new data
#if vertical = 'centre' slice convert to index and subset, this will interpolate 2 rows to get the center slice value
if vertical == 'centre':
dim = self.geometry.dimension_labels.index('vertical')

centre_slice_pos = (self.geometry.shape[dim]-1) / 2.
ind0 = int(numpy.floor(centre_slice_pos))
w2 = centre_slice_pos - ind0
out = DataContainer.get_slice(self, channel=channel, angle=angle, vertical=ind0, horizontal=horizontal)

if w2 > 0:
out2 = DataContainer.get_slice(self, channel=channel, angle=angle, vertical=ind0 + 1, horizontal=horizontal)
out = out * (1 - w2) + out2 * w2
else:
out = DataContainer.get_slice(self, channel=channel, angle=angle, vertical=vertical, horizontal=horizontal)

if len(out.shape) == 1 or geometry_new is None:
return out
else:
return AcquisitionData(out.array, deep_copy=False, geometry=geometry_new, suppress_warning=True)

def reorder(self, order):
'''
Reorders the data in memory as requested. This is an in-place operation.

Parameters
----------
order: list or str
Ordered list of labels from self.dimension_labels, or string 'astra' or 'tigre'.
'''
if order in Backend:
order = AcquisitionDimension.get_order_for_engine(order, self.geometry)

super().reorder(order)
Loading
Loading