Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tathey1 committed Jan 4, 2024
1 parent cfca215 commit 780987a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 34 deletions.
62 changes: 31 additions & 31 deletions brainlit/BrainLine/tests/test_apply_ilastik.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,35 @@
from datetime import date


@pytest.fixture(scope="session")
def axon_data_dir(tmp_path_factory):
data_dir = tmp_path_factory.mktemp("data")
brain_dir = data_dir / "braintest"
brain_dir.mkdir()
val_dir = brain_dir / "val"
val_dir.mkdir()

labels = np.ones((2, 10, 10, 10), dtype=np.uint16)
labels[0, 0, 0, :] = 2
labels_path = val_dir / "subvol-image_3channel_Labels.h5"
with h5py.File(str(labels_path), "w") as f:
dset = f.create_dataset("exported_data", data=labels)

im_probs = np.zeros((2, 10, 10, 10))
im_probs[0, 0, 0, :5] = 0.9
path = val_dir / "subvol_Probabilities.h5"
with h5py.File(path, "w") as f:
f.create_dataset("exported_data", data=im_probs)

im = np.zeros((3, 10, 10, 10))
im[0, 0, 0, :5] = 0.9
path = val_dir / "subvol.h5"
with h5py.File(path, "w") as f:
f.create_dataset("image_3channel", data=im)

return data_dir


# ApplyIlastik


Expand All @@ -34,7 +63,7 @@ def test_processsubvols_none(axon_data_dir):
apl.process_subvols()

# brainr1
val_dir = axon_data_dir / "brain8557"
val_dir = axon_data_dir / "brainr1"
val_dir.mkdir()
val_dir = val_dir / "val"
val_dir.mkdir()
Expand All @@ -50,7 +79,7 @@ def test_processsubvols_none(axon_data_dir):
apl.process_subvols()

# brainr2
val_dir = axon_data_dir / "brain8555"
val_dir = axon_data_dir / "brainr2"
val_dir.mkdir()
val_dir = val_dir / "val"
val_dir.mkdir()
Expand Down Expand Up @@ -89,35 +118,6 @@ def test_move_results(axon_data_dir):
# Other methods


@pytest.fixture(scope="session")
def axon_data_dir(tmp_path_factory):
data_dir = tmp_path_factory.mktemp("data")
brain_dir = data_dir / "braintest"
brain_dir.mkdir()
val_dir = brain_dir / "val"
val_dir.mkdir()

labels = np.ones((2, 10, 10, 10), dtype=np.uint16)
labels[0, 0, 0, :] = 2
labels_path = val_dir / "subvol-image_3channel_Labels.h5"
with h5py.File(str(labels_path), "w") as f:
dset = f.create_dataset("exported_data", data=labels)

im_probs = np.zeros((2, 10, 10, 10))
im_probs[0, 0, 0, :5] = 0.9
path = val_dir / "subvol_Probabilities.h5"
with h5py.File(path, "w") as f:
f.create_dataset("exported_data", data=im_probs)

im = np.zeros((3, 10, 10, 10))
im[0, 0, 0, :5] = 0.9
path = val_dir / "subvol.h5"
with h5py.File(path, "w") as f:
f.create_dataset("image_3channel", data=im)

return data_dir


def test_plot_results_axon(axon_data_dir):
data_dir_str = str(axon_data_dir)

Expand Down
29 changes: 26 additions & 3 deletions brainlit/BrainLine/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ def make_data_dir(tmp_path_factory):
return data_dir


@pytest.fixture(scope="session")
def make_bad_datafile(make_data_dir):
data_dir = make_data_dir
bad_data_file = data_dir / "bad_data.json"
bad_type = {"object_type": "invalid", "brain2paths": {}}
with open(bad_data_file, "w") as f:
json.dump(bad_type, f)

return bad_data_file


@pytest.fixture(scope="session")
def ontology_path():
ontology_json_path = (
Expand Down Expand Up @@ -48,10 +59,22 @@ def test_find_atlas_level_label(ontology_path):
assert new_label == 8


def test_download_subvolumes(make_data_dir):
# Axon
def test_download_subvolumes(make_data_dir, make_bad_datafile):
data_dir = make_data_dir # tmp_path_factory.mktemp("data")
layer_names = ["average_10um"] * 3
layer_names = ["average_10um", "average_10um", "zero"]

# Data file with bad object_fype
bad_data_file = make_bad_datafile
with pytest.raises(ValueError):
util.download_subvolumes(
data_dir=data_dir,
brain_id="pytest",
layer_names=layer_names,
dataset_to_save="val",
data_file=bad_data_file,
)

# Axon
data_file = (
Path(os.path.abspath(__file__)).parents[3]
/ "docs"
Expand Down

0 comments on commit 780987a

Please sign in to comment.