Ejemplo n.º 1
0
def compare_data(leftfiles, rightfiles, leftheader, rightheader):
    """Compare two simulations side by side"""
    figs = []
    axeslist = []
    psthaxlist = []
    for left, right in zip(leftfiles, rightfiles):
        fig, axes = plt.subplots(nrows=6, ncols=2, sharey='row')
        psth_axes = []
        
        for ii, fname in enumerate([left, right]):
            fpath = os.path.join(datadir, fname)                         
            with h5.File(fpath, 'r') as fd:
                config = nda.load_config(fd)
                bins = np.arange(0, nda.get_simtime(fd)+0.5, 50.0)
                try:
                    pns = list(fd[nda.pn_st_path].keys())
                except KeyError:
                    print('Could not find PNs in', fname)
                    return figs, axeslist, psthaxlist
                pns = sorted(pns, key=lambda x: int(x.split('_')[-1]))
                pn_st, pn_y = nda.get_event_times(fd[nda.pn_st_path], pns)
                axes[0, ii].plot(np.concatenate(pn_st), np.concatenate(pn_y), ',')
                psth_ax = axes[0, ii].twinx()
                psth_axes.append(psth_ax)
                plot_population_psth(psth_ax, pn_st, config['pn']['number'], bins)
                lines, kc_st, kc_y = plot_kc_spikes_by_cluster(axes[1, ii], fd, 'LCA')
                plot_population_psth(axes[2, ii], kc_st, len(kc_st), bins, rate_sym='b^', cell_sym='rv')
                stiminfo = nda.get_stimtime(fd)
                stimend = stiminfo['onset'] + stiminfo['duration'] + stiminfo['offdur']
                rates = [len(st[(st > stiminfo['onset']) & (st < stimend)]) * 1e3 
                         / (stimend - stiminfo['onset']) for st in kc_st]
                print(rates[:5])
                axes[3, ii].hist(rates, bins=np.arange(21))
                axes[3, ii].set_xlabel('Firing rate')
                plot_kc_vm(axes[4, ii], fd, 'LCA', 5)
                plot_ggn_vm(axes[5, ii], fd,
                                   fd['/data/uniform/ggn_output/GGN_output_Vm'],
                                   'LCA', 5, color='r')
                plot_ggn_vm(axes[5, ii], fd,
                                   fd['/data/uniform/ggn_basal/GGN_basal_Vm'],
                                   'basal', 5, color='g')
                axes[5, ii].set_ylim((-53, -35))
                axes[0, ii].set_title('{}\nFAKE? {}'.format(fname, nda.load_config(fd)['kc']['fake_clusters']))
        time_axes = [axes[ii, jj] for ii in [0, 1, 2, 4, 5] for jj in [0, 1]]
        for ax in time_axes[:-1]:
            ax.set_xticks([])
        axes[0, 0].get_shared_x_axes().join(*time_axes)
        axes[2, 0].get_shared_x_axes().join(*axes[2, :])
        # psth_axes[0].get_shared_y_axes().join(*psth_axes)
        psth_axes[0].autoscale()
        # axes[-1, -1].autoscale()
        fig.text(0.1, 0.95, leftheader, ha='left', va='bottom')
        fig.text(0.6, 0.95, rightheader, ha='left', va='bottom')
        fig.set_size_inches(15, 10)
        # fig.tight_layout()
        figs.append(fig)
        axeslist.append(axes)
        psthaxlist.append(psth_axes)
    return figs, axeslist, psthaxlist
# datadir = 'Z:/Subhasis/ggn_model_data/olfactory_network'
# datadir = '/data/rays3/ggn/olfactory_network/'
datadir = 'D:/biowulf_stage/olfactory_network'

#** jid_sc for only shifting PN, constant GGN->KC inhibition - but this did not
# have PN-KC clustered conn

jid_sc = '22087969'
fname_sc = nda.find_h5_file(jid_sc, datadir)
fd_sc = h5.File(fname_sc, 'r')
print('shifting PN, jid: {}, spiking KCs {}'.format(
    jid_sc, len(nda.get_spiking_kcs(fd_sc))))
print(yaml.dump(nda.load_config(fd_sc), default_style=''))
print('-' * 20)

stiminfo = nda.get_stimtime(fd_sc)
pn_st = []
pn_id = []
for pn in fd_sc[nda.pn_st_path].values():
    pn_st.append(pn[:])
    pn_id.append([int(pn.name.rpartition('_')[-1])] * len(pn))

kc_st = []
kc_id = []
for kc, st in fd_sc[nda.kc_st_path].items():
    kc_st.append(st[:])
    kc_id.append([int(kc)] * len(st))

fig, ax = plt.subplots(nrows=3, sharex='all')

ax[0].plot(np.concatenate(pn_st[::10]),
print(yaml.dump(nda.load_config(fd_lognorm), default_style=''))
print('-' * 20)
#** jid_constant for only shifting PN, constant GGN->KC inhibition - but this did not
# have PN-KC clustered conn
# jid_constant = '16562835'   # Thu Mar 14 13:49:49 EDT 2019 - this file was somehow lost from backup.
# jid_constant = '22295183'   # Redid simulations with constant synaptic conductances on 2019-03-13 PN-KC gmax=3 pS, spiking KCs 1707
jid_constant = '24211204'  # The jid '22295183' in fig 5 had off-time 0.2 s, this one has 0.5s
fname_constant = nda.find_h5_file(jid_constant, datadir)
fd_constant = h5.File(fname_constant, 'r')
print('shifting PN, jid: {}, spiking KCs {}'.format(
    jid_constant, len(nda.get_spiking_kcs(fd_constant))))
print(yaml.dump(nda.load_config(fd_constant), default_style=''))
print('-' * 20)

#* plot PN activity from jid_lognorm
stiminfo = nda.get_stimtime(fd_lognorm)
stiminfo_const = nda.get_stimtime(fd_constant)
pn_st = []
pn_id = []
for pn in fd_lognorm[nda.pn_st_path].values():
    pn_st.append(pn.value)
    pn_id.append([int(pn.name.rpartition('_')[-1])] * len(pn))
ax0.plot(np.concatenate(pn_st[::10]),
         np.concatenate(pn_id[::10]),
         color='#fdb863',
         ls='',
         marker='s',
         ms=1)
ax0.xaxis.set_visible(False)
ax0.yaxis.set_visible(False)