CIL icon indicating copy to clipboard operation
CIL copied to clipboard

Unit tests for out argument to processors

Open hrobarts opened this issue 1 year ago • 3 comments

Description

Add tests to check if processors work in place. Check if processors give the same result when:

  • Getting results directly with return
processor.set_input(data)
out = processor.get_output()
  • Getting result by editing in place
processor.set_input(data)
processor.get_output(out=data)
  • Getting result with an empty out array. Check also that this doesn't change the input data and that the processor does not suppress the return value.
input = data.copy()
out=0*(data.copy())
processor.set_input(input)
processor.get_output(out=out)

Added a check_output function in Processor to check the output type and size of an out argument that's passed to the prcessors. Slicer, Binner, Padded and MaskGenerator over-ride the base class to allow different type or size out argument.

Added a _set_up function in Processor to set the _shape_out attribute and other attributes that need to be set from the data.

CentreOfRotationCorrector only changes the data.geometry, not the data, so out_test fails. Instead we test the geometry is the same when used with or without out

Also update the documentation for Processor to reflect that the return value is not suppressed when out is passed

Added a new test to testclass.py to check if two DataContainers are close, by checking

  • they are the same class
  • they have arrays that are all close
  • if they have geometry, the geometries are equal
  • and if strict=True, their data type is the same

Testing you performed

New tests have been added to test_out_in_place

Related issues/links

Should close https://github.com/TomographicImaging/CIL/issues/1669 Similar to https://github.com/TomographicImaging/CIL/issues/1657 for processors

Checklist

  • [x] I have performed a self-review of my code
  • [x] I have added docstrings in line with the guidance in the developer guide
  • [x] I have updated the relevant documentation
  • [x] I have implemented unit tests that cover any new or modified functionality
  • [x] CHANGELOG.md has been updated with any functionality change
  • [x] Request review from all relevant developers
  • [x] Change pull request label to 'Waiting for review'

Contribution Notes

Please read and adhere to the developer guide and local patterns and conventions.

  • [x] 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
  • [x] I confirm that the contribution does not violate any intellectual property rights of third parties

hrobarts avatar May 14 '24 17:05 hrobarts

Thank you for the review @MargaretDuff :)

hrobarts avatar May 16 '24 09:05 hrobarts

Thanks for updating that Hannah! I am happy to approve.

Might suggest that we try and add some more comments to the unit tests so that if we implement new processors it is clear how add tests for them?

Thanks Margaret, I've added a few comments for new processors

hrobarts avatar May 22 '24 15:05 hrobarts

Thank you for the review Gemma, I think all the comments are resolved now

hrobarts avatar Jul 24 '24 10:07 hrobarts