bmtool 0.6.9.18__py3-none-any.whl → 0.6.9.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ import h5py
2
+ import numpy as np
3
+ import xarray as xr
4
+ import pandas as pd
5
+ from ..util.util import load_nodes_from_config
6
+
7
+ def load_synapse_report(h5_file_path, config_path):
8
+ """
9
+ Load and process a synapse report from a bmtk simulation into an xarray.
10
+
11
+ Parameters:
12
+ -----------
13
+ h5_file_path : str
14
+ Path to the h5 file containing the synapse report
15
+ config_path : str
16
+ Path to the simulation configuration file
17
+
18
+ Returns:
19
+ --------
20
+ xarray.Dataset
21
+ An xarray containing the synapse report data with proper population labeling
22
+ """
23
+ # Load the h5 file
24
+ with h5py.File(h5_file_path, 'r') as file:
25
+ # Get the report data
26
+ report = file['report']['cortex']
27
+ mapping = report['mapping']
28
+
29
+ # Get the data - shape is (n_timesteps, n_synapses)
30
+ data = report['data'][:]
31
+
32
+ # Get time information
33
+ time_info = mapping['time'][:] # [start_time, end_time, dt]
34
+ start_time = time_info[0]
35
+ end_time = time_info[1]
36
+ dt = time_info[2]
37
+
38
+ # Create time array
39
+ n_steps = data.shape[0]
40
+ time = np.linspace(start_time, start_time + (n_steps-1)*dt, n_steps)
41
+
42
+ # Get mapping information
43
+ src_ids = mapping['src_ids'][:]
44
+ trg_ids = mapping['trg_ids'][:]
45
+ sec_id = mapping['element_ids'][:]
46
+ sec_x = mapping['element_pos'][:]
47
+
48
+ # Load node information
49
+ nodes = load_nodes_from_config(config_path)
50
+ cortex_nodes = nodes['cortex']
51
+
52
+ # Create a mapping from node IDs to population names
53
+ node_to_pop = dict(zip(cortex_nodes.index, cortex_nodes['pop_name']))
54
+
55
+ # Get the number of synapses
56
+ n_synapses = data.shape[1]
57
+
58
+ # Create arrays to hold the source and target populations for each synapse
59
+ source_pops = []
60
+ target_pops = []
61
+ connection_labels = []
62
+
63
+ # Process each synapse
64
+ for i in range(n_synapses):
65
+ src_id = src_ids[i]
66
+ trg_id = trg_ids[i]
67
+
68
+ # Get population names (with fallback for unknown IDs)
69
+ src_pop = node_to_pop.get(src_id, f'unknown_{src_id}')
70
+ trg_pop = node_to_pop.get(trg_id, f'unknown_{trg_id}')
71
+
72
+ source_pops.append(src_pop)
73
+ target_pops.append(trg_pop)
74
+ connection_labels.append(f"{src_pop}->{trg_pop}")
75
+
76
+ # Create xarray dataset
77
+ ds = xr.Dataset(
78
+ data_vars={
79
+ 'synapse_value': (['time', 'synapse'], data)
80
+ },
81
+ coords={
82
+ 'time': time,
83
+ 'synapse': np.arange(n_synapses),
84
+ 'source_pop': ('synapse', source_pops),
85
+ 'target_pop': ('synapse', target_pops),
86
+ 'source_id': ('synapse', src_ids),
87
+ 'target_id': ('synapse', trg_ids),
88
+ 'sec_id': ('synapse', sec_id),
89
+ 'sec_x': ('synapse', sec_x),
90
+ 'connection_label': ('synapse', connection_labels)
91
+ },
92
+ attrs={
93
+ 'description': 'Synapse report data from bmtk simulation'
94
+ }
95
+ )
96
+
97
+ return ds
bmtool/util/util.py CHANGED
@@ -45,7 +45,7 @@ class CellVarsFile(object):
45
45
 
46
46
  import h5py
47
47
  self._h5_handle = h5py.File(filename, 'r')
48
- self._h5_root = self._h5_handle[params['h5_root']] if 'h5_root' in params else self._h5_handle['/']
48
+ self._h5_root = self._h5_handle[params['h5_root']] if 'h5_root' in params else self._h5_handle['/report/cortex']
49
49
  self._var_data = {}
50
50
  self._var_units = {}
51
51
 
@@ -53,6 +53,7 @@ class CellVarsFile(object):
53
53
 
54
54
  # Look for variabl and mapping groups
55
55
  for var_name in self._h5_root.keys():
56
+ print(self._h5_root.keys())
56
57
  hf_grp = self._h5_root[var_name]
57
58
 
58
59
  if var_name == 'data':
@@ -81,7 +82,7 @@ class CellVarsFile(object):
81
82
  if self._mapping is None:
82
83
  raise Exception('could not find /mapping group')
83
84
  else:
84
- gids_ds = self._mapping['gids']
85
+ gids_ds = self._mapping['node_ids']
85
86
  index_pointer_ds = self._mapping['index_pointer']
86
87
  for indx, gid in enumerate(gids_ds):
87
88
  self._gid2data_table[gid] = (index_pointer_ds[indx], index_pointer_ds[indx+1]) # slice(index_pointer_ds[indx], index_pointer_ds[indx+1])
@@ -139,6 +140,7 @@ class CellVarsFile(object):
139
140
  return self._mapping['element_pos'][bounds[0]:bounds[1]]
140
141
 
141
142
  def data(self, gid, var_name=VAR_UNKNOWN,time_window=None, compartments='origin'):
143
+ print(self.variables)
142
144
  if var_name not in self.variables:
143
145
  raise Exception('Unknown variable {}'.format(var_name))
144
146
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bmtool
3
- Version: 0.6.9.18
3
+ Version: 0.6.9.20
4
4
  Summary: BMTool
5
5
  Home-page: https://github.com/cyneuro/bmtool
6
6
  Download-URL:
@@ -10,18 +10,19 @@ bmtool/singlecell.py,sha256=imcdxIzvYVkaOLSGDxYp8WGGssGwXXBCRhzhlqVp7hA,44267
10
10
  bmtool/synapses.py,sha256=6h1V64b_KYHN589NFikHrt_Q3lXPvtEgIpwYFlInWb0,64551
11
11
  bmtool/analysis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  bmtool/analysis/lfp.py,sha256=KTDMzqhkpTI308sWqoJnbHeCMSFScaJCO4u50Kd4FzA,33570
13
+ bmtool/analysis/netcon_reports.py,sha256=WWh12H9gjEZXhI_q7RErgGQ9iSPoTvCUnUjwNGxRwsY,3071
13
14
  bmtool/analysis/spikes.py,sha256=qqJ4zD8xfvSwltlWm_Bhicdngzl6uBqH6Kn5wOMKRc8,11507
14
15
  bmtool/debug/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
16
  bmtool/debug/commands.py,sha256=AwtcR7BUUheM0NxvU1Nu234zCdpobhJv5noX8x5K2vY,583
16
17
  bmtool/debug/debug.py,sha256=xqnkzLiH3s-tS26Y5lZZL62qR2evJdi46Gud-HzxEN4,207
17
18
  bmtool/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
19
  bmtool/util/commands.py,sha256=zJF-fiLk0b8LyzHDfvewUyS7iumOxVnj33IkJDzux4M,64396
19
- bmtool/util/util.py,sha256=00vOAwTVIifCqouBoFoT0lBashl4fCalrk8fhg_Uq4c,56654
20
+ bmtool/util/util.py,sha256=RItVR56bNvuj8uDjqD3RnIDUfunLtVnQmfU-gcM4NNI,56741
20
21
  bmtool/util/neuron/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
22
  bmtool/util/neuron/celltuner.py,sha256=xSRpRN6DhPFz4q5buq_W8UmsD7BbUrkzYBEbKVloYss,87194
22
- bmtool-0.6.9.18.dist-info/licenses/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
23
- bmtool-0.6.9.18.dist-info/METADATA,sha256=spdS9_tiyimQL_IyZT52Osm15hNSWPqa6LLWiVW0j44,2769
24
- bmtool-0.6.9.18.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
25
- bmtool-0.6.9.18.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
26
- bmtool-0.6.9.18.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
27
- bmtool-0.6.9.18.dist-info/RECORD,,
23
+ bmtool-0.6.9.20.dist-info/licenses/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
24
+ bmtool-0.6.9.20.dist-info/METADATA,sha256=5G-e5UTTOhpErogevNUuuvU8IDP6dbPf76zLYbXlAQ4,2769
25
+ bmtool-0.6.9.20.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
26
+ bmtool-0.6.9.20.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
27
+ bmtool-0.6.9.20.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
28
+ bmtool-0.6.9.20.dist-info/RECORD,,