Skip to content

Commit

Permalink
Added a fix to a bug where windows did not match the length of the da…
Browse files Browse the repository at this point in the history
…taset, now shows a warning too
  • Loading branch information
DetectiveKiwi committed Nov 6, 2023
1 parent 9515beb commit ad42dec
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions nsdmd/nsdmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
from nsdmd import optdmd
from nsdmd import utils
from scipy.stats import circmean
import warnings

def custom_formatwarning(msg, *args, **kwargs):
# ignore everything except the message
return str(msg) + '\n'

warnings.formatwarning = custom_formatwarning

class NSDMD:
"""
Expand Down Expand Up @@ -470,9 +477,20 @@ def _opt_dmd_win(self, x, t, guess=None):
phis : complex spatial modes with shape (number of windows, rank, number of channels)
windows : exact windows used, for testing purposes
"""
windows = np.array(
[np.arange(i, i + self.w_len) for i in np.arange(0, x.shape[-1] - self.w_len + 1, self.stride)]
)
# windows = np.array(
# [np.arange(i, i + self.w_len) for i in np.arange(0, x.shape[-1] - self.w_len + 1, self.stride)]
# )
windows = [np.arange(i, i + self.w_len) for i in np.arange(0, x.shape[-1] - self.w_len + 1, self.stride)]
if windows[-1][-1]!=x.shape[-1]-1:
warnings.warn(
'\nUserWarning:\
\nWindow length plus stride does not cover time region of interest,\
\nAdding extra window to the end that arbitrarily overlaps previous windows...\
\nRecommended to adjust the stride or time range such that the final window naturally ends at the end of the dataset\n'
)
windows.append(np.arange(x.shape[-1]-self.w_len, x.shape[-1]))
windows = np.array(windows)

freqs = np.empty((len(windows), self.rank))
phis = np.empty((len(windows), self.rank, len(x)), dtype=complex)

Expand Down

0 comments on commit ad42dec

Please sign in to comment.