Skip to content

Absfunction sirf compatibility#2339

Draft
paskino wants to merge 2 commits into
TomographicImaging:masterfrom
paskino:absfunction-sirf-compatibility
Draft

Absfunction sirf compatibility#2339
paskino wants to merge 2 commits into
TomographicImaging:masterfrom
paskino:absfunction-sirf-compatibility

Conversation

@paskino

@paskino paskino commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Description

Function of Abs has been developed for CIL like objects and fails when used with SIRF.

These changes allow using the functionality with SIRF MR ImageData.

Example Usage

Contribution Notes

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in CIL (the Work) under the terms and conditions of the Apache-2.0 License
  • I confirm that the contribution does not violate any intellectual property rights of third parties

❤️ Thanks for your contribution!

Changes

Testing you performed

Please add any demo scripts to https://github.com/TomographicImaging/CIL-Demos/tree/main/misc

Related issues/links

Checklist

  • I have performed a self-review of my code
  • I have added docstrings in line with the guidance in the developer guide
  • I have updated the relevant documentation
  • I have implemented unit tests that cover any new or modified functionality
  • CHANGELOG.md has been updated with any functionality change
  • Request review from all relevant developers

Comment on lines +176 to +178
rgeo = x.geometry.copy()
rgeo.dtype = real_dtype
r = rgeo.allocate(None)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
rgeo = x.geometry.copy()
rgeo.dtype = real_dtype
r = rgeo.allocate(None)
r = x.geometry.allocate(None, dtype=real_dtype)

out = out_geom.allocate(None)
out = x * 0
if np.isreal(x.as_array()).all():
print("Input is real, returning real output")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
print("Input is real, returning real output")

print("Input is real, returning real output")
out.fill( np.real(fvals_np.astype(complex_dtype)*Phi))
else:
print("Input is complex, returning complex output")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
print("Input is complex, returning complex output")

Comment on lines +151 to +153
rgeo = x.geometry.copy()
rgeo.dtype = real_dtype
r = rgeo.allocate(0)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
rgeo = x.geometry.copy()
rgeo.dtype = real_dtype
r = rgeo.allocate(0)
r = x.geometry.allocate(None, dtype=read_dtype)

import numpy as np
from cil.optimisation.functions import Function
from cil.framework import DataContainer
from cil.framework import DataContainer, ImageGeometry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

DataContainer is only needed for type-hints reasons.

Comment on lines +201 to +203
tmparr = tmp.as_array()
tmparr[tmparr < 0] = 0.
tmp.fill(tmparr)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Check: tmp is a CIL ImageData so this could be simplified as:

Suggested change
tmparr = tmp.as_array()
tmparr[tmparr < 0] = 0.
tmp.fill(tmparr)
tmp.array[tmp.array < 0] = 0.

Or check IndicatorBox

'''An internal function to find the type of x and set the corresponding real and complex data types '''

x_dtype = x.as_array().dtype
x_dtype = x.dtype

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@fmwatson does your data container have a dtype member?

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.

1 participant