예제 #1
0
    def center(self, npoints=all, with_normals=False):
        """Returns center line of the worm
    
    Arguments:
      npoints (int or all): number of sample points
      
    Returns:
      array (nx2): points along center line
    """

        if npoints is all:
            points = None
        else:
            points = np.linspace(0, 1, npoints)

        theta = self.theta.get_values(points=points)
        return wormgeo.center_from_theta_discrete(theta,
                                                  orientation=self.orientation,
                                                  xy=self.xy,
                                                  length=self.length,
                                                  npoints=npoints,
                                                  nsamples=all,
                                                  resample=False,
                                                  smooth=0,
                                                  with_normals=with_normals)
예제 #2
0
 def curve(self, mode_amplitudes):
   """Change curvature properties of the worm
   
   Arguments:
     mode_amplitudes (number or array): additional power in the first fourier modes of the worms angles
   """
   #changes curvature by the mode amplitudes;
   #cos = np.cos(self.theta); -> ok to use theta directly 
   theta, orientation, xy, length = wormgeo.theta_from_center_discrete(self.center);
   t = np.fft.rfft(theta);
   mode_amplitudes = np.array(mode_amplitudes);
   t[:mode_amplitudes.shape[0]] += mode_amplitudes;
   theta = np.fft.irfft(t, n = self.npoints-2);
   self.center = wormgeo.center_from_theta_discrete(theta, orientation, xy, length);
 def center(self, with_normals = False):
   """Returns center line of the worm
   
   Arguments:
     with_normals (bool): if true also return normals along center points
     
   Returns:
     array (nx2): points along center line
     array (nx2): normals along center points
   """
   
   return wormgeo.center_from_theta_discrete(self.theta, orientation = self.orientation,
                                             xy = self.xy, length = self.length,
                                             npoints = all, nsamples = all, resample = False,
                                             smooth = 0, with_normals = with_normals);
예제 #4
0
 def curve(self, mode_amplitudes):
     """Change curvature properties of the worm
 
 Arguments:
   mode_amplitudes (number or array): additional power in the first fourier modes of the worms angles
 """
     #changes curvature by the mode amplitudes;
     #cos = np.cos(self.theta); -> ok to use theta directly
     theta, orientation, xy, length = wormgeo.theta_from_center_discrete(
         self.center)
     t = np.fft.rfft(theta)
     mode_amplitudes = np.array(mode_amplitudes)
     t[:mode_amplitudes.shape[0]] += mode_amplitudes
     theta = np.fft.irfft(t, n=self.npoints - 2)
     self.center = wormgeo.center_from_theta_discrete(
         theta, orientation, xy, length)
예제 #5
0
  def bend(self, bend, exponent = 4, head = True):
    """Change curvature properties of the worm
    
    Arguments:
      bend (number): bending amplitude
      exponent (number): expoential modulation of the bending
      head (bool): if True bend head side otherwise tail side
    """
    #head tail bend profile
    theta, orientation, xy, length = wormgeo.theta_from_center_discrete(self.center);
    n2 = theta.shape[0]//2;
    
    if head:
      theta[:n2-1] += bend * np.exp(-exponent * np.linspace(0,1,n2-1));
    else:
      theta[-(n2-1):] += bend * np.exp(-exponent * np.linspace(1,0,n2-1));

    self.center = wormgeo.center_from_theta_discrete(theta, orientation, xy, length);
예제 #6
0
    def center(self, with_normals=False):
        """Returns center line of the worm
    
    Arguments:
      with_normals (bool): if true also return normals along center points
      
    Returns:
      array (nx2): points along center line
      array (nx2): normals along center points
    """

        return wormgeo.center_from_theta_discrete(self.theta,
                                                  orientation=self.orientation,
                                                  xy=self.xy,
                                                  length=self.length,
                                                  npoints=all,
                                                  nsamples=all,
                                                  resample=False,
                                                  smooth=0,
                                                  with_normals=with_normals)
 def center(self, npoints = all, with_normals = False):
   """Returns center line of the worm
   
   Arguments:
     npoints (int or all): number of sample points
     
   Returns:
     array (nx2): points along center line
   """
   
   if npoints is all:
     points = None;
   else:
     points = np.linspace(0,1,npoints);
   
   theta = self.theta.get_values(points = points);
   return wormgeo.center_from_theta_discrete(theta, orientation = self.orientation,
                                             xy = self.xy, length = self.length,
                                             npoints = npoints, nsamples = all, resample = False,
                                             smooth = 0, with_normals = with_normals);
예제 #8
0
    def bend(self, bend, exponent=4, head=True):
        """Change curvature properties of the worm
    
    Arguments:
      bend (number): bending amplitude
      exponent (number): expoential modulation of the bending
      head (bool): if True bend head side otherwise tail side
    """
        #head tail bend profile
        theta, orientation, xy, length = wormgeo.theta_from_center_discrete(
            self.center)
        n2 = theta.shape[0] // 2

        if head:
            theta[:n2 -
                  1] += bend * np.exp(-exponent * np.linspace(0, 1, n2 - 1))
        else:
            theta[-(n2 - 1):] += bend * np.exp(
                -exponent * np.linspace(1, 0, n2 - 1))

        self.center = wormgeo.center_from_theta_discrete(
            theta, orientation, xy, length)
#plt.figure(12); plt.clf();
#aplt.plot_pca(theta)

pca = aplt.PCA(theta)

pca_comp = pca.Wt

import worm.model as wm
import worm.geometry as wgeo
w = wm.WormModel(npoints=22)

fig = plt.figure(170)
plt.clf()
for i in range(len(pca_comp)):
    tt = pca_comp[i] * 21
    cc = wgeo.center_from_theta_discrete(tt, length=95)
    dd = np.sum(np.diff(cc, axis=0), axis=0)
    oo = np.arctan2(dd[1], dd[0]) + 0 * np.pi

    w.center = wgeo.center_from_theta_discrete(tt, length=95, orientation=-oo)
    plt.subplot(5, 4, i + 1)
    plt.title('PCA %d' % (i + 1))
    w.plot(ccolor='b')
    plt.axis('equal')

fig.savefig(os.path.join(fig_dir, 'theta_pca_oriented.png'), facecolor='white')

fig = plt.figure(170)
plt.clf()
for i in range(9):
    tt = pca_comp[i] * 21
예제 #10
0
pcas = results.Y;

#%%
#import worm.model as wmod

fig = plt.figure(1); plt.clf();
ax = fig.add_subplot(1,1,1);

ax.set_color_cycle([plt.cm.gray(i) for i in np.linspace(0,1,50)])

k,m = 6,5
for i in range(3000):
  #th = pcas[i];# * len(pcas[i]);
  th = data_theta[i];
  c = wgeo.center_from_theta_discrete(th, length = 120)
  #ax = plt.subplot(k,m,i+1);
  #c = np.reshape(pcas[i], (2,-1))
  plt.plot(*c.T);


plt.xlim(-65,65);
plt.ylim(-65,65);
plt.axis('equal')

cax = plt.gca();
aax = cax.axes
aax.get_xaxis().set_visible(False);
aax.get_yaxis().set_visible(False);

plt.tight_layout()
import worm.model as wm
import worm.geometry as wgeo
w = wm.WormModel(npoints=22)

fig = plt.figure(17)
plt.clf()
for i in range(len(pca_comp)):
    tt = pca_comp[i] * 21
    tta = tt - np.mean(tt)
    if i == 0:
        oo = 0.2
    elif i == 1:
        oo = .9 + np.pi
    else:
        oo = 0
    w.center = wgeo.center_from_theta_discrete(tta, length=95, orientation=oo)
    plt.subplot(5, 4, i + 1)
    plt.title('PCA %d' % (i + 1))
    w.plot()
    plt.axis('equal')
fig.savefig(os.path.join(fig_dir, 'theta_pca.png'), facecolor='white')

fig = plt.figure(18)
plt.clf()
for i in range(len(pca_comp)):
    tt = pca_comp[i] * 21
    tta = tt - np.mean(tt)
    plt.subplot(5, 4, i + 1)
    plt.plot(tta, linewidth=2, c='r')
    plt.title('PCA %d' % (i + 1))
#plt.figure(12); plt.clf();
#aplt.plot_pca(theta)

pca = aplt.PCA(theta)

pca_comp = pca.Wt;

import worm.model as wm
import worm.geometry as wgeo
w = wm.WormModel(npoints = 22)

fig = plt.figure(170); plt.clf();
for i in range(len(pca_comp)):
  tt = pca_comp[i] * 21;
  cc = wgeo.center_from_theta_discrete(tt, length = 95);
  dd = np.sum(np.diff(cc, axis = 0), axis = 0);
  oo = np.arctan2(dd[1], dd[0]) + 0* np.pi;

  w.center = wgeo.center_from_theta_discrete(tt, length = 95, orientation = -oo);
  plt.subplot(5,4,i+1)
  plt.title('PCA %d' % (i+1))
  w.plot(ccolor='b')
  plt.axis('equal')

fig.savefig(os.path.join(fig_dir, 'theta_pca_oriented.png'), facecolor='white')
   
fig = plt.figure(170); plt.clf();
for i in range(9):
  tt = pca_comp[i] * 21;
  cc = wgeo.center_from_theta_discrete(tt, length = 95);