From be4adac9fdc6baf95fb19897c4fc860a22dbbe1b Mon Sep 17 00:00:00 2001 From: Alan Munoz <alan.munoz@ed.ac.uk> Date: Sun, 9 Jan 2022 20:58:23 +0000 Subject: [PATCH] test skips, bugfixes and postproc update --- aliby/io/omero.py | 2 +- aliby/tests/__init__.py | 0 aliby/tests/test_integration.py | 28 ------- aliby/tests/test_units.py | 99 ------------------------- aliby/tile/traps.py | 3 +- poetry.lock | 14 ++-- pyproject.toml | 2 +- tests/aliby/test_baby_client.py | 127 ++++++++++++++++++-------------- tests/aliby/test_local_expt.py | 3 + tests/aliby/test_pipeline.py | 28 +++++-- tests/aliby/test_segment.py | 2 +- 11 files changed, 108 insertions(+), 200 deletions(-) delete mode 100644 aliby/tests/__init__.py delete mode 100644 aliby/tests/test_integration.py delete mode 100644 aliby/tests/test_units.py diff --git a/aliby/io/omero.py b/aliby/io/omero.py index 914b68ba..124f562f 100644 --- a/aliby/io/omero.py +++ b/aliby/io/omero.py @@ -2,7 +2,7 @@ import h5py import omero from omero.gateway import BlitzGateway from aliby.experiment import get_data_lazy -from aliby.cells import CellsHDF +from agora.io.cells import CellsHDF class Argo: diff --git a/aliby/tests/__init__.py b/aliby/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/aliby/tests/test_integration.py b/aliby/tests/test_integration.py deleted file mode 100644 index 10e45f8a..00000000 --- a/aliby/tests/test_integration.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -Testing the "run" functions in the pipeline elements. -""" -import pytest -pytest.mark.skip(reason='All tests still WIP') - -# Todo: data needed: an experiment object -# Todo: data needed: an sqlite database -# Todo: data needed: a Shelf storage -class TestPipeline: - def test_experiment(self): - pass - - def test_omero_experiment(self): - pass - - def test_tiler(self): - pass - - def test_baby_client(self): - pass - - def test_baby_runner(self): - pass - - def test_pipeline(self): - pass - diff --git a/aliby/tests/test_units.py b/aliby/tests/test_units.py deleted file mode 100644 index 447ab601..00000000 --- a/aliby/tests/test_units.py +++ /dev/null @@ -1,99 +0,0 @@ -import pytest -pytest.mark.skip("all tests still WIP") - - -from core.core import PersistentDict - -# Todo: temporary file needed -class TestPersistentDict: - @pytest.fixture(autouse=True, scope='class') - def _get_json_file(self, tmp_path): - self._filename = tmp_path / 'persistent_dict.json' - - def test_persistent_dict(self): - p = PersistentDict(self._filename) - p['hello/from/the/other/side'] = "adele" - p['hello/how/you/doing'] = 'lionel' - # Todo: run checks - - -# Todo: data needed - small experiment -class TestExperiment: - def test_shape(self): - pass - def test_positions(self): - pass - def test_channels(self): - pass - def test_hypercube(self): - pass - -# Todo: data needed - a dummy OMERO server -class TestConnection: - def test_dataset(self): - pass - def test_image(self): - pass - -# Todo data needed - a position -class TestTimelapse: - def test_id(self): - pass - def test_name(self): - pass - def test_size_z(self): - pass - def test_size_c(self): - pass - def test_size_t(self): - pass - def test_size_x(self): - pass - def test_size_y(self): - pass - def test_channels(self): - pass - def test_channel_index(self): - pass - -# Todo: data needed image and template -class TestTrapUtils: - def test_trap_locations(self): - pass - def test_tile_shape(self): - pass - def test_get_tile(self): - pass - def test_centre(self): - pass - -# Todo: data needed - a functional experiment object -class TestTiler: - def test_n_timepoints(self): - pass - def test_n_traps(self): - pass - def test_get_trap_timelapse(self): - pass - def test_get_trap_timepoints(self): - pass - -# Todo: data needed - a functional tiler object -# Todo: running server needed -class TestBabyClient: - def test_get_new_session(self): - pass - def test_queue_image(self): - pass - def test_get_segmentation(self): - pass - -# Todo: data needed - a functional tiler object -class TestBabyRunner: - def test_model_choice(self): - pass - def test_properties(self): - pass - def test_segment(self): - pass - diff --git a/aliby/tile/traps.py b/aliby/tile/traps.py index e37eb925..b3563d6d 100644 --- a/aliby/tile/traps.py +++ b/aliby/tile/traps.py @@ -11,6 +11,7 @@ from skimage.filters import threshold_otsu from skimage.segmentation import clear_border from skimage.measure import label, regionprops from skimage.morphology import disk, closing, square +from skimage.registration import phase_cross_correlation def stretch_image(image): @@ -462,7 +463,7 @@ def align_timelapse_images( for i in range(1, size_t): img = centre(np.squeeze(raw_data[channel, i, :, :, 0])) - shifts, _, _ = feature.register_translation(ref, img) + shifts, _, _ = phase_cross_correlation(ref, img) # If a huge move is detected at a single time point it is taken # to be inaccurate and the correction from the previous time point # is used. diff --git a/poetry.lock b/poetry.lock index 68e0e8b1..f93587a0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -110,17 +110,21 @@ xgboost = "1.4.2" [[package]] name = "aliby-post" -version = "0.1.0" +version = "0.1.1" description = "Post-processing tools for aliby pipeline." category = "main" optional = false -python-versions = ">=3.7,<4.0" +python-versions = ">=3.7.1,<3.11" [package.dependencies] +aliby-agora = ">=0.2.0" catch22 = ">=0.2.0,<0.3.0" leidenalg = ">=0.8.8,<0.9.0" more-itertools = ">=8.12.0,<9.0.0" numpy = ">=1.17.3" +omni-gaussian = "*" +pandas = ">=1.3.5,<2.0.0" +PyYAML = ">=6.0,<7.0" scipy = ">=1.4.1" [[package]] @@ -1909,7 +1913,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = ">=3.7.1,<3.11" -content-hash = "b6fb40c30458a9245b90757bd4d62d41fc51d9ffa544a8f6812ce5acf0cfc8df" +content-hash = "e1e7066cb95566d8b8151a3dc7fc74d2dce27c535c55e6acdb708ce6a6b55c19" [metadata.files] absl-py = [ @@ -2015,8 +2019,8 @@ aliby-baby = [ {file = "aliby_baby-0.1.2-py3-none-any.whl", hash = "sha256:f8f11b82db89a74ad8cc48059370af889f246a83d4cbc45ce75d9475a15605f7"}, ] aliby-post = [ - {file = "aliby-post-0.1.0.tar.gz", hash = "sha256:aab49a84f17ac03b15ae41becd591716ad93cf35c12619f64794ef2aa86ccaad"}, - {file = "aliby_post-0.1.0-py3-none-any.whl", hash = "sha256:a4bcd6d5df5152f10c0bacd4970b59234df8eaa757ba2c0662d00f70d077949a"}, + {file = "aliby-post-0.1.1.tar.gz", hash = "sha256:426510854767402adc06ed62b7867866dcad054838432ffe26ebb91861c85828"}, + {file = "aliby_post-0.1.1-py3-none-any.whl", hash = "sha256:6bd666a37b83ee750c9837ce08a8541d16290811fadcf020378b6122f3b1f8bd"}, ] appdirs = [ {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, diff --git a/pyproject.toml b/pyproject.toml index 0d257b76..b46e1308 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,8 +30,8 @@ zeroc-ice = "3.6.5" tensorflow = ">=1.15,<=2.3" aliby-agora = ">=0.2.0" aliby-baby = "*" -aliby-post = "*" omni-gaussian = "*" +aliby-post = "^0.1.1" [tool.poetry.dev-dependencies] diff --git a/tests/aliby/test_baby_client.py b/tests/aliby/test_baby_client.py index 3c93a5be..f8ca071c 100644 --- a/tests/aliby/test_baby_client.py +++ b/tests/aliby/test_baby_client.py @@ -1,73 +1,88 @@ +import pytest + +pytest.mark.skip + import json import time import numpy as np from aliby.experiment import ExperimentLocal from aliby.baby_client import BabyClient -from tile.tiler import Tiler +from aliby.tile.tiler import Tiler + -root_dir = ( - "/Users/s1893247/PhD/pipeline-core/data/glclvl_0" ".1_mig1_msn2_maf1_sfp1_dot6_03" -) +@pytest.mark.skip(reason="No longer usable, requires local files. Kept until replaced.") +def test_client(): + root_dir = ( + "/Users/s1893247/PhD/pipeline-core/data/glclvl_0" + ".1_mig1_msn2_maf1_sfp1_dot6_03" + ) -expt = ExperimentLocal(root_dir, finished=True) -seg_expt = Tiler(expt, finished=True) + expt = ExperimentLocal(root_dir, finished=True) + seg_expt = Tiler(expt, finished=True) -print(seg_expt.positions) -seg_expt.current_position = "pos007" + print(seg_expt.positions) + seg_expt.current_position = "pos007" -config = {"camera": "evolve", "channel": "brightfield", "zoom": "60x", "n_stacks": "5z"} + config = { + "camera": "evolve", + "channel": "brightfield", + "zoom": "60x", + "n_stacks": "5z", + } -baby_client = BabyClient(expt, **config) + baby_client = BabyClient(expt, **config) -print("The session is {}".format(baby_client.sessions["default"])) + print("The session is {}".format(baby_client.sessions["default"])) -# Channel 0, 0, X,Y,Z all -num_timepoints = 5 + # Channel 0, 0, X,Y,Z all + num_timepoints = 5 -traps_tps = [ - seg_expt.get_traps_timepoint( - tp, tile_size=81, channels=[0], z=[0, 1, 2, 3, 4] - ).squeeze() - for tp in range(num_timepoints) -] + traps_tps = [ + seg_expt.get_traps_timepoint( + tp, tile_size=81, channels=[0], z=[0, 1, 2, 3, 4] + ).squeeze() + for tp in range(num_timepoints) + ] -segmentations = [] -try: - for i, timpoint in enumerate(traps_tps): - print("Sending timepoint {};".format(i)) - status = baby_client.queue_image( - timpoint, - baby_client.sessions["default"], - assign_mothers=True, - return_baprobs=True, - with_edgemasks=True, - ) - while True: - try: - print("Loading.", end="") - result = baby_client.get_segmentation(baby_client.sessions["default"]) - except: - print(".", end="") - time.sleep(1) - continue - break - print("Received timepoint {}".format(i)) - segmentations.append(result) -except Exception as e: - print(segmentations) - raise e + segmentations = [] + try: + for i, timpoint in enumerate(traps_tps): + print("Sending timepoint {};".format(i)) + status = baby_client.queue_image( + timpoint, + baby_client.sessions["default"], + assign_mothers=True, + return_baprobs=True, + with_edgemasks=True, + ) + while True: + try: + print("Loading.", end="") + result = baby_client.get_segmentation( + baby_client.sessions["default"] + ) + except: + print(".", end="") + time.sleep(1) + continue + break + print("Received timepoint {}".format(i)) + segmentations.append(result) + except Exception as e: + print(segmentations) + raise e -with open("segmentations.json", "w") as fd: - json.dump(segmentations, fd) + with open("segmentations.json", "w") as fd: + json.dump(segmentations, fd) -print("Done.") -# print(len(segmentations[0])) -# for i in range(5): -# print("trap {}".format(i)) -# for k, v in segmentations[0][i].items(): -# print(k, v) -# -# import matplotlib.pyplot as plt -# plt.imshow(np.squeeze(batches[0][0, ..., 0])) -# plt.savefig('test_baby.pdf') + print("Done.") + # print(len(segmentations[0])) + # for i in range(5): + # print("trap {}".format(i)) + # for k, v in segmentations[0][i].items(): + # print(k, v) + # + # import matplotlib.pyplot as plt + # plt.imshow(np.squeeze(batches[0][0, ..., 0])) + # plt.savefig('test_baby.pdf') diff --git a/tests/aliby/test_local_expt.py b/tests/aliby/test_local_expt.py index 026b54bb..d9a38b84 100644 --- a/tests/aliby/test_local_expt.py +++ b/tests/aliby/test_local_expt.py @@ -1,3 +1,5 @@ +import pytest + import logging from logging.handlers import RotatingFileHandler import unittest @@ -31,6 +33,7 @@ data_directory = Path(__file__).parent.parent / "data/" root_directory = data_directory / "glclvl_0.1_mig1_msn2_maf1_sfp1_dot6_03" +@pytest.mark.skip(reason="No longer usable, requires local files. Kept until replaced.") class TestCase(unittest.TestCase): def setUp(self): self.expt = Experiment.from_source(root_directory, finished=True) diff --git a/tests/aliby/test_pipeline.py b/tests/aliby/test_pipeline.py index 1adb4456..451a0504 100644 --- a/tests/aliby/test_pipeline.py +++ b/tests/aliby/test_pipeline.py @@ -1,19 +1,29 @@ -import os import unittest + +import pytest +import os + from pathlib import Path from aliby.baby_client import BabyRunner -from aliby.experiment import ExperimentOMERO -from aliby.pipeline import ExperimentLocal +from aliby.experiment import ExperimentOMERO, ExperimentLocal from aliby.tile.tiler import Tiler +@pytest.fixture +def server_user(): + return os.environ.get("SERVER_USER") + + +@pytest.fixture +def server_password(): + return os.environ.get("SERVER_PASSWORD") + + +@pytest.mark.skip(reason="Local analysis not yet implemented") class TestLocal(unittest.TestCase): def setUp(self) -> None: - self.root_dir = ( - "/Users/s1893247/PhD/pipeline-core/data/glclvl_0" - ".1_mig1_msn2_maf1_sfp1_dot6_03" - ) + self.root_dir = "./data/" ".1_mig1_msn2_maf1_sfp1_dot6_03" self.raw_expt = ExperimentLocal(self.root_dir, finished=True) self.tiler = Tiler(self.raw_expt, finished=False) @@ -50,9 +60,11 @@ class TestLocal(unittest.TestCase): p.unlink() +# FIXME reimplement this being careful with credentials +@pytest.mark.skip(reason="credentials are not present in current repo") class TestRemote(unittest.TestCase): def setUp(self) -> None: - self.root_dir = "/Users/s1893247/PhD/pipeline-core/data/ome_test" + self.root_dir = "./" self.raw_expt = ExperimentOMERO( 51, username="root", diff --git a/tests/aliby/test_segment.py b/tests/aliby/test_segment.py index 65c2bf6c..10a21d5c 100644 --- a/tests/aliby/test_segment.py +++ b/tests/aliby/test_segment.py @@ -1,7 +1,7 @@ import unittest import numpy as np -from aliby.tile.tiler import align_timelapse_images +from aliby.tile.traps import align_timelapse_images class TestCase(unittest.TestCase): -- GitLab