示例#1
0
def pdipole_with_hist(f_dpl, f_spk, dfig, f_param, key_types, plot_dict):
  """ this function has not been converted to use the Dipole() class yet
  """
  # dpl is an obj of Dipole() class
  dpl = Dipole(f_dpl)
  dpl.baseline_renormalize(f_param)
  dpl.convert_fAm_to_nAm()
  # split to find file prefix
  file_prefix = f_dpl.split('/')[-1].split('.')[0]
  # grabbing the p_dict from the f_param
  _, p_dict = paramrw.read(f_param)
  # get xmin and xmax from the plot_dict
  if plot_dict['xmin'] is None:
    xmin = 0.
  else:
    xmin = plot_dict['xmin']
  if plot_dict['xmax'] is None:
    xmax = p_dict['tstop']
  else:
    xmax = plot_dict['xmax']
  # truncate tvec and dpl data using logical indexing
  t_range = dpl.t[(dpl.t >= xmin) & (dpl.t <= xmax)]
  dpl_range = dpl.dpl['agg'][(dpl.t >= xmin) & (dpl.t <= xmax)]
  # Plotting
  f = ac.FigDplWithHist()
  # dipole
  f.ax['dipole'].plot(t_range, dpl_range)
  # set new xlim based on dipole plot
  xlim_new = f.ax['dipole'].get_xlim()
  # Get extinput data and account for delays
  extinputs = spikefn.ExtInputs(f_spk, f_param)
  extinputs.add_delay_times()
  # set number of bins (150 bins per 1000ms)
  bins = ceil(150. * (xlim_new[1] - xlim_new[0]) / 1000.) # bins needs to be an int
  # plot histograms
  hist = {}
  hist['feed_prox'] = extinputs.plot_hist(f.ax['feed_prox'], 'prox', dpl.t, bins, xlim_new, color='red')
  hist['feed_dist'] = extinputs.plot_hist(f.ax['feed_dist'], 'dist', dpl.t, bins, xlim_new, color='green')
  # Invert dist histogram
  f.ax['feed_dist'].invert_yaxis()
  # for now, set the xlim for the other one, force it!
  f.ax['dipole'].set_xlim(xlim_new)
  f.ax['feed_prox'].set_xlim(xlim_new)
  f.ax['feed_dist'].set_xlim(xlim_new)
  # set hist axis properties
  f.set_hist_props(hist)
  # Add legend to histogram
  for key in f.ax.keys():
    if 'feed' in key:
      f.ax[key].legend()
  # force xlim on histograms
  f.ax['feed_prox'].set_xlim((xmin, xmax))
  f.ax['feed_dist'].set_xlim((xmin, xmax))
  title_str = ac.create_title(p_dict, key_types)
  f.f.suptitle(title_str)
  fig_name = os.path.join(dfig, file_prefix+'.png')
  plt.savefig(fig_name)
  f.close()
示例#2
0
def pfreqpwr_with_hist(file_name, freqpwr_result, f_spk, gid_dict, p_dict,
                       key_types):
    f = ac.FigFreqpwrWithHist()
    f.ax['hist'].hold(True)

    xmin = 50.
    xmax = p_dict['tstop']

    f.ax['freqpwr'].plot(freqpwr_result['freq'], freqpwr_result['avgpwr'])

    # grab alpha feed data. spikes_from_file() from spikefn.py
    s_dict = spikefn.spikes_from_file(gid_dict, f_spk)

    # check for existance of alpha feed keys in s_dict.
    s_dict = spikefn.alpha_feed_verify(s_dict, p_dict)

    # Account for possible delays
    s_dict = spikefn.add_delay_times(s_dict, p_dict)

    # set number of bins (150 bins/1000ms)
    bins = 150. * (xmax - xmin) / 1000.
    hist_data = []

    # Proximal feed
    hist_data.extend(f.ax['hist'].hist(s_dict['alpha_feed_prox'].spike_list,
                                       bins,
                                       range=[xmin, xmax],
                                       color='red',
                                       label='Proximal feed')[0])

    # Distal feed
    hist_data.extend(f.ax['hist'].hist(s_dict['alpha_feed_dist'].spike_list,
                                       bins,
                                       range=[xmin, xmax],
                                       color='green',
                                       label='Distal feed')[0])

    # set hist axis props
    f.set_hist_props(hist_data)

    # axis labels
    f.ax['freqpwr'].set_xlabel('freq (Hz)')
    f.ax['freqpwr'].set_ylabel('power')
    f.ax['hist'].set_xlabel('time (ms)')
    f.ax['hist'].set_ylabel('# spikes')

    # create title
    title_str = ac.create_title(p_dict, key_types)
    f.f.suptitle(title_str)
    # title_str = [key + ': %2.1f' % p_dict[key] for key in key_types['dynamic_keys']]

    f.savepng(file_name)
    f.close()
示例#3
0
def pdipole(f_dpl, dfig, plot_dict, f_param=None, key_types={}):
    """ single dipole file combination (incl. param file)
        this should be done with an axis input too
        two separate functions, a pdipole kernel function and a specific function for this simple plot
    """
    # dpl is an obj of Dipole() class
    dpl = Dipole(f_dpl)

    if f_param:
        dpl.baseline_renormalize(f_param)

    dpl.convert_fAm_to_nAm()

    # split to find file prefix
    file_prefix = f_dpl.split('/')[-1].split('.')[0]


    # parse xlim from plot_dict
    if plot_dict['xlim'] is None:
        xmin = dpl.t[0]
        xmax = dpl.t[-1]

    else:
        xmin, xmax = plot_dict['xlim']

        if xmin < 0.:
            xmin = 0.

        if xmax < 0.:
            xmax = self.f[-1]

    # # get xmin and xmax from the plot_dict
    # if plot_dict['xmin'] is None:
    #     xmin = 0.
    # else:
    #     xmin = plot_dict['xmin']

    # if plot_dict['xmax'] is None:
    #     xmax = p_dict['tstop']
    # else:
    #     xmax = plot_dict['xmax']

    # truncate them using logical indexing
    t_range = dpl.t[(dpl.t >= xmin) & (dpl.t <= xmax)]
    dpl_range = dpl.dpl['agg'][(dpl.t >= xmin) & (dpl.t <= xmax)]

    f = ac.FigStd()
    f.ax0.plot(t_range, dpl_range)

    # sorry about the parity between vars here and above with xmin/xmax
    if plot_dict['ylim'] is None:
    # if plot_dict['ymin'] is None or plot_dict['ymax'] is None:
        pass
    else:
        f.ax0.set_ylim(plot_dict['ylim'][0], plot_dict['ylim'][1])
        # f.ax0.set_ylim(plot_dict['ymin'], plot_dict['ymax'])

    # Title creation
    if f_param and key_types:
        # grabbing the p_dict from the f_param
        _, p_dict = paramrw.read(f_param)

        # useful for title strings
        title_str = ac.create_title(p_dict, key_types)
        f.f.suptitle(title_str)

    # create new fig name
    fig_name = os.path.join(dfig, file_prefix+'.png')

    # savefig
    plt.savefig(fig_name, dpi=300)
    f.close()
示例#4
0
def pspec_with_hist(f_spec,
                    f_dpl,
                    f_spk,
                    dfig,
                    f_param,
                    key_types,
                    xlim=None,
                    ylim=None):
    # Generate file prefix
    # print('f_spec:',f_spec)
    fprefix = f_spec.split('/')[-1].split('.')[0]
    # Create the fig name
    fig_name = os.path.join(dfig, fprefix + '.png')
    # print('fig_name:',fig_name)
    # load param dict
    _, p_dict = paramrw.read(f_param)
    f = ac.FigSpecWithHist()
    # load spec data
    spec = specfn.Spec(f_spec)
    # Plot TFR data and add colorbar
    pc = spec.plot_TFR(f.ax['spec'], 'agg', xlim, ylim)
    f.f.colorbar(pc, ax=f.ax['spec'])
    # set xlim based on TFR plot
    xlim_new = f.ax['spec'].get_xlim()
    # grab the dipole data
    dpl = dipolefn.Dipole(f_dpl)
    dpl.baseline_renormalize(f_param)
    dpl.convert_fAm_to_nAm()
    # plot routine
    dpl.plot(f.ax['dipole'], xlim_new, 'agg')
    # data_dipole = np.loadtxt(open(f_dpl, 'r'))
    # t_dpl = data_dipole[xmin_ind:xmax_ind+1, 0]
    # dp_total = data_dipole[xmin_ind:xmax_ind+1, 1]
    # f.ax['dipole'].plot(t_dpl, dp_total)
    # x = (xmin, xmax)
    # # grab alpha feed data. spikes_from_file() from spikefn.py
    # s_dict = spikefn.spikes_from_file(f_param, f_spk)
    # # check for existance of alpha feed keys in s_dict.
    # s_dict = spikefn.alpha_feed_verify(s_dict, p_dict)
    # # Account for possible delays
    # s_dict = spikefn.add_delay_times(s_dict, p_dict)
    # Get extinput data and account for delays
    extinputs = spikefn.ExtInputs(f_spk, f_param)
    extinputs.add_delay_times()
    extinputs.get_envelope(dpl.t, feed='dist')
    # set number of bins (150 bins per 1000ms)
    bins = ceil(150. * (xlim_new[1] - xlim_new[0]) /
                1000.)  # bins should be int
    # plot histograms
    hist = {}
    hist['feed_prox'] = extinputs.plot_hist(f.ax['feed_prox'],
                                            'prox',
                                            dpl.t,
                                            bins=bins,
                                            xlim=xlim_new,
                                            color='red')
    hist['feed_dist'] = extinputs.plot_hist(f.ax['feed_dist'],
                                            'dist',
                                            dpl.t,
                                            bins=bins,
                                            xlim=xlim_new,
                                            color='green')
    f.ax['feed_dist'].invert_yaxis()
    # for now, set the xlim for the other one, force it!
    f.ax['dipole'].set_xlim(xlim_new)
    f.ax['spec'].set_xlim(xlim_new)
    f.ax['feed_prox'].set_xlim(xlim_new)
    f.ax['feed_dist'].set_xlim(xlim_new)
    # set hist axis props
    f.set_hist_props(hist)
    # axis labels
    f.ax['spec'].set_xlabel('Time (ms)')
    f.ax['spec'].set_ylabel('Frequency (Hz)')
    # Add legend to histogram
    for key in f.ax.keys():
        if 'feed' in key:
            f.ax[key].legend()
    # create title
    title_str = ac.create_title(p_dict, key_types)
    f.f.suptitle(title_str)
    f.savepng(fig_name)
    f.close()
示例#5
0
def pspec_dpl(f_spec,
              f_dpl,
              dfig,
              p_dict,
              key_types,
              xlim=None,
              ylim=None,
              f_param=None):
    # Generate file prefix
    fprefix = f_spec.split('/')[-1].split('.')[0]

    # using png for now
    # fig_name = os.path.join(dfig, fprefix+'.eps')
    fig_name = os.path.join(dfig, fprefix + '.png')

    # f.f is the figure handle!
    f = ac.FigSpec()

    # load spec data
    spec = specfn.Spec(f_spec)

    # Plot TFR data and add colorbar
    pc = spec.plot_TFR(f.ax['spec'], 'agg', xlim, ylim)
    f.f.colorbar(pc, ax=f.ax['spec'])

    # grab the dipole data
    # data_dipole = np.loadtxt(open(f_dpl, 'r'))
    dpl = dipolefn.Dipole(f_dpl)

    # If f_param supplied, renormalize dipole data
    if f_param:
        dpl.baseline_renormalize(f_param)
        dpl.convert_fAm_to_nAm()

    # plot routine
    dpl.plot(f.ax['dipole'], xlim, 'agg')

    # Plot Welch data
    # Use try/except for backwards compatibility
    try:
        spec.plot_pgram(f.ax['pgram'])

    except KeyError:
        pgram = specfn.Welch(dpl.t, dpl.dpl['agg'], p_dict['dt'])
        pgram.plot_to_ax(f.ax['pgram'], spec.spec['agg']['f'][-1])

    # plot and create an xlim
    xlim_new = f.ax['spec'].get_xlim()
    xticks = f.ax['spec'].get_xticks()
    xticks[0] = xlim_new[0]

    # for now, set the xlim for the other one, force it!
    f.ax['dipole'].set_xlim(xlim_new)
    f.ax['dipole'].set_xticks(xticks)
    f.ax['spec'].set_xticks(xticks)

    # axis labels
    f.ax['spec'].set_xlabel('Time (ms)')
    f.ax['spec'].set_ylabel('Frequency (Hz)')

    # create title
    title_str = ac.create_title(p_dict, key_types)
    f.f.suptitle(title_str)

    # use our fig classes to save and close
    f.savepng(fig_name)
    # f.saveeps(dfig, fprefix)
    f.close()