Skip to content

Commit

Permalink
Annotation as NewType dtcwt.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cako authored Mar 19, 2024
1 parent ae77c86 commit b8e35b2
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions pylops/signalprocessing/dtcwt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__all__ = ["DTCWT"]

from typing import Any, Union
from typing import Any, NewType, Union

import numpy as np

Expand All @@ -19,6 +19,8 @@
else:
pyramid_type = Any

PyramidType = NewType("PyramidType", pyramid_type)


class DTCWT(LinearOperator):
r"""Dual-Tree Complex Wavelet Transform
Expand Down Expand Up @@ -146,16 +148,12 @@ def _nd_to_2d(self, arr_nd: NDArray) -> NDArray:
arr_2d = arr_nd.reshape(self.dims[self.axis], -1).squeeze()
return arr_2d

def _coeff_to_array(
self, pyr: pyramid_type
) -> NDArray: # cannot use dtcwt types as it may not be installed
def _coeff_to_array(self, pyr: PyramidType) -> NDArray:
highpass_coeffs = np.vstack([h for h in pyr.highpasses])
coeffs = np.concatenate((highpass_coeffs, pyr.lowpass), axis=0)
return coeffs

def _array_to_coeff(
self, X: NDArray
) -> pyramid_type: # cannot use dtcwt types as it may not be installed
def _array_to_coeff(self, X: NDArray) -> PyramidType:
lowpass = (X[-self.lowpass_size :].real).reshape((-1, self.otherdims))
_ptr = 0
highpasses = ()
Expand All @@ -166,9 +164,7 @@ def _array_to_coeff(
highpasses += (_h,)
return dtcwt.Pyramid(lowpass, highpasses)

def get_pyramid(
self, x: NDArray
) -> pyramid_type: # cannot use dtcwt types as it may not be installed
def get_pyramid(self, x: NDArray) -> PyramidType:
"""Return Pyramid object from flat real-valued array"""
return self._array_to_coeff(x[0] + 1j * x[1])

Expand Down

0 comments on commit b8e35b2

Please sign in to comment.