def get_cutout(
            self, resource, resolution, x_range, y_range, z_range, time_range, id_list,
            url_prefix, auth, session, send_opts, access_mode=CacheMode.no_cache, **kwargs
        ):
        """
        Upload a cutout to the Boss data store.

        Args:
            resource (intern.resource.resource.Resource): Resource compatible
                with cutout operations
            resolution (int): 0 indicates native resolution.
            x_range (list[int]): x range such as [10, 20] which means x>=10 and x<20.
            y_range (list[int]): y range such as [10, 20] which means y>=10 and y<20.
            z_range (list[int]): z range such as [10, 20] which means z>=10 and z<20.
            time_range ([list[int]]|None): time range such as [30, 40] which means t>=30 and t<40.
            id_list (list[int]): list of object ids to filter the cutout by.
            url_prefix (string): Protocol + host such as https://api.theboss.io
            auth (string): Token to send in the request header.
            session (requests.Session): HTTP session to use for request.
            send_opts (dictionary): Additional arguments to pass to session.send().
            access_mode (optional [Enum]): Identifies one of three cache access options:
                cache = Will check both cache and for dirty keys
                no_cache = Will skip cache check but check for dirty keys
                raw = Will skip both the cache and dirty keys check
            chunk_size (optional Tuple[int, int, int]): The chunk size to request


        Returns:
            (numpy.array): A 3D or 4D numpy matrix in ZXY(time) order.

        Raises:
            requests.HTTPError
        """
        chunk_size = kwargs.pop("chunk_size", (512, 512, 16 * 8))
        # TODO: magic number
        chunk_limit = (chunk_size[0] * chunk_size[1] * chunk_size[2]) * 1.2

        # Check to see if this volume is larger than a single request. If so,
        # chunk it into several smaller bites:
        if time_range:
            cutout_size = (
                (x_range[1] - x_range[0]) *
                (y_range[1] - y_range[0]) *
                (z_range[1] - z_range[0]) *
                (time_range[1] - time_range[0])
            )
        else:
            cutout_size = (
                (x_range[1] - x_range[0]) *
                (y_range[1] - y_range[0]) *
                (z_range[1] - z_range[0])
            )

        if cutout_size > chunk_limit:
            blocks = block_compute(
                x_range[0], x_range[1],
                y_range[0], y_range[1],
                z_range[0], z_range[1],
                block_size=chunk_size
            )

            result = np.ndarray((
                z_range[1] - z_range[0],
                y_range[1] - y_range[0],
                x_range[1] - x_range[0]
            ), dtype=resource.datatype)

            for b in blocks:
                _data = self.get_cutout(
                    resource, resolution, b[0], b[1], b[2],
                    time_range, id_list, url_prefix, auth, session, send_opts, 
                    access_mode, **kwargs
                )

                result[
                    b[2][0] - z_range[0] : b[2][1] - z_range[0],
                    b[1][0] - y_range[0] : b[1][1] - y_range[0],
                    b[0][0] - x_range[0] : b[0][1] - x_range[0]
                ] = _data

            return result

        req = self.get_cutout_request(
            resource, 'GET', 'application/blosc',
            url_prefix, auth,
            resolution, x_range, y_range, z_range, time_range, access_mode=access_mode,
            id_list=id_list, **kwargs
        )
        prep = session.prepare_request(req)
        # Hack in Accept header for now.
        prep.headers['Accept'] = 'application/blosc'
        resp = session.send(prep, **send_opts)

        if resp.status_code == 200:
            raw_data = blosc.decompress(resp.content)
            data_mat = np.fromstring(raw_data, dtype=resource.datatype)

            if time_range:
                # Reshape including time
                return np.reshape(data_mat,
                                  (time_range[1] - time_range[0],
                                   z_range[1] - z_range[0],
                                   y_range[1] - y_range[0],
                                   x_range[1] - x_range[0]),
                                  order='C')
            else:
                # Reshape without including time
                return np.reshape(data_mat,
                                  (z_range[1] - z_range[0],
                                   y_range[1] - y_range[0],
                                   x_range[1] - x_range[0]),
                                  order='C')

        msg = ('Get cutout failed on {}, got HTTP response: ({}) - {}'.format(
            resource.name, resp.status_code, resp.text))
        raise HTTPError(msg, request=req, response=resp)
def get_cutout ( self , resource , resolution , x_range , y_range , z_range , time_range , id_list , url_prefix , auth , session , send_opts , access_mode = CacheMode . no_cache , ** kwargs ) : chunk_size = kwargs . pop ( "chunk_size" , ( 512 , 512 , 16 * 8 ) ) chunk_limit = ( chunk_size [ 0 ] * chunk_size [ 1 ] * chunk_size [ 2 ] ) * 1.2 if time_range : cutout_size = ( ( x_range [ 1 ] - x_range [ 0 ] ) * ( y_range [ 1 ] - y_range [ 0 ] ) * ( z_range [ 1 ] - z_range [ 0 ] ) * ( time_range [ 1 ] - time_range [ 0 ] ) ) else : cutout_size = ( ( x_range [ 1 ] - x_range [ 0 ] ) * ( y_range [ 1 ] - y_range [ 0 ] ) * ( z_range [ 1 ] - z_range [ 0 ] ) ) if cutout_size > chunk_limit : blocks = block_compute ( x_range [ 0 ] , x_range [ 1 ] , y_range [ 0 ] , y_range [ 1 ] , z_range [ 0 ] , z_range [ 1 ] , block_size = chunk_size ) result = np . ndarray ( ( z_range [ 1 ] - z_range [ 0 ] , y_range [ 1 ] - y_range [ 0 ] , x_range [ 1 ] - x_range [ 0 ] ) , dtype = resource . datatype ) for b in blocks : _data = self . get_cutout ( resource , resolution , b [ 0 ] , b [ 1 ] , b [ 2 ] , time_range , id_list , url_prefix , auth , session , send_opts , access_mode , ** kwargs ) result [ b [ 2 ] [ 0 ] - z_range [ 0 ] : b [ 2 ] [ 1 ] - z_range [ 0 ] , b [ 1 ] [ 0 ] - y_range [ 0 ] : b [ 1 ] [ 1 ] - y_range [ 0 ] , b [ 0 ] [ 0 ] - x_range [ 0 ] : b [ 0 ] [ 1 ] - x_range [ 0 ] ] = _data return result req = self . get_cutout_request ( resource , 'GET' , 'application/blosc' , url_prefix , auth , resolution , x_range , y_range , z_range , time_range , access_mode = access_mode , id_list = id_list , ** kwargs ) prep = session . prepare_request ( req ) prep . headers [ 'Accept' ] = 'application/blosc' resp = session . send ( prep , ** send_opts ) if resp . status_code == 200 : raw_data = blosc . decompress ( resp . content ) data_mat = np . fromstring ( raw_data , dtype = resource . datatype ) if time_range : return np . reshape ( data_mat , ( time_range [ 1 ] - time_range [ 0 ] , z_range [ 1 ] - z_range [ 0 ] , y_range [ 1 ] - y_range [ 0 ] , x_range [ 1 ] - x_range [ 0 ] ) , order = 'C' ) else : return np . reshape ( data_mat , ( z_range [ 1 ] - z_range [ 0 ] , y_range [ 1 ] - y_range [ 0 ] , x_range [ 1 ] - x_range [ 0 ] ) , order = 'C' ) msg = ( 'Get cutout failed on {}, got HTTP response: ({}) - {}' . format ( resource . name , resp . status_code , resp . text ) ) raise HTTPError ( msg , request = req , response = resp )
Upload a cutout to the Boss data store.

        Args:
            resource (intern.resource.resource.Resource): Resource compatible
                with cutout operations
            resolution (int): 0 indicates native resolution.
            x_range (list[int]): x range such as [10, 20] which means x>=10 and x<20.
            y_range (list[int]): y range such as [10, 20] which means y>=10 and y<20.
            z_range (list[int]): z range such as [10, 20] which means z>=10 and z<20.
            time_range ([list[int]]|None): time range such as [30, 40] which means t>=30 and t<40.
            id_list (list[int]): list of object ids to filter the cutout by.
            url_prefix (string): Protocol + host such as https://api.theboss.io
            auth (string): Token to send in the request header.
            session (requests.Session): HTTP session to use for request.
            send_opts (dictionary): Additional arguments to pass to session.send().
            access_mode (optional [Enum]): Identifies one of three cache access options:
                cache = Will check both cache and for dirty keys
                no_cache = Will skip cache check but check for dirty keys
                raw = Will skip both the cache and dirty keys check
            chunk_size (optional Tuple[int, int, int]): The chunk size to request


        Returns:
            (numpy.array): A 3D or 4D numpy matrix in ZXY(time) order.

        Raises:
            requests.HTTPError