model_old.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码
def move_forward(self, distance, smooth = 1.0, straight = True):
    """Move worm peristaltically forward

    Arguments:
      distance (number): distance to move forward
      smooth (number): smoothness of the interpolation
      straight (bool): if True extrapolated points move straight

    Note:
      The head is first point in center line and postive distances will move the
      worm in this direction.
    """

    length = self.length;
    cline = self.center_line();

    cinterp, u = splprep(cline.T, u = None, s = smooth, per = 0)
    us = u - distance / length;
    x, y = splev(us, cinterp, der = 0); 
    cline2 = np.array([x,y]).T;   
    if straight:
       if distance > 0:
         idx = np.nonzero(us < 0)[0];
         if len(idx) > 0:
           d = cline[0,:] - cline[1,:];
           #l = np.linalg.norm(d);
           l = self.length / (self.npoints -1);
           d = d / l;
           m = idx.max();
           for i in idx:
             cline2[i,:] = cline[0,:] + distance * d * (m + 1.0 - i)/(m + 1.0);
       elif distance < 0:
         idx = np.nonzero(us > 1)[0];
         if len(idx) > 0:
           d = cline[-1,:] - cline[-2,:];
           #l = np.linalg.norm(d);
           l = self.length / (self.npoints -1);
           d = d / l;
           m = idx.min(); mx = idx.max();
           for i in idx:
             cline2[i,:] = cline[-1,:] - distance * d * (i - m + 1.0)/(mx + 1.0 - m);

    self.from_center_line(cline2, self.width);
    self.stretch(length / self.length);
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号