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

Add content assertion XML tags for test output verification using images #17581

Merged
merged 50 commits into from
Mar 13, 2024

Conversation

kostrykin
Copy link
Contributor

@kostrykin kostrykin commented Mar 2, 2024

As part of the Imaging Hackathon in Freiburg. This is a follow-up PR of #17556.

Contributions

This PR adds content assertion XML tags for automated test output verification using 2-D single-channel and multi-channel images. The contributed XML tags are detailed below.

image_has_metadata

The image_has_metadata XML tag can be used for verification of the metadata of the images generated by a Galaxy tool wrapper. Currently supported metadata is:

Attribute Feature description
width The width of the image.
height The height of the image.
channels Number of channels.

Example:

<test>
  <output name="output">
    <assert_contents>
      <image_has_metadata width="512" height="512" channels="1" />
    </assert_contents>
  </output>
</test>

image_has_intensities

The image_has_intensities XML tag can be used for verification of the image intensities of the images generated by a Galaxy tool wrapper. Verification of the following features is supported:

Attribute Feature description
mean_intensity The mean image intensity.
mean_intensity_min Lower bound of the mean image intensity.
mean_intensity_max Upper bound of the mean image intensity.
center_of_mass The center of mass of the image intensities.
eps Absolute tolerance for mean_intensity and center_of_mass assertions.
channel Restricts the assertions to only a specific image channel.

The assertions are imposed for all image channels if the channel attribute is omitted.

Example:

<test>
  <output name="output">
    <assert_contents>
      <image_has_intensities channel="0" mean_intensity="0.24" eps="0.01" />
      <image_has_intensities channel="1" mean_intensity="0.66" eps="0.01" />
    </assert_contents>
  </output>
</test>

image_has_labels

The image_has_labels XML tag can be used for verification of label images (label maps) generated by a Galaxy tool wrapper. Verification of the following features is supported:

Attribute Feature description
number_of_objects The number of uniquely labeled objects.
mean_object_size The mean size (number of pixels) of uniquely labeled objects.
mean_object_size_min Lower bound of the mean size of uniquely labeled objects.
mean_object_size_max Upper bound of the mean size of uniquely labeled objects.
exclude_labels Excludes labels from the other assertions.
eps Absolute tolerance for the mean_object_size assertion.

The primary use case of the exclude_labels attribute is to exclude the image background from the number_of_objects and mean_object_size assertions, which is often labeled by 0 or -1.

Example:

<test>
  <output name="output">
    <assert_contents>
      <image_has_labels number_of_objects="187" exclude_labels="0" />
    </assert_contents>
  </output>
</test>

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

@kostrykin kostrykin changed the title Files assertions images Add content assertion XML tags for test output verification using images Mar 2, 2024
Copy link
Contributor

@bernt-matthias bernt-matthias left a comment

Choose a reason for hiding this comment

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

Super cool!

Maybe it would be good to reuse this scheme for asserting numeric values https://github.com/galaxyproject/galaxy/blob/cef07534d54b6e0ad55623534f909f446fb0a1c0/lib/galaxy/tool_util/verify/asserts/size.py#L22C5-L22C19, i.e. use delta, min and max?

@kostrykin
Copy link
Contributor Author

kostrykin commented Mar 2, 2024

Super cool!

Maybe it would be good to reuse this scheme for asserting numeric values https://github.com/galaxyproject/galaxy/blob/cef07534d54b6e0ad55623534f909f446fb0a1c0/lib/galaxy/tool_util/verify/asserts/size.py#L22C5-L22C19, i.e. use delta, min and max?

My intention in this PR was to use the same attribute names for image verification as in #17556. There, the absolute tolerance for verification is named eps. The issue that I see with using the delta attribute in #17556 is that it has a default value of 10000, which is rather inappropriate for image verification. This is why I used a dedicated attribute in #17556, for which I could use a meaningful default value (0.01), and, for consistency, also in this PR. What do you think? @bernt-matthias

@kostrykin
Copy link
Contributor Author

kostrykin commented Mar 2, 2024

Thanks for your suggestion regarding the lower/upper bounds scheme. I have added *_min and *_max attributes for the mean_intensity and mean_object_size assertions in 5ce6045.

The center_of_mass assertion is about coordinates, and using lower/upper bounds for coordinates is somewhat inconvenient, I think1. The other assertions (width, height, channels, number_of_objects) concern integer values, for which rather precise values are preferable for the checks, I think.

The _assert_number function cannot be used because it requires n to be int or str, but does not support float (see here). I have doubts whether we should extend this to float, because it contains some logic on parsing sizes (parse_bytesize), and mixing float logics into this function seems misplaced.

Footnotes

  1. Axis-wise bounds would induce a rectangular region of validity, but points closer the corner of the rectangle are more erroneous. This issue does not arise when using circular regions of validity, which the tolerance-based scheme is about (where eps is the radius).

@bernt-matthias
Copy link
Contributor

Sounds reasonable to me.

has a default value of 10000, which is rather inappropriate for image verification

We could have a separate default for images.

But anyway I'm happy with it.

lib/galaxy/tool_util/xsd/galaxy.xsd Outdated Show resolved Hide resolved
lib/galaxy/tool_util/xsd/galaxy.xsd Outdated Show resolved Hide resolved
lib/galaxy/tool_util/xsd/galaxy.xsd Show resolved Hide resolved
lib/galaxy/tool_util/xsd/galaxy.xsd Outdated Show resolved Hide resolved
lib/galaxy/tool_util/xsd/galaxy.xsd Outdated Show resolved Hide resolved
commit 33b660e
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 5 20:58:24 2024 +0000

    Fix XSD

commit 4ee6112
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 5 20:53:14 2024 +0000

    Add `labels` attribute for `has_image_labels` and `has_image_mean_object_size`

commit 4ff401c
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 5 20:32:57 2024 +0000

    Replace `image_has_labels` by `has_image_labels` and `has_image_mean_object_size`

commit 09149d1
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 5 19:51:56 2024 +0000

    Fix bug

commit 28fedb9
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 5 19:44:12 2024 +0000

    Replace `image_has_intensities` by `has_image_mean_intensity` and `has_image_center_of_mass`

commit fe96916
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 5 19:10:38 2024 +0000

    Replace `image_has_metadata` by `has_image_width`, etc.
@kostrykin
Copy link
Contributor Author

kostrykin commented Mar 5, 2024

Thanks for your comments, @bernt-matthias.

In the course of splitting the combined <image_has_*> assertions into individual ones, I have also renamed eps to delta, as you originally suggested (otherwise, I believe it would have been too confusing, why there are the min and max attributes, but delta is called eps). For consistency, we should also rename eps from #17556 to delta now.

You mentioned before, that

We could have a separate default for images.

can you please elaborate how this is possible? See the XSD snippet below.

Caution

We would also need to change to the type of delta to xs:float for images! If this isn't possible, I'd prefer to change delta back to eps in this PR for those assertions, which require a float-typed tolerance:

  • <has_image_mean_intensity>
  • <has_image_center_of_mass>
  • <assert_has_image_mean_object_size>

Then we would have delta for int-typed tolerances, and eps for float-typed.

This is the definition of the default in galaxy.xsd:

<xs:attribute name="delta" type="xs:integer" default="10000">
  ...
</xs:attribute>

Edit: After having thought about this for a while, I think that renaming delta back to eps for float-typed assertions is the best option. This establishes consistency with both #17556 and the previous schemes used for assertions. If you agree, I can merge kostrykin#1 into this PR. This establishes the attribute delta for integer-typed assertions (which is consistent with previous assertions), and the attribute eps for float-typed assertions (which is consistent with #17556).

@kostrykin
Copy link
Contributor Author

For some reason the TestGalaxyOIDCLoginIntegration::test_oidc_login_existing_user test is failing

@nsoranzo
Copy link
Member

nsoranzo commented Mar 6, 2024

For some reason the TestGalaxyOIDCLoginIntegration::test_oidc_login_existing_user test is failing

Unrelated to your PR, will be fixed by #17612 .

@bernt-matthias
Copy link
Contributor

Thanks so much. Really cool. This will be really helpful.

@mvdbeek mvdbeek merged commit e2b67da into galaxyproject:dev Mar 13, 2024
52 of 53 checks passed
@galaxyproject galaxyproject deleted a comment from github-actions bot Mar 13, 2024
kostrykin pushed a commit to kostrykin/galaxy that referenced this pull request Mar 18, 2024
…s_images

Add content assertion XML tags for test output verification using images
kostrykin added a commit to kostrykin/galaxy-image-analysis that referenced this pull request Mar 18, 2024
kostrykin added a commit to BMCV/galaxy-image-analysis that referenced this pull request Mar 18, 2024
* Update pr.yaml

* Update

* Update pr.yaml

* Add `pip install pillow`

* Temporarilly fix CI

* Update pr.yaml

* Update ci.yaml

* Add test tool from `/test/functional/tools/image_diff.xml`

* Update pr.yaml

* Add .shed.yml

* Add missing test files

* Switch CI to galaxy fork `kostrykin/galaxy` branch `galaxy-image-analysis`

This is a temporary change to enable the features from:

 - galaxyproject/galaxy#17556
 - galaxyproject/galaxy#17581

* Remove `test` tool
kostrykin added a commit to kostrykin/galaxy-image-analysis that referenced this pull request Mar 21, 2024
* Rename tools

Change the `Performs` in the name of the two tools

- `Performs projective transformation with/without labels`
- `Performs projective transformation`

to `Perform`, which is more consistent with the name of the other tools (imperative form).

* Update projective_transformation.xml

* Update projective_transformation_points.xml

* Add CONVENTIONS.md

* wip

* wip

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Remove help section

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update

* Update test data

* Add content assertions

* Update pr.yaml

* Update

* Update pr.yaml

* Add `pip install pillow`

* Merge CONVENTIONS.md into CONTRIBUTING.md

* Temporarilly fix CI

* Update `2d_feature_extraction` tool

* Update `2d_auto_threshold` tool

* Fix `2d_feature_extraction` tests

* Fix test data

* Fix tool

* Start refactoring `2d_simple_filter` tool

* Fix `2d_simple_filter` tool

* Add more tests

* Fix tests

* Update

* Fix

* Update CONTRIBUTING.md

* Fix bugs

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Fix linting issues

* Update CONTRIBUTING.md

* Refactor tests using macros

* Update tests

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update pr.yaml

* Update `anisotropic_diffusion` tool

* Fix spelling (was BE, using AE is more consistent)

* Update `2d_histogram_equalization` tool

* Update `colorize_labels` tool

* Update `bf2raw` tool

* Add `macros/creators.xml`

* Update `rfove` tool

* Fix `bioformats2raw` and `voronoi_tessellation` tools

* Fix labels

* Fix `rfove` tool

* Update `overlay_images` tool

* Add RGB test for `overlay_images`

* Update `overlay_images` help

* Add image verification support to CI (BMCV#117)

* Update pr.yaml

* Update

* Update pr.yaml

* Add `pip install pillow`

* Temporarilly fix CI

* Update pr.yaml

* Update ci.yaml

* Add test tool from `/test/functional/tools/image_diff.xml`

* Update pr.yaml

* Add .shed.yml

* Add missing test files

* Switch CI to galaxy fork `kostrykin/galaxy` branch `galaxy-image-analysis`

This is a temporary change to enable the features from:

 - galaxyproject/galaxy#17556
 - galaxyproject/galaxy#17581

* Remove `test` tool

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update test data

* Add RGB test for `overlay_images`

* Update `anisotropic_diffusion` to medpy 0.4.0

* Update PULL_REQUEST_TEMPLATE.md

* Update `projective_transformation_points` tool

* Update PULL_REQUEST_TEMPLATE.md

* Update `bioformats2raw`

* Update `projective_transformation` tool

* Update `bfconvert` tool (tests failing)

* Update CONTRIBUTING.md

* Fix `bfconvert` tests

* Fix test data size

* Update `projective_transformation_points` tool

* Remove spurious files

* Update requirements using `@TOOL_VERSION@` macro

* Update `segmetrics` tool

* Remove spurious sym links

* Update `superdsm` tool

* Update `scale_image` tool (not finished yet)

* Fix tests

* Fix `scale_image` tool

* Refactor

* Fix linting issues

* Update tests and help of `2d_simple_filter` tool

* Update `scale_image` help

* Update CI to use latest version of `galaxy` fork

* Fix tests for float TIFF in `scale_image` tool

* Add tifffile to CI workflows

* Fix tests of `bfconvert` tool

* Update `2d_filter_segmentation_by_features` tool

* Update `image_math` tool

* Update `orientationpy` tool

* Update `morphological_operations` tool

* Update `split_labelmap` tool

* Add float TIFF test for `2d_simple_filter`

* Update `slice_image` tool

* Add missing macros

* Update help of `2d_filter_segmentation_by_features` tool

* Update `concat_images` tool

* Fix linting issues

* Fix file sizes

* Fix missing `profile`
kostrykin added a commit to BMCV/galaxy-image-analysis that referenced this pull request Apr 4, 2024
Update 23 tools and macros

* Update 23 tools

* Rename tools

Change the `Performs` in the name of the two tools

- `Performs projective transformation with/without labels`
- `Performs projective transformation`

to `Perform`, which is more consistent with the name of the other tools (imperative form).

* Update projective_transformation.xml

* Update projective_transformation_points.xml

* Add CONVENTIONS.md

* wip

* wip

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Remove help section

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update CONVENTIONS.md

* Update

* Update test data

* Add content assertions

* Update pr.yaml

* Update

* Update pr.yaml

* Add `pip install pillow`

* Merge CONVENTIONS.md into CONTRIBUTING.md

* Temporarilly fix CI

* Update `2d_feature_extraction` tool

* Update `2d_auto_threshold` tool

* Fix `2d_feature_extraction` tests

* Fix test data

* Fix tool

* Start refactoring `2d_simple_filter` tool

* Fix `2d_simple_filter` tool

* Add more tests

* Fix tests

* Update

* Fix

* Update CONTRIBUTING.md

* Fix bugs

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Fix linting issues

* Update CONTRIBUTING.md

* Refactor tests using macros

* Update tests

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update pr.yaml

* Update `anisotropic_diffusion` tool

* Fix spelling (was BE, using AE is more consistent)

* Update `2d_histogram_equalization` tool

* Update `colorize_labels` tool

* Update `bf2raw` tool

* Add `macros/creators.xml`

* Update `rfove` tool

* Fix `bioformats2raw` and `voronoi_tessellation` tools

* Fix labels

* Fix `rfove` tool

* Update `overlay_images` tool

* Add RGB test for `overlay_images`

* Update `overlay_images` help

* Add image verification support to CI (#117)

* Update pr.yaml

* Update

* Update pr.yaml

* Add `pip install pillow`

* Temporarilly fix CI

* Update pr.yaml

* Update ci.yaml

* Add test tool from `/test/functional/tools/image_diff.xml`

* Update pr.yaml

* Add .shed.yml

* Add missing test files

* Switch CI to galaxy fork `kostrykin/galaxy` branch `galaxy-image-analysis`

This is a temporary change to enable the features from:

 - galaxyproject/galaxy#17556
 - galaxyproject/galaxy#17581

* Remove `test` tool

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update test data

* Add RGB test for `overlay_images`

* Update `anisotropic_diffusion` to medpy 0.4.0

* Update PULL_REQUEST_TEMPLATE.md

* Update `projective_transformation_points` tool

* Update PULL_REQUEST_TEMPLATE.md

* Update `bioformats2raw`

* Update `projective_transformation` tool

* Update `bfconvert` tool (tests failing)

* Update CONTRIBUTING.md

* Fix `bfconvert` tests

* Fix test data size

* Update `projective_transformation_points` tool

* Remove spurious files

* Update requirements using `@TOOL_VERSION@` macro

* Update `segmetrics` tool

* Remove spurious sym links

* Update `superdsm` tool

* Update `scale_image` tool (not finished yet)

* Fix tests

* Fix `scale_image` tool

* Refactor

* Fix linting issues

* Update tests and help of `2d_simple_filter` tool

* Update `scale_image` help

* Update CI to use latest version of `galaxy` fork

* Fix tests for float TIFF in `scale_image` tool

* Add tifffile to CI workflows

* Fix tests of `bfconvert` tool

* Update `2d_filter_segmentation_by_features` tool

* Update `image_math` tool

* Update `orientationpy` tool

* Update `morphological_operations` tool

* Update `split_labelmap` tool

* Add float TIFF test for `2d_simple_filter`

* Update `slice_image` tool

* Add missing macros

* Update help of `2d_filter_segmentation_by_features` tool

* Update `concat_images` tool

* Fix linting issues

* Fix file sizes

* Fix missing `profile`

* Update test macros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants