#!/usr/bin/env python # coding: utf-8 # In[ ]: import ipyvolume.pylab as p3 import cortex import numpy as np # In[ ]: p3.examples.klein_bottle() # In[ ]: get_ipython().run_cell_magic('javascript', '', '// for development, no need to execute this cell\nrequire.onResourceLoad = function(context, map)\n{\n console.log("loading " +map.name)\n // require.undef(map.name);\n};\nrequire.undef("nbextensions/ipyvolume/index")\nrequire(["nbextensions/ipyvolume/index"])\n') # In[ ]: from PIL import Image import urllib.request url = 'https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif' url = 'http://www.i-programmer.info/images/stories/News/2015/Mar/A/jupyter.jpg' im = Image.open(urllib.request.urlopen(url)) # In[ ]: pts, polys = cortex.db.get_surf('S1', 'fiducial', merge=True) pts_flat, polys_flat = cortex.db.get_surf('S1', 'flat', merge=True, nudge=True) pts_inf, polys_inf = cortex.db.get_surf('S1', 'inflated', merge=True, nudge=True) # In[ ]: x, y, z = pts.T x_flat, y_flat, z_flat = pts_flat.T def n(x): return (x - x.min()) / x.ptp() u = n(x_flat) v = n(y_flat) r = n(x) g = n(y) b = n(z) # In[ ]: # go to spherical coordinates x_inf, y_inf, z_inf = pts_inf.T r = np.sqrt(x_inf**2 + y_inf**2 + z_inf**2) phi = np.arctan2(x_inf,-z_inf) theta = np.arccos(y_inf/r) r.max() # In[ ]: # clip r r = np.minimum(r, 60) r.max() # In[ ]: # back to cartesian z_sphere = -r * np.sin(theta) * np.cos(phi) x_sphere = r * np.sin(theta) * np.sin(phi) y_sphere = r * np.cos(theta) # In[ ]: b = 60 x_box = np.clip(x_inf, -b, b) y_box = np.clip(y_inf, -b, b) z_box = np.clip(z_inf, -b, b) # In[ ]: theta = ((theta + (np.pi)) % (2*np.pi)) - (np.pi) # In[ ]: x_flat2 = (phi)*60 #-(((phi+np.pi) % (2*np.pi))- np.pi) * 30 #x_flat = -(((phi+2*np.pi) % (2*np.pi))- np.pi) * 30 y_flat2 = -(theta-np.pi/2) * 30*2 z_flat2 = phi * 0 # In[ ]: p3.figure() p3.style.use('dark') #p3.style.use(['light', 'minimal']) print(p3.gcf().style) x, y, z = pts.T x2, y2, z2 = pts_flat.T m = p3.plot_trisurf([x_flat2, x_box, x_sphere, x_inf, x, x_flat], [y_flat2, y_box, y_sphere, y_inf, y, y_flat], [z_flat2, z_box, z_sphere, z_inf, z, z_flat], polys_flat, u=u, v=v, texture=im) p3.animation_control(m, interval=1000) p3.squarelim() p3.show() # In[ ]: p3.movie('jupyter-brain.gif') # In[ ]: