Skip to content

Volume shrink examples#283

Open
hrobarts wants to merge 1 commit intomainfrom
volume_shrink_example
Open

Volume shrink examples#283
hrobarts wants to merge 1 commit intomainfrom
volume_shrink_example

Conversation

@hrobarts
Copy link
Contributor

Example notebook demonstrating functionality of the VolumeShrinker tool

Comment on lines +34 to +38
"source": [
"file_name = '/mnt/share/ALC_ptychography_alignment/simulations/cylinder_tilt_30.nxs'\n",
"data = NEXUSDataReader(file_name=file_name).read()\n",
"show2D(data, slice_list=('angle',0))"
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please can you add some text to say that the data is available on the share available internally to the tomography team

@lauramurgatroyd
Copy link
Member

Helpful demo for having a go with the volume shrinker :)

Copy link

@Neonbluestoplight Neonbluestoplight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hrobarts,

Just a tiny error I'm facing with the supported backends but the tool itself is really well thought out!

"vs = VolumeShrinker(data, recon_backend='astra')\n",
"ig_reduced = vs.run(limits={'horizontal_x':(10, 150), 'vertical':(5, 50)}, preview=True)"
]
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hrobarts,

I am encountering an error when change recon_backend from 'astra' to 'tigre':

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[23], [line 2](notebook-cell:?execution_count=23&line=2)
      1 vs = VolumeShrinker(data, recon_backend='tigre')
----> [2](notebook-cell:?execution_count=23&line=2) ig_reduced = vs.run(limits={'horizontal_x':(10, 150), 'vertical':(5, 50)}, preview=True)

File ~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/utilities/shrink_volume.py:168, in VolumeShrinker.run(self, limits, preview, method, **kwargs)
    166     if method.lower() == 'manual':
    167         mask_radius = kwargs.pop('mask_radius', None)
--> [168](/home/username/desktop/cil-demos/misc/~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/utilities/shrink_volume.py:168)         recon, binning = self._get_recon(mask_radius=mask_radius)
    170     self._plot_with_bounds(recon, bounds, binning)
    172 return self.update_ig(self.data.geometry.get_ImageGeometry(), bounds)

File ~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/utilities/shrink_volume.py:203, in VolumeShrinker._get_recon(self, mask_radius)
    200 ag = data_binned.geometry
    201 ig = ag.get_ImageGeometry()
--> [203](/home/username/desktop/cil-demos/misc/~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/utilities/shrink_volume.py:203) fbp = self.recon_method(ig, ag)
    204 recon = fbp(data_binned)
    206 if mask_radius is not None:

File ~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/plugins/tigre/FBP.py:67, in FBP.__init__(self, image_geometry, acquisition_geometry, **kwargs)
     63 if device != 'gpu':
     64     raise ValueError("TIGRE FBP is GPU only. Got device = {}".format(device))
---> [67](/home/username/desktop/cil-demos/misc/~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/plugins/tigre/FBP.py:67) AcquisitionDimension.check_order_for_engine('tigre', acquisition_geometry)
     68 ImageDimension.check_order_for_engine('tigre', image_geometry)
...
    127     f"Expected dimension_label order {order_requested},"
    128     f" got {tuple(geometry.dimension_labels)}."
    129     f" Try using `data.reorder('{engine}')` to permute for {engine}")

ValueError: Expected dimension_label order (<AcquisitionDimension.ANGLE: 'angle'>, <AcquisitionDimension.VERTICAL: 'vertical'>, <AcquisitionDimension.HORIZONTAL: 'horizontal'>), got (<AcquisitionDimension.VERTICAL: 'vertical'>, <AcquisitionDimension.ANGLE: 'angle'>, <AcquisitionDimension.HORIZONTAL: 'horizontal'>). Try using `data.reorder('tigre')` to permute for tigre

It seems to be tied to the preview=True option specifically which would explain why it didn't show up in tests since there are no test cases for preview=True.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error can be passed by just using

data.reorder('tigre')

vs = VolumeShrinker(data, recon_backend='tigre')
ig_reduced = vs.run(limits={'horizontal_x':(10, 150), 'vertical':(5, 50)}, preview=True)

But then another error is observed:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[29], [line 4](notebook-cell:?execution_count=29&line=4)
      1 data.reorder('tigre')
      3 vs = VolumeShrinker(data, recon_backend='tigre')
----> [4](notebook-cell:?execution_count=29&line=4) ig_reduced = vs.run(limits={'horizontal_x':(10, 150), 'vertical':(5, 50)}, preview=True)

File ~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/utilities/shrink_volume.py:168, in VolumeShrinker.run(self, limits, preview, method, **kwargs)
    166     if method.lower() == 'manual':
    167         mask_radius = kwargs.pop('mask_radius', None)
--> [168](/home/username/desktop/cil-demos/misc/~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/utilities/shrink_volume.py:168)         recon, binning = self._get_recon(mask_radius=mask_radius)
    170     self._plot_with_bounds(recon, bounds, binning)
    172 return self.update_ig(self.data.geometry.get_ImageGeometry(), bounds)

File ~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/utilities/shrink_volume.py:203, in VolumeShrinker._get_recon(self, mask_radius)
    200 ag = data_binned.geometry
    201 ig = ag.get_ImageGeometry()
--> [203](/home/username/desktop/cil-demos/misc/~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/utilities/shrink_volume.py:203) fbp = self.recon_method(ig, ag)
    204 recon = fbp(data_binned)
    206 if mask_radius is not None:

File ~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/plugins/tigre/FBP.py:71, in FBP.__init__(self, image_geometry, acquisition_geometry, **kwargs)
     67 AcquisitionDimension.check_order_for_engine('tigre', acquisition_geometry)
     68 ImageDimension.check_order_for_engine('tigre', image_geometry)
---> [71](/home/username/desktop/cil-demos/misc/~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/plugins/tigre/FBP.py:71) tigre_geom, tigre_angles = CIL2TIGREGeometry.getTIGREGeometry(image_geometry,acquisition_geometry)
...
---> [96](/home/username/desktop/cil-demos/misc/~/miniforge3/envs/cil_dev/lib/python3.12/site-packages/cil/plugins/tigre/Geometry.py:96)         raise NotImplementedError ("CIL cannot use TIGRE to process parallel geometries with tilted axes")
     98     self.DSO = clearance_len
     99     self.DSD = 2*clearance_len

NotImplementedError: CIL cannot use TIGRE to process parallel geometries with tilted axes

Which confuses me a bit because the code runs completely fine with Preview=False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants