@@ -2,6 +2,8 @@ import * as path from 'path';
22import { readFileSync } from 'fs' ;
33import { formatFilePath } from './functions' ;
44
5+ declare const pyodideWorker : Worker ;
6+
57// ---------------------------------
68// This file contains the JS functions that allow the app to access python-wasm through pyodide
79// These functions wrap the python strings defined in the
@@ -19,19 +21,23 @@ export const loadUtils = async () =>
1921 } ) ;
2022
2123export const loadCSV = async ( csvArray : Array < any > ) => {
22- window . csvArray = csvArray ;
2324 // TODO: Pass attached variable name as parameter to load_data
25+ // @ts -expect-error
26+ window . csvArray = csvArray ;
2427 await pyodideWorker . postMessage ( { data : `raw = load_data()` } ) ;
2528} ;
2629
2730// ---------------------------
2831// MNE-Related Data Processing
2932
30- // export const loadCleanedEpochs = (epocsArray: Array<any>) =>
31- // [
32- // `clean_epochs = concatenate_epochs([read_epochs(file) for file in files])`,
33- // `conditions = OrderedDict({key: [value] for (key, value) in clean_epochs.event_id.items()})`
34- // ].join("\n");
33+ export const loadCleanedEpochs = async ( epochsArray : string [ ] ) => {
34+ await pyodideWorker . postMessage ( {
35+ data : [
36+ `clean_epochs = concatenate_epochs([read_epochs(file) for file in ${ epochsArray } ])` ,
37+ `conditions = OrderedDict({key: [value] for (key, value) in clean_epochs.event_id.items()})` ,
38+ ] . join ( '\n' ) ,
39+ } ) ;
40+ } ;
3541
3642// NOTE: this command includes a ';' to prevent returning data
3743export const filterIIR = async ( lowCutoff : number , highCutoff : number ) =>
@@ -40,10 +46,10 @@ export const filterIIR = async (lowCutoff: number, highCutoff: number) =>
4046 } ) ;
4147
4248export const epochEvents = async (
43- eventIDs : { [ string ] : number } ,
49+ eventIDs : { [ k : string ] : number } ,
4450 tmin : number ,
4551 tmax : number ,
46- reject ?: Array < string > | string = 'None'
52+ reject ?: string [ ] | 'None'
4753) =>
4854 pyodideWorker . postMessage ( {
4955 data : [
@@ -78,24 +84,29 @@ export const requestChannelInfo = async () =>
7884
7985export const cleanEpochsPlot = async ( ) => {
8086 // TODO: Figure out how to get image results from pyodide
81- pyodideWorker . postMessage ( {
87+ await pyodideWorker . postMessage ( {
8288 data : `raw_epochs.plot(scalings='auto', n_epochs=6, title="Clean Data", events=None)` ,
8389 } ) ;
8490} ;
8591
8692export const plotPSD = async ( ) => {
8793 // TODO: Figure out how to get image results from pyodide
88- pyodideWorker . postMessage ( { data : `raw.plot_psd(fmin=1, fmax=30)` } ) ;
94+ return pyodideWorker . postMessage ( { data : `raw.plot_psd(fmin=1, fmax=30)` } ) ;
8995} ;
9096
9197export const plotTopoMap = async ( ) => {
9298 // TODO: Figure out how to get image results from pyodide
93- pyodideWorker . postMessage ( { data : `plot_topo(clean_epochs, conditions)` } ) ;
99+ return pyodideWorker . postMessage ( {
100+ data : `plot_topo(clean_epochs, conditions)` ,
101+ } ) ;
94102} ;
95103
96- export const plotERP = ( channelIndex : number ) =>
97- `X, y = plot_conditions(clean_epochs, ch_ind=${ channelIndex } , conditions=conditions,
98- ci=97.5, n_boot=1000, title='', diff_waveform=None)` ;
104+ export const plotERP = async ( channelIndex : number ) => {
105+ return pyodideWorker . postMessage ( {
106+ data : `X, y = plot_conditions(clean_epochs, ch_ind=${ channelIndex } , conditions=conditions,
107+ ci=97.5, n_boot=1000, title='', diff_waveform=None)` ,
108+ } ) ;
109+ } ;
99110
100111export const saveEpochs = ( workspaceDir : string , subject : string ) =>
101112 pyodideWorker . postMessage ( {
0 commit comments