Ejemplo n.º 1
0
def Emeanvar(q, mode_nums=None):
  """
  returns 2 dictionaries:
    key, value = modeNo, mean{E}
    key, value = modeNo, stdv{E}
  """
  if not mode_nums:
    mode_nums = range(len(q))

  E = nm_s.compute_E(q)
  n = len(E[0])
  Em = [1.0*sum(Ei)/n for Ei in E]
  Es = [(1.0*sum((Ei-Eim)**2)/(n-1))**0.5 for Ei, Eim in zip(E, Em)]

  return dict( (modeNo, Em[modeNo]) for modeNo in mode_nums ), dict( (modeNo, Es[modeNo]) for modeNo in mode_nums )
Ejemplo n.º 2
0
def plot(t_P, q, system, gens, mode_nums=None, verbose=False, tc="x", xmin=False, xmax=False, ymin=False, ymax=False):
    """ a wrapper for plotting routines we'll use a lot """

    n_l_m = system.network.nlm

    ans = []

    ### amp-time
    if verbose:
        print "amp_time"
    fig, ax = nmp.amp_plot(t_P, q, n_l_m=n_l_m, mode_nums=mode_nums)
    ax.set_ylabel(r"$|" + tc + "_i|$")
    ax.set_xlabel(r"$t/P_{\mathrm{orb}}$")
    if ymin:
        ax.set_ylim(ymin=ymin)
    if ymax:
        ax.set_ylim(ymax=ymax)
    if xmin:
        ax.set_xlim(xmin=xmin)
    if xmax:
        ax.set_xlim(xmax=xmax)
    ans.append((fig, ax))

    ### multi-gen-amp-time
    if verbose:
        print "multi-gen_amp_time"
    fig, axs = nmp.multi_gen_amp_plot(t_P, q, gens, n_l_m=n_l_m, mode_nums=mode_nums)
    for ax in axs:
        ax.set_ylabel(r"$|" + tc + "|$")
    ax.set_xlabel(r"$t/P_{\mathrm{orb}}$")
    if ymin:
        ax.set_ylim(ymin=ymin)
    if ymax:
        ax.set_ylim(ymax=ymax)
    if xmin:
        ax.set_xlim(xmin=xmin)
    if xmax:
        ax.set_xlim(xmax=xmax)
    ans.append((fig, axs))

    ### coupling diagrams
    colormap = nmd.plt.get_cmap("jet")

    ### nl-placement disp
    if verbose:
        print "nl-placmenet disp"
    myE = -np.array([np.mean(_) for _ in nms.viscous_disp(q, network, Eo=1.0)[-1]])
    mode_colors = [colormap(_) for _ in myE]
    mode_order = myE.argsort()
    fig = nmd.plt.figure()
    ax = fig.add_axes([0.1, 0.1, 0.750, 0.8])
    cbax = fig.add_axes([0.875, 0.1, 0.025, 0.8])
    fig, ax = nmd.coupling_tree_nl(
        system,
        tree_type="placement",
        genNos=[],
        verbose=verbose,
        mode_colors=mode_colors,
        mode_order=mode_order,
        fig_ax=(fig, ax),
        mode_nums=mode_nums,
    )
    # 	colorbar = nmd.matplotlib.colorbar.ColorbarBase(cbax, cmap=colormap, orientation='vertical', norm=nmd.matplotlib.colors.LogNorm())
    colorbar = nmd.matplotlib.colorbar.ColorbarBase(cbax, cmap=colormap, orientation="vertical")
    colorbar.ax.set_ylabel(r"$\gamma_i A_i^2/\mathrm{max}\{\gamma_i A_i^2\}$")
    ans.append((fig, ax, colorbar))

    ### nl-placement E
    if verbose:
        print "nl-placement E"
    mE = np.array([np.mean(_) for _ in nms.compute_E(q, Eo=1.0)])
    mode_colors = [colormap(_) for _ in mE / max(mE)]
    mode_order = mE.argsort()

    fig = nmd.plt.figure()
    ax = fig.add_axes([0.1, 0.1, 0.750, 0.8])
    cbax = fig.add_axes([0.875, 0.1, 0.025, 0.8])
    fig, ax = nmd.coupling_tree_nl(
        system,
        tree_type="placement",
        genNos=[],
        verbose=verbose,
        mode_colors=mode_colors,
        mode_order=mode_order,
        fig_ax=(fig, ax),
        mode_nums=mode_nums,
    )
    # 	colorbar = nmd.matplotlib.colorbar.ColorbarBase(cbax, cmap=colormap, orientation='vertical', norm=nmd.matplotlib.colors.LogNorm())
    colorbar = nmd.matplotlib.colorbar.ColorbarBase(cbax, cmap=colormap, orientation="vertical")
    colorbar.ax.set_ylabel(r"$A_i^2/\mathrm{max}\{A_i^2\}$")
    ans.append((fig, ax, colorbar))

    ### nl-siblings gens
    for genNo in xrange(1, len(gens)):
        if verbose:
            print "nl-siblings gen%d" % genNo
        fig, ax = nmd.coupling_tree_nl(
            system, tree_type="siblings", genNos=[genNo], verbose=verbose, mode_nums=mode_nums
        )
        ans.append((fig, ax))

    return ans
Ejemplo n.º 3
0
    for collE in opts.collE:
        if opts.verbose:
            print "\tcollE:", collE
        collE_modeNos[collE] = [
            [network.modeNoD[nlms] for nlms in _]
            for _ in pn.downselect_collE(collE, system, freqs=None, mode_nums=None)
        ]

        # =================================================
        ### plot data!
        # =================================================

        ### compute stuff for statistics
    myE = -np.array([np.mean(_) for _ in nms.viscous_disp(q, network, Eo=1.0)[-1]])
    myE /= sum(myE)
    mE = np.array([np.mean(_) for _ in nms.compute_E(q, Eo=1.0)])
    mE /= sum(mE)

    pkl_obj = {"myE": myE, "mE": mE}

    # === total data set
    if opts.plot:
        if opts.verbose:
            print "total data"
        tag = "" + opts.tag
        savefig(
            plot(t_P, q, system, gens, mode_nums=None, verbose=opts.vverbose, tc=opts.tc),
            opts.outfilename,
            opts.logfilename,
            tag=tag,
            no_legend=opts.no_legend,
Ejemplo n.º 4
0
if multi_gen:
  if opts.verbose: print "determining generational structure"
  gens, _ = system.network.gens()

####################################################################################################
#
#
#           stacked histograms
#
#
####################################################################################################
if opts.stacked_hist:
  if opts.verbose: print "\tstacked_hist"

  ### prepare data
  E = nms.compute_E(q, Eo=1.)
  mE = [nms.sample_mean(e) for e in E]
#  sE = [nms.sample_var(e, xo=mE[ind])**0.5 for ind, e in enumerate(E)]

  mdE = [2*network.wyU[ind][1]*e for ind, e in enumerate(mE)]
#  sdE = [2*network.wyU[ind][1]*e for ind, e in enumerate(sE)]

  data = [(1, len(network.K[ind]), mE[ind], mdE[ind]) for ind in range(N_m)] # number of modes, number of connections, mean Energy, mean dissipation

  ### make and save each plot
  for xvar, bin_width in opts.stacked_hist:

    #==========
    if xvar == "w":
      if opts.verbose: print "\t\tw"
      if not bin_width:
Ejemplo n.º 5
0
  if not len(t_P):
    raise ValueError, "no data loaded from "+opts.filename

  if opts.amplitude:
    if opts.verbose: print "computing mode amplitudes"
    x = nm_s.compute_A(q, Eo=1.)
    mA = []
    sA = []
    lA = []
    for A in x:
      mA.append( nm_s.sample_mean(A) )
      sA.append( nm_s.sample_var(A, xo=mA[-1])**0.5 )
      lA.append( A[-1] )
    del x

    x = nm_s.compute_E(q, Eo=1.)
    mE = []
    sE = []
    lE = []
    totE = [sum([x[modeNo][i] for modeNo in range(N_m)]) for i in range(len(t_P))]
    mean_tot_E = nm_s.sample_mean(totE)
    var_tot_E = nm_s.sample_var(totE, xo=mean_tot_E)
    for E in x:
      mE.append( nm_s.sample_mean(E) )
      sE.append( nm_s.sample_var(E, xo=mA[-1])**0.5 )
      lE.append( E[-1] )
    del x, totE

    if opts.conc_fit:
      if opts.verbose: print "\tattempting to fit concentration diagram"
      mE_fp, mE_cvr, mE_rchi2 = nm_s.broken_PowLaw_fitter(range(opts.conc_fit_start+1, opts.conc_fit_stop+1), np.array(sorted(mE)[opts.conc_fit_start:opts.conc_fit_stop])/mean_tot_E, np.ones((opts.conc_fit_stop-opts.conc_fit_start)), max_iters=opts.conc_fit_iters, rtol=opts.conc_fit_rtol, verbose=opts.conc_verbose)