Skip to content

Commit

Permalink
fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
toni-neurosc committed Sep 20, 2024
1 parent ffbac39 commit 998dbef
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
52 changes: 27 additions & 25 deletions py_neuromodulation/gui/backend/app_pynm.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import py_neuromodulation as nm
from py_neuromodulation import nm_mnelsl_stream, nm_define_nmchannels, nm_IO
import logging
import numpy as np
import pandas as pd
from multiprocessing import Process, Queue

from py_neuromodulation.stream import Stream, NMSettings
from py_neuromodulation.utils import set_channels
from py_neuromodulation.utils.io import read_mne_data


class PyNMState:
def __init__(
self,
Expand All @@ -13,13 +15,13 @@ def __init__(
self.logger = logging.getLogger("uvicorn.error")

if default_init:
self.stream: nm.Stream = nm.Stream(
sfreq=1500, data=np.random.random([1, 1])
)
self.stream: Stream = Stream(sfreq=1500, data=np.random.random([1, 1]))
# TODO: we currently can pass the sampling_rate_features to both the stream and the settings?
self.settings: nm.NMSettings = nm.NMSettings(sampling_rate_features=17)
self.settings: NMSettings = NMSettings(sampling_rate_features=17)

def start_run_function(self, out_dir: str="", experiment_name: str="sub") -> None:
def start_run_function(
self, out_dir: str = "", experiment_name: str = "sub"
) -> None:
# TODO: we should add a way to pass the output path and the foldername
# Initialize the stream with as process with a queue that is passed to the stream
# The stream will then put the results in the queue
Expand All @@ -31,12 +33,14 @@ def start_run_function(self, out_dir: str="", experiment_name: str="sub") -> Non
self.run_process = Process(
target=self.stream.run,
kwargs={
"out_dir" : out_dir,
"experiment_name" : experiment_name,
"feature_queue" : feature_queue,
"stream_handling_queue" : stream_handling_queue,
"stream_lsl" : self.lsl_stream_name is not None,
"stream_lsl_name" : self.lsl_stream_name if self.lsl_stream_name is not None else "",
"out_dir": out_dir,
"experiment_name": experiment_name,
"feature_queue": feature_queue,
"stream_handling_queue": stream_handling_queue,
"is_stream_lsl": self.lsl_stream_name is not None,
"stream_lsl_name": self.lsl_stream_name
if self.lsl_stream_name is not None
else "",
},
)

Expand Down Expand Up @@ -73,24 +77,22 @@ def setup_lsl_stream(
info_ = stream.get_channel_info()
self.logger.info(f"channel info: {info_}")

channels = nm_define_nmchannels.set_channels(
channels = set_channels(
ch_names=ch_names,
ch_types=ch_types,
used_types=["eeg", "ecog", "dbs", "seeg"],
)
self.logger.info(channels)
sfreq = stream.sfreq

self.stream: nm.Stream = nm.Stream(
self.stream: Stream = Stream(
sfreq=sfreq,
line_noise=line_noise,
nm_channels=channels,
channels=channels,
sampling_rate_features_hz=sampling_rate_features,
)
self.logger.info("stream setup")
self.settings: nm.NMSettings = nm.NMSettings(
sampling_rate_features=sfreq
)
self.settings: NMSettings = NMSettings(sampling_rate_features=sfreq)
self.logger.info("settings setup")
break

Expand All @@ -104,22 +106,22 @@ def setup_offline_stream(
line_noise: float = None,
sampling_rate_features: float = None,
):
data, sfreq, ch_names, ch_types, bads = nm_IO.read_mne_data(file_path)
data, sfreq, ch_names, ch_types, bads = read_mne_data(file_path)

channels = nm_define_nmchannels.set_channels(
channels = set_channels(
ch_names=ch_names,
ch_types=ch_types,
bads=bads,
used_types=["eeg", "ecog", "dbs", "seeg"],
)

self.stream: nm.Stream = nm.Stream(
self.stream: Stream = Stream(
sfreq=sfreq,
data=data,
nm_channels=channels,
channels=channels,
line_noise=line_noise,
sampling_rate_features_hz=sampling_rate_features,
)
self.settings: nm.NMSettings = nm.NMSettings(
self.settings: NMSettings = NMSettings(
sampling_rate_features=sampling_rate_features
)
2 changes: 2 additions & 0 deletions py_neuromodulation/stream/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .generator import RawDataGenerator
from .mnelsl_player import LSLOfflinePlayer
from .mnelsl_stream import LSLStream
from .stream import Stream
from .settings import NMSettings
6 changes: 4 additions & 2 deletions py_neuromodulation/stream/mnelsl_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import time
import signal

from py_neuromodulation import logger, nm_types, nm_IO
from py_neuromodulation.utils.types import _PathLike
from py_neuromodulation.utils.io import read_BIDS_data
from py_neuromodulation import logger


class LSLOfflinePlayer:
Expand Down Expand Up @@ -54,7 +56,7 @@ def __init__(

if f_name:
(self._path_raw, data, sfreq, line_noise, coord_list, coord_names) = (
nm_IO.read_BIDS_data(f_name)
read_BIDS_data(f_name)
)
elif raw:
self._path_raw = raw
Expand Down

0 comments on commit 998dbef

Please sign in to comment.