Skip to content

Commit

Permalink
Merge pull request #9 from Raghav67816/main
Browse files Browse the repository at this point in the history
Directory cleanup and restructure
  • Loading branch information
soulsyrup authored Apr 9, 2024
2 parents 3da6980 + 5fa7d29 commit 6792237
Show file tree
Hide file tree
Showing 18 changed files with 1,642 additions and 2,589 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

features = create_features_dict(get_features(), get_all_vals())
print(features)
num_signals = 5


# Function to generate base ECoG-like signals within the specified range
def generate_ecog_like_base_signals(length, num_signals_=num_signals):
signals = np.random.uniform(min_volt, max_volt, (num_signals_, length))
def generate_ecog_like_base_signals(length, num_signals):
signals = np.random.uniform(min_volt, max_volt, (int(num_signals), int(length)))
return signals


Expand Down Expand Up @@ -509,27 +508,3 @@ def generate_transformed_signals(signal_length, num_signals, transformation_func

return modified_signals


def plot_separate_signals(signals, title_prefix):
num_signals = signals.shape[0]
plt.figure(figsize=(15, num_signals * 5)) # Adjust figure size to make each subplot 5 times taller
plt.style.use('dark_background')
export_path = str(settings_obj.value("export_path"))

for i in range(num_signals):
ax = plt.subplot(num_signals, 1, i+1)
ax.plot(signals[i], color='red', linewidth=0.4)
ax.set_title(f'{title_prefix} Signal {i+1}', color='red')
ax.set_ylabel('Amplitude', color='red')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
ax.grid(True, which='both', color='red', linestyle='-', linewidth=0.2)
for spine in ax.spines.values():
spine.set_edgecolor('red')

plt.savefig(f"{export_path}/Transformed Signal {i+1}.png")

# Adjust the spacing between subplots
plt.subplots_adjust(hspace=0.1) # You can adjust this value as needed
plt.show()

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[General]
export_path=/mnt/Sector 16/BCI System/signals_simulator

[features]
blend_factor=0.2
causality_strength=0.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"num_signals": 5, "bit_depth": 16, "duration": 1.0, "fs": 500.0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""
The DataManager class is a data transmitter and receiver
Usage:
The files which need data to SEND & READ data simultaneously
"""
import time
from threading import Thread
from paho.mqtt.client import Client
from typing import Any


class DataManager:
def __init__(self, client_id: str, topic_sub: str | None, topic_pub: str | None,
processing_func: Any = None, close_after_first_list: bool = False):
super().__init__()

self.host = "127.0.0.1" # localhost
self.port = 3000

self.client = Client(client_id)
self.close_after_first_list = close_after_first_list

self.client.on_connect = self.on_connect
self.client.on_disconnect = self.on_disconnect
self.client.on_message = self.on_message

self.data = None

self.client.connect(self.host, self.port)

if topic_sub is None:
pass
else:
self.client.subscribe(topic_sub)

self.helper_func = processing_func
self.topic_pub = topic_pub
self.topic_sub = topic_sub

def server_loop(self):
self.client.loop_forever()

def listen(self):
if self.topic_sub is None:
raise Exception("Instance cannot subscribe to topic. Set topic_sub parameter to subscribe")
else:
thread = Thread(target=self.server_loop)
thread.start()

def set_data(self, data: Any):
self.data = data

def get_data(self):
return self.data

def publish(self, sleep_time: float):
if self.topic_pub is None:
raise Exception("Instance cannot publish data. Provide topic_pub parameter.")
thread = Thread(target=self.publish_data, args=[sleep_time])
thread.start()

def publish_data(self, sleep_time: float = 0):
data = self.get_data()
if data is None:
self.client.publish(topic=self.topic_pub, payload="NaN")
elif data is not None:
self.client.publish(topic=self.topic_pub, payload=data)
time.sleep(sleep_time)

# Callbacks
def on_connect(self, client, userdata, flags, rc):
print("connected to host")

def on_message(self, client, userdata, message):
self.helper_func(message.payload.decode("utf-8"))
if self.close_after_first_list:
self.client.unsubscribe(self.topic_sub)
else:
pass

def on_disconnect(self, client, userdata, flags, rc):
print(f"{client.client_id} disconnected from {self.host}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'signals_param.ui'
##
## Created by: Qt User Interface Compiler version 6.6.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QDialog, QDialogButtonBox,
QFormLayout, QFrame, QLabel, QLineEdit,
QSizePolicy, QVBoxLayout, QWidget)

class Ui_signalParams(object):
def setupUi(self, signalParams):
if not signalParams.objectName():
signalParams.setObjectName(u"signalParams")
signalParams.resize(400, 187)
self.verticalLayout = QVBoxLayout(signalParams)
self.verticalLayout.setObjectName(u"verticalLayout")
self.frame = QFrame(signalParams)
self.frame.setObjectName(u"frame")
self.frame.setFrameShape(QFrame.StyledPanel)
self.frame.setFrameShadow(QFrame.Raised)
self.formLayout = QFormLayout(self.frame)
self.formLayout.setObjectName(u"formLayout")
self.formLayout.setHorizontalSpacing(20)
self.num_signal_label = QLabel(self.frame)
self.num_signal_label.setObjectName(u"num_signal_label")

self.formLayout.setWidget(0, QFormLayout.LabelRole, self.num_signal_label)

self.numSignalInput = QLineEdit(self.frame)
self.numSignalInput.setObjectName(u"numSignalInput")

self.formLayout.setWidget(0, QFormLayout.FieldRole, self.numSignalInput)

self.bit_depth_label = QLabel(self.frame)
self.bit_depth_label.setObjectName(u"bit_depth_label")

self.formLayout.setWidget(1, QFormLayout.LabelRole, self.bit_depth_label)

self.bit_depth_input = QLineEdit(self.frame)
self.bit_depth_input.setObjectName(u"bit_depth_input")

self.formLayout.setWidget(1, QFormLayout.FieldRole, self.bit_depth_input)

self.fs_label = QLabel(self.frame)
self.fs_label.setObjectName(u"fs_label")

self.formLayout.setWidget(2, QFormLayout.LabelRole, self.fs_label)

self.fs_input = QLineEdit(self.frame)
self.fs_input.setObjectName(u"fs_input")

self.formLayout.setWidget(2, QFormLayout.FieldRole, self.fs_input)

self.durationLabel = QLabel(self.frame)
self.durationLabel.setObjectName(u"durationLabel")

self.formLayout.setWidget(3, QFormLayout.LabelRole, self.durationLabel)

self.durationLineEdit = QLineEdit(self.frame)
self.durationLineEdit.setObjectName(u"durationLineEdit")

self.formLayout.setWidget(3, QFormLayout.FieldRole, self.durationLineEdit)


self.verticalLayout.addWidget(self.frame)

self.buttonBox = QDialogButtonBox(signalParams)
self.buttonBox.setObjectName(u"buttonBox")
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)

self.verticalLayout.addWidget(self.buttonBox)


self.retranslateUi(signalParams)
self.buttonBox.accepted.connect(signalParams.accept)
self.buttonBox.rejected.connect(signalParams.reject)

QMetaObject.connectSlotsByName(signalParams)
# setupUi

def retranslateUi(self, signalParams):
signalParams.setWindowTitle(QCoreApplication.translate("signalParams", u"Signals Parameters", None))
self.num_signal_label.setText(QCoreApplication.translate("signalParams", u"Number Of Signals: ", None))
self.bit_depth_label.setText(QCoreApplication.translate("signalParams", u"Bit Depth:", None))
self.fs_label.setText(QCoreApplication.translate("signalParams", u"Sampling Freq: ", None))
self.durationLabel.setText(QCoreApplication.translate("signalParams", u"Duration", None))
# retranslateUi

Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>signalParams</class>
<widget class="QDialog" name="signalParams">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>187</height>
</rect>
</property>
<property name="windowTitle">
<string>Signals Parameters</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="horizontalSpacing">
<number>20</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="num_signal_label">
<property name="text">
<string>Number Of Signals: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="numSignalInput"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="bit_depth_label">
<property name="text">
<string>Bit Depth:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="bit_depth_input"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="fs_label">
<property name="text">
<string>Sampling Freq: </string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="fs_input"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="durationLabel">
<property name="text">
<string>Duration</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="durationLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>signalParams</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>signalParams</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading

0 comments on commit 6792237

Please sign in to comment.