nwb.py
DecimalEncoder
¶
Bases: json.JSONEncoder
Extension of json.JSONEncoder class
Source code in element_array_ephys/export/nwb/nwb.py
30 31 32 33 34 35 36 | |
LFPDataChunkIterator
¶
Bases: GenericDataChunkIterator
DataChunkIterator for LFP data that pulls data one channel at a time.
Used when reading LFP data from the database (as opposed to directly from source files).
Source code in element_array_ephys/export/nwb/nwb.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
__init__(lfp_electrodes_query, chunk_length=10000)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfp_electrodes_query |
datajoint table
|
element_array_ephys.ephys.LFP.Electrode |
required |
chunk_length |
int
|
Optional. Default 10,000. Chunks are blocks of disk space where data are stored contiguously and compressed. |
10000
|
Source code in element_array_ephys/export/nwb/nwb.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
add_electrodes_to_nwb(session_key, nwbfile)
¶
Add electrodes table to NWBFile.
This is needed for any ElectricalSeries, including raw source data and LFP.
Mapping
ephys.InsertionLocation -> ElectrodeGroup.location
probe.Probe::probe -> device.name probe.Probe::probe_comment -> device.description probe.Probe::probe_type -> device.manufacturer
probe.ProbeType.Electrode::electrode -> electrodes["id_in_probe"] probe.ProbeType.Electrode::y_coord -> electrodes["rel_y"] probe.ProbeType.Electrode::x_coord -> electrodes["rel_x"] probe.ProbeType.Electrode::shank -> electrodes["shank"] probe.ProbeType.Electrode::shank_col -> electrodes["shank_col"] probe.ProbeType.Electrode::shank_row -> electrodes["shank_row"]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_key |
dict
|
key from Session table |
required |
nwbfile |
pynwb.NWBFile
|
nwb file |
required |
Source code in element_array_ephys/export/nwb/nwb.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
create_units_table(session_key, nwbfile, paramset_record, name='units', desc='data on spiking units')
¶
Mapping
ephys.CuratedClustering.Unit::unit -> units.id ephys.CuratedClustering.Unit::spike_times -> units["spike_times"] ephys.CuratedClustering.Unit::spike_depths -> units["spike_depths"] ephys.CuratedClustering.Unit::cluster_quality_label -> units["cluster_quality_label"]
ephys.WaveformSet.PeakWaveform::peak_electrode_waveform -> units["waveform_mean"]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_key |
dict
|
key from Session table |
required |
nwbfile |
pynwb.NWBFile
|
nwb file |
required |
paramset_record |
int
|
paramset id from ephys schema |
required |
name |
str
|
Optional table name. Default "units" |
'units'
|
desc |
str
|
Optional table description. Default "data on spiking units" |
'data on spiking units'
|
Source code in element_array_ephys/export/nwb/nwb.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
add_ephys_units_to_nwb(session_key, nwbfile, primary_clustering_paramset_idx=0)
¶
Add spiking data to NWBFile.
In NWB, spiking data is stored in a Units table. The primary Units table is stored at /units. The spiking data in /units is generally the data used in downstream analysis. Only a single Units table can be stored at /units. Other Units tables can be stored in a ProcessingModule at /processing/ecephys/. Any number of Units tables can be stored in this ProcessingModule as long as they have different names, and these Units tables can store intermediate processing steps or alternative curations.
Use primary_clustering_paramset_idx to indicate which clustering is primary. All
others will be stored in /processing/ecephys/.
Mapping
ephys.CuratedClustering.Unit::unit -> units.id ephys.CuratedClustering.Unit::spike_times -> units["spike_times"] ephys.CuratedClustering.Unit::spike_depths -> units["spike_depths"] ephys.CuratedClustering.Unit::cluster_quality_label -> units["cluster_quality_label"]
ephys.WaveformSet.PeakWaveform::peak_electrode_waveform -> units["waveform_mean"]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_key |
dict
|
key from Session table |
required |
nwbfile |
pynwb.NWBFile
|
nwb file |
required |
primary_clustering_paramset_idx |
int
|
Optional. Default 0 |
0
|
Source code in element_array_ephys/export/nwb/nwb.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
get_electrodes_mapping(electrodes)
¶
Create mapping from probe and electrode id to row number in the electrodes table
This is used in the construction of the DynamicTableRegion that indicates what rows of the electrodes table correspond to the data in an ElectricalSeries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
electrodes |
hdmf.common.table.DynamicTable
|
hdmf Dynamic Table |
required |
Returns:
| Type | Description |
|---|---|
dict
|
dict using tuple (electrodes device name, probe id index) as key and index electrode index as value |
Source code in element_array_ephys/export/nwb/nwb.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
gains_helper(gains)
¶
This handles three different cases for gains. See below
Cases
- gains are all 1. In this case, return conversion=1e-6, which applies to all channels and converts from microvolts to volts.
- Gains are all equal, but not 1. In this case, multiply this by 1e-6 to apply this gain to all channels and convert units to volts.
- Gains are different for different channels. In this case use the
channel_conversionfield in addition to theconversionfield so that each channel can be converted to volts using its own individual gain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gains |
np.ndarray
|
array of gains |
required |
Returns:
| Type | Description |
|---|---|
dict
|
dict with conversion float as key and channel_conversion np.ndarray value |
Source code in element_array_ephys/export/nwb/nwb.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
add_ephys_recording_to_nwb(session_key, ephys_root_data_dir, nwbfile, end_frame=None)
¶
Read voltage data from source files and iteratively transfer to the NWB file.
Automatically applies lossless compression to the data, so the final file might be smaller than the original, without data loss. Currently supports Neuropixels data acquired with SpikeGLX or Open Ephys, and relies on SpikeInterface to read the data.
Mapping
source data -> acquisition["ElectricalSeries"]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_key |
dict
|
key from Session table |
required |
ephys_root_data_dir |
str
|
root data directory |
required |
nwbfile |
NWBFile
|
nwb file |
required |
end_frame |
int
|
Optional limit on frames for small test conversions |
None
|
Source code in element_array_ephys/export/nwb/nwb.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
add_ephys_lfp_from_dj_to_nwb(session_key, nwbfile)
¶
Read LFP data from the data in element-array-ephys
Mapping
ephys.LFP.Electrode::lfp -> processing["ecephys"].lfp.electrical_series[ "ElectricalSeries{insertion_number}" ].data ephys.LFP::lfp_time_stamps -> processing["ecephys"].lfp.electrical_series[ "ElectricalSeries{insertion_number}" ].timestamps
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_key |
dict
|
key from Session table |
required |
nwbfile |
NWBFile
|
nwb file |
required |
Source code in element_array_ephys/export/nwb/nwb.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
add_ephys_lfp_from_source_to_nwb(session_key, ephys_root_data_dir, nwbfile, end_frame=None)
¶
Read the LFP data from the source file. Currently, only works for SpikeGLX data.
ephys.EphysRecording::recording_datetime -> acquisition
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_key |
dict
|
key from Session table |
required |
nwbfile |
NWBFile
|
nwb file |
required |
end_frame |
int
|
Optional limit on frames for small test conversions |
None
|
Source code in element_array_ephys/export/nwb/nwb.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
ecephys_session_to_nwb(session_key, raw=True, spikes=True, lfp='source', end_frame=None, lab_key=None, project_key=None, protocol_key=None, nwbfile_kwargs=None)
¶
Main function for converting ephys data to NWB
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_key |
dict
|
key from Session table |
required |
raw |
bool
|
Optional. Default True. Include the raw data from source. SpikeGLX & OpenEphys are supported |
True
|
spikes |
bool
|
Optional. Default True. Whether to include CuratedClustering |
True
|
lfp |
str
|
One of the following. "dj", read LFP data from ephys.LFP. "source", read LFP data from source (SpikeGLX supported). False, do not convert LFP. |
'source'
|
end_frame |
int
|
Optional limit on frames for small test conversions. |
None
|
lab_key |
dict
|
Optional key to add metadata from other Element Lab. |
None
|
project_key |
dict
|
Optional key to add metadata from other Element Lab. |
None
|
protocol_key |
dict
|
Optional key to add metadata from other Element Lab. |
None
|
nwbfile_kwargs |
dict
|
Optional. If Element Session is not used, this argument is required and must be a dictionary containing 'session_description' (str), 'identifier' (str), and 'session_start_time' (datetime), the required minimal data for instantiating an NWBFile object. If element-session is being used, this argument can optionally be used to overwrite NWBFile fields. |
None
|
Source code in element_array_ephys/export/nwb/nwb.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
write_nwb(nwbfile, fname, check_read=True)
¶
Export NWBFile
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nwbfile |
NWBFile
|
nwb file |
required |
fname |
str
|
Absolute path including |
required |
check_read |
bool
|
If True, PyNWB will try to read the produced NWB file and ensure that it can be read. |
True
|
Source code in element_array_ephys/export/nwb/nwb.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |