1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import matplotlib.pyplot as plt
- import numpy as np
- import yaml
- import aux
- from helpers import data_management as dm
- import modules.classifier as clf
- import analytics
- import os
- import itertools
- from collections.abc import Iterable
-
- params = aux.load_config()
- if params.speller.type == 'exploration':
- data_tot, tt, triggers_tot, ch_rec_list, file_names = dm.get_raw(n_triggers=params.classifier.n_classes,
- exploration=True, trigger_pos=params.classifier.trigger_pos)
- elif params.speller.type == 'feedback':
- data_tot, tt, triggers_tot, ch_rec_list, file_names = dm.get_raw(n_triggers=params.classifier.n_classes,
- feedback=True, trigger_pos=params.classifier.trigger_pos)
- else:
- data_tot, tt, triggers_tot, ch_rec_list, file_names = dm.get_raw(n_triggers=params.classifier.n_classes,
- trigger_pos=params.classifier.trigger_pos)
- data = np.empty((0, params.daq.n_channels))
- for fids in range(data_tot.shape[0]):
- data = np.concatenate((data, data_tot[fids,0]))
- pp = np.percentile(data, params.daq.normalization.range, axis=0)
- def create_channels_yaml(channels):
- out_dict = {'channels': []}
- for ch in channels:
- out_dict['channels'].append({'id': int(ch['id']),
- 'bottom': float(pp[0, ch['id']]),
- 'top': float(pp[1, ch['id']]),
- 'invert': ch['invert']}
- )
- return out_dict
-
- print(f"\n\nSelected channels dynamic ranges:\n\n{yaml.dump(create_channels_yaml(params.daq.normalization.channels), sort_keys=False, default_flow_style=None)}\n")
- # print(yaml.dump(out_dict, sort_keys=False, default_flow_style=None))
- other_channels = [{'id':item, 'invert':False} for item in range(params.daq.n_channels) if item not in [ch.id for ch in params.daq.normalization.channels]]
- print(f"\nOther channels dynamic ranges (nb: 'invert' is set to default!):\n\n{yaml.dump(create_channels_yaml(other_channels), sort_keys=False, default_flow_style=None)}\n")
- pp_all = np.percentile(np.nanmean(data, axis=1), params.daq.normalization.range, axis=0)
- out_dict = {'all_channels': {'bottom': float(pp_all[0]), 'top': float(pp_all[1]), 'invert': params.daq.normalization.all_channels.invert}}
- print(f"All Channels bounds:\n\n{yaml.dump(out_dict, sort_keys=False, default_flow_style=None)}")
|