v2.0.0
Loading...
Searching...
No Matches
bids_channel.cpp
Go to the documentation of this file.
1//=============================================================================================================
34
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "bids_channel.h"
40#include "bids_tsv.h"
41
42//=============================================================================================================
43// USED NAMESPACES
44//=============================================================================================================
45
46using namespace BIDSLIB;
47
48//=============================================================================================================
49// LOCAL HELPERS
50//=============================================================================================================
51
52namespace
53{
54static const QString NA = QStringLiteral("n/a");
55
56QString naToEmpty(const QString& s)
57{
58 return (s == NA) ? QString() : s;
59}
60} // anonymous namespace
61
62//=============================================================================================================
63// STATIC METHODS
64//=============================================================================================================
65
66QList<BidsChannel> BidsChannel::readTsv(const QString& sFilePath)
67{
68 QStringList headers;
69 QList<BidsTsvRow> rawRows = BidsTsv::readTsv(sFilePath, headers);
70
71 QList<BidsChannel> channels;
72 channels.reserve(rawRows.size());
73
74 for(const auto& row : rawRows) {
75 BidsChannel ch;
76 ch.name = row.value(QStringLiteral("name"));
77 ch.type = row.value(QStringLiteral("type"));
78 ch.units = row.value(QStringLiteral("units"));
79 ch.samplingFreq = naToEmpty(row.value(QStringLiteral("sampling_frequency")));
80 ch.lowCutoff = naToEmpty(row.value(QStringLiteral("low_cutoff")));
81 ch.highCutoff = naToEmpty(row.value(QStringLiteral("high_cutoff")));
82 ch.notch = naToEmpty(row.value(QStringLiteral("notch")));
83 ch.status = naToEmpty(row.value(QStringLiteral("status")));
84 ch.description = naToEmpty(row.value(QStringLiteral("description")));
85 channels.append(ch);
86 }
87
88 return channels;
89}
90
91//=============================================================================================================
92
93bool BidsChannel::writeTsv(const QString& sFilePath,
94 const QList<BidsChannel>& channels)
95{
96 QStringList headers = {
97 QStringLiteral("name"),
98 QStringLiteral("type"),
99 QStringLiteral("units"),
100 QStringLiteral("sampling_frequency"),
101 QStringLiteral("low_cutoff"),
102 QStringLiteral("high_cutoff"),
103 QStringLiteral("notch"),
104 QStringLiteral("status"),
105 QStringLiteral("description"),
106 };
107
108 QList<BidsTsvRow> rows;
109 rows.reserve(channels.size());
110
111 for(const auto& ch : channels) {
112 BidsTsvRow row;
113 row[QStringLiteral("name")] = ch.name;
114 row[QStringLiteral("type")] = ch.type;
115 row[QStringLiteral("units")] = ch.units;
116 row[QStringLiteral("sampling_frequency")] = ch.samplingFreq;
117 row[QStringLiteral("low_cutoff")] = ch.lowCutoff;
118 row[QStringLiteral("high_cutoff")] = ch.highCutoff;
119 row[QStringLiteral("notch")] = ch.notch;
120 row[QStringLiteral("status")] = ch.status;
121 row[QStringLiteral("description")] = ch.description;
122 rows.append(row);
123 }
124
125 return BidsTsv::writeTsv(sFilePath, headers, rows);
126}
BidsTsv class declaration — generic BIDS TSV file reading and writing.
BidsChannel struct — channel metadata from *_channels.tsv.
BIDS dataset reading, writing, path construction, and sidecar metadata handling for iEEG/EEG/MEG.
QMap< QString, QString > BidsTsvRow
Definition bids_tsv.h:65
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:82
static bool writeTsv(const QString &sFilePath, const QStringList &headers, const QList< BidsTsvRow > &rows)
Definition bids_tsv.cpp:123