Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
6a95aba
Update feature extraction for heatmap visualization
cbmorrell Jul 24, 2024
1bf5dc3
Change features to fe in OnlineStreamer
cbmorrell Jul 24, 2024
3bd2657
Offline regression example
cbmorrell Aug 8, 2024
94091d9
Merge pull request #66 from LibEMG/main
eeddy Aug 14, 2024
353e286
Example for new streamer
eeddy Aug 14, 2024
df08317
Revert "Example for new streamer"
eeddy Aug 14, 2024
34de77a
Rename ColumnFetch to ColumnFetcher
cbmorrell Aug 16, 2024
2da2612
Remove duplicate method
cbmorrell Aug 16, 2024
bc0972f
Add feature queue for time series models
cbmorrell Aug 16, 2024
ae71d0f
Add explicit conditional check instead of relying on casting
cbmorrell Aug 19, 2024
8e71705
Only pop if queue is at max length
cbmorrell Aug 19, 2024
cfc9a84
Add feature queue parameter to child classes
cbmorrell Aug 19, 2024
6d83b96
Add online channel mask
cbmorrell Aug 19, 2024
f27c6e3
Merge branch 'online-model-feature-queue' into feature-extractor-rework
cbmorrell Aug 19, 2024
19f2049
Revert "Revert "Rework FeatureExtractor""
cbmorrell Aug 19, 2024
81318c1
Add skip until buffer fills up
cbmorrell Aug 19, 2024
d30f608
Merge pull request #68 from LibEMG/rename-column-fetch
eeddy Aug 20, 2024
457e5ec
Merge pull request #59 from LibEMG/offline-regression-example
eeddy Aug 20, 2024
e8701ad
Add TODO
cbmorrell Aug 20, 2024
5a6bd18
Add wildcard to regex helper
cbmorrell Aug 21, 2024
88821ef
Add check for None in RegexFilter
cbmorrell Aug 21, 2024
c5c8748
Add wildcard to regex helper
cbmorrell Aug 21, 2024
2e63dfd
Add check for None in RegexFilter
cbmorrell Aug 21, 2024
34cecb3
Add skip until buffer fills up
cbmorrell Aug 19, 2024
a751cbb
Add string parameters for common metadata operations
cbmorrell Aug 26, 2024
124a1dd
Merge pull request #71 from LibEMG/common-metadata-operations
ECEEvanCampbell Aug 26, 2024
60249b0
ninapro db2 dataglove support added
A-R-Hariri Aug 27, 2024
5d92b81
Merge branch 'feature-extractor-rework' into online-model-feature-queue
cbmorrell Aug 27, 2024
29e677c
Revert "Revert "Revert "Rework FeatureExtractor"""
cbmorrell Aug 27, 2024
8aaf19d
Add online standardization method
cbmorrell Aug 27, 2024
80969d8
Use proper FeatureExtractor interface
cbmorrell Aug 27, 2024
3466dad
Fix heatmap feature extraction
cbmorrell Sep 4, 2024
5f20583
Add clarification to install_standardization docstring
cbmorrell Sep 4, 2024
6f5e72d
Check for correct MacOS string
cbmorrell Sep 5, 2024
318fc0c
ninapro db2
A-R-Hariri Sep 6, 2024
24c1951
Remove unnecessary pop of oldest window
cbmorrell Sep 6, 2024
8254942
Merge pull request #79 from LibEMG/oymotion-streamer-incorrect-os-check
ECEEvanCampbell Sep 9, 2024
95e1111
Merge pull request #73 from LibEMG/online-model-feature-queue
ECEEvanCampbell Sep 9, 2024
25460b3
updates sifi streamer to accept bridge version. forked sifi bridge in…
ECEEvanCampbell Sep 9, 2024
8a20f1b
db2 dataglove support limited to NinaproDB2 class
A-R-Hariri Sep 9, 2024
6e436a9
documentation for NinaproDB2
A-R-Hariri Sep 9, 2024
c943fff
Merge pull request #80 from AmirRezaHariri/ninapro_regression
cbmorrell Sep 9, 2024
68942af
Merge pull request #81 from LibEMG/sifi-breakout
cbmorrell Sep 9, 2024
e631c6a
Dataset updates
eeddy Sep 13, 2024
0a89aa5
Updates
eeddy Sep 16, 2024
c7a6a12
Added Grab Myo
eeddy Sep 16, 2024
cd7f61d
Updates
eeddy Sep 16, 2024
4ea2ebc
Changed pathing
eeddy Sep 16, 2024
9c1f741
Update OneSubjectEMaGerDataset to new format
cbmorrell Sep 16, 2024
7573004
Add split parameter to prepare_data
cbmorrell Sep 16, 2024
642d26c
Updates
eeddy Sep 16, 2024
a8759c8
Updates
eeddy Sep 16, 2024
0e830bd
Fixed Grab Myo
eeddy Sep 16, 2024
48bdd44
Added resp to EPN
eeddy Sep 17, 2024
fff712d
Updated the data handler to run faster
eeddy Sep 17, 2024
dcaa006
Made them all parse fast
eeddy Sep 17, 2024
4267971
Sped up window parsing
eeddy Sep 18, 2024
e8284c7
Fixed data handler
eeddy Sep 18, 2024
203cbc8
Updated ref
eeddy Sep 18, 2024
30fef47
Made faster
eeddy Sep 18, 2024
ebd500b
Fixed
eeddy Sep 18, 2024
d8789d9
Updated
eeddy Sep 19, 2024
d74f08b
Updates
eeddy Sep 19, 2024
580094d
Updates
eeddy Sep 19, 2024
06e8dec
Updates
eeddy Sep 19, 2024
a9fc178
Added cropping
eeddy Sep 19, 2024
fa65513
Updated to crop better
eeddy Sep 20, 2024
6ed821a
Updates
eeddy Sep 24, 2024
bbf80c4
Undo
eeddy Sep 24, 2024
a65a8e9
Hyser dataset
cbmorrell Sep 24, 2024
31517ae
Updated libemg
eeddy Sep 25, 2024
0ed0e30
Fix zoom logical error
cbmorrell Sep 25, 2024
854e307
Merge branch 'dataset_updates' of https://github.com/LibEMG/libemg in…
cbmorrell Sep 25, 2024
44c7df4
Add regex filter packaging and .hea support to FilePackager
cbmorrell Sep 25, 2024
a7916e2
Add check in regex package function
cbmorrell Sep 25, 2024
12453e2
Fix Hyser1DOF
cbmorrell Sep 25, 2024
4f62584
Added CI dataset
eeddy Sep 26, 2024
981352f
Updates
eeddy Sep 26, 2024
2d58dae
Updates
eeddy Sep 26, 2024
6b609b8
UpdaTes
eeddy Sep 27, 2024
45e5abf
added limb position
eeddy Sep 27, 2024
275dd36
radman->radmand
ECEEvanCampbell Sep 27, 2024
a0a0e1e
added h5py req
ECEEvanCampbell Sep 27, 2024
e5d7a8e
added kaufmannMD
ECEEvanCampbell Sep 27, 2024
d1b5225
created kaufmann class
ECEEvanCampbell Sep 27, 2024
218e002
added submodules to _dataset
ECEEvanCampbell Sep 27, 2024
f3cd6b0
Updated myodisco
eeddy Sep 30, 2024
3c41d00
Updates
eeddy Sep 30, 2024
a3d4b2e
added h5py
ECEEvanCampbell Oct 1, 2024
1640821
HyserNDOF and HyserRandom Classes
cbmorrell Oct 1, 2024
66704a9
Merge branch 'dataset_updates' of https://github.com/LibEMG/libemg in…
cbmorrell Oct 1, 2024
050598b
Add type hint to RegexFilter
cbmorrell Oct 2, 2024
3242bb5
Handle single values from MetadataFetcher
cbmorrell Oct 2, 2024
70d8019
Hyser PR Dataset
cbmorrell Oct 2, 2024
ffb9564
Remove subject 10 from random task dataset
cbmorrell Oct 2, 2024
a4b2d3c
Rename Hyser to _Hyser
cbmorrell Oct 2, 2024
dbbd5fe
Hyser documentation
cbmorrell Oct 2, 2024
aa032c9
Don't do any processing on the dataset
eeddy Oct 7, 2024
de89e6d
Add NinaproDB8
cbmorrell Oct 11, 2024
898e59c
Merge branch 'dataset_updates' of https://github.com/LibEMG/libemg in…
cbmorrell Oct 11, 2024
cce14fc
Add note to NinaproDB8
cbmorrell Oct 11, 2024
0e9cf18
Add OneSubjectEMaGerDataset import to datasets.py
cbmorrell Oct 11, 2024
85b8a3a
Add OneSubjectEMaGerDataset to dataset list
cbmorrell Oct 11, 2024
58bc45c
Fix parse_windows for 2D metadata
cbmorrell Oct 11, 2024
f7e6178
Reimplement NinaPro cyberglove data
cbmorrell Oct 11, 2024
86e0aac
Allow empty strings in RegexFilter
cbmorrell Oct 17, 2024
20c585b
Properly handle cyberglove data
cbmorrell Oct 17, 2024
afed8a7
Merge branch 'dataset_updates' of https://github.com/LibEMG/libemg in…
ECEEvanCampbell Oct 17, 2024
acbbf90
added tmr data
ECEEvanCampbell Oct 18, 2024
f8dc05b
Updates
eeddy Oct 21, 2024
d0c1fe7
Updated logging
eeddy Oct 22, 2024
64cea6e
Updates
eeddy Oct 22, 2024
d31aa87
Updates
eeddy Oct 22, 2024
c1d2f06
Add UserComplianceDataset
cbmorrell Oct 22, 2024
16ead39
Updates
eeddy Oct 25, 2024
3c50c7b
Updates
eeddy Oct 25, 2024
b9edf73
Convert labels field to classes in HyserPR
cbmorrell Oct 28, 2024
a0cce07
added CIIL_WS. Fixed dataset exist check for regression & WS
ECEEvanCampbell Oct 28, 2024
137c5b2
initial commit for CIIL_WS
ECEEvanCampbell Oct 28, 2024
d9def07
added onedrive download method
ECEEvanCampbell Oct 28, 2024
ecd68cf
added onedrive download method
ECEEvanCampbell Oct 28, 2024
b805527
added one drive downloader
ECEEvanCampbell Oct 28, 2024
12a0b53
added arguments for unzip and clean
ECEEvanCampbell Oct 28, 2024
4c322de
now downloads
ECEEvanCampbell Oct 28, 2024
5105af3
Fixed one site bio
eeddy Oct 31, 2024
d6afd04
Hyser labels fix
cbmorrell Oct 31, 2024
bae186c
Add subjects to Hyser classes
cbmorrell Oct 31, 2024
62a85da
Continuous transitions debugging
cbmorrell Oct 31, 2024
36481e7
Add subjects to OneSubjectEMaGerDataset
cbmorrell Oct 31, 2024
e6f7a08
Evaluate method fixes
cbmorrell Oct 31, 2024
9fd0784
Fixed continuous
eeddy Oct 31, 2024
64335df
Fix subject indexing with Hyser
cbmorrell Oct 31, 2024
279ffca
Handle default subject values for Hyser datasets
cbmorrell Oct 31, 2024
61ef9c0
Fixed DB8
eeddy Oct 31, 2024
58896ce
Hyser missing subject fixes
cbmorrell Oct 31, 2024
ebf73e4
added onesiteBP
ECEEvanCampbell Oct 31, 2024
c8ab655
Fixed continuous transitions
eeddy Oct 31, 2024
fbf0581
Store metadata as values
cbmorrell Oct 31, 2024
79d594c
Add return_value parameter to RegexFilter
cbmorrell Oct 31, 2024
bba9694
Try to cast to number when grabbing metadata
cbmorrell Oct 31, 2024
2307e12
Replace list comprehension with mask operation
cbmorrell Oct 31, 2024
d891f28
Handle single element arrays
cbmorrell Oct 31, 2024
500aab3
Fixed Hyser workarounds
cbmorrell Oct 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,20 @@ test_*.py
*.csv
.vscode/*
test_delsys_api.py
resources/
resources/
*.csv
*.txt
ContinuousTransitions/*
FORS-EMG/*
MyoDisCo/*
NinaProDB1/*
*.zip
libemg/_datasets/__pycache__/*
CIILData/*
EMGEPN612.pkl
OneSubjectMyoDataset/
_3DCDataset/
ContractionIntensity/
CIILData/
*.pkl
LimbPosition/
4 changes: 4 additions & 0 deletions dataset_tryout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from libemg.datasets import *

accs = evaluate('LDA', 300, 100, feature_list=['MAV','SSC','ZC','WL'], included_datasets=['FougnerLP'], save_dir='')
print('\n' + str(accs))
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[View Source Code](https://github.com/LibEMG/LibEMG_OfflineRegression_Showcase)

<img src="https://github.com/LibEMG/LibEMG_OfflineRegression_Showcase/blob/main/docs/results.png?raw=true"/>

This simple offline example showcases some of the offline capabilities for regression analysis. In this example, we will load in the OneSubjectEMaGerDataset and assess the performance of multiple regressors. All code can be found in `main.py`.

## Step 1: Importing LibEMG

The very first step involves importing the modules needed. In general, each of LibEMG's modules has its own import. Make sure that you have successfully installed libemg through pip.

```Python
import numpy as np
import matplotlib.pyplot as plt
from libemg.offline_metrics import OfflineMetrics
from libemg.datasets import OneSubjectEMaGerDataset
from libemg.feature_extractor import FeatureExtractor
from libemg.emg_predictor import EMGRegressor
```

## Step 2: Setting up Constants

Preprocessing parameters, such as window size, window increment, and the feature set must be decided before EMG data can be prepared for estimation. LibEMG defines window and increment sizes as the number of samples. In this case, the dataset was recorded from the EMaGer cuff, which samples at 1 kHz, so a window of 150 samples corresponds to 150ms.

The window increment, window size, and feature set default to 40, 150, and 'HTD', respecively. These variables can be customized in this script using the provided CLI. Use `python main.py -h` for an explanation of the CLI. Example usage is also provided below:

```Bash
python main.py --window_size 200 --window_increment 50 --feature_set MSWT
```

# Step 3: Loading in Dataset

This example uses the `OneSubjectEMaGerDataset`. Instantiating the `Dataset` will automatically download the data into the specified directory, and calling the `prepare_data()` method will load EMG data and metadata (e.g., reps, movements, labels) into an `OfflineDataHandler`. This dataset consists of 5 repetitions, so we use 4 for training data and 1 for testing data. After splitting our data into training and test splits, we perform windowing on the raw EMG data. By default, the metadata assigned to each window will be based on the mode of that window. Since we are analyzing regression data, we pass in a function that tells the `OfflineDataHandler` to grab the label from the last sample in the window instead of taking the mode of the window. We can specify how we want to handle windowing of each type of metadata by passing in a `metadata_operations` dictionary.

```Python
# Load data
odh = OneSubjectEMaGerDataset().prepare_data()

# Split into train/test reps
train_odh = odh.isolate_data('reps', [0, 1, 2, 3])
test_odh = odh.isolate_data('reps', [4])

# Extract windows
metadata_operations = {'labels': lambda x: x[-1]} # grab label of last sample in window
train_windows, train_metadata = train_odh.parse_windows(args.window_size, args.window_increment, metadata_operations=metadata_operations)
test_windows, test_metadata = test_odh.parse_windows(args.window_size, args.window_increment, metadata_operations=metadata_operations)
```

# Step 4: Feature Extraction

We then extract features using the `FeatureExtractor` for our training and test data. The `fit()` method expects a dictionary with the keys `training_features` and `training_labels`, so we create one and pass in our extracted features and training labels.

```Python
training_features = fe.extract_feature_group(args.feature_set, train_windows, array=True),
training_labels = train_metadata['labels']
test_features = fe.extract_feature_group(args.feature_set, test_windows, array=True)
test_labels = test_metadata['labels']

training_set = {
'training_features': training_features,
'training_labels': training_labels
}
```

# Step 5: Regression

`LibEMG` allows you to pass in custom models, but you can also pass in a string that will create a model for you. In this example, we compare a linear regressor to a gradient boosting regressor. We iterate through a list of the models we want to observe, fit the model to the training data, and calculate metrics based on predictions on the test data. We then store these metrics for plotting later.

```Python
results = {metric: [] for metric in ['R2', 'NRMSE', 'MAE']}
for model in models:
reg = EMGRegressor(model)

# Fit and run model
print(f"Fitting {model}...")
reg.fit(training_set.copy())
predictions = reg.run(test_features)

metrics = om.extract_offline_metrics(results.keys(), test_labels, predictions)
for metric in metrics:
results[metric].append(metrics[metric].mean())
```

# Step 6: Visualization

Finally, we visualize our results. We first plot the decision stream for each model. After each model is fitted, we plot the offline metrics for each type of model.

```Python
# Note: this will block the main thread once the plot is shown. Close the plot to continue execution.
reg.visualize(test_labels, predictions)

fig, axs = plt.subplots(nrows=len(results), layout='constrained', figsize=(8, 8), sharex=True)
for metric, ax in zip(results.keys(), axs):
ax.bar(models, np.array(results[metric]) * 100)
ax.set_ylabel(f"{metric} (%)")

fig.suptitle('Metrics Summary')
plt.show()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Offline Regression Analysis
==========================================
.. include:: offline_regression.md
:parser: myst_parser.sphinx_
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ LibEMG
examples/features_and_group_example/features_and_group_example
examples/feature_optimization_example/feature_optimization_example
examples/deep_learning_example/deep_learning_example
examples/offline_regression_example/offline_regression_example

.. toctree::
:maxdepth: 1
Expand Down
45 changes: 45 additions & 0 deletions libemg/_datasets/_3DC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from libemg._datasets.dataset import Dataset
from libemg.data_handler import OfflineDataHandler, RegexFilter

class _3DCDataset(Dataset):
def __init__(self, dataset_folder="_3DCDataset/"):
Dataset.__init__(self,
1000,
10,
'3DC Armband (Prototype)',
22,
{0: "Neutral", 1: "Radial Deviation", 2: "Wrist Flexion", 3: "Ulnar Deviation", 4: "Wrist Extension", 5: "Supination", 6: "Pronation", 7: "Power Grip", 8: "Open Hand", 9: "Chuck Grip", 10: "Pinch Grip"},
'8 (4 Train, 4 Test)',
"The 3DC dataset including 11 classes.",
"https://doi.org/10.3389/fbioe.2020.00158")
self.url = "https://github.com/libemg/3DCDataset"
self.dataset_folder = dataset_folder

def prepare_data(self, split = False, subjects_values = None, sets_values = None, reps_values = None,
classes_values = None):
if subjects_values is None:
subjects_values = [str(i) for i in range(1,23)]
if sets_values is None:
sets_values = ["train", "test"]
if reps_values is None:
reps_values = ["0","1","2","3"]
if classes_values is None:
classes_values = [str(i) for i in range(11)]

print('\nPlease cite: ' + self.citation+'\n')
if (not self.check_exists(self.dataset_folder)):
self.download(self.url, self.dataset_folder)

regex_filters = [
RegexFilter(left_bound = "/", right_bound="/EMG", values = sets_values, description='sets'),
RegexFilter(left_bound = "_", right_bound=".txt", values = classes_values, description='classes'),
RegexFilter(left_bound = "EMG_gesture_", right_bound="_", values = reps_values, description='reps'),
RegexFilter(left_bound="Participant", right_bound="/",values=subjects_values, description='subjects')
]
odh = OfflineDataHandler()
odh.get_data(folder_location=self.dataset_folder, regex_filters=regex_filters, delimiter=",")
data = odh
if split:
data = {'All': odh, 'Train': odh.isolate_data("sets", [0], fast=True), 'Test': odh.isolate_data("sets", [1], fast=True)}

return data
17 changes: 17 additions & 0 deletions libemg/_datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from libemg._datasets import _3DC
from libemg._datasets import ciil
from libemg._datasets import continous_transitions
from libemg._datasets import dataset
from libemg._datasets import emg_epn612
from libemg._datasets import fors_emg
from libemg._datasets import fougner_lp
from libemg._datasets import grab_myo
from libemg._datasets import hyser
from libemg._datasets import intensity
from libemg._datasets import kaufmann_md
from libemg._datasets import myodisco
from libemg._datasets import nina_pro
from libemg._datasets import one_subject_emager
from libemg._datasets import one_subject_myo
from libemg._datasets import radmand_lp
from libemg._datasets import tmr_shirleyryanabilitylab
148 changes: 148 additions & 0 deletions libemg/_datasets/ciil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
from libemg._datasets.dataset import Dataset
from libemg.data_handler import OfflineDataHandler, RegexFilter, FilePackager
from pathlib import Path



class CIIL_MinimalData(Dataset):
def __init__(self, dataset_folder='CIILData/'):
Dataset.__init__(self,
200,
8,
'Myo Armband',
11,
{0: 'Close', 1: 'Open', 2: 'Rest', 3: 'Flexion', 4: 'Extension'},
'1 Train (1s), 15 Test',
"The goal of this Myo dataset is to explore how well models perform when they have a limited amount of training data (1s per class).",
'https://ieeexplore.ieee.org/abstract/document/10394393')
self.url = "https://github.com/LibEMG/CIILData"
self.dataset_folder = dataset_folder

def prepare_data(self, split = False):
print('\nPlease cite: ' + self.citation+'\n')
if (not self.check_exists(self.dataset_folder)):
self.download(self.url, self.dataset_folder)

subfolder = 'MinimalTrainingData'
subjects = [str(i) for i in range(0, 11)]
classes_values = [str(i) for i in range(0,5)]
reps_values = ["0","1","2"]
sets = ["train", "test"]
regex_filters = [
RegexFilter(left_bound = "/", right_bound="/", values = sets, description='sets'),
RegexFilter(left_bound = "/subject", right_bound="/", values = subjects, description='subjects'),
RegexFilter(left_bound = "R_", right_bound="_", values = reps_values, description='reps'),
RegexFilter(left_bound = "C_", right_bound=".csv", values = classes_values, description='classes')
]
odh = OfflineDataHandler()
odh.get_data(folder_location=self.dataset_folder + '/' + subfolder, regex_filters=regex_filters, delimiter=",")

data = odh
if split:
data = {'All': odh, 'Train': odh.isolate_data("sets", [0], fast=True), 'Test': odh.isolate_data("sets", [1], fast=True)}

return data

class CIIL_ElectrodeShift(Dataset):
def __init__(self, dataset_folder='CIILData/'):
Dataset.__init__(self,
200,
8,
'Myo Armband',
21,
{0: 'Close', 1: 'Open', 2: 'Rest', 3: 'Flexion', 4: 'Extension'},
'5 Train (Before Shift), 8 Test (After Shift)',
"An electrode shift confounding factors dataset.",
'https://link.springer.com/article/10.1186/s12984-024-01355-4')
self.url = "https://github.com/LibEMG/CIILData"
self.dataset_folder = dataset_folder

def prepare_data(self, split = False):
print('\nPlease cite: ' + self.citation+'\n')
if (not self.check_exists(self.dataset_folder)):
self.download(self.url, self.dataset_folder)

subfolder = 'ElectrodeShift'
subjects = [str(i) for i in range(0, 21)]
classes_values = [str(i) for i in range(0,5)]
reps_values = ["0","1","2","3","4"]
sets = ["training", "trial_1", "trial_2", "trial_3", "trial_4"]
regex_filters = [
RegexFilter(left_bound = "/", right_bound="/", values = sets, description='sets'),
RegexFilter(left_bound = "/subject", right_bound="/", values = subjects, description='subjects'),
RegexFilter(left_bound = "R_", right_bound="_", values = reps_values, description='reps'),
RegexFilter(left_bound = "C_", right_bound=".csv", values = classes_values, description='classes')
]
odh = OfflineDataHandler()
odh.get_data(folder_location=self.dataset_folder + '/' + subfolder, regex_filters=regex_filters, delimiter=",")

data = odh
if split:
data = {'All': odh, 'Train': odh.isolate_data("sets", [0], fast=True), 'Test': odh.isolate_data("sets", [1,2,3,4], fast=True)}

return data


class CIIL_WeaklySupervised(Dataset):
def __init__(self, dataset_folder='CIIL_WeaklySupervised/'):
Dataset.__init__(self,
1000,
8,
'OyMotion gForcePro+ EMG Armband',
16,
{0: 'Close', 1: 'Open', 2: 'Rest', 3: 'Flexion', 4: 'Extension'},
'30 min weakly supervised, 1 rep calibration, 14 reps test',
"A weakly supervised environment with sparse supervised calibration.",
'In Submission')
self.url = "https://unbcloud-my.sharepoint.com/:u:/g/personal/ecampbe2_unb_ca/EaABHYybhfJNslTVcvwPPwgB9WwqlTLCStui30maqY53kw?e=MbboMd"
self.dataset_folder = dataset_folder

def prepare_data(self, split = False):
print('\nPlease cite: ' + self.citation+'\n')
if (not self.check_exists(self.dataset_folder)):
self.download_via_onedrive(self.url, self.dataset_folder)

# supervised odh loading
subjects = [str(i) for i in range(0, 16)]
classes_values = [str(i) for i in range(0,5)]
reps_values = [str(i) for i in range(0,15)]
setting_values = [".csv", ""] # this is arbitrary to get a field that separates WS from S
regex_filters = [
RegexFilter(left_bound = "", right_bound="", values = setting_values, description='settings'),
RegexFilter(left_bound = "/S", right_bound="/", values = subjects, description='subjects'),
RegexFilter(left_bound = "R", right_bound=".csv", values = reps_values, description='reps'),
RegexFilter(left_bound = "C", right_bound="_R", values = classes_values, description='classes')
]
odh_s = OfflineDataHandler()
odh_s.get_data(folder_location=self.dataset_folder+"CIIL_WeaklySupervised/",
regex_filters=regex_filters,
delimiter=",")

# weakly supervised odh loading
subjects = [str(i) for i in range(0, 16)]
reps_values = [str(i) for i in range(3)]
setting_values = ["", ".csv"] # this is arbitrary to get a field that separates WS from S
regex_filters = [
RegexFilter(left_bound = "", right_bound="", values = setting_values, description='settings'),
RegexFilter(left_bound = "/S", right_bound="/", values = subjects, description='subjects'),
RegexFilter(left_bound = "WS", right_bound=".csv", values = reps_values, description='reps'),
]
metadata_fetchers = [
FilePackager(regex_filter=RegexFilter(left_bound="", right_bound="targets.csv", values=["_"], description="classes"),
package_function=lambda x, y: (x.split("WS")[1][0] == y.split("WS")[1][0]) and (Path(x).parent == Path(y).parent)
)
]
odh_ws = OfflineDataHandler()
odh_ws.get_data(folder_location=self.dataset_folder+"CIIL_WeaklySupervised/",
regex_filters=regex_filters,
metadata_fetchers=metadata_fetchers,
delimiter=",")

data = odh_s + odh_ws
if split:
data = {'All': data,
'Pretrain': odh_ws,
'Train': odh_s.isolate_data("reps", [0], fast=True),
'Test': odh_s.isolate_data("reps", list(range(1,15)), fast=True)}

return data
Loading