Exemple #1
0
def readStack(x, y, z, r):
    xmin = 0
    xmax = 1023
    ymin = 0
    ymax = 1023
    zmin = 0
    zmax = 99

    if (Local_Neuroseg.IS_IN_CLOSE_RANGE(
            x, xmin, xmax)) & (Local_Neuroseg.IS_IN_CLOSE_RANGE(
                y, ymin, ymax)) & (Local_Neuroseg.IS_IN_CLOSE_RANGE(
                    z, zmin, zmax)):
        box = np.zeros(6)
        box[0] = math.floor(x - r)
        box[1] = math.floor(y - r)
        box[2] = math.floor(z - r)
        box[3] = math.ceil(x + r)
        box[4] = math.ceil(y + r)
        box[5] = math.ceil(z + r)
        boxSize = int(
            (box[5] - box[2]) * (box[4] - box[1]) * (box[3] - box[0]))

        connection = httplib.HTTPConnection("localhost:2048", timeout=5.0)
        uuid = "hatu"
        dvid_volume = voxels.VoxelsAccessor(connection, uuid, "grayscale")
        stack = dvid_volume.get_ndarray(
            (0, int(box[0]), int(box[1]), int(box[2])),
            (1, int(box[3]), int(box[4]), int(box[5])))
        stack = stack.reshape(boxSize)
        return stack
    else:
        return np.zeros(0)
Exemple #2
0
    def test_get_partial_slicing(self):
        # Retrieve from server
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        subvolume = dvid_vol[0:4, 9:10, 5:20, 50:150]
        start, stop = (0, 9, 5, 50, 0), (4, 10, 20, 150, 3)

        # Compare to file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #3
0
    def test_get_ellipsis_slicing(self):
        # Retrieve from server
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        subvolume = dvid_vol[0:4, 9:10, ..., 1:2]
        start, stop = (0, 9, 0, 0, 1), (4, 10, 100, 200, 2)

        # Compare to file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #4
0
    def test_get_ndarray(self):
        """
        Get some data from the server and check it.
        """
        # Retrieve from server
        start, stop = (0, 9, 5, 50, 0), (4, 10, 20, 150, 3)
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        subvolume = dvid_vol.get_ndarray(start, stop)

        # Compare to file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #5
0
    def test_get_channel_slicing(self):
        """
        Test that slicing in the channel dimension works.
        This is a special case because the entire volume needs to be requested from DVID, 
        but only the requested subset of channels will be returned.
        """
        # Retrieve from server
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        subvolume = dvid_vol[1:3, 9:10, 5:20, 50:150]

        # Compare to file
        start, stop = (1, 9, 5, 50, 0), (3, 10, 20, 150, 3)
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #6
0
    def test_get_full_volume_via_slicing(self):
        # Retrieve from server
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        subvolume1 = dvid_vol[:]
        start = (0, ) * len(self.original_data.shape)
        stop = self.original_data.shape

        # Compare to file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume1)

        # Alternate sytax: Use Ellipsis
        subvolume2 = dvid_vol[...]
        # Results should match
        assert (subvolume1 == subvolume2).all()
Exemple #7
0
    def test_post_reduced_dim_slicing(self):
        # Cutout dims
        start, stop = (0, 9, 5, 50, 0), (4, 10, 20, 150, 3)
        shape = numpy.subtract(stop, start)

        # Generate test data
        subvolume = numpy.random.randint(0, 1000, shape).astype(numpy.uint32)

        # Send to server
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        dvid_vol[0:4, 9, 5:20, 50:150, 0:3] = subvolume[:, 0, ...]

        # Check file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #8
0
def readStack(x, y, z, r, address, port, uuid):
    xmin = 0
    xmax = 99
    ymin = 0
    ymax = 99
    zmin = 0
    zmax = 99

    if (Local_Neuroseg.IS_IN_CLOSE_RANGE(
            x, xmin, xmax)) & (Local_Neuroseg.IS_IN_CLOSE_RANGE(
                y, ymin, ymax)) & (Local_Neuroseg.IS_IN_CLOSE_RANGE(
                    z, zmin, zmax)):
        box = np.zeros(6)
        box[0] = math.floor(x - r)
        box[1] = math.floor(y - r)
        box[2] = math.floor(z - r)
        box[3] = math.ceil(x + r) + 1
        box[4] = math.ceil(y + r) + 1
        box[5] = math.ceil(z + r) + 1

        boxSize = int(
            (box[5] - box[2]) * (box[4] - box[1]) * (box[3] - box[0]))

        connection = httplib.HTTPConnection(address + ":" + port, timeout=5.0)
        # uuid = "ae87"
        dvid_volume = voxels.VoxelsAccessor(connection, uuid, "grayscale")

        stack = dvid_volume.get_ndarray(
            (0, int(box[0]), int(box[1]), int(box[2])),
            (1, int(box[3]), int(box[4]), int(box[5])))
        stack2 = np.zeros(boxSize)
        t, a, b, c = stack.shape
        index = 0
        for i in range(c):
            for j in range(b):
                for k in range(a):
                    stack2[index] = stack[0][k][j][i]
                    k += 1
                    index += 1
                j += 1
            i += 1
        return stack2.reshape(1, int(box[3] - box[0]), int(box[4] - box[1]),
                              int(box[5] - box[2]))
    else:
        return np.zeros(0)
Exemple #9
0
    def test_extra_query_args(self):
        """
        Create a VoxelsAccessor that uses extra query args 
        They come after the '?' in the REST URI.  For example:
        http://localhost/api/node/mydata/_0_1_2/10_10_10/0_0_0?roi=whatever&attenuation=3
        """
        # Retrieve from server
        start, stop = (0, 9, 5, 50, 0), (4, 10, 20, 150, 3)
        query_args = {'roi': 'some_ref', 'attenuation': 5}
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid,
                                         self.data_name,
                                         query_args=query_args)
        subvolume = dvid_vol.get_ndarray(start, stop)

        # Compare to file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #10
0
    def test_get_ndarray_throttled_2(self):
        """
        Get some data from the server and check it.
        Enable throttle via query_args

        Note: This test doesn't really exercise our handling of 503 responses...
        """
        # Retrieve from server
        start, stop = (0, 9, 5, 50, 0), (4, 10, 20, 150, 3)
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid,
                                         self.data_name,
                                         query_args={'throttle': 'on'})
        subvolume = dvid_vol.get_ndarray(start, stop)

        # Compare to file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #11
0
    def test_post_ndarray(self):
        """
        Modify a remote subvolume and verify that the server wrote it.
        """
        # Cutout dims
        start, stop = (0, 9, 5, 50, 0), (4, 10, 20, 150, 3)
        shape = numpy.subtract(stop, start)

        # Generate test data
        subvolume = numpy.random.randint(0, 1000, shape).astype(numpy.uint32)

        # Send to server
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        dvid_vol.post_ndarray(start, stop, subvolume)

        # Check file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #12
0
    def test_zy_post_negative_coordinates(self):
        """
        Just make sure nothing blows up if we post to negative coordinates.
        (Right now, the mock server doesn't actually store this data, but it shouldn't crash.)
        """
        # Cutout dims
        start, stop = (0, -10, 5, -50, 0), (4, 10, 20, 150, 10)
        shape = numpy.subtract(stop, start)

        # Generate test data
        subvolume = numpy.random.randint(0, 1000, shape).astype(numpy.uint32)

        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)

        # Send to server
        dvid_vol.post_ndarray(start, stop, subvolume)

        # Now try to 'get' data from negative coords
        dvid_vol.get_ndarray(start, stop)
Exemple #13
0
    def test_get_stepped_slicing(self):
        """
        """
        # Retrieve from server
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        subvolume = dvid_vol[0:4:2, 1:10:3, 5:20:5, 50:150:10]

        # Compare to file
        full_start = (0, ) * len(self.original_data.shape)
        full_stop = self.original_data.shape
        full_stored_volume = self._get_subvolume_from_file(
            self.test_filepath, self.data_uuid, self.data_name, full_start,
            full_stop)
        stored_stepped_volume = full_stored_volume[0:4:2, 1:10:3, 5:20:5,
                                                   50:150:10]

        assert subvolume.shape == stored_stepped_volume.shape
        assert subvolume.dtype == stored_stepped_volume.dtype
        assert (subvolume == stored_stepped_volume).all()
Exemple #14
0
    def test_get_reduced_dim_slicing(self):
        # Retrieve from server
        dvid_vol = voxels.VoxelsAccessor(self.client_connection,
                                         self.data_uuid, self.data_name)
        subvolume = dvid_vol[
            0:4, 9:10, 3, :,
            1:2]  # Note that the third dimension will be dropped...
        start, stop = (0, 9, 3, 0, 1), (4, 10, 4, 200, 2)

        # Check dimensionality/shape of returned volume
        full_shape = numpy.array(stop) - start
        reduced_shape = list(full_shape[:2]) + list(full_shape[3:])
        assert subvolume.shape == tuple(reduced_shape)

        # Before we compare to the file, re-insert the dropped axis
        subvolume = subvolume[:, :, numpy.newaxis, ...]

        # Compare to file
        self._check_subvolume(self.test_filepath, self.data_uuid,
                              self.data_name, start, stop, subvolume)
Exemple #15
0
    def test_zz_quickstart_usage(self):
        import json
        import httplib
        import numpy
        from pydvid import voxels, general

        # Open a connection to DVID
        connection = httplib.HTTPConnection("localhost:8000", timeout=5.0)

        # Get detailed dataset info: /api/datasets/info
        dataset_details = general.get_repos_info(connection)
        # print json.dumps( dataset_details, indent=4 )

        # Create a new remote volume
        uuid = 'abcde'
        voxels_metadata = voxels.VoxelsMetadata.create_default_metadata(
            (4, 0, 0, 0), numpy.uint8, 'cxyz', 1.0, "")
        voxels.create_new(connection, uuid, "my_volume", voxels_metadata)

        # Use the VoxelsAccessor convenience class to manipulate a particular data volume
        dvid_volume = voxels.VoxelsAccessor(connection, uuid, "my_volume")
        # print dvid_volume.axiskeys, dvid_volume.dtype, dvid_volume.minindex, dvid_volume.shape

        # Add some data
        updated_data = numpy.ones(
            (4, 100, 100, 100),
            dtype=numpy.uint8)  # Must include all channels.
        dvid_volume[:, 10:110, 20:120, 30:130] = updated_data
        # OR:
        dvid_volume.post_ndarray((0, 10, 20, 30), (4, 110, 120, 130),
                                 updated_data)

        # Read from it (First axis is channel.)
        cutout_array = dvid_volume[:, 10:110, 20:120, 30:130]
        # OR:
        cutout_array = dvid_volume.get_ndarray((0, 10, 20, 30),
                                               (4, 110, 120, 130))

        assert isinstance(cutout_array, numpy.ndarray)
        assert cutout_array.shape == (4, 100, 100, 100)
Exemple #16
0
import numpy
from pydvid import voxels, general

connection = httplib.HTTPConnection("localhost:8001", timeout=5.0)

# Get detailed dataset info: /api/datasets/info
dataset_details = general.get_repos_info(connection)
# print json.dumps( dataset_details, indent=4 )

# Create a new remote volume
uuid = "25eb4d877a0d4f8391014fe1237ada8a"
voxels_metadata = voxels.VoxelsMetadata.create_default_metadata(
    (4, 0, 0, 0), numpy.uint8, "cxyz", 1.0, "")
# voxels.create_new( connection, uuid, "my_volume", voxels_metadata )
# Use the VoxelsAccessor convenience class to manipulate a particular data volume
dvid_volume = voxels.VoxelsAccessor(connection, uuid, "my_volume")
print(dvid_volume.axiskeys, dvid_volume.dtype, dvid_volume.minindex,
      dvid_volume.shape)

# Add some data
updated_data = numpy.ones((4, 100, 100, 100),
                          dtype=numpy.uint8)  # Must include all channels.
# dvid_volume[:, 10:110, 20:120, 30:130] = updated_data
# OR:
dvid_volume.post_ndarray((0, 10, 20, 30), (4, 110, 120, 130), updated_data)

# Read from it (First axis is channel.)
cutout_array = dvid_volume[:, 10:110, 20:120, 30:130]
# OR:
cutout_array = dvid_volume.get_ndarray((0, 10, 20, 30), (4, 110, 120, 130))