-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/pattern change detection #17
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
base: development
Are you sure you want to change the base?
Changes from all commits
7001639
7f236a6
8135a9d
7c197bf
59000b8
1062ef7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes here are not needed. Please remove them |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,10 @@ def ftio_dft( | |
| - analysis_figures (AnalysisFigures): Data and plot figures. | ||
| - share (SharedSignalData): Contains shared information, including sampled bandwidth and total bytes. | ||
| """ | ||
| # Suppress numpy warnings for empty array operations | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not want to filter warnings, rather they should be visibile and fixed |
||
| import warnings | ||
| warnings.filterwarnings('ignore', category=RuntimeWarning, module='numpy') | ||
|
|
||
| #! Default values for variables | ||
| share = SharedSignalData() | ||
| prediction = Prediction(args.transformation) | ||
|
|
@@ -75,42 +79,66 @@ def ftio_dft( | |
| n = len(b_sampled) | ||
| frequencies = args.freq * np.arange(0, n) / n | ||
| X = dft(b_sampled) | ||
| X = X * np.exp( | ||
| -2j * np.pi * frequencies * time_stamps[0] | ||
| ) # Correct phase offset due to start time t0 | ||
|
|
||
| # Safety check for empty time_stamps array | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for safety checks here |
||
| if len(time_stamps) > 0: | ||
| X = X * np.exp( | ||
| -2j * np.pi * frequencies * time_stamps[0] | ||
| ) # Correct phase offset due to start time t0 | ||
| # If time_stamps is empty, skip phase correction | ||
|
|
||
| amp = abs(X) | ||
| phi = np.arctan2(X.imag, X.real) | ||
| conf = np.zeros(len(amp)) | ||
| # welch(bandwidth,freq) | ||
|
|
||
| #! Find the dominant frequency | ||
| (dominant_index, conf[1 : int(n / 2) + 1], outlier_text) = outlier_detection( | ||
| amp, frequencies, args | ||
| ) | ||
| # Safety check for empty arrays | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed. Please remove it. |
||
| if n > 0: | ||
| (dominant_index, conf[1 : int(n / 2) + 1], outlier_text) = outlier_detection( | ||
| amp, frequencies, args | ||
| ) | ||
|
|
||
| # Ignore DC offset | ||
| conf[0] = np.inf | ||
| if n % 2 == 0: | ||
| conf[int(n / 2) + 1 :] = np.flip(conf[1 : int(n / 2)]) | ||
| # Ignore DC offset | ||
| conf[0] = np.inf | ||
| if n % 2 == 0: | ||
| conf[int(n / 2) + 1 :] = np.flip(conf[1 : int(n / 2)]) | ||
| else: | ||
| conf[int(n / 2) + 1 :] = np.flip(conf[1 : int(n / 2) + 1]) | ||
| else: | ||
| conf[int(n / 2) + 1 :] = np.flip(conf[1 : int(n / 2) + 1]) | ||
| # Handle empty data case | ||
| dominant_index = np.array([]) | ||
| outlier_text = "No data available for outlier detection" | ||
|
|
||
| #! Assign data | ||
| prediction.dominant_freq = frequencies[dominant_index] | ||
| prediction.conf = conf[dominant_index] | ||
| if args.periodicity_detection is not None: | ||
| prediction.periodicity = conf[dominant_index] | ||
| prediction.amp = amp[dominant_index] | ||
| prediction.phi = phi[dominant_index] | ||
| prediction.t_start = time_stamps[0] | ||
| prediction.t_end = time_stamps[-1] | ||
| if n > 0 and len(dominant_index) > 0: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes below are not needed. Please remove them. Especially, as time does not always start at 0. |
||
| prediction.dominant_freq = frequencies[dominant_index] | ||
| prediction.conf = conf[dominant_index] | ||
| if args.periodicity_detection is not None: | ||
| prediction.periodicity = conf[dominant_index] | ||
| prediction.amp = amp[dominant_index] | ||
| prediction.phi = phi[dominant_index] | ||
| else: | ||
| # Handle empty data case | ||
| prediction.dominant_freq = np.array([]) | ||
| prediction.conf = np.array([]) | ||
| prediction.amp = np.array([]) | ||
| prediction.phi = np.array([]) | ||
|
|
||
| # Safety check for empty time_stamps | ||
| if len(time_stamps) > 0: | ||
| prediction.t_start = time_stamps[0] | ||
| prediction.t_end = time_stamps[-1] | ||
| else: | ||
| prediction.t_start = 0.0 | ||
| prediction.t_end = 0.0 | ||
| prediction.freq = args.freq | ||
| prediction.ranks = ranks | ||
| prediction.total_bytes = total_bytes | ||
| prediction.n_samples = n | ||
|
|
||
| #! Save up to n_freq from the top candidates | ||
| if args.n_freq > 0: | ||
| if args.n_freq > 0 and n > 0: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed. Please remove it. |
||
| arr = amp[0 : int(np.ceil(n / 2))] | ||
| top_candidates = np.argsort(-arr) # from max to min | ||
| n_freq = int(min(len(arr), args.n_freq)) | ||
|
|
@@ -124,7 +152,11 @@ def ftio_dft( | |
|
|
||
| periodicity_score = new_periodicity_scores(amp, b_sampled, prediction, args) | ||
|
|
||
| t_sampled = time_stamps[0] + np.arange(0, n) * 1 / args.freq | ||
| # Safety check for empty time_stamps | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed. please remvove it. |
||
| if len(time_stamps) > 0 and args.freq > 0: | ||
| t_sampled = time_stamps[0] + np.arange(0, n) * 1 / args.freq | ||
| else: | ||
| t_sampled = np.arange(0, n) * (1 / args.freq if args.freq > 0 else 1.0) | ||
| #! Fourier fit if set | ||
| if args.fourier_fit: | ||
| fourier_fit(args, prediction, analysis_figures, b_sampled, t_sampled) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes here are not needed. Please remove them. |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes here are not needed |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The algorithm is too general. "online_adaptation" would be a better fit |
Uh oh!
There was an error while loading. Please reload this page.