Skip to content

Commit 3f23bdc

Browse files
committed
Update Interpolator.create type hint to accept Path objects
1 parent a52aecc commit 3f23bdc

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

experanto/interpolators.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
from typing import Union
35
import json
46
import logging
57
import os
@@ -86,7 +88,9 @@ def __exit__(self, *exc):
8688
self.close()
8789

8890
@staticmethod
89-
def create(root_folder: str, cache_data: bool = False, **kwargs) -> "Interpolator":
91+
def create(
92+
root_folder: Union[str, Path], cache_data: bool = False, **kwargs
93+
) -> "Interpolator":
9094
"""Factory method to create the appropriate interpolator for a modality.
9195
9296
Reads the ``meta.yml`` file in the folder to determine the modality type
@@ -239,12 +243,12 @@ def __init__(
239243
def normalize_init(self):
240244
self.mean = np.load(self.root_folder / "meta/means.npy")
241245
self.std = np.load(self.root_folder / "meta/stds.npy")
242-
assert (
243-
self.mean.shape[0] == self.n_signals
244-
), f"mean shape does not match: {self.mean.shape} vs {self._data.shape}"
245-
assert (
246-
self.std.shape[0] == self.n_signals
247-
), f"std shape does not match: {self.std.shape} vs {self._data.shape}"
246+
assert self.mean.shape[0] == self.n_signals, (
247+
f"mean shape does not match: {self.mean.shape} vs {self._data.shape}"
248+
)
249+
assert self.std.shape[0] == self.n_signals, (
250+
f"std shape does not match: {self.std.shape} vs {self._data.shape}"
251+
)
248252
self.mean = self.mean.T
249253
self.std = self.std.T
250254
if self.normalize_std_threshold:
@@ -538,12 +542,12 @@ def normalize_init(self):
538542
if self.rescale:
539543
self.mean = self.rescale_frame(self.mean.T).T
540544
self.std = self.rescale_frame(self.std.T).T
541-
assert (
542-
self.mean.shape == self._image_size
543-
), f"mean size is different: {self.mean.shape} vs {self._image_size}"
544-
assert (
545-
self.std.shape == self._image_size
546-
), f"std size is different: {self.std.shape} vs {self._image_size}"
545+
assert self.mean.shape == self._image_size, (
546+
f"mean size is different: {self.mean.shape} vs {self._image_size}"
547+
)
548+
assert self.std.shape == self._image_size, (
549+
f"std size is different: {self.std.shape} vs {self._image_size}"
550+
)
547551

548552
def normalize_data(self, data):
549553
return (data - self.mean) / self.std
@@ -615,9 +619,9 @@ def interpolate(
615619
idx = cast(
616620
np.ndarray, np.searchsorted(self.timestamps, valid_times) - 1
617621
) # convert times to frame indices
618-
assert np.all(
619-
(idx >= 0) & (idx < len(self.timestamps))
620-
), "All times must be within the valid range"
622+
assert np.all((idx >= 0) & (idx < len(self.timestamps))), (
623+
"All times must be within the valid range"
624+
)
621625
data_file_idx = self._data_file_idx[idx]
622626

623627
# Go through files, load them and extract all frames

0 commit comments

Comments
 (0)