Skip to content

Commit

Permalink
Use warnings module
Browse files Browse the repository at this point in the history
  • Loading branch information
sitic committed Oct 26, 2023
1 parent a083fea commit eb64693
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion optimap/motion/_flowestimator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Union
import warnings

import cv2
import numpy as np
Expand Down Expand Up @@ -129,7 +130,7 @@ def _check_and_convert(imgs: Union[np.ndarray, list], method: str):
if isinstance(imgs, list):
imgs = np.array(imgs)
if imgs.min() < 0 or imgs.max() > 1:
print(
warnings.warn(
"WARNING: image values are not in range [0,1], which may lead to unexpected motion tracking"
)
return (imgs * 255).astype(np.uint8)
Expand Down
3 changes: 2 additions & 1 deletion optimap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import functools
import urllib.parse
import warnings

import matplotlib as mpl
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -168,7 +169,7 @@ def retrieve_example_data(name, directory="./example_data", silent=False):
"""
known_hash = FILE_HASHES.get(name, None)
if known_hash is None:
print(f"WARNING: Example file '{name}' is not known. Attempting to download it anyway.")
warnings.warn(f"WARNING: Example file '{name}' is not known. Attempting to download it anyway.", UserWarning)
if silent:
silent = pooch.get_logger().level
pooch.get_logger().setLevel("WARNING")
Expand Down
7 changes: 4 additions & 3 deletions optimap/video/_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime
from pathlib import Path
from typing import BinaryIO
import warnings

import numpy as np

Expand Down Expand Up @@ -39,7 +40,7 @@ def load_video(self, start_frame=0, frames=None, step=1, use_mmap=False):
if frames is not None:
nframes = frames
if nframes > self._Nt - start_frame:
print(f"Warning: requested {nframes} frames, but only {self._Nt - start_frame} frames available. Loading all available frames.")
warnings.warn(f"requested {nframes} frames, but only {self._Nt - start_frame} frames available. Loading all available frames.", UserWarning)
nframes = self._Nt - start_frame
else:
nframes = self._Nt - start_frame
Expand Down Expand Up @@ -182,7 +183,7 @@ def load_video(self, start_frame=0, frames=None, step=1):
if frames is not None:
end_frame = start_frame + frames
if end_frame > self._Nt:
print(f"Warning: requested {frames} frames, but only {self._Nt - start_frame} frames available. Loading all available frames.")
warnings.warn(f"requested {frames} frames, but only {self._Nt - start_frame} frames available. Loading all available frames.", UserWarning)
end_frame = None
else:
end_frame = None
Expand Down Expand Up @@ -281,7 +282,7 @@ def load_video(self, start_frame=0, frames=None, step=1):
if frames is not None:
end_frame = start_frame + frames
if end_frame > self._Nt:
print(f"Warning: requested {frames} frames, but only {self._Nt - start_frame} frames available. Loading all available frames.")
warnings.warn(f"requested {frames} frames, but only {self._Nt - start_frame} frames available. Loading all available frames.", UserWarning)
end_frame = None
else:
end_frame = None
Expand Down
4 changes: 2 additions & 2 deletions optimap/video/_load.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from pathlib import Path
import warnings

import numpy as np
import skimage.io as sio
Expand Down Expand Up @@ -110,8 +111,7 @@ def load_MATLAB(filename, fieldname=None, start_frame=0, end_frame=None, step=1)
if len(fields) == 0:
raise ValueError(f"No fields found in file '{filename}'")
elif len(fields) > 1:
print(f"WARNING: Multiple fields found in file '{filename}', loading first field '{fields[0]}'"
)
warnings.warn(f"Multiple fields found in file '{filename}', loading first field '{fields[0]}'", UserWarning)
fieldname = fields[0]
video = data[fieldname]
return video[start_frame:end_frame:step]
Expand Down

0 comments on commit eb64693

Please sign in to comment.