25 #ifdef WBIOSIG_ENABLED
33 #include "WReaderBiosig.h"
34 #include "core/common/WAssert.h"
35 #include "core/common/WException.h"
36 #include "core/common/WLogger.h"
37 #include "core/common/WStringUtils.h"
38 #include "core/dataHandler/WEEG.h"
39 #include "core/dataHandler/WSubject.h"
41 WReaderBiosig::WReaderBiosig( std::string fileName )
48 void WReaderBiosig::fillSegmentColumnBased( std::vector<std::vector<double> >* segment, biosig_data_type* data )
50 for(
unsigned int i = 0; i < m_columns; ++i )
52 WEEGElectrode channel( 0 );
53 for(
unsigned int j = 0; j < m_rows; ++j )
55 channel.push_back( data[i*m_rows+j] );
57 segment->push_back( channel );
61 void WReaderBiosig::fillSegmentRowBased( std::vector<std::vector<double> >* segment, biosig_data_type* data )
63 for(
unsigned int j = 0; j < m_rows; ++j )
65 WEEGElectrode channel( 0 );
66 for(
unsigned int i = 0; i < m_columns; ++i )
68 channel.push_back( data[i*m_rows+j] );
70 segment->push_back( channel );
74 std::shared_ptr< WDataSet > WReaderBiosig::load()
76 WAssert( m_fname.substr( m_fname.size() - 4 ) ==
".edf",
"We expect only EDF for the biosig loader so far." );
78 hd = sopen( m_fname.c_str(),
"r", 0 );
80 #if( BIOSIG_VERSION >= 10400 )
81 switch( serror2( hd ) )
88 case B4C_FORMAT_UNKNOWN:
89 throw WException( std::string(
"BIOSIG: Unknown format!" ) );
91 case B4C_FORMAT_UNSUPPORTED:
92 throw WException( std::string(
"BIOSIG: Unsupported format!" ) );
94 case B4C_UNSPECIFIC_ERROR:
95 throw WException( std::string(
"BIOSIG: Unspecific error occured!" ) );
98 throw WException( std::string(
"BIOSIG: An error occured! The type is not known to OpenWalnut biosig loader." ) );
103 throw WException( std::string(
"Unknown number of blocks in file loaded by biosig!" ) );
107 bool rowBasedChannels = hd->FLAG.ROW_BASED_CHANNELS;
108 if( rowBasedChannels )
110 wlog::info(
"BIOSIG channels stored as rows." );
114 wlog::info(
"BIOSIG channels stored as cols." );
117 biosig_data_type* DATA = 0;
119 size_t dummy = sread( DATA, 0, LEN, hd );
120 wlog::info(
"BIOSIG" ) <<
" DataSize " << dummy;
121 size_t nbSamples = LEN*hd->SPR*hd->NS;
122 m_rows = hd->data.size[0];
123 m_columns = hd->data.size[1];
124 wlog::info(
"BIOSIG" ) <<
" nbSamples " << nbSamples;
127 std::vector<std::vector<double> > segment;
128 if( rowBasedChannels )
130 fillSegmentRowBased( &segment, hd->data.block );
134 fillSegmentColumnBased( &segment, hd->data.block );
138 std::vector<std::vector<std::vector<double> > > segments( 0 );
139 segments.push_back( segment );
142 WEEGElectrodeLibrary lib = extractElectrodePositions();
144 if( hd->NS != lib.size() )
145 throw WDHException( std::string(
"Contents of edf and elc files are not compatible: Different number of channels." ) );
147 WEEGChannelLabels labels( hd->NS );
148 for(
unsigned int i = 0; i < hd->NS; ++i )
151 labels[i].first = hd->CHANNEL[i].Label;
155 std::shared_ptr< WEEG > eeg(
new WEEG( segments, lib, labels ) );
156 eeg->setFilename( m_fname );
General purpose exception and therefore base class for all DataHandler related exceptions.
Contains EEG recording data.
Abstract base class for all Readers who handle with EEG data.
WStreamedLogger info(const std::string &source)
Logging an information message.