v2.0.0
Loading...
Searching...
No Matches
bids_channel.cpp
Go to the documentation of this file.
1//=============================================================================================================
12
13//=============================================================================================================
14// INCLUDES
15//=============================================================================================================
16
17#include "bids_channel.h"
18#include "bids_tsv.h"
19
20//=============================================================================================================
21// USED NAMESPACES
22//=============================================================================================================
23
24using namespace BIDSLIB;
25
26//=============================================================================================================
27// LOCAL HELPERS
28//=============================================================================================================
29
30namespace
31{
32static const QString NA = QStringLiteral("n/a");
33
34QString naToEmpty(const QString& s)
35{
36 return (s == NA) ? QString() : s;
37}
38} // anonymous namespace
39
40//=============================================================================================================
41// STATIC METHODS
42//=============================================================================================================
43
44QList<BidsChannel> BidsChannel::readTsv(const QString& sFilePath)
45{
46 QStringList headers;
47 QList<BidsTsvRow> rawRows = BidsTsv::readTsv(sFilePath, headers);
48
49 QList<BidsChannel> channels;
50 channels.reserve(rawRows.size());
51
52 for(const auto& row : rawRows) {
53 BidsChannel ch;
54 ch.name = row.value(QStringLiteral("name"));
55 ch.type = row.value(QStringLiteral("type"));
56 ch.units = row.value(QStringLiteral("units"));
57 ch.samplingFreq = naToEmpty(row.value(QStringLiteral("sampling_frequency")));
58 ch.lowCutoff = naToEmpty(row.value(QStringLiteral("low_cutoff")));
59 ch.highCutoff = naToEmpty(row.value(QStringLiteral("high_cutoff")));
60 ch.notch = naToEmpty(row.value(QStringLiteral("notch")));
61 ch.status = naToEmpty(row.value(QStringLiteral("status")));
62 ch.description = naToEmpty(row.value(QStringLiteral("description")));
63 channels.append(ch);
64 }
65
66 return channels;
67}
68
69//=============================================================================================================
70
71bool BidsChannel::writeTsv(const QString& sFilePath,
72 const QList<BidsChannel>& channels)
73{
74 QStringList headers = {
75 QStringLiteral("name"),
76 QStringLiteral("type"),
77 QStringLiteral("units"),
78 QStringLiteral("sampling_frequency"),
79 QStringLiteral("low_cutoff"),
80 QStringLiteral("high_cutoff"),
81 QStringLiteral("notch"),
82 QStringLiteral("status"),
83 QStringLiteral("description"),
84 };
85
86 QList<BidsTsvRow> rows;
87 rows.reserve(channels.size());
88
89 for(const auto& ch : channels) {
90 BidsTsvRow row;
91 row[QStringLiteral("name")] = ch.name;
92 row[QStringLiteral("type")] = ch.type;
93 row[QStringLiteral("units")] = ch.units;
94 row[QStringLiteral("sampling_frequency")] = ch.samplingFreq;
95 row[QStringLiteral("low_cutoff")] = ch.lowCutoff;
96 row[QStringLiteral("high_cutoff")] = ch.highCutoff;
97 row[QStringLiteral("notch")] = ch.notch;
98 row[QStringLiteral("status")] = ch.status;
99 row[QStringLiteral("description")] = ch.description;
100 rows.append(row);
101 }
102
103 return BidsTsv::writeTsv(sFilePath, headers, rows);
104}
Generic tab-separated-value reader/writer for BIDS sidecars (UTF-8, LF, n/a for missing values,...
Reader/writer for the BIDS _channels.tsv sidecar — one record per recorded channel.
BIDS dataset reading, writing, path construction, and sidecar metadata handling for iEEG/EEG/MEG.
QMap< QString, QString > BidsTsvRow
Definition bids_tsv.h:54
Channel metadata record corresponding to one row in *_channels.tsv.
static QList< BidsChannel > readTsv(const QString &sFilePath)
Read a BIDS *_channels.tsv file.
static bool writeTsv(const QString &sFilePath, const QList< BidsChannel > &channels)
Write a BIDS *_channels.tsv file.
static QList< BidsTsvRow > readTsv(const QString &sFilePath, QStringList &headers)
Definition bids_tsv.cpp:60
static bool writeTsv(const QString &sFilePath, const QStringList &headers, const QList< BidsTsvRow > &rows)
Definition bids_tsv.cpp:101