def testEmptyResult(self): rois = [([0,0,0], [10,10,10]), ([5,3,2], [11,12,13]), ([4,6,4], [5,9,9])] result = containing_rois( rois, ( [100,100,100], [200,200,200] ) ) assert result.shape == (0, 2, 3)
def testBasic(self): rois = [([0, 0, 0], [10, 10, 10]), ([5, 3, 2], [11, 12, 13]), ([4, 6, 4], [5, 9, 9])] result = containing_rois(rois, ([4, 7, 6], [5, 8, 8])) assert (result == [([0, 0, 0], [10, 10, 10]), ([4, 6, 4], [5, 9, 9])]).all()
def testBasic(self): rois = [([0,0,0], [10,10,10]), ([5,3,2], [11,12,13]), ([4,6,4], [5,9,9])] result = containing_rois( rois, ( [4,7,6], [5,8,8] ) ) assert ( result == [([0,0,0], [10,10,10]), ([4,6,4], [5,9,9])] ).all()
def _get_containing_block_roi(self, request_roi): # Does this roi happen to fit ENTIRELY within an existing stored block? request_roi = self._standardize_roi(*request_roi) outer_rois = containing_rois(self._block_data.keys(), request_roi) if len(outer_rois) > 0: # Standardize roi for usage as dict key block_roi = self._standardize_roi(*outer_rois[0]) return block_roi return None
def _get_containing_block_roi(self, request_roi): # Does this roi happen to fit ENTIRELY within an existing stored block? request_roi = self._standardize_roi(*request_roi) outer_rois = containing_rois(list(self._block_data.keys()), request_roi) if len(outer_rois) > 0: # Standardize roi for usage as dict key block_roi = self._standardize_roi(*outer_rois[0]) return block_roi return None
def execute(self, slot, subindex, roi, result): with self._lock: # Does this roi happen to fit ENTIRELY within an existing stored block? outer_rois = containing_rois( self._block_data.keys(), (roi.start, roi.stop) ) if len(outer_rois) > 0: # Use the first one we found block_roi = self._standardize_roi( *outer_rois[0] ) block_relative_roi = numpy.array( (roi.start, roi.stop) ) - block_roi[0] self.Output.stype.copy_data(result, self._block_data[block_roi][ roiToSlice(*block_relative_roi) ]) return # Standardize roi for usage as dict key block_roi = self._standardize_roi( roi.start, roi.stop ) # Get lock for this block (create first if necessary) with self._lock: if block_roi not in self._block_locks: self._block_locks[block_roi] = RequestLock() block_lock = self._block_locks[block_roi] # Handle identical simultaneous requests with block_lock: try: # Extra [:] here is in case we are decompressing from a chunkedarray self.Output.stype.copy_data(result, self._block_data[block_roi][:]) return except KeyError: # Not yet stored: Request it now. # We attach a special attribute to the array to allow the upstream operator # to optionally tell us not to bother caching the data. self.Input(roi.start, roi.stop).writeInto(result).block() if self.Input.meta.dontcache: # The upstream operator says not to bother caching the data. # (For example, see OpCacheFixer.) return if self.CompressionEnabled.value and numpy.dtype(result.dtype) in [numpy.dtype(numpy.uint8), numpy.dtype(numpy.uint32), numpy.dtype(numpy.float32)]: compressed_block = vigra.ChunkedArrayCompressed( result.shape, vigra.Compression.LZ4, result.dtype ) compressed_block[:] = result block_storage_data = compressed_block else: block_storage_data = result.copy() with self._lock: # Store the data. # First double-check that the block wasn't removed from the # cache while we were requesting it. # (Could have happened via propagateDirty() or eventually the arrayCacheMemoryMgr) if block_roi in self._block_locks: self._block_data[block_roi] = block_storage_data self._last_access_times[block_roi] = time.time()
def execute(self, slot, subindex, roi, result): with self._lock: # Does this roi happen to fit ENTIRELY within an existing stored block? outer_rois = containing_rois(self._block_data.keys(), (roi.start, roi.stop)) if len(outer_rois) > 0: # Use the first one we found block_roi = self._standardize_roi(*outer_rois[0]) block_relative_roi = numpy.array( (roi.start, roi.stop)) - block_roi[0] self.Output.stype.copy_data( result, self._block_data[block_roi][roiToSlice( *block_relative_roi)]) return # Standardize roi for usage as dict key block_roi = self._standardize_roi(roi.start, roi.stop) # Get lock for this block (create first if necessary) with self._lock: if block_roi not in self._block_locks: self._block_locks[block_roi] = RequestLock() block_lock = self._block_locks[block_roi] # Handle identical simultaneous requests with block_lock: try: self.Output.stype.copy_data(result, self._block_data[block_roi]) return except KeyError: # Not yet stored: Request it now. # We attach a special attribute to the array to allow the upstream operator # to optionally tell us not to bother caching the data. self.Input(roi.start, roi.stop).writeInto(result).block() if self.Input.meta.dontcache: # The upstream operator says not to bother caching the data. # (For example, see OpCacheFixer.) return block = result.copy() with self._lock: # Store the data. # First double-check that the block wasn't removed from the # cache while we were requesting it. # (Could have happened via propagateDirty() or eventually the arrayCacheMemoryMgr) if block_roi in self._block_locks: self._block_data[block_roi] = block self._last_access_times[block_roi] = time.time()
def execute(self, slot, subindex, roi, result): with self._lock: # Does this roi happen to fit ENTIRELY within an existing stored block? outer_rois = containing_rois( self._block_data.keys(), (roi.start, roi.stop) ) if len(outer_rois) > 0: # Use the first one we found block_roi = self._standardize_roi( *outer_rois[0] ) block_relative_roi = numpy.array( (roi.start, roi.stop) ) - block_roi[0] result[:] = self._block_data[block_roi][ roiToSlice(*block_relative_roi) ] return # Standardize roi for usage as dict key block_roi = self._standardize_roi( roi.start, roi.stop ) # Get lock for this block (create first if necessary) with self._lock: if block_roi not in self._block_locks: self._block_locks[block_roi] = RequestLock() block_lock = self._block_locks[block_roi] # Handle identical simultaneous requests with block_lock: try: result[:] = self._block_data[block_roi] return except KeyError: # Not yet stored: Request it now. self.Input(roi.start, roi.stop).writeInto(result).block() block = result.copy() with self._lock: # Store the data. # First double-check that the block wasn't removed from the # cache while we were requesting it. # (Could have happened via propagateDirty() or eventually the arrayCacheMemoryMgr) if block_roi in self._block_locks: self._block_data[block_roi] = block
def testEmptyInput(self): rois = [] result = containing_rois(rois, ([100, 100, 100], [200, 200, 200])) assert result.shape == (0, )
def testEmptyInput(self): rois = [] result = containing_rois( rois, ( [100,100,100], [200,200,200] ) ) assert result.shape == (0,)