-
Notifications
You must be signed in to change notification settings - Fork 1
Clustering and mode tracking #22
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
Merged
prasadtalasila
merged 8 commits into
INTO-CPS-Association:main
from
au650680:clustering_and_mode_tracking
Nov 9, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0cd32ae
Added clustering and mode tracking
1f711db
Added clustering and mode tracking
d34018c
Merge branch 'main' of https://github.com/au650680/example-shm
a487753
Merge branch 'main' into clustering_and_mode_tracking
62bddcd
Edits to last pull
aedc878
Bug fix and small change to plot_cluster
802139e
Small changes
9d145fd
Small changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,53 @@ | ||
| { | ||
| "MQTT": { | ||
| "host": "test.mosquitto.org", | ||
| "port": 1883, | ||
| "host": "", | ||
| "port": , | ||
| "userId": "", | ||
| "password": "", | ||
| "ClientID": "ReplaySubscriber", | ||
| "ClientID": "NOT_NEEDED", | ||
| "QoS": 1, | ||
| "TopicsToSubscribe": [ | ||
| "cpsens/recorded/1/data", | ||
| "cpsens/recorded/1/metadata", | ||
| "cpsens/recorded/2/data", | ||
| "cpsens/recorded/+/data" | ||
| "cpsens/d8-3a-dd-37-d2-7e/3050-A-060_sn_106209/1/acc/raw/data", | ||
| "cpsens/d8-3a-dd-37-d2-7e/3050-A-060_sn_106209/1/acc/raw/metadata", | ||
| "cpsens/d8-3a-dd-37-d2-7e/3050-A-060_sn_106209/2/acc/raw/data", | ||
| "cpsens/d8-3a-dd-37-d2-7e/3050-A-060_sn_106209/3/acc/raw/data", | ||
| "cpsens/d8-3a-dd-37-d2-7e/3050-A-060_sn_106209/4/acc/raw/data" | ||
| ] | ||
| }, | ||
|
|
||
| "sysID": { | ||
| "host": "", | ||
| "port": 1883, | ||
| "port": , | ||
| "userId": "", | ||
| "password": "", | ||
| "ClientID": "sub.232.sds.213s", | ||
| "QoS": 1, | ||
| "TopicsToSubscribe": ["cpsens/d8-3a-dd-f5-92-48/cpsns_Simulator/1_2/oma_results"] | ||
| "ClientID": "NOT_NEEDED", | ||
| "QoS": 2, | ||
| "TopicsToSubscribe": ["cpsens/d8-3a-dd-37-d2-7e/3050-A-060_sn_106209/1/acc/sysid/data"] | ||
| }, | ||
|
|
||
| "mode_cluster": { | ||
| "host": "", | ||
| "port": , | ||
| "userId": "", | ||
| "password": "", | ||
| "ClientID": "NOT_NEEDED", | ||
| "QoS": 2, | ||
| "TopicsToSubscribe": ["cpsens/d8-3a-dd-37-d2-7e/3050-A-060_sn_106209/1/acc/mode_cluster/data"] | ||
| }, | ||
|
|
||
| "model_update": { | ||
| "host": "", | ||
| "port": , | ||
| "userId": "", | ||
| "password": "", | ||
| "ClientID": "NOT_NEEDED", | ||
| "QoS": 2, | ||
| "TopicsToSubscribe": ["cpsens/d8-3a-dd-37-d2-7e/3050-A-060_sn_106209/1/acc/model_update/data"] | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import sys | ||
| import time | ||
| import matplotlib.pyplot as plt | ||
| from data.comm.mqtt import load_config | ||
| from data.accel.hbk.aligner import Aligner | ||
| from methods import sysid as sysID | ||
| from methods import mode_clustering as MC | ||
| from methods.constants import PARAMS | ||
| from functions.plot_clusters import plot_clusters | ||
|
|
||
| # pylint: disable=R0914 | ||
| def run_mode_clustering_with_local_sysid(config_path): | ||
| number_of_minutes = 1 | ||
| config = load_config(config_path) | ||
| mqtt_config = config["MQTT"] | ||
|
|
||
| # Setting up the client and extracting Fs | ||
| data_client, fs = sysID.setup_client(mqtt_config) | ||
|
|
||
| # Setting up the aligner | ||
| data_topic_indexes = [0, 2, 3, 4] | ||
| selected_topics = [mqtt_config["TopicsToSubscribe"][i] for i in data_topic_indexes] | ||
| aligner = Aligner(data_client, topics=selected_topics) | ||
|
|
||
| aligner_time = None | ||
| t1 = time.time() | ||
| while aligner_time is None: | ||
| time.sleep(0.1) | ||
| t2 = time.time() | ||
| t_text = f"Waiting for data for {round(t2-t1,1)} seconds" | ||
| print(t_text,end="\r") | ||
| sysid_output, aligner_time = sysID.get_sysid_results(number_of_minutes, aligner, fs) | ||
| data_client.disconnect() | ||
|
|
||
| # Mode Tracks | ||
| dictionary_of_clusters, median_frequencies = MC.cluster_sysid( | ||
| sysid_output,PARAMS) | ||
|
|
||
| # Print frequencies | ||
| print("\nMedian frequencies:", median_frequencies) | ||
|
|
||
| fig_ax = plot_clusters(dictionary_of_clusters, sysid_output, PARAMS, fig_ax = None) | ||
| plt.show(block=True) | ||
| sys.stdout.flush() | ||
|
|
||
| def run_mode_clustering_with_remote_sysid(config_path): | ||
| sysid_output, dictionary_of_clusters, meadian_frequencies = MC.subscribe_and_cluster(config_path,PARAMS) | ||
| fig_ax = plot_clusters(dictionary_of_clusters, sysid_output, PARAMS, fig_ax = None) | ||
| plt.show(block=True) | ||
| sys.stdout.flush() | ||
|
|
||
| def run_live_mode_clustering_with_remote_sysid(config_path): | ||
| MC.live_mode_clustering(config_path,topic_index=0,plot=[1,1]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import sys | ||
| import time | ||
| import matplotlib.pyplot as plt | ||
| from data.comm.mqtt import load_config | ||
| from data.accel.hbk.aligner import Aligner | ||
| from methods import sysid as sysID | ||
| from methods import mode_clustering as MC | ||
| from methods import mode_tracking as MT | ||
| from methods.constants import PARAMS | ||
| from functions.plot_mode_tracking import plot_tracked_modes | ||
|
|
||
| # pylint: disable=R0914 | ||
| def run_mode_tracking_with_local_sysid(config_path): | ||
| number_of_minutes = 1 | ||
| config = load_config(config_path) | ||
| mqtt_config = config["MQTT"] | ||
|
|
||
| # Setting up the client and extracting Fs | ||
| data_client, fs = sysID.setup_client(mqtt_config) | ||
|
|
||
| # Setting up the aligner | ||
| data_topic_indexes = [0, 2, 3, 4] | ||
| selected_topics = [mqtt_config["TopicsToSubscribe"][i] for i in data_topic_indexes] | ||
| aligner = Aligner(data_client, topics=selected_topics) | ||
|
|
||
| aligner_time = None | ||
| t1 = time.time() | ||
| while aligner_time is None: | ||
| time.sleep(0.1) | ||
| t2 = time.time() | ||
| t_text = f"Waiting for data for {round(t2-t1,1)} seconds" | ||
| print(t_text,end="\r") | ||
| sysid_output, aligner_time = sysID.get_sysid_results(number_of_minutes, aligner, fs) | ||
| data_client.disconnect() | ||
|
|
||
| # Mode Tracks | ||
| dictionary_of_clusters, median_frequencies = MC.cluster_sysid( | ||
| sysid_output,PARAMS) | ||
|
|
||
| # Print frequencies | ||
| print("\nMedian frequencies:", median_frequencies) | ||
|
|
||
| tracked_clusters = {} | ||
| tracked_clusters = MT.track_clusters(dictionary_of_clusters,tracked_clusters,PARAMS) | ||
|
|
||
| fig_ax = plot_tracked_modes(tracked_clusters, PARAMS, fig_ax = None, x_length = None) | ||
| plt.show(block=True) | ||
| sys.stdout.flush() | ||
|
|
||
| def run_mode_tracking_with_remote_sysid(config_path): | ||
| sysid_output, clusters, tracked_clusters = MT.subscribe_and_track_clusters(config_path) | ||
| fig_ax = plot_tracked_modes(tracked_clusters, PARAMS, fig_ax = None, x_length = None) | ||
| plt.show(block=True) | ||
| sys.stdout.flush() | ||
|
|
||
| def run_live_mode_tracking_with_remote_sysid(config_path): | ||
| MT.live_mode_tracking(config_path,plot=[1,1]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice