8000 Move the registration tests next to their sources. by ttung · Pull Request #1134 · spacetx/starfish · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move the registration tests next to their sources. #1134

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

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/api/image/apply_transform/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ ApplyTransform can be imported using ``starfish.image.ApplyTransform``, the subc
Warp
-----

.. autoclass:: starfish.image._apply_transform.warp.Warp
:members:
.. autoclass:: starfish.image._registration._apply_transform.warp.Warp
:members:
4 changes: 2 additions & 2 deletions docs/source/api/image/learn_transform/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ LearnTransform can be imported using ``starfish.image.LearnTransform``, the subc
Translation
------------

.. autoclass:: starfish.image._learn_transform.translation.Translation
:members:
.. autoclass:: starfish.image._registration._learn_transform.translation.Translation
:members:
4 changes: 2 additions & 2 deletions starfish/image/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._apply_transform import ApplyTransform
from ._filter import Filter
from ._learn_transform import LearnTransform
from ._registration._apply_transform import ApplyTransform
from ._registration._learn_transform import LearnTransform
from ._segmentation import Segmentation
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import abstractmethod
from typing import Type

from starfish.image._learn_transform.transforms_list import TransformsList
from starfish.image._registration.transforms_list import TransformsList
from starfish.imagestack.imagestack import ImageStack
from starfish.pipeline import PipelineComponent
from starfish.pipeline.algorithmbase import AlgorithmBase
Expand Down
Empty file.
44 changes: 44 additions & 0 deletions starfish/image/_registration/_apply_transform/test/test_warp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np

from starfish import data
from starfish.image._registration._apply_transform.warp import Warp
from starfish.image._registration._learn_transform.translation import Translation
from starfish.types import Axes


expected_registered_values = np.array(
[[0.090654, 0.090593, 0.091554, 0.091661, 0.089967, 0.094072, 0.097398,
0.099046, 0.100969, 0.112108],
[0.09926, 0.096925, 0.096269, 0.097002, 0.095842, 0.097704, 0.09984,
0.101457, 0.105455, 0.106004],
[0.109834, 0.103609, 0.102693, 0.099931, 0.098222, 0.10074, 0.10251,
0.103838, 0.106874, 0.113451],
[0.12369, 0.112428, 0.111482, 0.10631, 0.106203, 0.104753, 0.106706,
0.105013, 0.10811, 0.11371],
[0.141802, 0.129946, 0.124285, 0.120928, 0.115908, 0.110735, 0.110735,
0.107454, 0.109468, 0.109255],
[0.147326, 0.14464, 0.141436, 0.132845, 0.124071, 0.121828, 0.118074,
0.112306, 0.109163, 0.109483],
[0.145296, 0.150362, 0.15082, 0.140337, 0.133806, 0.1299, 0.120592,
0.114046, 0.115496, 0.111666],
[0.131121, 0.145525, 0.150011, 0.146609, 0.137407, 0.129198, 0.127306,
0.118029, 0.116594, 0.111559],
[0.126482, 0.132372, 0.142596, 0.149538, 0.144701, 0.137469, 0.125353,
0.121996, 0.117342, 0.118273],
[0.122866, 0.126543, 0.133669, 0.145418, 0.150515, 0.140139, 0.129992,
0.124605, 0.120867, 0.121889]], dtype=np.float32)


def test_calculate_translation_transforms_and_apply():
exp = data.ISS(use_test_data=True)
stack = exp.fov().get_image('primary')
reference_stack = exp.fov().get_image('dots')
translation = Translation(reference_stack=reference_stack, axes=Axes.ROUND)
# Calculate max_proj accrss
mp = stack.max_proj(Axes.CH, Axes.ZPLANE)
transform_list = translation.run(mp)
apply_transform = Warp()
warped_stack = apply_transform.run(stack=stack, transforms_list=transform_list)
assert np.allclose(
expected_registered_values,
warped_stack.xarray[2, 2, 0, 40:50, 40:50])
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from tqdm import tqdm

from starfish.config import StarfishConfig
from starfish.image._apply_transform._base import ApplyTransformBase
from starfish.image._learn_transform.transforms_list import TransformsList
from starfish.image._registration._apply_transform._base import ApplyTransformBase
from starfish.image._registration.transforms_list import TransformsList
from starfish.imagestack.imagestack import ImageStack
from starfish.types import Axes
from starfish.util import click
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Type


from starfish.image._learn_transform.transforms_list import TransformsList
from starfish.image._registration.transforms_list import TransformsList
from starfish.imagestack.imagestack import ImageStack
from starfish.pipeline.algorithmbase import AlgorithmBase
from starfish.pipeline.pipelinecomponent import PipelineComponent
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np

from starfish import data
from starfish.image._registration._learn_transform.translation import Translation
from starfish.types import Axes


ISS_SHIFTS = [[-23, 6], [-22, 2], [-22, -3], [-15, -4]]


def test_learn_transforms_throws_error():
exp = data.ISS(use_test_data=True)
stack = exp.fov().get_image('primary')
reference_stack = exp.fov().get_image('dots')
translation = Translation(reference_stack=reference_stack, axes=Axes.ROUND)
try:
translation.run(stack)
except ValueError as e:
# Assert value error is thrown when the stack is not max projected across all other axes.
assert e.args[0] == "Only axes: r can have a length > 1, please use the MaxProj filter."


def test_learn_transforms_translation():
exp = data.ISS(use_test_data=True)
stack = exp.fov().get_image('primary')
reference_stack = exp.fov().get_image('dots')
translation = Translation(reference_stack=reference_stack, axes=Axes.ROUND)
# Calculate max_proj accrss CH/Z
stack = stack.max_proj(Axes.CH, Axes.ZPLANE)
transform_list = translation.run(stack)
# assert there's a transofrmation object for each round
assert len(transform_list.transforms) == stack.num_rounds
for (_, _, transform), shift in zip(transform_list.transforms, ISS_SHIFTS):
# assert that each TransformationObject has the correct translation shift
assert np.array_equal(transform.translation, shift)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from skimage.feature import register_translation
from skimage.transform._geometric import SimilarityTransform

from starfish.image._learn_transform.transforms_list import TransformsList
from starfish.image._registration.transforms_list import TransformsList
from starfish.imagestack.imagestack import ImageStack
from starfish.types import Axes, TransformType
from starfish.util import click
Expand Down
Empty file.
29 changes: 29 additions & 0 deletions starfish/image/_registration/test/test_transforms_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import tempfile

import numpy as np

from starfish import data
from starfish.image._registration._learn_transform.translation import Translation
from starfish.image._registration.transforms_list import TransformsList
from starfish.types import Axes, TransformType


ISS_SHIFTS = [[-23, 6], [-22, 2], [-22, -3], [-15, -4]]


def test_export_import_transforms_object():
exp = data.ISS(use_test_data=True)
stack = exp.fov().get_image('primary')
reference_stack = exp.fov().get_image('dots')
translation = Translation(reference_stack=reference_stack, axes=Axes.ROUND)
# Calculate max_proj accrss CH/Z
stack = stack.max_proj(Axes.CH, Axes.ZPLANE)
tr 945B ansform_list = translation.run(stack)
_, filename = tempfile.mkstemp()
# save to tempfile and import
transform_list.to_json(filename)
imported = TransformsList.from_json(filename)
for (_, transform_type, transform), shift in zip(imported.transforms, ISS_SHIFTS):
# assert that each TransformationObject has the correct translation shift
assert transform_type == TransformType.SIMILARITY
assert np.array_equal(transform.translation, shift)
97 changes: 0 additions & 97 deletions starfish/test/image/registration/test_registration.py

This file was deleted.

0