Skip to content

Commit

Permalink
Remove libdvid references in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grisaitis committed Oct 7, 2016
1 parent 5a7f85a commit 738e9e1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions tests/data_io/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from __future__ import print_function

import os
from libdvid.voxels import VoxelsAccessor
import h5py

DEBUG = True

using_in_memory = False

# dataset_source_type = VoxelsAccessor
# dataset_source_type = 'hdf5 file paths'
dataset_source_type = h5py.File

Expand Down
10 changes: 5 additions & 5 deletions tests/data_io/load_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import malis
import numpy as np

from libdvid.voxels import VoxelsAccessor

from dvision import DVIDDataInstance
from .config import using_in_memory, path_to_training_datasets, training_dataset_names, dataset_source_type, dvid_uuid


Expand All @@ -25,14 +24,15 @@ def get_train_dataset(dataset_source_type_, using_in_memory=False):
data='grayscale',
components='labels',
)
dvid_hostname = 'emdata2.int.janelia.org:7000'
dvid_hostname = 'emdata2.int.janelia.org'
dvid_port = 7000
dataset['name'] = dname
dataset['nhood'] = malis.mknhood3d()
for key in ['data', 'components']:
if dataset_source_type_ == VoxelsAccessor:
if dataset_source_type_ == DVIDDataInstance:
if key in dvid_data_names:
data_name = dvid_data_names[key]
dataset[key] = VoxelsAccessor(hostname=dvid_hostname, uuid=dvid_uuid, data_name=data_name)
dataset[key] = DVIDDataInstance(dvid_hostname, dvid_port, dvid_uuid, data_name)
elif dataset_source_type_ == h5py.File:
dataset[key] = h5py.File(h5_filenames[key], 'r')['main']
if using_in_memory:
Expand Down
4 changes: 2 additions & 2 deletions tests/data_io/test_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import unittest

import h5py
from libdvid.voxels import VoxelsAccessor
import numpy as np

from data_io import DataLoader
from data_io.dataset_reading import get_numpy_dataset
from dvision import DVIDDataInstance
from .load_datasets import get_train_dataset


class TestDataLoader(unittest.TestCase):
# @mock.patch('data_io.get_numpy_dataset', side_effect=mock_get_numpy_dataset)
def test_loads_data_chunks_from_dvid(self):
train_dataset = get_train_dataset(VoxelsAccessor)
train_dataset = get_train_dataset(DVIDDataInstance)
dataset_to_test = train_dataset[0]
dataset, numpy_dataset = self.get_datasets_for(dataset_to_test, offset=(3000, 3000, 3000))
for key in ['data', 'components', 'label', 'mask']:
Expand Down
15 changes: 8 additions & 7 deletions tests/data_io/test_get_numpy_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import unittest

import numpy as np
from libdvid.voxels import VoxelsAccessor
import h5py
import malis

from data_io.dataset_reading import get_numpy_dataset
from .load_datasets import get_train_dataset
from data_io.dvid_connectivity import get_good_components
from data_io.util import replace_array_except_whitelist
from dvision import DVIDDataInstance
from dvision.component_filtering import get_good_components
from tests.data_io.load_datasets import get_train_dataset


class TestGetNumpyDataset(unittest.TestCase):
def test_works_with_hdf5_fibsem(self):
Expand All @@ -27,7 +28,7 @@ def test_works_with_hdf5_fibsem(self):
)

def test_works_with_dvid(self):
train_dataset = get_train_dataset(VoxelsAccessor)
train_dataset = get_train_dataset(DVIDDataInstance)
dataset = train_dataset[0]
dataset['body_names_to_exclude'] = ['out']
origin = (3000, 3000, 3000)
Expand Down Expand Up @@ -61,8 +62,8 @@ def get_datasets(dataset, origin):
components_slices[-3:] = output_slices
components_slices = tuple(components_slices)
expected_components_array = np.array(dataset['components'][components_slices]).reshape((1,) + output_shape)
if type(dataset['components']) is VoxelsAccessor:
print("Is VoxelsAccessor...")
if type(dataset['components']) is DVIDDataInstance:
print("Is DVIDDataInstance...")
print("uniques before:", np.unique(expected_components_array))
dvid_uuid = dataset['components'].uuid
body_names_to_exclude = dataset.get('body_names_to_exclude')
Expand All @@ -74,7 +75,7 @@ def get_datasets(dataset, origin):
components_for_affinity_generation = expected_components_array.reshape(output_shape)
expected_label = malis.seg_to_affgraph(components_for_affinity_generation, malis.mknhood3d())
expected_dataset['label'] = expected_label
if type(dataset['components']) is VoxelsAccessor:
if type(dataset['components']) is DVIDDataInstance:
expected_mask = np.array(expected_components_array > 0).astype(np.uint8)
else:
expected_mask = np.ones(shape=(1,) + output_shape, dtype=np.uint8)
Expand Down

0 comments on commit 738e9e1

Please sign in to comment.