Skip to content

Commit

Permalink
Add two more failing tests and two passers
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Nov 1, 2024
1 parent 2c1804e commit b0b272b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 43 deletions.
26 changes: 13 additions & 13 deletions tests/images/test_image_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_full_resolution_RGB_image_with_region():

image = sample_RGB_server.read_region(
sample_RGB_metadata.downsamples[level],
Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height)
region=Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height)
)

np.testing.assert_array_equal(image, expected_image)
Expand All @@ -109,7 +109,7 @@ def test_full_resolution_RGB_image_with_region_tuple():

image = sample_RGB_server.read_region(
sample_RGB_metadata.downsamples[level],
(0, 0, sample_RGB_metadata.width, sample_RGB_metadata.height)
region=(0, 0, sample_RGB_metadata.width, sample_RGB_metadata.height)
)

np.testing.assert_array_equal(image, expected_image)
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_lowest_resolution_RGB_image():

image = sample_RGB_server.read_region(
sample_RGB_metadata.downsamples[level],
Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height)
region=Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height)
)

np.testing.assert_array_equal(image, expected_image)
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_tile_of_full_resolution_RGB_image():

image = sample_RGB_server.read_region(
sample_RGB_metadata.downsamples[level],
Region2D(x=xFrom, y=yFrom, width=xTo-xFrom+1, height=yTo-yFrom+1)
region=Region2D(x=xFrom, y=yFrom, width=xTo-xFrom+1, height=yTo-yFrom+1)
)

np.testing.assert_array_equal(image, expected_image)
Expand All @@ -201,7 +201,7 @@ def test_downsampled_RGB_image():
.resize((round(sample_RGB_metadata.width / downsample), round(sample_RGB_metadata.height / downsample)))
sample_RGB_server = SampleRGBServer()

pixels = sample_RGB_server.read_region(downsample, Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height))
pixels = sample_RGB_server.read_region(downsample, region=Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height))

np.testing.assert_array_equal(pixels[c, ...], expected_pixels)

Expand All @@ -216,7 +216,7 @@ def test_scaled_RGB_image():
.resize((round(sample_RGB_metadata.width / downsample), round(sample_RGB_metadata.height / downsample)))
sample_RGB_server = SampleRGBServer()

pixels = sample_RGB_server.read_region(downsample, Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height))
pixels = sample_RGB_server.read_region(downsample, region=Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height))

np.testing.assert_array_equal(pixels[c, ...], expected_pixels)

Expand All @@ -231,7 +231,7 @@ def test_downsampled_RGB_image_with_dask():
.resize((round(sample_RGB_metadata.width / downsample), round(sample_RGB_metadata.height / downsample)))
sample_RGB_server = SampleRGBServer()

pixels = sample_RGB_server.read_region(downsample, Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height))
pixels = sample_RGB_server.read_region(downsample, region=Region2D(x=0, y=0, width=sample_RGB_metadata.width, height=sample_RGB_metadata.height))

np.testing.assert_array_equal(pixels[c, ...], expected_pixels)

Expand Down Expand Up @@ -262,7 +262,7 @@ def test_full_resolution_float32_image_with_region():

image = sample_float32_server.read_region(
sample_float32_metadata.downsamples[level],
Region2D(x=0, y=0, width=sample_float32_metadata.width, height=sample_float32_metadata.height, z=z, t=t)
region=Region2D(x=0, y=0, width=sample_float32_metadata.width, height=sample_float32_metadata.height, z=z, t=t)
)

np.testing.assert_array_equal(image, expected_image)
Expand All @@ -279,7 +279,7 @@ def test_full_resolution_float32_image_with_region_tuple():

image = sample_float32_server.read_region(
sample_float32_metadata.downsamples[level],
(0, 0, sample_float32_metadata.width, sample_float32_metadata.height, z, t)
region=(0, 0, sample_float32_metadata.width, sample_float32_metadata.height, z, t)
)

np.testing.assert_array_equal(image, expected_image)
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_lowest_resolution_float32_image():

image = sample_float32_server.read_region(
sample_float32_metadata.downsamples[level],
Region2D(x=0, y=0, width=sample_float32_metadata.width, height=sample_float32_metadata.height, z=z, t=t)
region=Region2D(x=0, y=0, width=sample_float32_metadata.width, height=sample_float32_metadata.height, z=z, t=t)
)

np.testing.assert_array_equal(image, expected_image)
Expand Down Expand Up @@ -363,7 +363,7 @@ def test_tile_of_full_resolution_float32_image():

image = sample_float32_server.read_region(
sample_float32_metadata.downsamples[level],
Region2D(x=xFrom, y=yFrom, width=xTo-xFrom+1, height=yTo-yFrom+1, z=z, t=t)
region=Region2D(x=xFrom, y=yFrom, width=xTo-xFrom+1, height=yTo-yFrom+1, z=z, t=t)
)

np.testing.assert_array_equal(image, expected_image)
Expand All @@ -383,7 +383,7 @@ def test_downsampled_float32_image():

pixels = sample_float32_server.read_region(
downsample,
Region2D(0, 0, sample_float32_metadata.width, sample_float32_metadata.height, z, t)
region=Region2D(0, 0, sample_float32_metadata.width, sample_float32_metadata.height, z, t)
)

np.testing.assert_array_equal(pixels[c, ...], expected_pixels)
Expand All @@ -403,7 +403,7 @@ def test_scaled_float32_image():

pixels = sample_float32_server.read_region(
downsample,
Region2D(0, 0, sample_float32_metadata.width, sample_float32_metadata.height, z, t)
region=Region2D(0, 0, sample_float32_metadata.width, sample_float32_metadata.height, z, t)
)

np.testing.assert_array_equal(pixels[c, ...], expected_pixels)
Expand Down
87 changes: 76 additions & 11 deletions tests/images/test_labeled_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_read_points_in_single_channel_image_without_label_map_without_downsampl
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

np.testing.assert_array_equal(image, expected_image)

Expand Down Expand Up @@ -279,7 +279,7 @@ def test_read_points_in_multi_channel_image_without_label_map_without_downsample
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=True)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

np.testing.assert_array_equal(image, expected_image)

Expand All @@ -306,7 +306,7 @@ def test_read_points_in_single_channel_image_with_label_map_without_downsample()
)
labeled_server = LabeledImageServer(sample_metadata, features, label_map=label_map, multichannel=False)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

np.testing.assert_array_equal(image, expected_image)

Expand All @@ -327,7 +327,7 @@ def test_read_points_in_single_channel_image_without_label_map_with_downsample()
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False, downsample=downsample)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

np.testing.assert_array_equal(image, expected_image)

Expand All @@ -344,7 +344,7 @@ def test_read_line_in_single_channel_image_without_label_map_without_downsample(
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

np.testing.assert_array_equal(image, expected_image)

Expand All @@ -359,7 +359,7 @@ def test_read_line_in_single_channel_image_without_label_map_with_downsample():
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False, downsample=downsample)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

np.testing.assert_array_equal(image, expected_image)

Expand All @@ -376,7 +376,7 @@ def test_read_polygon_in_single_channel_image_without_label_map_without_downsamp
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

np.testing.assert_array_equal(image, expected_image)

Expand All @@ -391,7 +391,7 @@ def test_read_polygon_in_single_channel_image_without_label_map_with_downsample(
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False, downsample=downsample)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

np.testing.assert_array_equal(image, expected_image)

Expand All @@ -412,7 +412,7 @@ def rands():
features = [ImageFeature(geojson.Polygon([coords[i]])) for i in range(n_objects)]
labeled_server = LabeledImageServer(large_metadata, features, multichannel=False, downsample=downsample)

image = labeled_server.read_region(1, Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))
image = labeled_server.read_region(1, region=Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height))

assert np.max(image) > 255

Expand All @@ -427,10 +427,40 @@ def test_single_channel_labeled_image_with_region_request():
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False, downsample=downsample)
region = Region2D(5, 3, labeled_server.metadata.width-5, labeled_server.metadata.height-3)
image = labeled_server.read_region(1, region)
image = labeled_server.read_region(1, region=region)

np.testing.assert_array_equal(image, expected_image)

def test_single_channel_labeled_image_with_starting_downsample():
features = [ImageFeature(geojson.LineString([(6, 5), (9, 5)]))]
expected_image = np.array(
[[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 1, 1]]]
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False, downsample=1)
downsample = 2
region = Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height)
image = labeled_server.read_region(downsample=downsample, region=region)

np.testing.assert_array_equal(image, expected_image)


def test_single_channel_labeled_image_with_request_downsample():
features = [ImageFeature(geojson.LineString([(6, 5), (9, 5)]))]
expected_image = np.array(
[[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 1, 1]]]
)
downsample = 2
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=False, downsample=downsample)
region = Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height)
image = labeled_server.read_region(downsample=1, region=region)

np.testing.assert_array_equal(image, expected_image)


def test_multi_channel_labeled_image_with_region_request():
downsample = 1
features = [ImageFeature(geojson.LineString([(7, 5), (9, 5)]))]
Expand All @@ -445,6 +475,41 @@ def test_multi_channel_labeled_image_with_region_request():
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=True, downsample=downsample)
region = Region2D(5, 3, labeled_server.metadata.width-5, labeled_server.metadata.height-3)
region = Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height)
image = labeled_server.read_region(1, region)
image = labeled_server.read_region(1, region=region)

np.testing.assert_array_equal(image, expected_image)

def test_multi_channel_labeled_image_with_starting_downsample():
features = [ImageFeature(geojson.LineString([(6, 5), (9, 5)]))]
expected_image = np.array(
[[[False, False, False, False, False],
[False, False, False, False, False],
[False, False, False, False, False]],
[[False, False, False, False, False],
[False, False, False, False, False],
[False, False, False, True, True]]]
)
downsample = 2
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=True, downsample=downsample)
region = Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height)
image = labeled_server.read_region(downsample=1, region=region)

np.testing.assert_array_equal(image, expected_image)

def test_multi_channel_labeled_image_with_request_downsample():
features = [ImageFeature(geojson.LineString([(6, 5), (9, 5)]))]
expected_image = np.array(
[[[False, False, False, False, False],
[False, False, False, False, False],
[False, False, False, False, False]],
[[False, False, False, False, False],
[False, False, False, False, False],
[False, False, False, True, True]]]
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=True, downsample=1)
downsample = 2
region = Region2D(0, 0, labeled_server.metadata.width, labeled_server.metadata.height)
image = labeled_server.read_region(downsample=downsample, region=region)

np.testing.assert_array_equal(image, expected_image)

2 changes: 1 addition & 1 deletion tests/images/test_openslide_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_read_full_resolution_image():

image = openslide_server.read_region(
downsample,
Region2D(width=openslide_server.metadata.width, height=openslide_server.metadata.height)
region=Region2D(width=openslide_server.metadata.width, height=openslide_server.metadata.height)
)

np.testing.assert_array_equal(image, expected_pixels)
Expand Down
Loading

0 comments on commit b0b272b

Please sign in to comment.