forked from ilastik/lazyflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestOpRESTfulVolumeReader.py
106 lines (92 loc) · 4.19 KB
/
testOpRESTfulVolumeReader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from builtins import object
###############################################################################
# lazyflow: data flow based lazy parallel computation framework
#
# Copyright (C) 2011-2014, the ilastik developers
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Lesser GNU General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# See the files LICENSE.lgpl2 and LICENSE.lgpl3 for full text of the
# GNU Lesser General Public License version 2.1 and 3 respectively.
# This information is also available on the ilastik web site at:
# http://ilastik.org/license/
###############################################################################
import nose
import os
import sys
import tempfile
import h5py
from lazyflow.operators.ioOperators.opRESTfulVolumeReader import OpRESTfulVolumeReader
from lazyflow.graph import Graph
import logging
logger = logging.getLogger(__name__)
logger.addHandler( logging.StreamHandler( sys.stdout ) )
logger.setLevel(logging.INFO)
#logger.setLevel(logging.DEBUG)
class TestRESTfulVolume(object):
def testBasic(self):
# The openconnectome site appears to be down at the moment.
# This test fails when that happens...
raise nose.SkipTest
if 'TRAVIS' in os.environ:
raise nose.SkipTest
testConfig0 = """
{
"_schema_name" : "RESTful-volume-description",
"_schema_version" : 1.0,
"name" : "Bock11-level0",
"format" : "hdf5",
"axes" : "zyx",
"##NOTE":"The first z-slice of the bock dataset is 2917, so the origin_offset must be at least 2917",
"origin_offset" : [2917, 50000, 50000],
"bounds" : [4156, 135424, 119808],
"dtype" : "numpy.uint8",
"url_format" : "http://openconnecto.me/ocp/ca/bock11/hdf5/0/{x_start},{x_stop}/{y_start},{y_stop}/{z_start},{z_stop}/",
"hdf5_dataset" : "CUTOUT"
}
"""
testConfig4 = """
{
"_schema_name" : "RESTful-volume-description",
"_schema_version" : 1.0,
"name" : "Bock11-level4",
"format" : "hdf5",
"axes" : "zyx",
"##NOTE":"The first z-slice of the bock dataset is 2917, so the origin_offset must be at least 2917",
"origin_offset" : [2917, 0, 0],
"bounds" : [4156, 8704, 7680],
"dtype" : "numpy.uint8",
"url_format" : "http://openconnecto.me/ocp/ca/bock11/hdf5/4/{x_start},{x_stop}/{y_start},{y_stop}/{z_start},{z_stop}/",
"hdf5_dataset" : "CUTOUT"
}
"""
descriptionFilePath = os.path.join(tempfile.mkdtemp(), 'desc.json')
with open(descriptionFilePath, 'w') as descFile:
descFile.write( testConfig4 )
graph = Graph()
op = OpRESTfulVolumeReader(graph=graph)
op.DescriptionFilePath.setValue( descriptionFilePath )
#data = op.Output[0:100, 50000:50200, 50000:50200].wait()
data = op.Output[0:10, 4000:4100, 4000:4100, 0:1].wait()
# We expect a channel dimension to be added automatically...
assert data.shape == ( 10, 100, 100, 1 )
outputDataFilePath = os.path.join(tempfile.mkdtemp(), 'testOutput.h5')
with h5py.File( outputDataFilePath, 'w' ) as outputDataFile:
outputDataFile.create_dataset('volume', data=data)
logger.debug( "Wrote data to {}".format(outputDataFilePath) )
if __name__ == "__main__":
import sys
import nose
sys.argv.append("--nocapture") # Don't steal stdout. Show it on the console as usual.
sys.argv.append("--nologcapture") # Don't set the logging level to DEBUG. Leave it alone.
ret = nose.run(defaultTest=__file__)
if not ret: sys.exit(1)