Skip to content

Commit f67439a

Browse files
authored
Merge pull request #131 from open-ephys-plugins/issue-129
Update Probe Interface compatibility
2 parents 7b181e4 + 15b123c commit f67439a

File tree

1 file changed

+64
-6
lines changed

1 file changed

+64
-6
lines changed

Source/Formats/ProbeInterface.h

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,48 +120,77 @@ namespace OnixSourcePlugin
120120
auto json = JSON::parse(file);
121121

122122
if (json == var())
123+
{
124+
Onix1::showWarningMessageBoxAsync("Unable to Parse File", "The file '" + file.getFileName().toStdString() + "' could not be parsed. " +
125+
"Please ensure that the file exists and is in the correct format.");
123126
return false;
127+
}
124128

125129
DynamicObject::Ptr obj = json.getDynamicObject();
126130

127131
if (obj->hasProperty(Identifier("specification")))
128132
{
129133
std::string specification = obj->getProperty(Identifier("specification")).toString().toStdString();
130134

131-
if (specification.compare("probeinterface") != 0)
135+
const std::string probeInterfaceSpecification = "probeinterface";
136+
137+
if (specification.compare(probeInterfaceSpecification) != 0)
138+
{
139+
Onix1::showWarningMessageBoxAsync("Invalid Specification", "The specification listed in the Probe Interface file is '" + specification +
140+
"', but it is expected to be '" + probeInterfaceSpecification + "'.");
132141
return false;
142+
}
133143
}
134144
else
145+
{
146+
Onix1::showWarningMessageBoxAsync("No Specification Found", "No specification field was found in the JSON file.");
135147
return false;
148+
}
136149

137150
if (obj->hasProperty(Identifier("probes")))
138151
{
139152
Array<var>* probes = obj->getProperty(Identifier("probes")).getArray();
140153

141154
if (probes->size() != 1)
155+
{
156+
Onix1::showWarningMessageBoxAsync("Wrong Number of Probes", "Expected to find one probe listed in this file, but found " +
157+
std::to_string(probes->size()) + " probes in the file.");
142158
return false;
159+
}
143160

144161
DynamicObject::Ptr probe = probes->getReference(0).getDynamicObject();
145162

146163
if (probe->hasProperty(Identifier("ndim")))
147164
{
148165
if (!probe->getProperty(Identifier("ndim")).equalsWithSameType(2))
149166
{
167+
Onix1::showWarningMessageBoxAsync("Invalid Number of Dimensions", "Expected this file to contain two dimensions, but found `"
168+
+ probe->getProperty(Identifier("ndim")).toString().toStdString() + "` instead.");
150169
return false;
151170
}
152171
}
153172
else
173+
{
174+
Onix1::showWarningMessageBoxAsync("No Dimensions Found", "Could not find the number of dimensions in the file.");
154175
return false;
176+
}
155177

156178
if (probe->hasProperty(Identifier("si_units")))
157179
{
158-
if (!probe->getProperty(Identifier("si_units")).equalsWithSameType("um"))
180+
const std::string um = "um";
181+
182+
if (!probe->getProperty(Identifier("si_units")).equalsWithSameType(var(um)))
159183
{
184+
Onix1::showWarningMessageBoxAsync("Unexpected Units Found", "Expected to see units `" + um + "`, but found `"
185+
+ probe->getProperty(Identifier("si_units")).toString().toStdString() + "` instead.");
160186
return false;
161187
}
162188
}
163189
else
190+
{
191+
Onix1::showWarningMessageBoxAsync("No Units Found", "Could not find any units in the file.");
164192
return false;
193+
}
165194

166195
Array<var>* contact_positions = nullptr;
167196

@@ -170,10 +199,17 @@ namespace OnixSourcePlugin
170199
contact_positions = probe->getProperty(Identifier("contact_positions")).getArray();
171200

172201
if (contact_positions->size() != settings->electrodeMetadata.size())
202+
{
203+
Onix1::showWarningMessageBoxAsync("Different Number of Contacts", "Expected to find " + std::to_string(settings->electrodeMetadata.size()) +
204+
" contacts, but found " + std::to_string(contact_positions->size()) + " contacts instead.");
173205
return false;
206+
}
174207
}
175208
else
209+
{
210+
Onix1::showWarningMessageBoxAsync("No Contacts Found", "Could not find any contacts in the file.");
176211
return false;
212+
}
177213

178214
Array<var>* probe_planar_contour = nullptr;
179215

@@ -182,7 +218,9 @@ namespace OnixSourcePlugin
182218
probe_planar_contour = probe->getProperty(Identifier("probe_planar_contour")).getArray();
183219
}
184220
else
185-
return false;
221+
{
222+
LOGD("No probe planar contour found.");
223+
}
186224

187225
Array<var>* device_channel_indices = nullptr;
188226

@@ -191,10 +229,17 @@ namespace OnixSourcePlugin
191229
device_channel_indices = probe->getProperty(Identifier("device_channel_indices")).getArray();
192230

193231
if (device_channel_indices->size() != settings->electrodeMetadata.size())
232+
{
233+
Onix1::showWarningMessageBoxAsync("Wrong Number of Indices Found", "Expected to find " + std::to_string(settings->electrodeMetadata.size()) +
234+
" device channel indices, but found " + std::to_string(device_channel_indices->size()) + " instead.");
194235
return false;
236+
}
195237
}
196238
else
239+
{
240+
Onix1::showWarningMessageBoxAsync("No Indices Found", "No device channel indices found in the file.");
197241
return false;
242+
}
198243

199244
Array<var>* shank_ids = nullptr;
200245

@@ -203,10 +248,17 @@ namespace OnixSourcePlugin
203248
shank_ids = probe->getProperty(Identifier("shank_ids")).getArray();
204249

205250
if (shank_ids->size() != settings->electrodeMetadata.size())
251+
{
252+
Onix1::showWarningMessageBoxAsync("Wrong Number of Shank IDs Found", "Expected to find " + std::to_string(settings->electrodeMetadata.size()) +
253+
" shank IDs, but found " + std::to_string(shank_ids->size()) + " instead.");
206254
return false;
255+
}
207256
}
208257
else
258+
{
259+
Onix1::showWarningMessageBoxAsync("No Shank IDs Found", "No shank IDs found in the file.");
209260
return false;
261+
}
210262

211263
for (int ch = 0; ch < contact_positions->size(); ch++)
212264
{
@@ -218,11 +270,14 @@ namespace OnixSourcePlugin
218270

219271
settings->probeMetadata.probeContour.clear();
220272

221-
for (int i = 0; i < probe_planar_contour->size(); i++)
273+
if (probe_planar_contour != nullptr)
222274
{
223-
Array<var>* point = probe_planar_contour->getReference(i).getArray();
275+
for (int i = 0; i < probe_planar_contour->size(); i++)
276+
{
277+
Array<var>* point = probe_planar_contour->getReference(i).getArray();
224278

225-
settings->probeMetadata.probeContour.emplace_back(std::array<float, 2>{float(point->getReference(0)), float(point->getReference(1))});
279+
settings->probeMetadata.probeContour.emplace_back(std::array<float, 2>{float(point->getReference(0)), float(point->getReference(1))});
280+
}
226281
}
227282

228283
for (int ch = 0; ch < shank_ids->size(); ch++)
@@ -244,7 +299,10 @@ namespace OnixSourcePlugin
244299
settings->selectElectrodes(selectedChannels);
245300
}
246301
else
302+
{
303+
Onix1::showWarningMessageBoxAsync("No Probes Found", "Could not find any probes in the file.");
247304
return false;
305+
}
248306

249307
return true;
250308
}

0 commit comments

Comments
 (0)