Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalkolar committed Jun 11, 2023
2 parents 0ab60d7 + 1ee2a66 commit f00949f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
48 changes: 43 additions & 5 deletions mesmerize_core/arrays/_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ def __init__(
self, path: Union[Path, str],
min_max: Tuple[int, int] = None,
as_grayscale: bool = False,
rgb_weights: Tuple[float, float, float] = (0.299, 0.587, 0.114)
rgb_weights: Tuple[float, float, float] = (0.299, 0.587, 0.114),
**kwargs,
):
"""
LazyVideo reader, basically just a wrapper for ``decord.VideoReader``.
Should support opening anything that decord can open.
**Requires ``decord`` to be installed**: https://github.com/dmlc/decord
**Important:** requires ``decord`` to be installed: https://github.com/dmlc/decord
Parameters
----------
Expand All @@ -41,11 +42,45 @@ def __init__(
rgb_weights: Tuple[float, float, float], optional
(r, g, b) weights used for grayscale conversion if ``as_graycale`` is ``True``.
default is (0.299, 0.587, 0.114)
kwargs
passed to ``decord.VideoReader``
Examples
--------
Lazy loading with CPU
.. code-block:: python
from mesmerize_core.arrays import LazyVideo
vid = LazyVideo("path/to/video.mp4")
# use fpl to visualize
import fastplotlib as fpl
iw = fpl.ImageWidget(vid)
iw.show()
Lazy loading with GPU, decord must be compiled with CUDA options to use this
.. code-block:: python
from decord import gpu
from mesmerize_core.arrays import LazyVideo
gpu_context = gpu(0)
vid = LazyVideo("path/to/video.mp4", ctx=gpu_context)
"""
if not HAS_DECORD:
raise ImportError("You must install `decord` to use LazyVideo")

self._video_reader = VideoReader(str(path))
self._video_reader = VideoReader(str(path), **kwargs)

try:
frame0 = self._video_reader[10].asnumpy()
Expand All @@ -63,8 +98,11 @@ def __init__(

self._dtype = frame0.dtype

self._min = frame0.min()
self._max = frame0.max()
if min_max is not None:
self._min, self._max = min_max
else:
self._min = frame0.min()
self._max = frame0.max()

self.as_grayscale = as_grayscale
self.rgb_weights = rgb_weights
Expand Down
12 changes: 11 additions & 1 deletion mesmerize_core/caiman_extensions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,18 @@ def remove_item(self, index: Union[int, str, UUID], remove_data: bool = True, sa
-------
"""
if self._df.iloc[index]["outputs"] is not None:
if self._df.iloc[index]["outputs"]["success"] is True:
# if success, don't skip checks
skip_checks = False
else:
# if failed item, skip checks, allow removal since it cannot have children
skip_checks = True
else:
# if not run, skip checks, it cannot have children
skip_checks = True

if self._df.iloc[index]["algo"] == "mcorr":
if self._df.iloc[index]["algo"] == "mcorr" and not skip_checks:
if safe_removal:
children = self.get_children(index)
if len(children) > 0:
Expand Down

0 comments on commit f00949f

Please sign in to comment.