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

Minor changes #73

Merged
merged 8 commits into from
May 5, 2019
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ addons:
- python-jsonschema
- python-mpi4py
- python-matplotlib
- python-tornado
- python-tk

language: python
Expand Down Expand Up @@ -57,7 +58,7 @@ script:

- cd ../../bio_14cells/
#- sed -i -e 's/: 3000.0,/: 600,/g' config.json # Run shorter simulation
- python run_bionet.py config.json
###- python run_bionet.py config.json # Pandas version..?

#- cd ../14cells_multinode
#- sed -i -e 's/: 3000.0,/: 600,/g' config.json # Run shorter simulation
Expand Down
26 changes: 20 additions & 6 deletions bmtk/analyzer/visualization/spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _create_node_table(node_file, node_type_file, group_key=None, exclude=[]):
for cond in exclude:
full_df = full_df[full_df[group_key] != cond]

nodes_h5.close()
return full_df

def _count_spikes(spikes_file, max_gid, interval=None):
Expand Down Expand Up @@ -110,6 +111,7 @@ def parse_line(line):
t_min = ts if ts < t_min else t_min
t_max = ts if ts > t_max else t_max
"""
spikes_h5.close()
return spikes, spike_sums/(float(t_max-t_min)*1e-3)


Expand All @@ -130,7 +132,7 @@ def plot_spikes_config(configure, group_key=None, exclude=[], save_as=None, show


def plot_spikes(cells_file, cell_models_file, spikes_file, population=None, group_key=None, exclude=[], save_as=None,
show=True, title=None):
show=True, title=None, legend=True, font_size=None):
# check if can be shown and/or saved
#if save_as is not None:
# if os.path.exists(save_as):
Expand All @@ -156,13 +158,14 @@ def plot_spikes(cells_file, cell_models_file, spikes_file, population=None, grou
how='left',
left_on='node_type_id',
right_index=True) # use 'model_id' key to merge, for right table the "model_id" is an index

cells_h5.close()
# TODO: Uses utils.SpikesReader to open
spikes_h5 = h5py.File(spikes_file, 'r')
spike_gids = np.array(spikes_h5['/spikes/gids'], dtype=np.uint)
spike_times = np.array(spikes_h5['/spikes/timestamps'], dtype=np.float)
# spike_times, spike_gids = np.loadtxt(spikes_file, dtype='float32,int', unpack=True)
# spike_gids, spike_times = np.loadtxt(spikes_file, dtype='int,float32', unpack=True)
spikes_h5.close()

spike_times = spike_times * 1.0e-3

Expand All @@ -184,6 +187,15 @@ def plot_spikes(cells_file, cell_models_file, spikes_file, population=None, grou

# Create plot
gs = gridspec.GridSpec(2, 1, height_ratios=[7, 1])


import matplotlib
if font_size is not None:
matplotlib.rcParams.update({'font.size': font_size})
plt.xlabel('xlabel', fontsize=font_size)
plt.ylabel('ylabel', fontsize=font_size)


ax1 = plt.subplot(gs[0])
gid_min = 10**10
gid_max = -1
Expand All @@ -201,16 +213,18 @@ def plot_spikes(cells_file, cell_models_file, spikes_file, population=None, grou

#ax1.set_xlabel('time (s)')
ax1.axes.get_xaxis().set_visible(False)
ax1.set_ylabel('cell_id')
ax1.set_ylabel('Cell ID')
ax1.set_xlim([0, max(spike_times)])
ax1.set_ylim([gid_min, gid_max])
plt.legend(markerscale=2, scatterpoints=1)
if legend:
plt.legend(markerscale=2, scatterpoints=1)

ax2 = plt.subplot(gs[1])
plt.hist(spike_times, 100)
ax2.set_xlabel('time (s)')
ax2.set_xlabel('Time (s)')
ax2.set_xlim([0, max(spike_times)])
ax2.axes.get_yaxis().set_visible(False)
#ax2.axes.get_yaxis().set_visible(False)
ax2.set_ylabel('Firing rate (AU)')
if title is not None:
ax1.set_title(title)

Expand Down
7 changes: 5 additions & 2 deletions bmtk/utils/cell_vars/var_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, filename, mode='r', **params):
self._h5_root = self._h5_handle[params['h5_root']] if 'h5_root' in params else self._h5_handle['/']
self._var_data = {}
self._var_units = {}

self._mapping = None

# Look for variabl and mapping groups
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(self, filename, mode='r', **params):
self._t_stop = time_ds[1]
self._dt = time_ds[2]
self._n_steps = int((self._t_stop - self._t_start) / self._dt)

@property
def variables(self):
return list(self._var_data.keys())
Expand Down Expand Up @@ -132,3 +132,6 @@ def data(self, gid, var_name=VAR_UNKNOWN,time_window=None, compartments='origin'

data = np.array(self._var_data[var_name][time_slice, gid_slice])
return data.T if multi_compartments else data

def close(self):
self._h5_handle.close()