Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONATA update: expect synapse_replay files as h5 #171

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions bluecellulab/circuit/simulation_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pathlib import Path
from typing import Optional, Protocol

import h5py
import pandas as pd

from bluecellulab.circuit.config import SimulationConfig, SonataSimulationConfig
Expand Down Expand Up @@ -172,12 +173,14 @@ def get_spikes(self) -> dict[CellId, np.ndarray]:

def get_synapse_replay_spikes(f_name: str) -> dict:
"""Read the .dat file containing the spike replays."""
data = np.genfromtxt(f_name, skip_header=1)
spikes = pd.DataFrame(data=data, columns=["t", "node_id"]).astype({"node_id": int})
# subtract 1 from all node_ids to make them 0-based
# source: https://sonata-extension.readthedocs.io/
# en/latest/blueconfig-projection-example.html#dat-spike-files
spikes["node_id"] -= 1
with h5py.File(f_name, 'r') as f:
# Access the timestamps and node_ids datasets
timestamps = f['/spikes/All/timestamps'][:]
node_ids = f['/spikes/All/node_ids'][:]

spikes = pd.DataFrame(data={'t': timestamps, 'node_id': node_ids})
spikes = spikes.astype({"node_id": int})

if (spikes["t"] < 0).any():
logger.warning("Found negative spike times... Clipping them to 0")
spikes["t"].clip(lower=0., inplace=True)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies = [
"pydantic>=2.5.2,<3.0.0",
"typing-extensions>=4.8.0",
"networkx>=3.1",
"h5py>=3.11.0",
]
requires-python = ">=3.8"

Expand Down
4 changes: 0 additions & 4 deletions tests/data/synapse_replay_file/spikes.dat

This file was deleted.

Binary file added tests/data/synapse_replay_file/spikes.h5
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"delay": 0.0,
"duration": 300.0,
"module": "synapse_replay",
"spike_file": "tests/examples/sonata_unit_test_sims/synapse_replay/synapse_replay.dat"
"spike_file": "tests/examples/sonata_unit_test_sims/synapse_replay/synapse_replay.h5"
}
},
"connection_overrides": [
Expand Down

This file was deleted.

Binary file not shown.
2 changes: 1 addition & 1 deletion tests/test_circuit/test_simulation_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_get_spikes(self):
def test_get_synapse_replay_spikes():
""".Test get_synapse_replay_spikes."""
res = get_synapse_replay_spikes(
parent_dir / "data" / "synapse_replay_file" / "spikes.dat"
parent_dir / "data" / "synapse_replay_file" / "spikes.h5"
)
assert set(res.keys()) == {5382}
assert res[5382].tolist() == [1500.0, 2000.0, 2500.0]
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ deps =
pytest-timeout>=2.1.0
pytest-xdist>=3.3.1 # multiprocessing
pytest-forked>=1.6.0 # isolation
libsonata<=0.1.25 # 0.1.26 supports h5 synapse_replay only, some of our tests atm use .dat
download = true
allowlist_externals =
make
Expand Down