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

Fix bug with show2D and 3D DataContainers #1539

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
* x.x.x
- Allow reduction methods on the DataContainer class to accept axis argument as string which matches values in dimension_labels
- Added the functions `set_norms` and `get_norms` to the `BlockOperator` class
- Internal variable name change in BlockOperator to aid understanding
- Internal variable name change in BlockOperator to aid understanding
- Bug fix for BlockDataContainer as iterator
- Dropped support for IPP versions older than 2021.10 due to header changes
- Fix build include directories
- proximal of MixedL21Norm with numpy backend now accepts numpy ndarray, DataContainer and float as tau parameter
- Allow show2D to be used with 3D `DataContainer` instances

* 23.1.0
- Fix bug in IndicatorBox proximal_conjugate
Expand Down
7 changes: 5 additions & 2 deletions Wrappers/Python/cil/framework/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -2791,11 +2791,14 @@ def as_array(self):
return self.array


def get_slice(self,**kw):
def get_slice(self, **kw):
'''
Returns a new DataContainer containing a single slice of in the requested direction. \
Returns a new DataContainer containing a single slice in the requested direction. \
Pass keyword arguments <dimension label>=index
'''
# Force is not relevant for a DataContainer:
kw.pop('force', None)

new_array = None

#get ordered list of current dimensions
Expand Down
4 changes: 2 additions & 2 deletions Wrappers/Python/cil/utilities/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class show2D(show_base):

Plots 1 or more 2D plots in an (n x num_cols) matrix.
Can plot multiple slices from one 3D dataset, or compare multiple datasets
Inputs can be single arguments or list of arguments that will be sequentally applied to subplots
Inputs can be single arguments or list of arguments that will be sequentially applied to subplots
If no slice_list is passed a 3D dataset will display the centre slice of the outer dimension, a 4D dataset will show the centre slices of the two outer dimension.


Expand All @@ -392,7 +392,7 @@ class show2D(show_base):
The title for each figure
slice_list: tuple, int, list of tuples, list of ints, optional
The slices to show. A list of integers will show slices for the outer dimension. For 3D datacontainers single slice: (direction, index). For 4D datacontainers two slices: [(direction0, index),(direction1, index)].
fix_range: boolian, tuple, list of tuples
fix_range: boolean, tuple, list of tuples
Sets the display range of the data. `True` sets all plots to the global (min, max).
axis_labels: tuple, list of tuples, optional
The axis labels for each figure e.g. ('x','y')
Expand Down
31 changes: 30 additions & 1 deletion Wrappers/Python/test/test_DataContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,36 @@ def test_ImageDataSubset(self):
ss3 = vol.get_slice(channel=0)
self.assertListEqual([ImageGeometry.HORIZONTAL_Y, ImageGeometry.HORIZONTAL_X], list(ss3.geometry.dimension_labels))

def test_DataContainerSubset(self):
dc = DataContainer(numpy.ones((2,3,4,5)))

dc.dimension_labels =[AcquisitionGeometry.CHANNEL ,
AcquisitionGeometry.ANGLE , AcquisitionGeometry.VERTICAL ,
AcquisitionGeometry.HORIZONTAL]

# test reshape
new_order = [AcquisitionGeometry.HORIZONTAL ,
AcquisitionGeometry.CHANNEL , AcquisitionGeometry.VERTICAL ,
AcquisitionGeometry.ANGLE]
dc.reorder(new_order)

self.assertListEqual(new_order, list(dc.dimension_labels))

ss1 = dc.get_slice(vertical=0)

self.assertListEqual([AcquisitionGeometry.HORIZONTAL ,
AcquisitionGeometry.CHANNEL ,
AcquisitionGeometry.ANGLE], list(ss1.dimension_labels))

ss2 = dc.get_slice(vertical=0, channel=0)
self.assertListEqual([AcquisitionGeometry.HORIZONTAL ,
AcquisitionGeometry.ANGLE], list(ss2.dimension_labels))

# Check we can get slice still even if force parameter is passed:
ss3 = dc.get_slice(vertical=0, channel=0, force=True)
self.assertListEqual([AcquisitionGeometry.HORIZONTAL ,
AcquisitionGeometry.ANGLE], list(ss3.dimension_labels))


def test_DataContainerChaining(self):
dc = self.create_DataContainer(256,256,256,1)
Expand Down Expand Up @@ -1286,4 +1316,3 @@ def test_fill_dimension_AcquisitionData(self):
numpy.testing.assert_array_equal(u.get_slice(channel=1, vertical=1).as_array(), 3 * a)