Skip to content

Commit

Permalink
[build]: isort, pylint, mypy ran across files since type checking is …
Browse files Browse the repository at this point in the history
…now working in openseize, still pylint complaints but all test passing
  • Loading branch information
mscaudill committed Sep 1, 2023
1 parent 8afa05c commit 66541e4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/openseize/demos/demopaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import reprlib

# wget missing stubs & request usage here is very limited
import requests # type: ignore
import wget # type: ignore
import requests # type: ignore
import wget # type: ignore

from openseize.file_io.dialogs import message

Expand Down
12 changes: 6 additions & 6 deletions src/openseize/file_io/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def __init__(self, path: typing.Union[str, Path], mode: str, **kwargs: str
self.path = Path(path)
self.mode = mode
self.kwargs = kwargs
self._fobj = None
self.open()

def open(self):
Expand Down Expand Up @@ -255,7 +254,6 @@ def __init__(self, path: typing.Union[str, Path], mode: str) -> None:

self.path = Path(path)
self.mode = mode
self._fobj = None

def __enter__(self):
"""Return instance as target variable of this context."""
Expand All @@ -271,6 +269,8 @@ def __exit__(self, exc_type, exc_value, traceback):

if self._fobj:
self._fobj.close()
# closed file links not pickleable so reassign file obj.
self._fobj = None

@abc.abstractmethod
def write(self, *args, **kwargs) -> None:
Expand Down Expand Up @@ -348,19 +348,19 @@ def open(self, path: Path) -> typing.Tuple[typing.IO, typing.Iterable]:
"""Opens a file at path returning a file handle & row iterator."""

@abc.abstractmethod
def label(self, row: typing.Iterable) -> str:
def label(self, row) -> str:
"""Reads the annotation label at row in this file."""

@abc.abstractmethod
def time(self, row: typing.Iterable) -> float:
def time(self, row) -> float:
"""Reads annotation time in secs from recording start at row."""

@abc.abstractmethod
def duration(self, row: typing.Iterable) -> float:
def duration(self, row) -> float:
"""Returns the duration of the annotated event in secs."""

@abc.abstractmethod
def channel(self, row: typing.Iterable) -> typing.Union[int, str]:
def channel(self, row) -> typing.Union[int, str]:
"""Returns the channel this annotated event was detected on."""

def read(self,
Expand Down
16 changes: 8 additions & 8 deletions src/openseize/file_io/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@

import copy
from pathlib import Path
from typing import (cast, Dict, Generator, List, Optional, Sequence, Tuple,
Union)
from typing import cast, Dict, Generator, List, Optional, Sequence, Tuple, Union

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -379,7 +378,7 @@ def shape(self) -> Tuple[int, ...]:
return len(self.channels), max(self.header.samples)

def _decipher(self,
arr: np.ndarray,
arr: npt.NDArray,
channels: Sequence[int],
axis: int = -1,
):
Expand Down Expand Up @@ -480,7 +479,7 @@ def _records(self, a: int, b: int):
return arr

def _padstack(self,
arrs: Sequence[np.ndarray],
arrs: Sequence[npt.NDArray],
value: float,
axis: int = 0
):
Expand Down Expand Up @@ -641,9 +640,9 @@ def _write_header(self, header: Header) -> None:
self._fobj.write(bytestr)

def _records(self,
data: Union[np.ndarray, Reader],
data: Union[npt.NDArray, Reader],
channels: Sequence[int]
) -> Generator[List[np.ndarray], None, None]:
) -> Generator[List[npt.NDArray], None, None]:
"""Yields 1-D arrays, one per channel, to write to a data record.
Args:
Expand Down Expand Up @@ -697,7 +696,8 @@ def _encipher(self, arrs: Sequence):
results.append(arr)
return results

def _validate(self, header: Header, data: np.ndarray) -> None:
def _validate(self, header: Header, data: Union[npt.NDArray, Reader],
) -> None:
"""Ensures the number of samples is divisible by the number of
records.
Expand Down Expand Up @@ -732,7 +732,7 @@ def _progress(self, record_idx: int) -> None:
# pylint: disable-next=arguments-differ
def write(self,
header: Header,
data: Union[np.ndarray, Reader],
data: Union[npt.NDArray, Reader],
channels: Sequence[int],
verbose: bool = True,
) -> None:
Expand Down
35 changes: 18 additions & 17 deletions src/openseize/filtering/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
from typing import Optional, Sequence, Tuple, Union

import numpy as np
import numpy.typing as npt
import scipy.signal as sps

from openseize.core import mixins
from openseize.core import numerical as nm
from openseize.core.producer import Producer, producer
from openseize.filtering.mixins import FIRViewer, IIRViewer
from openseize.core.producer import Producer
from openseize.core.producer import producer
from openseize.filtering.mixins import FIRViewer
from openseize.filtering.mixins import IIRViewer


class IIR(abc.ABC, IIRViewer, mixins.ViewInstance):
Expand Down Expand Up @@ -53,10 +57,10 @@ class IIR(abc.ABC, IIRViewer, mixins.ViewInstance):
"""

def __init__(self,
fpass: Union[float, Sequence[float]],
fstop: Union[float, Sequence[float]],
fpass: Union[float, Sequence[float], npt.NDArray],
fstop: Union[float, Sequence[float], npt.NDArray],
gpass: float,
gstop: float,
gstop: Union[float, None],
fs: float,
fmt: str,
) -> None:
Expand Down Expand Up @@ -141,12 +145,12 @@ def _build(self):
output=self.fmt, fs=self.fs)

def __call__(self,
data: Union[Producer, np.ndarray],
data: Union[Producer, npt.NDArray],
chunksize: int,
axis: int = -1,
dephase: bool = True,
zi: Optional[np.ndarray] = None,
**kwargs) -> Union[Producer, np.ndarray]:
zi: Optional[npt.NDArray] = None,
**kwargs) -> Union[Producer, npt.NDArray]:
"""Apply this filter to an ndarray or producer of ndarrays.
Args:
Expand Down Expand Up @@ -180,19 +184,16 @@ def __call__(self,

if self.fmt == 'sos':
if dephase:
filtfunc = nm.sosfiltfilt
genfunc = partial(nm.sosfiltfilt, pro, self.coeffs, axis)
else:
filtfunc = nm.sosfilt
genfunc = partial(nm.sosfilt, pro, self.coeffs, axis, zi)

if self.fmt == 'ba':
if dephase:
filtfunc = nm.filtfilt
genfunc = partial(nm.filtfilt, pro, self.coeffs, axis)
else:
filtfunc = nm.lfilter
genfunc = partial(nm.lfilter, pro, self.coeffs, axis, zi)

# zi is ignored if filtfunc is a forward/backward filter
genfunc = partial(filtfunc, pro, self.coeffs, axis, zi=zi)

# build producer from a generating function
result = producer(genfunc, chunksize, axis, shape=pro.shape)

Expand Down Expand Up @@ -344,11 +345,11 @@ def _build(self, **kwargs):
scale=True, fs=self.fs, **kwargs)

def __call__(self,
data: Union[Producer, np.ndarray],
data: Union[Producer, npt.NDArray],
chunksize: int,
axis: int = -1,
mode: str = 'same',
**kwargs) -> Union[Producer, np.ndarray]:
**kwargs) -> Union[Producer, npt.NDArray]:
"""Apply this filter to an ndarray or producer of ndarrays.
Args:
Expand Down
1 change: 1 addition & 0 deletions src/openseize/filtering/fir.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import numpy as np
import scipy.signal as sps

from openseize.filtering.bases import FIR


Expand Down
5 changes: 3 additions & 2 deletions src/openseize/filtering/iir.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import numpy as np
import scipy.signal as sps

from openseize.filtering.bases import IIR


Expand Down Expand Up @@ -384,10 +385,10 @@ def __init__(self, fstop: float, width: float, fs:float) -> None:
"""

fpass = np.array([fstop - width / 2, fstop + width / 2])
fstop = np.array([fstop, fstop])
fstops = np.array([fstop, fstop])
self.width = width
# gpass is 3dB, gstop is determined by width
super().__init__(fpass, fstop, gpass=3, gstop=None, fs=fs, fmt='ba')
super().__init__(fpass, fstops, gpass=3, gstop=None, fs=fs, fmt='ba')

@property
def order(self):
Expand Down
Loading

0 comments on commit 66541e4

Please sign in to comment.