import numpy as np from scipy import integrate import sys sys.path.append("/Users/ahagen/code") from pymf import ctmfd as ahi from pym import func as ahf from pyg import twod as ahp import glob plot = ahp.ah2d() fname = glob.glob('fem_sol/*.dat') for i in range(len(fname)): arr = np.loadtxt(fname[i]) z = arr[:, 0] * 1.0E4 C = arr[:, 1] fem = ahf.curve(z, C, name=r'fem') plot = fem.plot(linestyle='-', linecolor='#5C8727') plot.lines_on() plot.markers_off() arr = np.loadtxt(fname[i].replace('fem', 'fdm')) z = arr[:, 0] * 1.0E4 C = arr[:, 1] fdm = ahf.curve(z, C, name=r'fdm') fdm.plot(linestyle='-', linecolor='#2EAFA4', addto=plot) plot.lines_on() plot.markers_off()
import sys import os sys.path.append(os.environ['HOME'] + '/code') from pyg import twod as pyg2 import numpy as np # first lets make some cool data with trigonometric functions x = np.linspace(0., 4. * np.pi, 500.) y1 = np.sin(x) y2 = np.power(np.sin(x), 2.) # create three plot objects, two for one column, and another for two column plot1 = pyg2.ah2d() plot2 = pyg2.ah2d() plot3 = pyg2.ah2d() # add one line each to our single column plots plot1.add_line(x, y1, linecolor='#285668', linestyle='-', name=r'$\sin$') plot2.add_line(x, y2, linecolor='#285668', linestyle='-', name=r'$\sin^{2}$') # add both of them to our double width object plot3.add_line(x, y1, linecolor='#285668', linestyle='-', name=r'$\sin$') plot3.add_line(x, y2, linecolor='#FC8D82', linestyle='--', name=r'$\sin^{2}$') # make them pretty with labels and a legend for plot in [plot1, plot2, plot3]: plot.markers_off() plot.lines_on() plot.ylim(-1.1, 1.1) plot.xlabel(r'$x$') plot.ylabel(r'$y$')
# pwr = [np.mean(pwr_new[0:1]), np.mean(pwr_new[2]), np.mean(pwr_new[3]), # np.mean(pwr_new[4:])] # u_pwr = [np.std(pwr_new[0:1]), np.std(pwr_new[2]), np.std(pwr_new[3]), # np.std(pwr_new[4:])] # eff = np.array([np.mean(eff_new[0:1]), np.mean(eff_new[2]), np.mean(eff_new[3]), # np.mean(eff_new[4:])]) / nps_dd # u_eff = np.array([np.mean(u_eff[0:1]), np.mean(u_eff[2]), np.mean(u_eff[3]), # np.mean(u_eff[4:])]) / nps_dd # std_eff = np.array([np.std(eff_new[0:1]), np.std(eff_new[2]), np.std(eff_new[3]), # np.std(eff_new[4:])]) / nps_dd # u_eff = np.sqrt(np.power(u_eff, 2.0) + np.power(std_eff, 2.0)) pwr = pwr_new eff = eff_new dd_tena_eta = ahf.curve(pwr, 100. * eff, u_y=u_eff, name="dd_tena_setup") plot = ahp.ah2d() plot = dd_tena_eta.plot(linecolor='#746C66', linestyle='-') plot = cf_tena_eta.plot(linecolor='#E3AE24', linestyle='-', addto=plot) plot.lines_off() plot.ax.set_yscale('log') plot.add_data_pointer(3.5, curve=cf_tena_eta, string=r"$Cf$", place=(2.2, 6E-3)) plot.add_data_pointer(6.5, curve=dd_tena_eta, string=r"$DD$", place=(7.5, 1E-5)) plot.xlabel(r'Power ($P$) [$W$]') plot.ylabel(r'Efficiency ($\eta$) [$\%$]') plot.export('../img/ef15_eff',
ode_solution = ahf.curve(x, sol[:, 0], name='ode') t_0_25, y_0_25 = np.loadtxt('pendulum_0.250000.dat', usecols=(0, 1), unpack=True) h_0_25_solution = ahf.curve(t_0_25, y_0_25, name=r'$h = 0.25 \mathrm{s}$') t_0_125, y_0_125 = np.loadtxt('pendulum_0.125000.dat', usecols=(0, 1), unpack=True) h_0_125_solution = ahf.curve(t_0_125, y_0_125, name=r'$h = 0.125 \mathrm{s}$') t_0_00001, y_0_00001 = np.loadtxt('pendulum_0.000244.dat', usecols=(0, 1), unpack=True) h_0_00001_solution = ahf.curve(t_0_00001, y_0_00001, name=r'$h = 0.000244 \mathrm{s}$') plot = ahp.ah2d() plot = h_0_25_solution.plot(linecolor='#7ED0E0', linestyle='-', addto=plot) plot = h_0_125_solution.plot(linecolor='#7299C6', linestyle='-', addto=plot) plot = h_0_00001_solution.plot(linecolor='#B63F97', linestyle='-', addto=plot) plot = ode_solution.plot(linecolor='#2EAFA4', linestyle='--', addto=plot) plot.lines_on() plot.markers_off() plot.ylabel(r'Position ($y$) [$\mathrm{cm}$]') plot.xlabel(r'Time ($t$) [$\mathrm{s}$]') plot.legend() plot.export('full_result', formats=['pdf', 'pgf'], sizes=['2']) plot.show() h, y = np.loadtxt('convergence.dat', unpack=True)
unpack=True) h_0_25_solution = ahf.curve(t_0_25, y_0_25, name=r'$h = 0.25 \mathrm{s}$') t_0_125, y_0_125 = np.loadtxt('pendulum_0.125000.dat', usecols=(0, 1), unpack=True) h_0_125_solution = ahf.curve(t_0_125, y_0_125, name=r'$h = 0.125 \mathrm{s}$') t_0_00001, y_0_00001 = np.loadtxt('pendulum_0.000244.dat', usecols=(0, 1), unpack=True) h_0_00001_solution = ahf.curve(t_0_00001, y_0_00001, name=r'$h = 0.000244 \mathrm{s}$') plot = ahp.ah2d() plot = h_0_25_solution.plot(linecolor='#7ED0E0', linestyle='-', addto=plot) plot = h_0_125_solution.plot(linecolor='#7299C6', linestyle='-', addto=plot) plot = h_0_00001_solution.plot(linecolor='#B63F97', linestyle='-', addto=plot) plot = ode_solution.plot(linecolor='#2EAFA4', linestyle='--', addto=plot) plot.lines_on() plot.markers_off() plot.ylabel(r'Position ($y$) [$\mathrm{cm}$]') plot.xlabel(r'Time ($t$) [$\mathrm{s}$]') plot.legend() plot.export('full_result', formats=['pdf', 'pgf'], sizes=['2']) plot.show() h, y = np.loadtxt('convergence.dat', unpack=True)
import sys import os sys.path.append(os.environ['HOME'] + '/code') from pyg import twod as pyg2 import numpy as np # first lets make some data which relates to each other, but is way off scale x = np.linspace(0., 4. * np.pi, 500.) y1 = np.sin(x) y2 = np.exp(np.sin(x)) # create three plot objects, two for one column, and another for two column plot = pyg2.ah2d() # add one line each to our single column plots plot.add_line(x, y1, linecolor='#285668', linestyle='-', name=r'$\sin$') plot.fill_between(x, np.zeros_like(y1), y1, fc='#ccccff', name=r'$\int y dx$') plot.add_line_yy(x, y2, linecolor='#FC8D82', linestyle='-', name=r'$\exp \left( \sin \right)$') plot.fill_between(x, np.zeros_like(y2), y2, fc='#ffcccc', name=r'$\int y dx$', axes=plot.ax2) # make them pretty with labels and a legend plot.markers_off() plot.lines_on() plot.xlim(0., 4. * np.pi) plot.ylim(-1.5, 1.5) plot.ylim(0.0, 4.0, axes=plot.ax2) plot.xlabel(r'$x$') plot.ylabel(r'$y = \sin$') plot.ylabel(r'$y = \exp \left( \sin \right)$', axes=plot.ax2)
def cluster_power(self, fnames, nps, u_nps): t_pwr = [] pwr = [] u_pwr = [] t_det = [] det = [] levels = [] # plot the average power plot = ahp.ah2d() colors = ['#E3AE24', '#B63F97', '#5C6F7B', '#5C8727', '#7E543A', '#A3792C', '#7299C6', '#B8B308'] for fname in fnames: # check if an alex fileset or a brian file if "pwr" in fname: # open power file t_pwr_new, pwr_new, u_pwr_new = \ np.loadtxt(expanduser("~") + '/data/tena/' + fname + '.dat', delimiter=",", dtype=object, converters={0: strpdate2num("%d-%b-%Y %H:%M:%S"), 1: float, 2: float}, unpack=True) t_pwr_new = np.array(t_pwr_new) * 3600. * 24. t_det_new, det_new, _ = \ np.loadtxt(expanduser("~") + "/data/tena/" + fname.replace("pwr", "det") + '.dat', delimiter=",", dtype=object, converters={0: strpdate2num("%d-%b-%Y %H:%M:%S"), 1: float, 2: float}, unpack=True) t_det_new = np.array(t_det_new) * 3600. * 24. eps = 0.1 min_samples = 10 else: # get the date from the filename # find string matching %i_min_%2i_%2i_%2i[_%i] at end of filename # get the count interval from the filename # find string matching %i_min at end of string pattern = \ ".*_([0-9]*)_min_([0-9]*)_([0-9]*)_([0-9]*)(?:_([0-9]*))?$" result = re.split(pattern, fname) mm = result[2] dd = result[3] yy = result[4] t_int = float(result[1]) * 60. epoch = datetime.utcfromtimestamp(0) t_start = (datetime.strptime( mm + "/" + dd + "/" + yy + " 01:00:00", "%m/%d/%y %H:%M:%S") - epoch).total_seconds() pwr_new, eff_new, u_eff_new = \ np.loadtxt(expanduser("~") + '/data/tena/' + fname + '.dat', delimiter=",", dtype=object, converters={0: float, 1: float, 2: float}, unpack=True) u_pwr_new = 0.2 * np.ones_like(pwr_new) det_new = nps * np.array(eff_new) u_eff_new = u_nps * np.array(u_eff_new) t = t_start t_pwr_new = [] for i in range(len(pwr_new)): t_pwr_new = np.append(t_pwr_new, t) t += t_int t_det_new = t_pwr_new.copy() eps = 0.24 min_samples = 2 # put the data in row form pwr_data = \ [[float(t_pwr_new[i]), float(pwr_new[i])] for i in range(len(pwr_new))] # use the dbscan clustering algorithm X = StandardScaler().fit_transform(pwr_data) db = DBSCAN(eps=eps, min_samples=min_samples).fit(X) core_samples_mask = np.zeros_like(db.labels_, dtype=bool) core_samples_mask[db.core_sample_indices_] = True labels = db.labels_ # Number of clusters in labels, ignoring noise if present. n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0) marked = np.zeros_like(t_pwr_new) for i in range(len(t_pwr_new))[::-1]: label = labels[i] other_labels = [x for x in np.unique(labels) if x != label] for other in other_labels: if (other >= 0) and inrange(t_pwr_new[i], t_pwr_new[labels == other]): marked[i] = 1 labels[marked == 1] = -1 for i in [x for x in np.unique(labels) if x != -1]: if len(pwr_new[labels == i]) >= min_samples: level = power_level(t_pwr_new[labels == i], pwr_new[labels == i], t_det_new, det_new) levels = np.append(levels, level) t_det = np.append(t_det, t_det_new) t_pwr = np.append(t_pwr, t_pwr_new) pwr = np.append(pwr, pwr_new) u_pwr = np.append(u_pwr, u_pwr_new) det = np.append(det, det_new) return levels