mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Add *_min and *_max for mean_intensity and mean_object_size, fix default value for eps
- Add `mean_intensity_min` and `mean_intensity_max` attributes for `image_has_intensities` assertion tag - Add `mean_object_size_min` and `mean_object_size_max` attributes for `image_has_labels` assertion tag - Fix default value for `eps`.
This commit is contained in:
@@ -59,8 +59,10 @@ def assert_image_has_intensities(
|
||||
output_bytes: bytes,
|
||||
channel: Optional[Union[int, str]] = None,
|
||||
mean_intensity: Optional[Union[float, str]] = None,
|
||||
mean_intensity_min: Optional[Union[float, str]] = None,
|
||||
mean_intensity_max: Optional[Union[float, str]] = None,
|
||||
center_of_mass: Optional[Union[Tuple[float, float], str]] = None,
|
||||
eps: Union[float, str] = 1e-8,
|
||||
eps: Union[float, str] = 0.01,
|
||||
) -> None:
|
||||
"""
|
||||
Assert the image output has specific intensity content.
|
||||
@@ -74,10 +76,26 @@ def assert_image_has_intensities(
|
||||
im_arr = im_arr[:, :, int(channel)]
|
||||
|
||||
# Perform `mean_intensity` assertion.
|
||||
actual_mean_intensity = im_arr.mean()
|
||||
if mean_intensity is not None:
|
||||
actual = im_arr.mean()
|
||||
expected = float(mean_intensity)
|
||||
assert abs(actual - expected) <= float(eps), f"Wrong mean intensity: {actual} (expected {expected}, eps: {eps})"
|
||||
mean_intensity = float(mean_intensity)
|
||||
assert abs(actual_mean_intensity - mean_intensity) <= float(
|
||||
eps
|
||||
), f"Wrong mean intensity: {actual_mean_intensity} (expected {mean_intensity}, eps: {eps})"
|
||||
|
||||
# Perform `mean_intensity_min` assertion.
|
||||
if mean_intensity_min is not None:
|
||||
mean_intensity_min = float(mean_intensity_min)
|
||||
assert (
|
||||
actual_mean_intensity >= mean_intensity_min
|
||||
), f"Wrong mean intensity: {actual_mean_intensity} (mean_intensity_min: {mean_intensity_min})"
|
||||
|
||||
# Perform `mean_intensity_max` assertion.
|
||||
if mean_intensity_max is not None:
|
||||
mean_intensity_max = float(mean_intensity_max)
|
||||
assert (
|
||||
actual_mean_intensity <= mean_intensity_max
|
||||
), f"Wrong mean intensity: {actual_mean_intensity} (mean_intensity_max: {mean_intensity_max})"
|
||||
|
||||
# Perform `center_of_mass` assertion.
|
||||
if center_of_mass is not None:
|
||||
@@ -86,19 +104,21 @@ def assert_image_has_intensities(
|
||||
assert len(center_of_mass_parts) == 2
|
||||
center_of_mass = (float(center_of_mass_parts[0]), float(center_of_mass_parts[1]))
|
||||
assert len(center_of_mass) == 2, "center_of_mass must have two components"
|
||||
actual = _compute_center_of_mass(im_arr)
|
||||
distance = numpy.linalg.norm(numpy.subtract(center_of_mass, actual))
|
||||
actual_center_of_mass = _compute_center_of_mass(im_arr)
|
||||
distance = numpy.linalg.norm(numpy.subtract(center_of_mass, actual_center_of_mass))
|
||||
assert distance <= float(
|
||||
eps
|
||||
), f"Wrong center of mass: {actual} (expected {center_of_mass}, distance: {distance}, eps: {eps})"
|
||||
), f"Wrong center of mass: {actual_center_of_mass} (expected {center_of_mass}, distance: {distance}, eps: {eps})"
|
||||
|
||||
|
||||
def assert_image_has_labels(
|
||||
output_bytes: bytes,
|
||||
number_of_objects: Optional[Union[int, str]] = None,
|
||||
mean_object_size: Optional[Union[float, str]] = None,
|
||||
mean_object_size_min: Optional[Union[float, str]] = None,
|
||||
mean_object_size_max: Optional[Union[float, str]] = None,
|
||||
exclude_labels: Optional[Union[str, List[int]]] = None,
|
||||
eps: Union[float, str] = 1e-8,
|
||||
eps: Union[float, str] = 0.01,
|
||||
) -> None:
|
||||
"""
|
||||
Assert the image output has specific label content.
|
||||
@@ -134,9 +154,23 @@ def assert_image_has_labels(
|
||||
), f"Wrong number of objects: {actual_number_of_objects} (expected {expected_number_of_objects})"
|
||||
|
||||
# Perform `mean_object_size` assertion.
|
||||
actual_mean_object_size = sum((im_arr == label).sum() for label in labels) / len(labels)
|
||||
if mean_object_size is not None:
|
||||
actual_mean_object_size = sum((im_arr == label).sum() for label in labels) / len(labels)
|
||||
expected_mean_object_size = float(mean_object_size)
|
||||
assert abs(actual_mean_object_size - expected_mean_object_size) <= float(
|
||||
eps
|
||||
), f"Wrong mean object size: {actual_mean_object_size} (expected {expected_mean_object_size}, eps: {eps})"
|
||||
|
||||
# Perform `mean_object_size_min` assertion.
|
||||
if mean_object_size_min is not None:
|
||||
mean_object_size_min = float(mean_object_size_min)
|
||||
assert (
|
||||
actual_mean_object_size >= mean_object_size_min
|
||||
), f"Wrong mean object size: {actual_mean_object_size} (mean_object_size_min: {mean_object_size_min})"
|
||||
|
||||
# Perform `mean_object_size_max` assertion.
|
||||
if mean_object_size_max is not None:
|
||||
mean_object_size_max = float(mean_object_size_max)
|
||||
assert (
|
||||
actual_mean_object_size <= mean_object_size_max
|
||||
), f"Wrong mean object size: {actual_mean_object_size} (mean_object_size_max: {mean_object_size_max})"
|
||||
|
||||
@@ -2798,19 +2798,29 @@ $attribute_list::5
|
||||
<xs:documentation xml:lang="en">The required mean value of the image intensities.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="mean_intensity_min" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">A lower bound of the required mean value of the image intensities.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="mean_intensity_max" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">An upper bound of the required mean value of the image intensities.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="center_of_mass" type="xs:string" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required center of mass of the image intensities (horizontal and vertical coordinate, separated by a comma).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="eps" type="xs:float" use="optional" default="1e-8">
|
||||
<xs:attribute name="eps" type="xs:float" use="optional" default="0.01">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The absolute tolerance to be used for the ``mean_intensity`` and ``center_of_mass`` assertions (defaults to ``1e-8``).</xs:documentation>
|
||||
<xs:documentation xml:lang="en">The absolute tolerance to be used for the ``mean_intensity`` and ``center_of_mass`` assertions (defaults to ``0.01``).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="channel" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Restricts the ``mean_intensity`` and ``center_of_mass`` assertions to a specific channel of the image (where the value ``0`` corresponds to the first image channel).</xs:documentation>
|
||||
<xs:documentation xml:lang="en">Restricts the ``mean_intensity``, ``mean_intensity_min``, ``mean_intensity_max``, and ``center_of_mass`` assertions to a specific channel of the image (where the value ``0`` corresponds to the first image channel).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
@@ -2837,9 +2847,19 @@ $attribute_list::5
|
||||
<xs:documentation xml:lang="en">The required mean size of the objects in the image, where the size of an object is measured by the number of pixels. It is assumed that each individual object corresponds to a unique label.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="eps" type="xs:float" use="optional" default="1e-8">
|
||||
<xs:attribute name="mean_object_size_min" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The absolute tolerance to be used for the ``mean_object_size`` assertion (defaults to ``1e-8``).</xs:documentation>
|
||||
<xs:documentation xml:lang="en">A lower bound of the required mean size of the objects in the image, where the size of an object is measured by the number of pixels. It is assumed that each individual object corresponds to a unique label.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="mean_object_size_max" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">An upper bound of the required mean size of the objects in the image, where the size of an object is measured by the number of pixels. It is assumed that each individual object corresponds to a unique label.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="eps" type="xs:float" use="optional" default="0.01">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The absolute tolerance to be used for the ``mean_object_size`` assertion (defaults to 0.01).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="exclude_labels" type="xs:string" use="optional">
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_metadata width="32" height="32" channels="1" />
|
||||
<image_has_intensities center_of_mass="15.61, 15.48" eps="0.01" />
|
||||
<image_has_intensities center_of_mass="15.61, 15.48" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -47,6 +47,30 @@
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test>
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_intensities channel="0" mean_intensity_min="0.24" mean_intensity_max="0.26" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_test_failure="true">
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_intensities channel="0" mean_intensity_max="0.24" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_test_failure="true">
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_intensities channel="0" mean_intensity_min="0.26" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<!-- Tests with label images -->
|
||||
<test>
|
||||
<param name="input" value="im2_b.png" />
|
||||
@@ -83,5 +107,29 @@
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test>
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_labels mean_object_size_min="511" mean_object_size_max="513" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_test_failure="true">
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_labels mean_object_size_max="511" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_test_failure="true">
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_labels mean_object_size_min="513" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
</tests>
|
||||
</tool>
|
||||
Reference in New Issue
Block a user