Skip to content

Commit

Permalink
fix createStore setup
Browse files Browse the repository at this point in the history
  • Loading branch information
timonmerk committed Nov 25, 2024
1 parent a712b3f commit 2691d38
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
Binary file modified gui_dev/bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions gui_dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"@mui/icons-material": "latest",
"@mui/material": "latest",
"cbor-js": "^0.1.0",
Expand All @@ -29,11 +29,11 @@
"@babel/eslint-parser": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.25.9",
"@eslint/compat": "^1.2.2",
"@eslint/compat": "^1.2.3",
"@vitejs/plugin-react": "^4.3.3",
"@welldone-software/why-did-you-render": "^8.0.3",
"babel-plugin-react-compiler": "latest",
"eslint": "^9.14.0",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^50.5.0",
"eslint-plugin-react": "^7.37.2",
Expand Down
16 changes: 2 additions & 14 deletions gui_dev/src/pages/SourceSelection/StreamSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ export const StreamSelector = () => {
);
const updateStreamParameter = useSessionStore((state) => state.updateStreamParameter);

const setLineNoiseValue = useSessionStore((state) => state.setLineNoiseValue);
const setSamplingRateFeaturesValue = useSessionStore(
(state) => state.setSamplingRateFeaturesValue
);
const setSamplingRateValue = useSessionStore(
(state) => state.setSamplingRateValue
);
const setStreamParametersAllValid = useSessionStore(
(state) => state.setStreamParametersAllValid
);
const setSourceType = useSessionStore((state) => state.setSourceType);

const validateStreamName = (name) => {
Expand Down Expand Up @@ -65,13 +55,11 @@ export const StreamSelector = () => {
const handleSelectStream = (streamName, sfreq) => {
setSelectedStreamName(streamName);

updateStreamParameter('lineNoise', 50);
/* updateStreamParameter('lineNoise', 50);*/
updateStreamParameter('samplingRate', sfreq);
updateStreamParameter('samplingRateFeatures', 10);
/*updateStreamParameter('samplingRateFeatures', 10);*/
updateStreamParameter('allValid', true);



setIsStreamNameValid(true);
};

Expand Down
20 changes: 10 additions & 10 deletions gui_dev/src/stores/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// session information, such as the experiment name,
// the data source, stream paramerters, the output files paths, etc

import { createPersistStore } from "@/stores/createStore";
import { createStore } from "@/stores/createStore";
import { getBackendURL } from "@/utils/getBackendURL";

// Workflow stages enum-like object
Expand All @@ -13,7 +13,7 @@ export const WorkflowStage = Object.freeze({
VISUALIZATION: Symbol("VISUALIZATION"),
});

export const useSessionStore = createPersistStore("session", (set, get) => ({
export const useSessionStore = createStore("session", (set, get) => ({
// Sync status
syncStatus: "synced", // 'synced', 'syncing', 'error'
syncError: null,
Expand Down Expand Up @@ -48,9 +48,9 @@ export const useSessionStore = createPersistStore("session", (set, get) => ({
streamParameters: {
samplingRate: 1000,
lineNoise: 50,
samplingRateFeatures: 10,
samplingRateFeatures: 11,
allValid: false,
experimentName: "sub",
experimentName: "subject",
outputDirectory: "default",
},

Expand Down Expand Up @@ -107,9 +107,9 @@ export const useSessionStore = createPersistStore("session", (set, get) => ({

// Check that all stream parameters are valid
checkStreamParameters: () => {
const { samplingRate, lineNoise, samplingRateFeatures } = get();
// const { samplingRate, lineNoise, samplingRateFeatures } = get();
set({
areParametersValid: samplingRate && lineNoise && samplingRateFeatures,
areParametersValid: get().streamParameters.samplingRate && get().streamParameters.lineNoise && get().streamParameters.samplingRateFeatures,
});
},

Expand All @@ -130,8 +130,8 @@ export const useSessionStore = createPersistStore("session", (set, get) => ({
file_path: get().fileSource.path,
sampling_rate_features: get().streamParameters.samplingRateFeatures,
line_noise: get().streamParameters.lineNoise,
experimentName: get().streamParameters.experimentName,
outputDirectory: get().streamParameters.outputDirectory,
experiment_name: get().streamParameters.experimentName,
out_dir: get().streamParameters.outputDirectory,
}),
});

Expand Down Expand Up @@ -172,8 +172,8 @@ export const useSessionStore = createPersistStore("session", (set, get) => ({
stream_name: lslSource.availableStreams[0].name,
sampling_rate_features: streamParameters.samplingRate,
line_noise: streamParameters.lineNoise,
experimentName: streamParameters.experimentName,
outputDirectory: streamParameters.outputDirectory,
experiment_name: streamParameters.experimentName,
out_dir: streamParameters.outputDirectory,
}),
});

Expand Down
4 changes: 4 additions & 0 deletions py_neuromodulation/gui/backend/app_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ async def setup_lsl_stream(data: dict):
lsl_stream_name=stream_name,
sampling_rate_features=data["sampling_rate_features"],
line_noise=data["line_noise"],
out_dir=data["out_dir"],
experiment_name=data["experiment_name"],
)
return {"message": f"LSL stream '{stream_name}' setup successfully"}
except Exception as e:
Expand All @@ -205,6 +207,8 @@ async def setup_offline_stream(data: dict):
file_path=data["file_path"],
line_noise=float(data["line_noise"]),
sampling_rate_features=float(data["sampling_rate_features"]),
out_dir=data["out_dir"],
experiment_name=data["experiment_name"],
)
return {"message": "Offline stream setup successfully"}
except ValueError:
Expand Down
15 changes: 12 additions & 3 deletions py_neuromodulation/gui/backend/app_pynm.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def start_run_function(
target=self.stream.run,
daemon=True,
kwargs={
"out_dir" : out_dir,
"experiment_name" : experiment_name,
"out_dir" : self.out_dir,
"experiment_name" : self.experiment_name,
"stream_handling_queue" : self.stream_handling_queue,
"is_stream_lsl" : is_stream_lsl,
"stream_lsl_name" : stream_lsl_name,
Expand All @@ -100,6 +100,8 @@ def setup_lsl_stream(
lsl_stream_name: str | None = None,
line_noise: float | None = None,
sampling_rate_features: float | None = None,
out_dir: str = "",
experiment_name: str = "sub",
):
from mne_lsl.lsl import resolve_streams

Expand Down Expand Up @@ -145,16 +147,21 @@ def setup_lsl_stream(
#self.settings: NMSettings = NMSettings(sampling_rate_features=sfreq)
self.logger.info("settings setup")
break

if channels.shape[0] == 0:
self.logger.error(f"Stream {lsl_stream_name} not found")
raise ValueError(f"Stream {lsl_stream_name} not found")

self.out_dir = out_dir
self.experiment_name = experiment_name

def setup_offline_stream(
self,
file_path: str,
line_noise: float | None = None,
sampling_rate_features: float | None = None,
out_dir: str = "",
experiment_name: str = "sub",
):
data, sfreq, ch_names, ch_types, bads = read_mne_data(file_path)

Expand All @@ -177,3 +184,5 @@ def setup_offline_stream(
sampling_rate_features_hz=sampling_rate_features,
)

self.out_dir = out_dir
self.experiment_name = experiment_name

0 comments on commit 2691d38

Please sign in to comment.