Exemple #1
0
def command():
    repo = Mock(BaseAtlasRepo)
    repo.load_atlas.side_effect = [
        Atlas(volume=random.normal(size=(4, 4, 4)), resolution_um=25),
        Atlas(volume=random.normal(size=(4, 4, 4)), resolution_um=100),
    ]
    return LoadAtlasCommand(_repo=repo, atlas_updated=Mock(Signal))
Exemple #2
0
def test_slicing_atlas_along_infsup_axis_gets_correct_section_image(superior, out):
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 16, 21]), (3, 3, 3)).swapaxes(1, 2),
        resolution_um=1,
    )
    section = atlas.slice(AtlasTransform(superior=superior, rot_lateral=90))
    assert np.all(section.image.channels == out)
Exemple #3
0
def test_slicing_atlas_along_postant_axis_gets_correct_section_image(anterior, out):
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 16, 21]), (3, 3, 3)),
        resolution_um=1,
    )
    section = atlas.slice(AtlasTransform(anterior=anterior))
    assert np.all(section.image.channels == out)
Exemple #4
0
def test_slicing_atlas_along_leftright_axis_gets_correct_section_image(right, out):
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 16, 21]), (3, 3, 3)).swapaxes(0, 2),
        resolution_um=1,
    )
    section = atlas.slice(AtlasTransform(right=right, rot_axial=-90))
    assert np.all(section.image.channels == out)
Exemple #5
0
def test_slicing_atlas_along_z_axis_gets_correct_section_image(z, out):
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 16, 21]), (3, 3, 3)),
        resolution_um=1,
    )
    section = atlas.slice(Plane3D(z=z))
    assert np.all(section.image.channels == out)
Exemple #6
0
def test_slicing_atlas_along_y_axis_gets_correct_section_image(y, out):
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 16, 21]),
                               (3, 3, 3)).swapaxes(1, 2),
        resolution_um=1,
    )
    section = atlas.slice(Plane3D(y=y, rx=90))
    assert np.all(section.image.channels == out)
Exemple #7
0
def test_slicing_an_atlas_gets_a_new_section_with_correct_parameters():
    atlas = Atlas(volume=np.broadcast_to(np.array([10, 20, 30]),
                                         (3, 3, 3)).swapaxes(0, 2),
                  resolution_um=1)
    plane = Plane3D()
    section = atlas.slice(plane)
    assert isinstance(section, Section)
    assert section.plane_3d == plane
    assert section.plane_2d == Plane2D()
    assert section.image.pixel_resolution_um == atlas.resolution_um
    assert section.image.channels.shape == (1, 3, 3)
    assert section.thickness_um == atlas.resolution_um
Exemple #8
0
def atlas_repo():
    repo = Mock(BaseAtlasRepo)
    repo.get_atlas.return_value = Atlas(
        volume=random.normal(size=(10, 10, 10)),
        resolution_um=25,
    )
    return repo
Exemple #9
0
def test_atlas_is_settable_gettable_for_repo_state():
    repo = BrainglobeAtlasRepo()
    atlas = Atlas(volume=np.random.random((3, 3, 3)), resolution_um=1)
    assert repo.get_atlas() is None

    repo.set_atlas(atlas=atlas)
    assert repo.get_atlas() == atlas
Exemple #10
0
def test_section_registration_cuts_correctly_with_diff_resolutions(case):
    volume = np.zeros((3, 3, 3))
    volume[1, 1, 1] = 1
    volume[0, 0, 0] = 2
    volume[0, 0, 0] = 2
    atlas = Atlas(
        volume=volume,
        resolution_um=case['atlas_res'],
    )
    section = Section(
        image=ImageData(
            channels=np.ones((1, 3, 3)),
            pixel_resolution_um=case["section_res"],
        ),
        plane_3d=AtlasTransform(**case["pos"]),
    )
    atlas_slice = register(section, atlas).image.channels[0]
    expected_slice = np.array(case['expected']).astype(float)
    try:
        assert np.all(np.isclose(atlas_slice, expected_slice))
    except:
        assert np.all(
            atlas_slice ==
            expected_slice)  # similar, but nicer printout of arrays in pytest


# # different dimensions
# # rotate
# # plane_2d: image origin
# # (get visibility on atlas indices)
Exemple #11
0
def test_atlas_scale_matrix_is_3D_and_matches_resolution(res):
    atlas = Atlas(volume=np.empty(shape=(5, 5, 5)), resolution_um=res)
    expected_matrix = [
        [res, 0, 0, 0],
        [0, res, 0, 0],
        [0, 0, res, 0],
        [0, 0, 0, 1],
    ]
    assert np.all(np.isclose(atlas.scale_matrix, expected_matrix))
Exemple #12
0
def test_atlas_matrix_is_scaled_to_um_according_to_resolution_and_shape(res, w, h, d):
    atlas = Atlas(volume=np.random.random((w, h, d)), resolution_um=res)
    expected = [
        [res, 0, 0, -w / 2 * res],
        [0, res, 0, -h / 2 * res],
        [0, 0, res, -d / 2 * res],
        [0, 0, 0, 1],
    ]
    observed = atlas.affine_transform
    assert np.all(np.isclose(observed, np.array(expected)))
Exemple #13
0
    def load_atlas(self, resolution: int) -> Atlas:
        if resolution not in [10, 25, 100]:
            raise ValueError(
                "Only 10um, 25um and 100um atlas resolutions available.")

        with redirect_stdout(
                StringIO()):  # blocks the BrainGlobeAtlas print to console
            bgatlas = BrainGlobeAtlas(f"allen_mouse_{resolution}um")

        return Atlas(
            volume=bgatlas.reference,
            resolution_um=bgatlas.resolution[0],
        )
def test_section_registration_to_an_atlas_gets_a_section_that_matches_sections_parameters():
    section = Section(
        image=ImageData(
            channels=np.random.random((3, 4, 5)), 
            pixel_resolution_um=10,
        ),
        plane_2d=Plane2D(x=3, y=5, theta=20),
        plane_3d=Plane3D(x=10, y=-5, z=10),
        )
    atlas = Atlas(volume=np.random.random((5, 5, 5)), resolution_um=20)
    s2 = register(section, atlas)
    assert type(s2) is Section
    assert s2.image.pixel_resolution_um == section.image.pixel_resolution_um
    assert s2.id != section.id and s2 is not section
    assert s2.image.width == section.image.width
    assert s2.image.height == section.image.height
    assert np.all(np.isclose(s2.affine_transform, section.affine_transform))
Exemple #15
0
def command():
    repo = Mock(BaseAtlasRepo)
    repo.get_downloaded_resolutions.return_value = (25,)
    repo.load_atlas.return_value = Atlas(volume=random.normal(size=(4, 4, 4)), resolution_um=25)
    return LoadAtlasCommand(_repo=repo, atlas_updated=Mock(Signal))