Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug where windows did not match the length of the dataset #3

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading