|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from pathlib import Path |
| 4 | +from typing import Union |
3 | 5 | import json |
4 | 6 | import logging |
5 | 7 | import os |
@@ -86,7 +88,9 @@ def __exit__(self, *exc): |
86 | 88 | self.close() |
87 | 89 |
|
88 | 90 | @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": |
90 | 94 | """Factory method to create the appropriate interpolator for a modality. |
91 | 95 |
|
92 | 96 | Reads the ``meta.yml`` file in the folder to determine the modality type |
@@ -239,12 +243,12 @@ def __init__( |
239 | 243 | def normalize_init(self): |
240 | 244 | self.mean = np.load(self.root_folder / "meta/means.npy") |
241 | 245 | 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 | + ) |
248 | 252 | self.mean = self.mean.T |
249 | 253 | self.std = self.std.T |
250 | 254 | if self.normalize_std_threshold: |
@@ -538,12 +542,12 @@ def normalize_init(self): |
538 | 542 | if self.rescale: |
539 | 543 | self.mean = self.rescale_frame(self.mean.T).T |
540 | 544 | 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 | + ) |
547 | 551 |
|
548 | 552 | def normalize_data(self, data): |
549 | 553 | return (data - self.mean) / self.std |
@@ -615,9 +619,9 @@ def interpolate( |
615 | 619 | idx = cast( |
616 | 620 | np.ndarray, np.searchsorted(self.timestamps, valid_times) - 1 |
617 | 621 | ) # 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 | + ) |
621 | 625 | data_file_idx = self._data_file_idx[idx] |
622 | 626 |
|
623 | 627 | # Go through files, load them and extract all frames |
|
0 commit comments