Skip to content

Commit c499df9

Browse files
committed
Updated utils to typescript
1 parent 84ef1cb commit c499df9

File tree

6 files changed

+33
-278
lines changed

6 files changed

+33
-278
lines changed

app/utils/pyodide/cell.js

Lines changed: 0 additions & 115 deletions
This file was deleted.

app/utils/pyodide/functions.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

app/utils/pyodide/functions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// -------------------------------------------
2+
// Helper & utility functions
3+
4+
export const parseSingleQuoteJSON = (string: string) =>
5+
JSON.parse(string.replace(/'/g, '"'));
6+
7+
export const formatFilePath = (filePath: string) =>
8+
`"${filePath.replace(/\\/g, '/')}"`;
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as path from 'path';
22
import { readFileSync } from 'fs';
33
import { 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

2123
export 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
3743
export const filterIIR = async (lowCutoff: number, highCutoff: number) =>
@@ -40,10 +46,10 @@ export const filterIIR = async (lowCutoff: number, highCutoff: number) =>
4046
});
4147

4248
export 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

7985
export 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

8692
export 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

9197
export 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

100111
export const saveEpochs = (workspaceDir: string, subject: string) =>
101112
pyodideWorker.postMessage({

app/utils/pyodide/pipes.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/utils/pyodide/statements.json

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)