Beispiel #1
0
    def _do_modify_data(self, uuid, dataname, dims, shape, offset):
        """
        Respond to a POST request to modify a subvolume of data.

        All parameters are strings from the REST string.
        """
        dataset = self._get_h5_dataset(uuid, dataname)
        roi_start, roi_stop = self._determine_request_roi( dataset, dims, shape, offset )
        # Prepend channel to make "full" roi
        full_roi_start = (0,) + roi_start
        full_roi_stop = (dataset.shape[0],) + roi_stop
        full_roi_shape = numpy.subtract(full_roi_stop, full_roi_start)
        slicing = tuple( slice(x,y) for x,y in zip(full_roi_start, full_roi_stop) )
        
        # If the user is writing data beoyond the current extents of the dataset,
        #  resize the dataset first.
        if (numpy.array(full_roi_stop) > dataset.shape).any():
            dataset.resize( full_roi_stop )
        
        voxels_metadata = VoxelsMetadata.create_from_h5_dataset(dataset)
        codec = VoxelsNddataCodec( voxels_metadata )
        data = codec.decode_to_ndarray(self.rfile, full_roi_shape)

        dataset[slicing] = data
        self.server.h5_file.flush()

        #self.send_response(httplib.NO_CONTENT) # "No Content" (accepted)
        self.send_response(httplib.OK)
        self.send_header("Content-length", 0 )
        self.end_headers()
Beispiel #2
0
    def _do_modify_data(self, uuid, dataname, dims, shape, offset):
        """
        Respond to a POST request to modify a subvolume of data.

        All parameters are strings from the REST string.
        """
        dataset = self._get_h5_dataset(uuid, dataname)

        roi_start, roi_stop = self._determine_request_roi(
            dataset, dims, shape, offset)

        # Prepend channel to make "full" roi
        full_roi_start = (0, ) + roi_start
        full_roi_stop = (dataset.shape[0], ) + roi_stop
        full_roi_shape = numpy.subtract(full_roi_stop, full_roi_start)
        slicing = tuple(
            slice(x, y) for x, y in zip(full_roi_start, full_roi_stop))

        if 'dvid_metadata' in dataset.attrs:
            voxels_metadata = VoxelsMetadata(dataset.attrs['dvid_metadata'])
            del dataset.attrs['dvid_metadata']
        else:
            voxels_metadata = VoxelsMetadata.create_from_h5_dataset(dataset)

        # If the user is writing data beyond the current extents of the dataset,
        #  resize the dataset first.
        if (numpy.array(full_roi_stop) > dataset.shape).any():
            dataset.resize(numpy.maximum(full_roi_stop, dataset.shape))
            voxels_metadata.shape = tuple(
                map(int, numpy.maximum(voxels_metadata.shape, full_roi_stop)))

        # Overwrite minindex is needed
        if (numpy.array(full_roi_start) < voxels_metadata.minindex).any():
            voxels_metadata.minindex = tuple(
                numpy.minimum(voxels_metadata.minindex, full_roi_start))

        dataset.attrs['dvid_metadata'] = voxels_metadata.to_json()

        # Must read the entire message body, even if it isn't used below.
        codec = VoxelsNddataCodec(dataset.dtype)
        data = codec.decode_to_ndarray(self.rfile, full_roi_shape)

        if (numpy.array(roi_start) < 0).any():
            # We don't support negative coordinates in this mock server.
            #  But as a compromise, we don't choke here.
            #  Instead, we simply do nothing.
            pass
        else:
            dataset[slicing] = data
        self.server.h5_file.flush()

        #self.send_response(httplib.NO_CONTENT) # "No Content" (accepted)
        self.send_response(httplib.OK)
        self.send_header("Content-length", 0)
        self.end_headers()
Beispiel #3
0
    def _do_modify_data(self, uuid, dataname, dims, shape, offset):
        """
        Respond to a POST request to modify a subvolume of data.

        All parameters are strings from the REST string.
        """
        dataset = self._get_h5_dataset(uuid, dataname)

        roi_start, roi_stop = self._determine_request_roi( dataset, dims, shape, offset )

        # Prepend channel to make "full" roi
        full_roi_start = (0,) + roi_start
        full_roi_stop = (dataset.shape[0],) + roi_stop
        full_roi_shape = numpy.subtract(full_roi_stop, full_roi_start)
        slicing = tuple( slice(x,y) for x,y in zip(full_roi_start, full_roi_stop) )

        if 'dvid_metadata' in dataset.attrs:
            voxels_metadata = VoxelsMetadata(dataset.attrs['dvid_metadata'])
            del dataset.attrs['dvid_metadata']
        else:
            voxels_metadata = VoxelsMetadata.create_from_h5_dataset(dataset)

        # If the user is writing data beyond the current extents of the dataset,
        #  resize the dataset first.
        if (numpy.array(full_roi_stop) > dataset.shape).any():
            dataset.resize( numpy.maximum(full_roi_stop, dataset.shape) )
            voxels_metadata.shape = tuple( map(int, numpy.maximum( voxels_metadata.shape, full_roi_stop )) )

        # Overwrite minindex is needed
        if (numpy.array(full_roi_start) < voxels_metadata.minindex).any():
            voxels_metadata.minindex = tuple( numpy.minimum( voxels_metadata.minindex, full_roi_start ) )

        dataset.attrs['dvid_metadata'] = voxels_metadata.to_json()

        # Must read the entire message body, even if it isn't used below.
        codec = VoxelsNddataCodec( dataset.dtype )
        data = codec.decode_to_ndarray(self.rfile, full_roi_shape)
    
        if (numpy.array(roi_start) < 0).any():        
            # We don't support negative coordinates in this mock server.
            #  But as a compromise, we don't choke here.
            #  Instead, we simply do nothing.
            pass
        else:
            dataset[slicing] = data
        self.server.h5_file.flush()

        #self.send_response(httplib.NO_CONTENT) # "No Content" (accepted)
        self.send_response(httplib.OK)
        self.send_header("Content-length", 0 )
        self.end_headers()
Beispiel #4
0
    def _do_get_data(self, uuid, dataname, dims, shape, offset):
        """
        Respond to a query for volume data.
        
        All parameters are strings from the REST string.
        """
        if self.server.busy_count:
            self.server.busy_count -= 1
            raise self.RequestError(httplib.SERVICE_UNAVAILABLE,
                                    "I'm busy. Try again later.")

        dataset = self._get_h5_dataset(uuid, dataname)
        roi_start, roi_stop = self._determine_request_roi(
            dataset, dims, shape, offset)

        if (numpy.array(roi_start) < 0).any():
            # prepend channel
            roi_start = (0, ) + tuple(roi_start)
            roi_stop = (dataset.shape[0], ) + tuple(roi_stop)

            # This mock server doesn't really support negative coordinates,
            #  but as a compromise, we don't choke here.  Instead, we return an array of zeros.
            data = numpy.zeros(
                numpy.array(roi_stop) - roi_start, dataset.dtype)
        else:
            if (numpy.array(roi_stop) > dataset.shape[1:]).any():
                raise Exception(
                    "roi {} is out-of-bounds for dataset with shape {}".format(
                        (roi_start, roi_stop), dataset.shape[1:]))

            # Prepend channel slicing
            slicing = (slice(None), ) + tuple(
                slice(x, y) for x, y in zip(roi_start, roi_stop))
            data = dataset[slicing]

        codec = VoxelsNddataCodec(dataset.dtype)
        buffer_len = codec.calculate_buffer_len(data.shape)

        self.send_response(httplib.OK)
        self.send_header("Content-type", VoxelsNddataCodec.VOLUME_MIMETYPE)
        self.send_header("Content-length", str(buffer_len))
        self.end_headers()

        codec.encode_from_ndarray(self.wfile, data)
Beispiel #5
0
    def _do_get_data(self, uuid, dataname, dims, shape, offset):
        """
        Respond to a query for volume data.
        
        All parameters are strings from the REST string.
        """
        if self.server.busy_count:
            self.server.busy_count -= 1
            raise self.RequestError( httplib.SERVICE_UNAVAILABLE, "I'm busy. Try again later." )
        
        dataset = self._get_h5_dataset(uuid, dataname)
        roi_start, roi_stop = self._determine_request_roi( dataset, dims, shape, offset )

        if (numpy.array(roi_start) < 0).any():
            # prepend channel
            roi_start = (0,) + tuple(roi_start)
            roi_stop = (dataset.shape[0],) + tuple(roi_stop)
            
            # This mock server doesn't really support negative coordinates,
            #  but as a compromise, we don't choke here.  Instead, we return an array of zeros.
            data = numpy.zeros( numpy.array(roi_stop) - roi_start, dataset.dtype )
        else:
            if (numpy.array(roi_stop) > dataset.shape[1:]).any():
                raise Exception("roi {} is out-of-bounds for dataset with shape {}".format( (roi_start, roi_stop), dataset.shape[1:] ) )
    
            # Prepend channel slicing
            slicing = (slice(None),) + tuple( slice(x,y) for x,y in zip(roi_start, roi_stop) )
            data = dataset[slicing]
        
        codec = VoxelsNddataCodec( dataset.dtype )
        buffer_len = codec.calculate_buffer_len( data.shape )

        self.send_response(httplib.OK)
        self.send_header("Content-type", VoxelsNddataCodec.VOLUME_MIMETYPE)
        self.send_header("Content-length", str(buffer_len) )
        self.end_headers()

        codec.encode_from_ndarray( self.wfile, data )
Beispiel #6
0
    def _do_get_data(self, uuid, dataname, dims, shape, offset):
        """
        Respond to a query for volume data.
        
        All parameters are strings from the REST string.
        """
        dataset = self._get_h5_dataset(uuid, dataname)
        roi_start, roi_stop = self._determine_request_roi( dataset, dims, shape, offset )
        # Prepend channel slicing
        slicing = (slice(None),) + tuple( slice(x,y) for x,y in zip(roi_start, roi_stop) )
        
        data = dataset[slicing]
        
        voxels_metadata = VoxelsMetadata.create_from_h5_dataset(dataset)
        codec = VoxelsNddataCodec( voxels_metadata )
        buffer_len = codec.calculate_buffer_len( data.shape )

        self.send_response(httplib.OK)
        self.send_header("Content-type", VoxelsNddataCodec.VOLUME_MIMETYPE)
        self.send_header("Content-length", str(buffer_len) )
        self.end_headers()

        codec.encode_from_ndarray( self.wfile, data )