def get_colors(palette, num): # palette = 'vaporwave' # palette = 'cool' colors = np.array([ colorsys.rgb_to_hsv(*tuple(int(c[i:i + 2], 16) for i in (1, 3, 5)))[0] for c in vapeplot.palette(palette) ]) f = interp1d(np.arange(len(colors)), colors) return f(np.arange(num) / (num - 1) * (len(colors) - 1))
""" # import holoviews as hv import matplotlib.gridspec as gridspec import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns import traces import vapeplot from bokeh.models import LinearAxis, Range1d from bokeh.plotting import figure from scipy import stats # vapeplot.set_palette('sunset') pal = sns.blend_palette(vapeplot.palette('sunset')) # hv.extension('bokeh') localData = np.load("localdata.npy") globalData = np.load("globaldata.npy") print globalData.shape, 'before' g = 0 for i in xrange(globalData[:, 1].shape[0]): # print globalData[138-i,-1] if globalData[138 - i, -1] != 'nan': g = globalData[138 - i, -1] else: globalData[138 - i, -1] = g
import os import matplotlib.pyplot as plt import pandas as pd import seaborn as sns import vapeplot if __name__ == "__main__": curdir = os.path.dirname(os.path.realpath(__file__)) pkl_path = os.path.join(curdir, "data-control-cloth.pkl") df = pd.read_pickle(pkl_path) pal = vapeplot.palette("vaporwave") print(pal, len(pal)) gradsim_color = "#966bff" physicsonly_color = "#ff6a8b" # noisyphysics_color = "#20de8b" random_color = "#94d0ff" pal = [gradsim_color, physicsonly_color, random_color] sns.lineplot(x="Epoch", y="Position error", hue="Approach", data=df, palette=pal) plt.xlabel("Optimization iterations") plt.ylabel("Position error (meters)") # savepath = os.path.join(curdir, "plot-control-cloth.svg")
def recursivecell( levels=3, init=None, tEnd=100, dt=0.001, couplcoeff=0.3, drive=0.5, plots=True, plots2=True, parallel=True, #for if we want the video paralellized or not vidja=True, scalefactor=0.8, step=10, width=1080, height=1080, dpi=100): #video parameters #finding amount of cells cellnr = cellamount(levels) #random startvector if np.any(init == None): startvect = np.empty((cellnr, 1)) for i in range(cellnr): startvect[i, 0] = random.random() * 2 * np.pi else: startvect = np.array(init) startvect = np.reshape(startvect, (cellnr, 1)) initcon = np.array2string(np.reshape(startvect, (1, cellnr))) #coupling matrices totcoupl = n_matrixgen(levels, 0.25) #using function to generate coupling matrix drivevect = np.ones(cellnr) * drive #simulation setup phasevect = startvect lensarray = np.empty(1) lensarray[0] = np.linalg.norm(phasevect) # array of lengths t = 0 #+dt print(totcoupl) #phasearray = np.array([phasevect],) #total array of all the phases phasearray = np.empty((cellnr, int(tEnd / dt + 1))) phasearray[:, 0] = phasevect[:, 0] bar1 = Bar('simulating', max=int(tEnd / dt)) stepcounter = 1 #stepcounter since int(t/dt) did strange things #actually simulating while stepcounter < tEnd / dt + 1: dphase = couplcoeff * ( np.mod(-np.matmul(totcoupl, phasevect) + np.pi, np.pi * 2) - np.pi) + drivevect #calculating derivative #phasevect = RK4(phasevect,dt,totcoupl,couplcoeff,drivevect) phasevect = phasevect + dt * dphase lensarray = np.append(lensarray, np.linalg.norm(phasevect)) phasearray[:, stepcounter] = phasevect[:, 0] stepcounter += 1 t = t + dt bar1.next() bar1.finish() #finding time for filenames now = datetime.now() #transposing the array bc I didn't want to rewrite half the plots phasearray = np.transpose(phasearray) #dumping the whole thing to a csv for later use np.savetxt( 'outputs/recursive/{now}drive{drive}coupl{coup}.csv'.format( now=now, drive=drive, coup=couplcoeff), phasearray) if plots: #plot phase stuff vp.set_palette('cool') tarr = np.arange(0, tEnd + 1 * dt, dt) plt.figure(figsize=(15, 10)) for i in range(cellnr): plt.plot(tarr, np.mod(phasearray[:, i], 2 * np.pi)) plt.savefig('outputs/recursive/phase_{}.png'.format(now)) plt.close() #plot sine plt.figure(figsize=(15, 5)) for i in range(cellnr): plt.plot(tarr, np.sin(phasearray[:, i])) plt.savefig('outputs/recursive/sine_{}.png'.format(now)) plt.close() #plots that are more useful for bigger sytems if plots2: cool = vp.palette('cool') #let's make em pretty plotbar = Bar('plotting...', max=cellnr) tarr = np.arange(0, tEnd + 1 * dt, dt) fig = plt.figure(figsize=(15, 5 * math.ceil(cellnr / 3))) for i in range(cellnr): data = phasearray[:, i] sins = np.sin(data) diffs = centerdif(sins, dt) #phasespace ax = fig.add_subplot(int(math.ceil(cellnr / 3)), 3, i + 1) ax.plot(sins, diffs, c=cool[np.mod(i, len(cool))]) ax.set_xlabel('x{}'.format(i + 1)) ax.set_ylabel("x'{}".format(i + 1)) ax.set_ylim(top=1, bottom=-1) plotbar.next() plt.savefig('outputs/recursive/{}phaseplane.png'.format(now)) plotbar.finish() plt.close() #sineplots fig2 = plt.figure(figsize=(15, 5 * math.ceil(cellnr / 3))) plotbar = Bar('plotting...', max=cellnr) for i in range(cellnr): data = phasearray[:, i] sins = np.sin(data) ax2 = fig2.add_subplot(cellnr, 1, i + 1) ax2.plot(tarr, sins, c=cool[np.mod(i, len(cool))]) ax2.set_xlabel('t') ax2.set_ylabel("x{}".format(i + 1)) plotbar.next() plt.savefig('outputs/recursive/{}sins.png'.format(now)) plt.close() plotbar.finish() #Video stuff if vidja == True: if parallel == True: parallelvideo(cellnr, levels, tEnd, dt, phasearray, totcoupl, now, scalefactor, step, width, height, dpi) else: videomaker(cellnr, levels, tEnd, dt, phasearray, totcoupl, now, scalefactor, step, width, height, dpi)
""" from icecream import ic import numpy as np import pint import vapeplot from vapeplot import palette import pandas as pd import scipy.stats as st import matplotlib.pyplot as plt import seaborn as sns ureg = pint.UnitRegistry() ureg.auto_reduce_dimensions = True Q_ = ureg.Quantity pal = sns.blend_palette(vapeplot.palette("vaporwave")) # radius of a 98A^2 surface "sphere" # https://pubchem.ncbi.nlm.nih.gov/compound/439520#section=Top r = (98e-20 / (4 * 3.14))**(1 / 2) * ureg.meter k = 1.38e-23 * ureg.joule / ureg.K mu = 0.001 * ureg.pascal * ureg.second T = 320 * ureg.K # data Lanzini, Bile 2003 r_BS_CH = 1e-9 * ureg.meter r_BS_L_CH = 2.5e-9 * ureg.meter r_BS_L_CH_vesicle = 35e-9 * ureg.meter