def __get_spec(self, array_key): info = self.__get_info(array_key) roi_min = info['Extended']['MinPoint'] if roi_min is not None: roi_min = Coordinate(roi_min[::-1]) roi_max = info['Extended']['MaxPoint'] if roi_max is not None: roi_max = Coordinate(roi_max[::-1]) data_roi = Roi(offset=roi_min, shape=(roi_max - roi_min)) data_dims = Coordinate(data_roi.get_shape()) if self.ndims is None: self.ndims = len(data_dims) else: assert self.ndims == len(data_dims) if array_key in self.array_specs: spec = self.array_specs[array_key].copy() else: spec = ArraySpec() if spec.voxel_size is None: spec.voxel_size = Coordinate(info['Extended']['VoxelSize']) if spec.roi is None: spec.roi = data_roi * spec.voxel_size data_dtype = dvision.DVIDDataInstance(self.hostname, self.port, self.uuid, self.datasets[array_key]).dtype if spec.dtype is not None: assert spec.dtype == data_dtype, ( "dtype %s provided in array_specs for %s, " "but differs from instance %s dtype %s" % (self.array_specs[array_key].dtype, array_key, self.datasets[array_key], data_dtype)) else: spec.dtype = data_dtype if spec.interpolatable is None: spec.interpolatable = spec.dtype in [ np.float, np.float32, np.float64, np.float128, np.uint8 # assuming this is not used for labels ] logger.warning( "WARNING: You didn't set 'interpolatable' for %s. " "Based on the dtype %s, it has been set to %s. " "This might not be what you want.", array_key, spec.dtype, spec.interpolatable) return spec
def __read_gt(self, roi): slices = roi.get_bounding_box() data_instance = dvision.DVIDDataInstance(self.hostname, self.port, self.uuid, self.gt_array_name) try: return data_instance[slices] except Exception as e: print(e) msg = "Failure reading GT at slices {} with {}".format(slices, repr(self)) raise DvidSourceReadException(msg)
def __read_array(self, instance, roi): data_instance = dvision.DVIDDataInstance( self.hostname, self.port, self.uuid, instance) return data_instance[roi.get_bounding_box()]
def __get_roi(self, array_name): data_instance = dvision.DVIDDataInstance(self.hostname, self.port, self.uuid, array_name) info = data_instance.info roi_min = info['Extended']['MinPoint'] if roi_min is not None: roi_min = Coordinate(roi_min[::-1]) roi_max = info['Extended']['MaxPoint'] if roi_max is not None: roi_max = Coordinate(roi_max[::-1]) return Roi(offset=roi_min, shape=roi_max - roi_min)
def __get_info(self, array_key): if array_key in self.datasets: data = dvision.DVIDDataInstance(self.hostname, self.port, self.uuid, self.datasets[array_key]) elif array_key in self.masks: data = dvision.DVIDRegionOfInterest(self.hostname, self.port, self.uuid, self.masks[array_key]) else: assert False, ("Encountered a request that is neither a volume " "nor a mask.") return data.info