epiphyte.data ¶
mock_data_inits ¶
Seed spike shapes for randomized mock data generation.
These are used in epiphyte.data.mock_data_utils
to generate mock spike timeseries data.
Notes:
spike_shape_u
is the mean spike shape (in microvolts) for a spike with 64 samples.spike_shape_sd
is the standard deviation of the spike shape (in microvolts) for a spike with 64 samples.
mock_data_utils ¶
Mock neural-data generator and file writer.
This module contains GenerateData, which synthesizes spike trains, LFP-like signals, channel metadata, event streams, DAQ logs, and watchlogs, and for saves them to the on-disk layout expected by Epiphyte. Constants such as output roots (e.g., PATH_TO_DATA, PATH_TO_LABELS), annotation metadata (e.g., annotators), and spike-shape parameters are read from epiphyte.database.config and .mock_data_inits.
Example
from epiphyte.data.mock_data_utils import GenerateData
gen = GenerateData(patient_id=1, session_nr=1, stimulus_len=83.33)
gen.summarize()
gen.save_session_info()
gen.save_spike_trains()
gen.save_lfp_data()
gen.save_channel_names()
gen.save_events()
gen.save_daq_log()
gen.save_watchlog_with_artifacts()
Running the module as a script executes run_data_generation(), which creates a small demo dataset for a few patients/sessions.
Outputs & directory layout:
Created under:
{PATH_TO_DATA}/patient_data/{patient_id}/session_{session_nr}/
- session_info.npy
Dict with keys: patient_id, session_nr, date, time
- ChannelNames.txt
One ".ncs" channel name per line
- spiking_data/CSC{channel}_{MU|SU}{idx}.npy
Dict with "spike_times" (ms, Unix epoch) and "spike_amps" (waveform arrays)
- lfp_data/CSC1_lfp.npy
Dict with "ts" (ms, Unix epoch) and "samples" (1 kHz sine)
- event_file/Events.npy
Rows of (timestamp, code); codes tile over [1, 2, 4, 8, 16, 32, 64, 128]
- daq_files/timedDAQ-log-<YYYY-mm-dd_HH-MM-SS>.log
Tabular DAQ log
- watchlogs/ffplay-watchlog-<YYYY-mm-dd_HH-MM-SS>.log
PTS/CPU-time log with pauses/skips
Annotation stubs are written to:
{PATH_TO_LABELS}/
as simple *.npy arrays with on/off segments.
Conventions
- Time bases:
- Spike times / LFP timestamps: milliseconds since Unix epoch
- stim_on_time / stim_off_time: microseconds since Unix epoch
- Watchlog PTS increments: ~0.04 s per frame
- Sampling: LFP synthesized at 1 kHz
- Randomness: Data are randomized per run (no fixed seed by default)
Public API
- GenerateData: main generator with save_* methods for each artifact
- run_data_generation(): convenience entry point to populate a demo dataset
Notes
- Relies on configuration constants from epiphyte.database.config and waveform shape parameters from .mock_data_inits.
- Use GenerateData.summarize() to quickly inspect randomized session settings.
- For reproducible outputs, set seeds in both random and numpy.random before instantiation.
GenerateData ¶
Generate mock neural data and related metadata.
Attributes:
Name | Type | Description |
---|---|---|
patient_id |
int
|
Integer identifier for the mock patient. |
session_nr |
int
|
Session number for this recording. |
stimulus_len |
float
|
Stimulus length in minutes. |
nr_channels |
int
|
Number of channels simulated. |
nr_units |
int
|
Number of units across all channels. |
nr_channels_per_region |
int
|
Channels per brain region label. |
unit_types |
enum
|
Allowed unit type codes (e.g., |
brain_regions |
List[str]
|
Region codes used to synthesize channel names. |
rec_length |
int
|
Recording length in milliseconds. |
rectime_on |
int
|
Start time (unix epoch ms) for recording. |
rectime_off |
int
|
End time (unix epoch ms) for recording. |
spike_times |
List[ndarray]
|
Generated spike time arrays per unit. |
spike_amps |
List[ndarray]
|
Generated spike amplitude arrays per unit. |
channel_dict |
dict
|
Mapping of channel index to list of unit types. |
sampling_rate |
int
|
LFP sampling rate (Hz) used in mock signal. |
len_context_files |
int
|
Number of entries for events/DAQ logs. |
datetime |
str
|
ISO-like timestamp used in filenames. |
signal_tile |
ndarray
|
Bit-pattern tile used to synthesize event codes. |
stim_on_time |
int
|
Estimated stimulus onset (microseconds). |
stim_off_time |
int
|
Estimated stimulus offset (microseconds). |
Source code in epiphyte/data/mock_data_utils.py
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 171 172 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 250 251 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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 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 438 439 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 490 491 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 565 566 567 568 569 570 571 572 573 574 575 576 |
|
summarize ¶
summarize()
Print key randomized parameters for quick inspection.
Source code in epiphyte/data/mock_data_utils.py
144 145 146 147 148 |
|
format_save_dir ¶
format_save_dir(subdir=None)
Build and ensure the output directory exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subdir
|
str | None
|
Optional subdirectory under the session path. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Path |
Path
|
Absolute path to the created directory:
|
Source code in epiphyte/data/mock_data_utils.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
generate_spike_trains ¶
generate_spike_trains()
Generate mock spike trains and amplitudes for all units.
Returns:
Type | Description |
---|---|
List[ndarray]
|
Tuple[List[np.ndarray], List[np.ndarray]]: |
List[ndarray]
|
|
Tuple[List[ndarray], List[ndarray]]
|
sorted |
Tuple[List[ndarray], List[ndarray]]
|
|
Tuple[List[ndarray], List[ndarray]]
|
|
Notes
The number of spikes per unit is randomized per unit.
Source code in epiphyte/data/mock_data_utils.py
171 172 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 |
|
generate_channelwise_unit_distribution ¶
generate_channelwise_unit_distribution()
Distribute units across channels and assign unit types.
Returns:
Type | Description |
---|---|
dict[int, List[str]]
|
dict[int, List[str]]: Mapping from channel index (1-based) to a list |
dict[int, List[str]]
|
of unit-type codes (e.g., |
Source code in epiphyte/data/mock_data_utils.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
generate_lfp_channel ¶
generate_lfp_channel()
Generate a simple sine-wave LFP-like channel.
Returns:
Type | Description |
---|---|
ndarray
|
Tuple[np.ndarray, np.ndarray]: |
ndarray
|
|
Tuple[ndarray, ndarray]
|
array representing an 8 Hz sine wave at 1 kHz. |
Source code in epiphyte/data/mock_data_utils.py
218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
generate_channel_list ¶
generate_channel_list()
Create channel names like LA1
, LA2
, ..., RPCH8
.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of channel name strings. |
Source code in epiphyte/data/mock_data_utils.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
save_spike_trains ¶
save_spike_trains()
Save generated spike trains and amplitudes as .npy
files.
Writes
spiking_data/CSC{channel}_{TYPE}{idx}.npy
under the session
directory. Each file contains a dict with keys:
"spike_times"
: Unix epoch ms (1D array)"spike_amps"
: waveform amplitudes, shape(n_spikes, 64)
Source code in epiphyte/data/mock_data_utils.py
247 248 249 250 251 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 |
|
save_lfp_data ¶
save_lfp_data()
Generate and save the LFP channel as CSC1_lfp.npy
.
Writes
lfp_data/CSC1_lfp.npy
containing a dict with:
"ts"
: timestamps (Unix epoch ms)"samples"
: LFP-like samples at 1 kHz
Notes
Only one LFP channel is generated due to the size of each channel. A single channel suffices for demonstration purposes. If you include field potential data, consider using a large-storage backend.
Source code in epiphyte/data/mock_data_utils.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
save_channel_names ¶
save_channel_names()
Save ChannelNames.txt
listing channel names one per line.
Writes
ChannelNames.txt
in the session root. Each line ends with
.ncs
(e.g., LA1.ncs
).
Source code in epiphyte/data/mock_data_utils.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
save_session_info ¶
save_session_info()
Save a session_info.npy
dictionary.
Writes
session_info.npy
containing a dict with
patient_id
, session_nr
, date
, and time
(UTC).
Source code in epiphyte/data/mock_data_utils.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
generate_pings ¶
generate_pings()
Create a repeating event-code tile.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: 1D integer array of length |
ndarray
|
elements tiled from |
Source code in epiphyte/data/mock_data_utils.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
generate_events ¶
generate_events()
Generate mock event timestamps and (timestamp, code) matrix.
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]:
- |
Source code in epiphyte/data/mock_data_utils.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
save_events ¶
save_events()
Save generated events to event_file/Events.npy
.
Source code in epiphyte/data/mock_data_utils.py
372 373 374 375 376 377 378 379 380 381 |
|
generate_stimulus_onsets ¶
generate_stimulus_onsets()
Generate approximate onset and offset timestamps for the stimulus.
Returns:
Type | Description |
---|---|
Tuple[int, int]
|
Tuple[int, int]: |
Source code in epiphyte/data/mock_data_utils.py
383 384 385 386 387 388 389 390 391 392 393 394 395 |
|
seed_and_interval ¶
seed_and_interval()
Compute DAQ interval and initial seed time for log synthesis.
Returns:
Type | Description |
---|---|
Tuple[int, int]
|
Tuple[int, int]: |
Source code in epiphyte/data/mock_data_utils.py
397 398 399 400 401 402 403 404 405 406 |
|
generate_daq_log ¶
generate_daq_log()
Generate DAQ log entries.
Each entry is a tuple (code, idx, pre_us, post_us)
.
Returns:
Type | Description |
---|---|
List[Tuple[int, int, int, int]]
|
List[Tuple[int, int, int, int]]: DAQ log with one row per event. |
Source code in epiphyte/data/mock_data_utils.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
save_daq_log ¶
save_daq_log()
Save the generated DAQ log as a text file in daq_files
.
Source code in epiphyte/data/mock_data_utils.py
430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
generate_perfect_watchlog ¶
generate_perfect_watchlog()
Generate watchlog without pauses or skips.
Returns:
Type | Description |
---|---|
Tuple[int, List[float], List[int]]
|
Tuple[int, List[float], List[int]]:
- |
Source code in epiphyte/data/mock_data_utils.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
|
save_perfect_watchlog ¶
save_perfect_watchlog()
Write a perfect (no pauses/skips) watchlog to watchlogs
.
Source code in epiphyte/data/mock_data_utils.py
466 467 468 469 470 471 472 473 474 475 476 477 478 |
|
make_pauses_and_skips ¶
make_pauses_and_skips()
Generate a watchlog with pauses and skips.
Returns:
Type | Description |
---|---|
Tuple[int, List[float], List[int], List[int]]
|
Tuple[int, List[float], List[int], List[int]]:
- |
Notes
Pause lengths and skip magnitudes are randomized. PTS values are clamped to the movie duration and non-negative.
Source code in epiphyte/data/mock_data_utils.py
480 481 482 483 484 485 486 487 488 489 490 491 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 |
|
save_watchlog_with_artifacts ¶
save_watchlog_with_artifacts()
Save a watchlog including pauses and skips to watchlogs
dir.
Source code in epiphyte/data/mock_data_utils.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
|
run_data_generation ¶
run_data_generation()
Populate a small mock dataset and minimal annotation arrays.
Iterates through hard-coded patients
and sessions
and, for each
(patient, session) pair, uses :class:GenerateData
to synthesize and write:
session info, spike trains, an LFP-like channel, channel-name list, events,
a DAQ log, and a watchlog with artifacts. After data generation, it also
writes a few toy annotation arrays into PATH_TO_LABELS
.
Steps
- For each patient/session:
- Print a short summary (:meth:
GenerateData.summarize
). - Save
session_info.npy
. - Save spike trains (
spiking_data/*.npy
). - Save LFP data (
lfp_data/CSC1_lfp.npy
). - Save channel names (
ChannelNames.txt
). - Save events (
event_file/Events.npy
). - Save DAQ log (
daq_files/timedDAQ-log-<timestamp>.log
). - Save watchlog with pauses/skips (
watchlogs/ffplay-watchlog-<timestamp>.log
). - Create three example
*.npy
annotation files underPATH_TO_LABELS
, with filenames including a randomannotator_id
and the current date.
Writes
- Under
{PATH_TO_DATA}/patient_data/{patient_id}/session_{session_nr}/
:session_info.npy
ChannelNames.txt
spiking_data/CSC{channel}_{MU|SU}{idx}.npy
lfp_data/CSC1_lfp.npy
event_file/Events.npy
daq_files/timedDAQ-log-<YYYY-mm-dd_HH-MM-SS>.log
watchlogs/ffplay-watchlog-<YYYY-mm-dd_HH-MM-SS>.log
- Under
{PATH_TO_LABELS}/
:1_character1_<annotator_id>_<YYYYMMDD>_character.npy
2_character2_<annotator_id>_<YYYYMMDD>_character.npy
3_location1_<annotator_id>_<YYYYMMDD>_character.npy
Notes
- Relies on configuration/constants imported elsewhere:
PATH_TO_DATA
,PATH_TO_LABELS
, andannotators
. - Data are randomized on each run; for reproducibility, set seeds in both
random
andnumpy.random
before calling. - Time bases follow the conventions used in :class:
GenerateData
(e.g., spike/event timestamps in ms, some logs in µs).
Returns:
Type | Description |
---|---|
None
|
None |
Example
run_data_generation()
Source code in epiphyte/data/mock_data_utils.py
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 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
|