Exemple #1
0
    def delete(self, bbox, mip=None):
        if mip is None:
            mip = self.config.mip

        if mip in self.meta.locked_mips():
            raise exceptions.ReadOnlyException(
                "MIP {} is currently write locked. If this should not be the case, run vol.meta.unlock_mip({})."
                .format(mip, mip))

        bbox = Bbox.create(bbox, self.meta.bounds(mip), bounded=True)
        realized_bbox = bbox.expand_to_chunk_size(
            self.meta.chunk_size(mip), offset=self.meta.voxel_offset(mip))
        realized_bbox = Bbox.clamp(realized_bbox, self.meta.bounds(mip))

        if bbox != realized_bbox:
            raise exceptions.AlignmentError(
                "Unable to delete non-chunk aligned bounding boxes. Requested: {}, Realized: {}"
                .format(bbox, realized_bbox))

        cloudpaths = lambda: chunknames(
            realized_bbox,
            self.meta.bounds(mip),
            self.meta.key(mip),
            self.meta.chunk_size(mip),
            protocol=self.meta.path.protocol
        )  # need to regenerate so that generator isn't used up

        CloudFiles(self.meta.cloudpath, progress=self.config.progress, secrets=self.config.secrets) \
          .delete(cloudpaths())

        if self.cache.enabled:
            CloudFiles('file://' + self.cache.path, progress=self.config.progress, secrets=self.config.secrets) \
              .delete(cloudpaths())
Exemple #2
0
    def upload(self,
               image,
               offset,
               mip,
               parallel=1,
               location=None,
               location_bbox=None,
               order='F',
               use_shared_memory=False,
               use_file=False):

        if mip in self.meta.locked_mips():
            raise exceptions.ReadOnlyException(
                "MIP {} is currently write locked. If this should not be the case, run vol.meta.unlock_mip({})."
                .format(mip, mip))

        offset = Vec(*offset)
        bbox = Bbox(offset, offset + Vec(*image.shape[:3]))

        self.check_bounded(bbox, mip)

        if self.autocrop:
            image, bbox = autocropfn(self.meta, image, bbox, mip)
            offset = bbox.minpt

        if location is None:
            location = self.shared_memory_id

        if self.is_sharded(mip):
            (filename, shard) = self.make_shard(image, bbox, mip)
            basepath = self.meta.join(self.meta.cloudpath, self.meta.key(mip))
            CloudFiles(basepath, progress=self.config.progress).put(
                filename,
                shard,
                compress=self.config.compress,
                cache_control=self.config.cdn_cache)
            return

        return tx.upload(
            self.meta,
            self.cache,
            image,
            offset,
            mip,
            compress=self.config.compress,
            compress_level=self.config.compress_level,
            cdn_cache=self.config.cdn_cache,
            parallel=parallel,
            progress=self.config.progress,
            location=location,
            location_bbox=location_bbox,
            location_order=order,
            use_shared_memory=use_shared_memory,
            use_file=use_file,
            delete_black_uploads=self.delete_black_uploads,
            background_color=self.background_color,
            non_aligned_writes=self.non_aligned_writes,
            green=self.config.green,
            fill_missing=self.fill_missing,  # applies only to unaligned writes
        )