Skip to content

Commit

Permalink
Handle "All-NaN slice encountered" warnings for video.normalize_pixel…
Browse files Browse the repository at this point in the history
…wise
  • Loading branch information
sitic committed Oct 26, 2023
1 parent 2bec762 commit 66043ef
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions optimap/video/_filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import numpy as np
from scipy import ndimage

Expand Down Expand Up @@ -66,8 +68,10 @@ def normalize_pixelwise(video: np.ndarray, ymin=0, ymax=1):
"""
_print(f"normalizing video pixel-wise to interval [{ymin}, {ymax}] ...")
video = video.astype("float32")
min_ = np.nanmin(video, axis=0)
max_ = np.nanmax(video, axis=0)
with warnings.catch_warnings(): # ignore "All-NaN slice encountered" warnings
warnings.simplefilter("ignore", category=RuntimeWarning)
min_ = np.nanmin(video, axis=0)
max_ = np.nanmax(video, axis=0)
eps = np.finfo(np.float32).eps
video = (video - min_) / (max_ - min_ + eps) * (ymax - ymin) + ymin
return video
Expand Down

0 comments on commit 66043ef

Please sign in to comment.