-
Notifications
You must be signed in to change notification settings - Fork 6
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
Compute Operation Flat Field #2125
Conversation
1fdbaef
to
e8040be
Compare
def execute_wrapper( # type: ignore | ||
flat_before_widget: DatasetSelectorWidgetView, flat_after_widget: DatasetSelectorWidgetView, | ||
dark_before_widget: DatasetSelectorWidgetView, dark_after_widget: DatasetSelectorWidgetView, | ||
selected_flat_fielding_widget: QComboBox, use_dark_widget: QCheckBox) -> partial: | ||
def execute_wrapper(**kwargs): | ||
flat_before_widget = kwargs['flat_before_widget'] | ||
flat_after_widget = kwargs['flat_after_widget'] | ||
dark_before_widget = kwargs['dark_before_widget'] | ||
dark_after_widget = kwargs['dark_after_widget'] | ||
selected_flat_fielding_widget = kwargs['selected_flat_fielding_widget'] | ||
use_dark_widget = kwargs['use_dark_widget'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should stay as normal arguments. Going though kwargs makes type checking less useful.
def _divide(data, norm_divide): | ||
np.true_divide(data, norm_divide, out=data) | ||
|
||
def _subtract(data, dark=None): | ||
# specify out to do in place, otherwise the data is copied | ||
np.subtract(data, dark, out=data) | ||
|
||
def _norm_divide(flat: np.ndarray, dark: np.ndarray) -> np.ndarray: | ||
# subtract dark from flat | ||
return np.subtract(flat, dark) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be @staticmethod
s or to move outside the class.
task_name='Background Correction') | ||
_execute(images, flat_avg, dark_avg, progress) | ||
params = {'flat_avg': flat_avg, 'dark_avg': dark_avg} | ||
ps.run_compute_func(FlatFieldFilter.compute_function, len(images.data), [images.shared_array], params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to keep the dimension checks.
The current set of changes have several things that seem unrelated to switching to a compute function and seem to be the source of the test errors: Changes to the logic that checks if the flats and darks are present, changes to execute_wrapper, changes to validate_execute_kwargs. |
63a69ba
to
8ea30a7
Compare
The 2 test fails seem odd, so I have set them to re run |
"""Uses the flat (open beam) and dark images to normalise a stack of images (radiograms, projections), | ||
and to correct for a beam profile, scintillator imperfections and/or detector inhomogeneities. This | ||
operation produces images of transmission values. | ||
|
||
In practice, several open beam and dark images are averaged in the flat-fielding process. | ||
|
||
Intended to be used on: Projections | ||
|
||
When: As one of the first pre-processing steps | ||
|
||
Caution: Make sure the correct stacks are selected for flat and dark. | ||
|
||
Caution: Check that the flat and dark images don't have any very bright pixels, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you avoid removing the spaces here. They are needed for nice formatting in the docs.
https://mantidproject.github.io/mantidimaging/user_guide/operations/index.html#flat-fielding
With spaces
@staticmethod | ||
def _divide(data, norm_divide): | ||
np.true_divide(data, norm_divide, out=data) | ||
|
||
@staticmethod | ||
def _subtract(data, dark=None): | ||
# specify out to do in place, otherwise the data is copied | ||
np.subtract(data, dark, out=data) | ||
|
||
@staticmethod | ||
def _norm_divide(flat: np.ndarray, dark: np.ndarray) -> np.ndarray: | ||
# subtract dark from flat | ||
return np.subtract(flat, dark) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Looking good now. I am going to squish the commits and tweak the spacing to reduce churn.
afb62c8
to
6220d70
Compare
Issue
Closes #2051
Description
This pull request refactors the Flat Field operation to transition from the partial function style to the compute_function approach. The changes enhance code clarity, maintainability, and performance.
Changes
Refactored FlatFieldFilter: Replaced the partial function with a structured compute_function method to encapsulate the core logic.
Introduced _compute_flat_field: Encapsulated core computation logic for parallel execution.
Shared Memory Allocation: Utilized shared memory for necessary arrays to improve performance.
Testing
Verified the refactored FlatFieldFilter by running all existing unit tests.
Ensured that _compute_flat_field computes flat field normalization correctly in parallel.
Acceptance Criteria
All unit tests pass.
FlatFieldFilter performs as expected with various image inputs.
Documentation
Updated the relevant documentation to reflect changes in the FlatFieldFilter operation.
Noted all changes in the appropriate file in docs/release_notes.