Skip to content

Common

pydatalab.blocks.common

NotSupportedBlock (DataBlock)

Source code in pydatalab/blocks/common.py
class NotSupportedBlock(DataBlock):
    blocktype = "notsupported"
    description = "Block not supported"
    _supports_collections = True

blocktype: str

description: str

CommentBlock (DataBlock)

Source code in pydatalab/blocks/common.py
class CommentBlock(DataBlock):
    blocktype = "comment"
    description = "Comment"
    _supports_collections = True

blocktype: str

description: str

MediaBlock (DataBlock)

Source code in pydatalab/blocks/common.py
class MediaBlock(DataBlock):
    blocktype = "media"
    description = "Media"
    accepted_file_extensions = (".png", ".jpeg", ".jpg", ".tif", ".tiff", ".mp4", ".mov", ".webm")
    _supports_collections = False

    @property
    def plot_functions(self):
        return (self.encode_tiff,)

    def encode_tiff(self):
        if "file_id" not in self.data:
            LOGGER.warning("ImageBlock.encode_tiff(): No file set in the DataBlock")
            return
        if "b64_encoded_image" not in self.data:
            self.data["b64_encoded_image"] = {}
        file_info = get_file_info_by_id(self.data["file_id"], update_if_live=True)
        if file_info["name"].endswith(".tif") or file_info["name"].endswith(".tiff"):
            im = Image.open(file_info["location"])
            LOGGER.warning("Making base64 encoding of tif")
            with io.BytesIO() as f:
                im.save(f, format="PNG")
                f.seek(0)
                self.data["b64_encoded_image"][self.data["file_id"]] = base64.b64encode(
                    f.getvalue()
                ).decode()

accepted_file_extensions: Sequence[str]

blocktype: str

description: str

plot_functions property readonly

encode_tiff(self)

Source code in pydatalab/blocks/common.py
def encode_tiff(self):
    if "file_id" not in self.data:
        LOGGER.warning("ImageBlock.encode_tiff(): No file set in the DataBlock")
        return
    if "b64_encoded_image" not in self.data:
        self.data["b64_encoded_image"] = {}
    file_info = get_file_info_by_id(self.data["file_id"], update_if_live=True)
    if file_info["name"].endswith(".tif") or file_info["name"].endswith(".tiff"):
        im = Image.open(file_info["location"])
        LOGGER.warning("Making base64 encoding of tif")
        with io.BytesIO() as f:
            im.save(f, format="PNG")
            f.seek(0)
            self.data["b64_encoded_image"][self.data["file_id"]] = base64.b64encode(
                f.getvalue()
            ).decode()