def compile_histograms(): res_dir = '/home/mogeb/git/benchtrace/trace-client/' # none_values = np.genfromtxt(res_dir + 'none.out', delimiter=',', skip_header=2, # names=['latency'], dtype=None) none_values = [ ( pylab.loadtxt(filename) ) for filename in [(res_dir + 'none.hist')] ] [0] lttng_values = [ ( pylab.loadtxt(filename) ) for filename in [(res_dir + 'lttng.hist')] ] [0] ftrace_values = [ ( pylab.loadtxt(filename) ) for filename in [(res_dir + 'ftrace.hist')] ][0] perf_values = [ ( pylab.loadtxt(filename) ) for filename in [(res_dir + 'perf.hist')] ][0] print('Mean none: ' + str(mean(none_values.tolist()))) print('Median none: ' + str(median(none_values.tolist()))) print('90th per none: ' + str(np.percentile(none_values.tolist(), 90))) print('95th per none: ' + str(np.percentile(none_values.tolist(), 95))) print() print('Mean lttng: ' + str(mean(lttng_values.tolist()))) print('Median lttng: ' + str(median(lttng_values.tolist()))) print('90th per lttng: ' + str(np.percentile(lttng_values.tolist(), 90))) print('95th per lttng: ' + str(np.percentile(lttng_values.tolist(), 95))) print() print('Mean ftrace: ' + str(mean(ftrace_values.tolist()))) print('Median ftrace: ' + str(median(ftrace_values.tolist()))) print('90th per ftrace: ' + str(np.percentile(ftrace_values.tolist(), 90))) print('95th per ftrace: ' + str(np.percentile(ftrace_values.tolist(), 95))) print() print('Mean perf: ' + str(mean(perf_values.tolist()))) print('Median perf: ' + str(median(perf_values.tolist()))) print('90th per perf: ' + str(np.percentile(perf_values.tolist(), 90))) print('95th per perf: ' + str(np.percentile(perf_values.tolist(), 95))) nbins=1000 isnormed=False iscumul=False if isnormed == True: plt.axis([30, 400, 0, 1]) else: plt.axis([30, 400, 0, 11000]) lttng_filtered = lttng_values[~is_outlier(lttng_values)] ftrace_filtered = ftrace_values[~is_outlier(ftrace_values)] none_filtered = none_values[~is_outlier(none_values)] perf_filtered = perf_values[~is_outlier(perf_values)] plt.hist(none_filtered.tolist(), normed=isnormed, cumulative=iscumul, bins=nbins, color='y', alpha=0.5, label='none') plt.hist(lttng_filtered.tolist(), normed=isnormed, cumulative=iscumul, bins=nbins, color='b', label='lttng') plt.hist(ftrace_filtered.tolist(), normed=isnormed, cumulative=iscumul, bins=nbins, color='r', alpha=0.5, label='ftrace') plt.hist(perf_filtered.tolist(), normed=isnormed, cumulative=iscumul, bins=nbins, color='g', alpha=0.5, label='perf') plt.title("Gaussian Histogram") plt.xlabel("Value") plt.ylabel("Frequency") plt.legend() print('none: ' + str(len(none_filtered.tolist()))) print('lttng: ' + str(len(lttng_filtered.tolist()))) print('ftrace: ' + str(len(ftrace_filtered.tolist()))) print('perf: ' + str(len(perf_filtered.tolist()))) plt.show()
def get_number_flow_rate(self, path="./"): filename = path + "/statistics/count_periodic.txt" count_periodic = pylab.loadtxt(filename) last_count_periodic = count_periodic[-1] time = last_count_periodic[0] count_z = last_count_periodic[3] number_flow_rate = count_z / time return number_flow_rate
def plot_data(): datalist = [ ( plt.loadtxt("myfile.txt"), "label")] for data, label in datalist: plt.plot( data[:,0], data[:,1], label=label ) plt.legend() plt.title("Plot of coupled oscillator") plt.xlabel("Time") plt.ylabel("Position") plt.show() plt.pause(0.000005)
def convertTxtFile(iFile,oFile): hf=tables.openFile(oFile,'w') rdArray=pylab.loadtxt(iFile,comments='x1') rdArray.shape # It'd be nice to grab the names from the file, but it should be # obvious how one would do so for idx in range(rdArray.shape[1]): name="x"+str(idx) hf.createArray(hf.root,name,rdArray[:,idx]) hf.close() return
def plot_permeability(self, state_path="./", output = None, show_plot=False): """ Reads a file containing several timesteps with average velocity profile across a cylinder. Function will take average of all timesteps in order to get good statistics. """ data = pylab.loadtxt(state_path+"/statistics/permeability.txt") num_timesteps = len(data) # Number of lines equals number of timesteps time = data[:,0] # Number of elements on first line equals number of bins permeabilities = data[:,1] # Number of elements on first line equals number of bins print "Plotting time vs permeability during "+str(num_timesteps)+" timesteps." self.plot(x=time, y=permeabilities, x_axis_label="t", y_axis_label="k", filename=output) if show_plot: plt.show()
def plot_linear_density_profile(self, state_path="./", length=1.0, output = None, show_plot=False): """ Reads a file containing several timesteps with average velocity profile across two parallel plates. Function will take average of all timesteps in order to get good statistics. """ densities = pylab.loadtxt(state_path+"/statistics/linear_density.txt") num_timesteps = len(densities) # Number of lines equals number of timesteps num_bins = len(densities[0]) # Number of elements on first line equals number of bins densities = sum(densities,0) / num_timesteps # Sum each column and normalize to take time average print "Plotting linear density profile with "+str(num_timesteps)+" timesteps and "+str(num_bins)+" bins." x_axis = linspace(0,length,num_bins) # Create x_axis with possible real channel height self.plot(x=x_axis, y=densities, x_axis_label="x", y_axis_label="# molecules", filename=output) if show_plot: plt.show()
def polyfit_velocity(self, state_path="./", height=1.0): """ Reads a file containing several timesteps with average velocity profile across two parallel plates. Function will take average of all timesteps in order to get good statistics. """ velocities = pylab.loadtxt(state_path+"/statistics/velocity.txt") num_timesteps = len(velocities) # Number of lines equals number of timesteps num_bins = len(velocities[0]) # Number of elements on first line equals number of bins velocities = sum(velocities,0) / num_timesteps # Sum each column and normalize to take time average x_axis = linspace(0,height*1e-6,num_bins) # Create x_axis with possible real channel height x_axis = x_axis[velocities>0] velocities = velocities[velocities>0] p = polyfit(x_axis, velocities, 2) return x_axis, velocities, p
def plot_linear_temperature_profile(self, state_path="./", length=1.0, output = None, skip_zeros=True, show_plot=False): """ Reads a file containing several timesteps with average velocity profile across two parallel plates. Function will take average of all timesteps in order to get good statistics. """ temperatures = pylab.loadtxt(state_path+"/statistics/linear_temperature.txt") num_bins = len(temperatures) # Number of elements on first line equals number of bins print "Plotting linear temperature profile with "+str(num_bins)+" bins." x_axis = linspace(0,length,num_bins) # Create x_axis with possible real channel height if skip_zeros: self.plot(x=x_axis[temperatures>0], y=temperatures[temperatures>0], x_axis_label="x", y_axis_label="Temperature [K]", filename=output) else: self.plot(x=x_axis, y=temperatures, x_axis_label="x", y_axis_label="Temperature [K]", filename=output) if show_plot: plt.show()
def plot_velocity_distribution_box(self, state_path="./", height=1.0, output = None, show_plot=False, skip_zeros = True, factor=1.0): """ Reads a file containing several timesteps with average velocity profile across two parallel plates. Function will take average of all timesteps in order to get good statistics. """ velocities = pylab.loadtxt(state_path+"/statistics/velocity.txt") num_bins = len(velocities) # Number of elements on first line equals number of bins velocities = factor*velocities print "Plotting velocity profile with "+str(num_bins)+" bins." x_axis = linspace(0,height,num_bins) # Create x_axis with possible real channel height if skip_zeros: self.plot(x=x_axis[velocities>0], y=velocities[velocities>0], x_axis_label="x", y_axis_label="v(x)", filename=output) else: self.plot(x=x_axis, y=velocities, x_axis_label="x", y_axis_label="v(x)", filename=output) if show_plot: plt.show()
from matplotlib import pylab as pl from getworkingpath import * filnavn = getworkingpath()+'/dobbel.txt' myfile = pl.loadtxt(filnavn, int) for i in range(len(myfile)): if (myfile[i] != myfile[i-1] and myfile[i] != myfile[i+1]): print(myfile[i]) # 724
from matplotlib import pylab as pl from getworkingpath import * filnavn = getworkingpath() + '/juksogfanteri.csv' myFile = pl.loadtxt(filnavn, float, skiprows=1, delimiter=";") years = myFile[:, 0] juks = myFile[:, 1] fanteri = myFile[:, 2] diff = juks - fanteri pl.plot(years, juks, label="Juks", color="blue") pl.plot(years, fanteri, label="Fanteri", color="orange") pl.plot(years, diff, label="Differanse", color="green") pl.axhline(0, color="black") pl.axvline(years[0], color="black") pl.title("Juks og fanteri") pl.xlabel('År') pl.ylabel('Antall solgt pr år') pl.legend() pl.show()
from matplotlib import pylab import tables rdArray = pylab.loadtxt('dataFile1.txt', comments='x1') rdArray.shape x1 = rdArray[:, 0] y1 = rdArray[:, 1] hf = tables.openFile('dataFile1.h5', 'w') x1n = hf.createArray(hf.root, "x1", x1) hf.setNodeAttr(x1n, "vsType", "mesh") hf.setNodeAttr(x1n, "vsKind", "structured") y1n = hf.createArray(hf.root, "y1", y1) hf.setNodeAttr(x1n, "vsType", "variable") hf.setNodeAttr(x1n, "vsMesh", "x1") hf.close()
from matplotlib import pylab import tables rdArray=pylab.loadtxt('dataFile1.txt',comments='x1') rdArray.shape x1=rdArray[:,0] y1=rdArray[:,1] hf=tables.openFile('dataFile1.h5','w') x1n=hf.createArray(hf.root,"x1",x1) hf.setNodeAttr(x1n,"vsType", "mesh") hf.setNodeAttr(x1n,"vsKind", "structured") y1n=hf.createArray(hf.root,"y1",y1) hf.setNodeAttr(x1n,"vsType", "variable") hf.setNodeAttr(x1n,"vsMesh", "x1") hf.close()
from matplotlib import pylab as pl from getworkingpath import * filnavn = getworkingpath() + '/bokstaver.txt' myfile = pl.loadtxt(filnavn, str) word = [] for letter in myfile: if (letter.islower()): word.append(letter) print(word) #covid
def read_data(path): '''Reads data from txt file and returns an array of form ([line1], [line2]...)''' data = plb.loadtxt(path) return data
# -*- coding: utf-8 -*- """ Created on Mon Apr 27 22:17:28 2015 @author: alumno """ import os os.chdir('/home/alumno/L5/cristales/dia2/') from matplotlib.pylab import loadtxt, plot datos = loadtxt('cal_corta1.csv', delimiter=",") v = datos[:, 2] print(v) plot(range(2000, 16000, 1000), v)
##plot accuracy log file # arguments import argparse parser = argparse.ArgumentParser(description='PyLab plot accuracy log') parser.add_argument('--file-name', default = 'dummy_accuracy.log', help ='file name') args = parser.parse_args() import matplotlib.pylab as pylab init_row = 1 #skip heading of the log file data = pylab.loadtxt(args.file_name)#, dtype = np.float128) for it, cost in data: pylab.plot(data[init_row:,0], data[init_row:,1]) pylab.xlabel('iterations') pylab.ylabel('cost function') #pylab.legend('SGD') pylab.title('Training') pylab.show()
print "MODULES OFF" send_enable(0x0,Device_ID['ENABLE_MODULES']) time.sleep(1) print "LOG RUN OFF" send_enable(0x0,Device_ID['LOG_RUN']) time.sleep(1) print "RESET OFF" send_enable(0x0,Device_ID['SOFT_RST']) time.sleep(1) print "ENB MODULES" enables = raw_input('Value: ') send_enable(int(enables),Device_ID['ENABLE_MODULES']) time.sleep(5) time.sleep(1) print "LOG" log_all() time.sleep(10) print "End Script" #exit() dataS = plt.loadtxt('./logs/%s.out'%LOG_NAME) plt.figure() plt.plot(dataS) #plt.plot(dataS[:,1]) plt.grid() plt.show(block=False) raw_input('Press Enter to Continue') plt.close()
axs[1][0].set_xticks(X + width / 2) axs[1][0].set_xticklabels(map(int, data[:, 0])) axs[1][0].set_ylabel('avg. number of gained genes') axs[1][0].set_xlabel(r'$\delta$') axs[1][0].set_title('spatial gain of 3D clusters', fontsize=title_fontsize) axs[1][0].set_yscale('log') for axsx in axs: for axsy in axsx: for label in axsy.get_xmajorticklabels(): label.set_rotation(90) label.set_fontsize(label_fontsize) #label.set_horizontalalignment('right') for label in axsy.get_ymajorticklabels(): label.set_fontsize(label_fontsize) plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0) f.savefig(out, format='pdf') if __name__ == '__main__': parser = ArgumentParser(formatter_class=ADHF) parser.add_argument('cluster_statistics', type=str, help='TAB-separated file containing statistical assessment ' + \ 'from 3D gene cluster evaluation') args = parser.parse_args() out = stdout data = plt.loadtxt(args.cluster_statistics) visualize_stats(data, out)
found = True break if found: return i, data[i] else: return None pylab.ion() reader = ArrayReader(port='/dev/ttyUSB0', baudrate=115200, timeout=0.05) # Get background if 1: if os.path.isfile(BACKGROUND_FILE): print 'reading background.txt' background = pylab.loadtxt(BACKGROUND_FILE) else: print 'getting new background image for equalization' numBackground = 5 background = pylab.zeros((768, )) for i in range(0, numBackground): print i data = reader.getData() background = background + data background = background / numBackground print pylab.savetxt('background.txt', background) delta = 500.0 - background else: print 'background subtraction disabled'
#!/usr/bin/python3.7 import matplotlib.pyplot as pl import matplotlib.pylab as lab import numpy as np from scipy.optimize import curve_fit def f(u, a, b, c): return a * np.exp(b*u) - c def g(i, a, ig): return a * np.log(i/ig + 1) r = 1.00082e3 data = lab.loadtxt("dane.txt") # napięcia są w woltach u_gen = data[:, 0] * 1e-3 u_r = data[:, 1] * 1e-3 u_d = data[: ,2] * 1e-3 _sigma = data[:, 3] * 1e-3 #natężenie zrobimy w mikroapmerach i_d = u_r/r * 1e3 print(data) p, cov = curve_fit(g, i_d, u_d, sigma = _sigma) print(f"Parameters: {p}") print(f"Covariance: {cov}") print(f"u_a: {cov[0][0]**0.5}")