Dynamic logging from cryosparc-tools

Hi there,

Is it possible to log progress dynamically, as is done when copying particle data to the cache for refinements, in an external job from the python interface?

Many thanks!

Alister

Do you mean, similar to the Event Log in the GUI, but observable and updating in a text-based terminal?

I’m asking if I, as a consumer of the cryosparc-tools Python API, can log dynamically updating progress bars to the event log in the cryoSPARC GUI.

I see the various log methods which I’ve copied below. I don’t see a way to dynamically update text in the event log. These dynamic updates are done by CS itself when copying particles to the cache and was wondering if this is possible via cryosparc-tools :slight_smile:


    def log(self, text: str, level: Literal["text", "warning", "error"] = "text"):
        """
        Append to a job's event log.

        Args:
            text (str): Text to log
            level (str, optional): Log level ("text", "warning" or "error").
                Defaults to "text".

        Returns:
            str: Created log event ID
        """
        return self.cs.cli.job_send_streamlog(  # type: ignore
            project_uid=self.project_uid, job_uid=self.uid, message=text, error=level != "text"
        )

    def log_checkpoint(self, meta: dict = {}):
        """
        Append a checkpoint to the job's event log.

        Args:
            meta (dict, optional): Additional meta information. Defaults to {}.

        Returns:
            str: Created checkpoint event ID
        """
        return self.cs.cli.job_checkpoint_streamlog(  # type: ignore
            project_uid=self.project_uid, job_uid=self.uid, meta=meta
        )

    def log_plot(
        self,
        figure: Union[str, PurePath, IO[bytes], Any],
        text: str,
        formats: Iterable[ImageFormat] = ["png", "pdf"],
        raw_data: Union[str, bytes, None] = None,
        raw_data_file: Union[str, PurePath, IO[bytes], None] = None,
        raw_data_format: Optional[TextFormat] = None,
        flags: List[str] = ["plots"],
        savefig_kw: dict = dict(bbox_inches="tight", pad_inches=0),
    ):
        """
        Add a log line with the given figure.

        ``figure`` must be one of the following

        - Path to an existing image file in PNG, JPEG, GIF, SVG or PDF format
        - A file handle-like object with the binary data of an image
        - A matplotlib plot

        If a matplotlib figure is specified, Uploads the plots in ``png`` and
        ``pdf`` formats. Override the ``formats`` argument with
        ``formats=['<format1>', '<format2>', ...]`` to save in different image
        formats.

        If a text-version of the given plot is available (e.g., in ``csv``
        format), specify ``raw_data`` with the full contents or
        ``raw_data_file`` with a path or binary file handle pointing to the
        contents. Assumes file format from extension or ``raw_data_format``.
        Defaults to ``"txt"`` if cannot be determined.

        Args:
            figure (str | Path | IO | Figure): Image file path, file handle or
                matplotlib figure instance
            text (str): Associated description for given figure
            formats (list[ImageFormat], optional): Image formats to save plot
                into. If a ``figure`` is a file handle, specify
                ``formats=['<format>']``, where ``<format>`` is a valid image
                extension such as ``png`` or ``pdf``. Assumes ``png`` if not
                specified. Defaults to ["png", "pdf"].
            raw_data (str | bytes, optional): Raw text data for associated plot,
                generally in CSV, XML or JSON format. Cannot be specified with
                ``raw_data_file``. Defaults to None.
            raw_data_file (str | Path | IO, optional): Path to raw text data.
                Cannot be specified with ``raw_data``. Defaults to None.
            raw_data_format (TextFormat, optional): Format for raw text data.
                Defaults to None.
            flags (list[str], optional): Flags to use for UI rendering.
                Generally should not be specified. Defaults to ["plots"].
            savefig_kw (dict, optional): If a matplotlib figure is specified
                optionally specify keyword arguments for the ``savefig`` method.
                Defaults to dict(bbox_inches="tight", pad_inches=0).

        Returns:
            str: Created log event ID
        """
        imgfiles = self.upload_plot(
            figure,
            name=text,
            formats=formats,
            raw_data=raw_data,
            raw_data_file=raw_data_file,
            raw_data_format=raw_data_format,
            savefig_kw=savefig_kw,
        )

        return self.cs.cli.job_send_streamlog(  # type: ignore
            project_uid=self.project_uid, job_uid=self.uid, message=text, flags=flags, imgfiles=imgfiles
        )

Thanks @AlisterBurt for your question. We made an note about your interest and consider incorporating this functionality in a future release of cryosparc-tools.