Esempio n. 1
0
def get_data_in_path(data_repo, params):
    if data_repo is not None:
        sname = io.sim_name(params)
        data_in_path = data_repo + sname + '_v0.hdf5'
    elif data_repo is None:
        data_in_path = io.default_file_name(params, 'data', '.hdf5')
    return data_in_path
Esempio n. 2
0
def rule_plot(params_list_list, show_S=[1, 6, 9, 14], show_L=[15]):
    fignum = 0
    c_list = ['c', 'orange', 'crimson', 'limegreen']
    c_list = cycle(c_list)
    m_list = ['s', 'o', '^', 'd']
    m_list = cycle(m_list)
    fig = plt.figure(fignum, figsize=(3, 3))
    ax = fig.add_subplot(1, 1, 1)
    for m, params_list in enumerate(params_list_list):
        avg_list = []
        for n, params in enumerate(params_list):
            if data_repo is not None:
                sname = io.sim_name(params)
                data_path = data_repo + sname + '_v0.hdf5'
            else:
                sname = io.sim_name(params)
                data_path = io.default_file_name(params, 'data', '.hdf5')
            data_set = h5py.File(data_path)
            L = params['L']
            S = params['S']
            T = params['T']
            sb = data_set['sbond'][::]

            print(sb[0:3, int(L / 2)])
            sb[::, int(L / 2)] = np.zeros(params['T'] + 1)
            sb /= [min(c + 1, L - c - 1) for c in range(L - 1)]

            center_sb = sb[::, int(L / 2)]

            avg_sb = np.mean(sb, axis=1)
            avg_avg_sb = np.mean(avg_sb[500::])
            avg_center_sb = np.mean(center_sb[500::])
            avg_list.append([L, S, avg_avg_sb])

            #S_plot(ax, c_list, center_sb, r'$L={}$'.format(L), r'$S={}$'.format(S))

        L_avg_plot(ax, c_list, m_list, avg_list, r'$S={}$'.format(S))

    bn = io.base_name(output_dir, 'plots/sbond/')
    #fn = 'S1_sbond_center_growth'+'.pdf'
    fn = 'S1-6-9-14_th0_sbond_center_tavg_Lscale' + '.pdf'
    io.multipage(bn + fn)
Esempio n. 3
0
                'S' : [6],
                'mode': ['alt'],
                'IC': ['f0'],
                'BC': ['1_00']
                 }

    #inner params
    var_params_dict = {
                'V' : ['HP_80'],
                 }

    params_list_list = io.make_params_list_list(fixed_params_dict, var_params_dict)

    for params_list in params_list_list:
        for params in params_list:
            res = h5py.File(io.default_file_name(params, 'data', '.hdf5'))
            mode = params['mode']
            S = params['S']
            V = params['V']
            T = params['T']
            L = params['L']
            th = get_th(V)

            n = 2
            sds_frac = 0.6

            grid = ms.get_diag_vecs(res['zz'][::])
            grid = 0.5 * (1.0 - grid)

            impact_t = np.argmax(grid[:,L-1])
Esempio n. 4
0
            for m, params_list in enumerate(params_list_list):
                for j, obs_key in enumerate(obs_list):
                    for n, params in enumerate(params_list):
                        val, val_min, val_max, cbar_label = set_color(
                            color_by, params)
                        cb_tick_labels = None
                        if color_by is 'mode':
                            cb_tick_labels = ['ALT', 'SWP', 'BLK']
                        elif color_by is 'L':
                            cb_tick_labels = Ls

                        if data_repo is not None:
                            sname = io.sim_name(params)
                            res_path = data_repo + sname + '_v0.hdf5'
                        elif data_repo is None:
                            res_path = io.default_file_name(
                                params, 'data', '.hdf5')
                        res = h5py.File(res_path)
                        obs = res[obs_key][500:]
                        obs[np.isnan(obs)] = 0
                        obs_mean = np.nanmean(obs)
                        obs_means[m, j, n] = obs_mean
                        colors[m, j, n] = val

                if typ == 'PCA':
                    plot_PCA(obs_means, fignum)
                    clip = False

                if typ == 'scatter':
                    ncplus = False
                    if color_by == 'S':
                        ncplus = True
Esempio n. 5
0
def transport_calc(params,
                   tmax_1,
                   span=[0, 61],
                   n=2,
                   tmin=2,
                   sds_frac=0.6,
                   speed_f=ft.flin,
                   speed_Bs_est=[1.0, 0.0],
                   diff_f=ft.flin,
                   diff_Bs_est=[1.0, 0.0],
                   dirr='R-L',
                   g_fignum=1000):

    transport = {}
    res = h5py.File(io.default_file_name(params, 'data', '.hdf5'))
    print(io.default_file_name(params, 'data', '.hdf5'))
    print([key for key in res.keys()])
    exp = ms.get_diag_vecs(res['zz'][::])
    Ptj = ((1.0 - exp) / 2.0)[span[0]:span[1]]

    if dirr == 'L-R':
        reflect_t = np.argmax(Ptj[:, params['L'] - 1])
    if dirr == 'R-L':
        reflect_t = np.argmax(Ptj[:, 0])

    transport['grid'] = Ptj

    M1_0, M1_1, M2_0, M2_1, intersection = fit_gmix(Ptj,
                                                    params,
                                                    n=n,
                                                    sds_frac=sds_frac,
                                                    g_fignum=g_fignum)

    keys = ['Bs', 'chi2', 'dBs']
    for moment in [1, 2]:
        for peak in [0, 1]:
            moment_name = 'M' + str(moment) + '_' + str(peak)
            mom = eval(moment_name)
            tmax = reflect_t

            if moment == 2:
                tmin = 1
                tmax = np.argmax(M2_0[0:params['L'] - 2])

            if moment == 1 and peak == 1:
                if tmax_1 is None:
                    tmax_1 = tmax
                transport['tmax_1'] = tmax_1
                tmax = tmax_1

            if moment == 1 and peak == 0:
                transport['intersection'] = intersection[tmin:tmax]

            times = np.array(range(tmin, tmax))

            Bs_chi2_dBs = \
                list(ft.f_fits(speed_f, speed_Bs_est, times, mom[tmin:tmax]))
            transport[moment_name] = eval(moment_name)
            transport['times_' + moment_name] = times
            for j, key in enumerate(keys):
                transport_key = '_'.join([moment_name, key])
                transport[transport_key] = Bs_chi2_dBs[j]
    return transport
Esempio n. 6
0
def main():

    # locate the data you're interested in
    output_dir = 'fock_IC'
    mount_point = '/mnt/ext0/'
    data_repo = mount_point + 'qca_output/' + output_dir + '/data/'
    #data_repo = None

    # describe the simulations you'd like to load

    # params looped through at outer layer
    fixed_params_dict = {
        'output_dir': [output_dir],
        'T': [1000],
        'BC': ['1_00'],
        'mode': ['alt'],
        'S': [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14]
    }

    # params looped through at inner layer
    var_params_dict = {
        'L': [19],
        'V': ['HP_' + str(deg) for deg in [0, 45, 90]],
        'IC': ['c3_f1'],
    }

    colors = ['c', 'm', 'limegreen']
    # histogram parameters
    partition_size = 19
    n_partitions = 49
    include_remaining = True
    n_bins = 40

    barmode = False
    aggregate_mode = True

    measure_name = "$\Delta s^{\mathrm{bond}}$"
    #measure_name = "$\Delta ND$"

    colormap = plt.cm.get_cmap('jet')

    # function to extract data to put into histogram
    def obtain_hist(data_set, i, j):
        # helper
        def delta(values):
            return np.abs(values[i:j - 1] - values[i + 1:j])

        #return data_set['Y'][i:j] # Y
        #return delta(data_set['Y']) # \Delta Y

        #return data_set['ND'][i:j] # ND
        #return delta(data_set['ND']) # \Delta ND

        #return data_set['CC'][i:j] # ND
        #return delta(data_set['CC']) # \Delta CC

        #return data_set['m'][i:j] # Mutual information
        #return delta(data_set['m']) # Mutual information change

        #return data_set['s'][i:j] # s
        #return delta(data_set['s']) # \Delta s

        #return get_diag_vecs(data_set['zz'][i:j]) # Z
        #return np.abs(get_diag_vecs(data_set['zz'][i:j-1]) -
        #        get_diag_vecs(data_set['zz'][i+1:j]))  # \Delta Z

        L = len(data_set['sbond'][1])
        sb = data_set['sbond'][::]
        sb /= [min(c + 1, L - c) for c in range(L)]
        return delta(sb)

    #aggregate data

    params_list_list = io.make_params_list_list(fixed_params_dict,
                                                var_params_dict)
    fignum = 0
    for m, params_list in enumerate(params_list_list):

        all_means = []
        all_stds = []
        names = []
        labels = []
        #print(fignum)
        fig = plt.figure(fignum, figsize=(3, 3))
        ax = fig.add_subplot(1, 1, 1)
        for n, params in enumerate(params_list):
            if data_repo is not None:
                sname = io.sim_name(params)
                data_path = data_repo + sname + '_v0.hdf5'
            else:
                sname = io.sim_name(params)
                data_path = io.default_file_name(params, 'data', '.hdf5')

            data_set = h5py.File(data_path)
            names.append(sname)

            #full_hist(ax, params, data_set)

            simulation_hists = []
            #aggregate
            means = []
            stds = []
            #bin range
            maximum = 0
            minimum = 0

            for i in range(0, partition_size * n_partitions, partition_size):

                # get data from helper defined above
                partition_hist = obtain_hist(data_set, i, i + partition_size)

                # dataset may be multi-dimensional. reduce to one dimension
                while (len(partition_hist.shape) > 1):
                    partition_hist = np.concatenate(partition_hist)

                simulation_hists.append(
                    (partition_hist, i, i + partition_size))

                means.append(np.mean(partition_hist))
                stds.append(np.std(partition_hist))

                # update minima and maxima
                if (np.max(partition_hist) > maximum):
                    maximum = np.max(partition_hist)
                if (np.min(partition_hist) > minimum):
                    minimum = np.min(partition_hist)

            # same thing for the remaining iterations
            if include_remaining:
                low = partition_size * n_partitions
                partition_hist = obtain_hist(data_set, low, 1000)
                while (len(partition_hist.shape) > 1):
                    partition_hist = np.concatenate(partition_hist)
                simulation_hists.append((partition_hist, low, 1000))
                means.append(np.mean(partition_hist))
                stds.append(np.std(partition_hist))
                if (np.max(partition_hist) > maximum):
                    maximum = np.max(partition_hist)
                if (np.min(partition_hist) > minimum):
                    minimum = np.min(partition_hist)

            means = np.array(means)
            stds = np.array(stds)

            all_means.append(means)
            all_stds.append(stds)
            labels.append(r'$\theta = ' + str(pt.get_th(params['V'])) +
                          '^\circ$')

            #compute bin range
            if (minimum == maximum):
                raise ValueError("Values are constant throughout simulation.")
            bins = np.arange(minimum, maximum, (maximum - minimum) / n_bins)
            maxbin = 0

            if aggregate_mode: continue

            plt.clf()

            idx = 0
            for (values, i, j) in simulation_hists:
                #make histogram
                hist, _ = np.histogram(values, bins=bins)
                hist = hist / (j - i)  #normalize
                #hist = hist/sum(hist) #normalize

                # help decide y axis maximum
                if (np.max(hist) > maxbin): maxbin = np.max(hist)

                fraction = idx / len(simulation_hists)
                color = colormap(fraction)

                if barmode:
                    #plot as bar graph
                    width = (0.75 + 0.75 * fraction) * (bins[1] - bins[0])
                    center = (bins[:-1] + bins[1:]) / 2
                    plt.bar(center,
                            hist,
                            align='center',
                            width=width,
                            color=color,
                            alpha=0.5,
                            label="%d to %d" % (i, j))
                    plt.gca().set_yscale("log")
                    plt.gca().set_ylim([min(hist), max(hist)])
                else:
                    #plot as filled region
                    centers = (bins[:-1] + bins[1:]) / 2
                    plt.fill_between(centers,
                                     0,
                                     hist,
                                     color=color,
                                     alpha=0.5,
                                     label="%d to %d" % (i, j))
                idx += 1

            #configure plot
            plt.xlim(bins[0], bins[-1])
            plt.ylim(0, maxbin + 1)

            plt.title("Histograms of %s in %s in groups of %d iterations" %
                      (measure_name, sname, partition_size))
            plt.ylabel("Frequency (normalized by partition size)")
            plt.xlabel(measure_name)

            plt.grid(True)
            plt.legend(loc='best')
            plt.show()

        if aggregate_mode:
            if include_remaining:
                agg_range = np.arange(n_partitions + 1)
            else:
                agg_range = np.arange(n_partitions)

            mins, maxs = [], []
            for i, c in zip(range(len(all_means)), ['c', 'm', 'limegreen']):
                fraction = i / len(all_means)
                means = all_means[i]
                stds = all_stds[i]
                label = labels[i]
                # color=colormap(fraction)
                ax.plot(agg_range,
                        means,
                        color=c,
                        markeredgecolor=c,
                        label=label,
                        lw=0.8,
                        markeredgewidth=1.2,
                        marker='o',
                        markerfacecolor='None')
                #ax.fill_between(agg_range, means+stds, means-stds, alpha=0.5,color=c)
                #ax.errorbar(agg_range, means, stds)
                #plt.plot(agg_range, [1.0/20]*len(means))
                mins.append(min(means))
                maxs.append(max(means))
            ax.set_title(r'$S=' + str(params['S']) + '$')
            ax.set_ylabel(measure_name)
            ax.set_xlabel(r"Iteration [$t/\tau$]")
            ax.grid(True)
            ax.legend(loc='best', fontsize=11, numpoints=1, handlelength=1)
            ax.set_xscale("log", nonposx='clip')
            ax.set_yscale("log", nonposy='clip')
            ax.set_ylim([min(mins), max(maxs)])
            ax.margins(0.001)

            letters = ['(a)', '(b)', '(c)', '(d)']
            labeled_rules = [6, 7, 9, 14]
            letter_dict = dict(zip(labeled_rules, letters))
            S = params['S']
            if S in labeled_rules:
                panel_label = letter_dict[S]
                ax.text(0.5,
                        -0.28,
                        panel_label,
                        verticalalignment='bottom',
                        horizontalalignment='center',
                        transform=ax.transAxes)
            ax.set_ylim([1e-5, 1e-1])
        fignum += 1
    io.multipage('./../output/fock_IC/plots/L19_delta_sbond_means.pdf')