def __init__(self):
        self.fig = plt.figure(facecolor = 'w', figsize = [12, 6])
        self.fig.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
        
        ax1 = self.fig.add_subplot(2, 1, 1, projection='3d')
        ax2 = self.fig.add_subplot(2, 1, 2, projection='3d')
        
        self.track_data = track_data
        
        self.t = np.arange(0,len(track_data['no_ll'][0]['track']))
        self.flow = flow[self.t]
        self.flow_flash = 0


        self.info1 = ax2.text2D(0.90,0.95,'State key',fontsize = 18,transform=ax2.transAxes)
        self.info2 = ax2.text2D(0.90,0.90,'------------',fontsize = 18, transform=ax2.transAxes)
        self.info2 = ax2.text2D(0.90,0.75,'Blue: rest',fontsize = 18, transform=ax2.transAxes, color = 'blue')
        self.info3 = ax2.text2D(0.90,0.60,'Black: swim ', fontsize = 18, transform=ax2.transAxes, color = 'black')
        self.info4 = ax2.text2D(0.90,0.45,'Red: lat. line', fontsize = 18, transform=ax2.transAxes, color = 'red')

        self.flowtexta1 = ax1.text2D(0.001, 0.65, 'Flow 0 cm/s', fontsize=18, transform=ax1.transAxes)
        self.flowtexta2 = ax2.text2D(0.001, 0.65, 'Flow 0 cm/s', fontsize=18, transform=ax2.transAxes)

        self.meantext1 = ax1.text2D(0.4, 0, 'X mean = 37.5 +/- 0', fontsize=18, color = 'green', transform=ax1.transAxes)
        self.meantext2 = ax2.text2D(0.4, 0, 'X mean = 37.5 +/- 0', fontsize=18, color = 'green', transform=ax2.transAxes)

        self.ax1mean = Line3D([37.5, 37.5], [0, 15], [0, 0], color = 'green', linewidth = 2)
        ax1.add_line(self.ax1mean)
        self.ax2mean = Line3D([37.5, 37.5], [0, 15], [0, 0], color = 'green', linewidth = 2)
        ax2.add_line(self.ax2mean)

        plot_functions.plot_tank(ax1)
        plot_functions.plot_tank(ax2)

        self.ax1_lines = []
        for animal in self.track_data['no_ll']:
            line_dict = {}
            line_dict['head'] = Line3D([], [], [], color='blue', marker='o', markeredgecolor='black')
            line_dict['tail'] = Line3D([], [], [], color='blue', linewidth=2)
            ax1.add_line(line_dict['head'])
            ax1.add_line(line_dict['tail'])
            self.ax1_lines.append(line_dict)

        self.ax2_lines = []
        for animal in self.track_data['ll']:
            line_dict = {}
            line_dict['head'] = Line3D([], [], [], color='blue', marker='o', markeredgecolor='black')
            line_dict['tail'] = Line3D([], [], [], color='blue', linewidth=2)
            ax2.add_line(line_dict['head'])
            ax2.add_line(line_dict['tail'])
            self.ax2_lines.append(line_dict)

        ax1.set_xlim(0, 68)
        ax1.set_ylim(0, 15)
        ax1.set_zlim(0, 15)
        ax1.set_title('Passive Model')
        ax1.set_aspect('equal')

        ax2.set_xlim(0, 68)
        ax2.set_ylim(0, 15)
        ax2.set_zlim(0, 15)
        ax2.set_title('Active Lateral Line')
        ax2.set_aspect('equal')
        
        ax1.set_xticks([0, 68])
        ax1.set_yticks([])
        ax1.set_zticks([0, 15])

        ax2.set_xticks([0, 68])
        ax2.set_yticks([])
        ax2.set_zticks([0, 15])

        plt.rc('xtick', labelsize=20)

        animation.TimedAnimation.__init__(self, self.fig, interval=10, blit=False)
Example #2
0
    def __init__(self):
        fig = plt.figure(facecolor="w", figsize=[12, 6])
        # fig.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)

        ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3, projection="3d")
        ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
        ax3 = plt.subplot2grid((3, 3), (2, 0), colspan=2)
        ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)

        self.t = np.arange(0, len(frog1["track"]))
        self.x = frog1["track"][self.t, 0]
        self.y = frog1["track"][self.t, 1]
        self.z = frog1["track"][self.t, 2]
        self.state = frog1["state"][self.t]

        self.x2 = frog1["time"][self.t]
        self.y2 = frog1["flow_rate"][self.t]
        self.y3 = frog1["lateral_line"][self.t]

        ax2.text(0.01, 0.8, str(current) + " cm/s", fontsize=16, transform=ax2.transAxes)
        ax2.text(0.01, 0.08, "0 cm/s", fontsize=16, transform=ax2.transAxes)
        ax3.text(0.01, 0.8, "threshold", fontsize=16, transform=ax3.transAxes)
        ax3.text(0.01, 0.08, "baseline", fontsize=16, transform=ax3.transAxes)

        ax1.text2D(0.90, 0.95, "State key", fontsize=16, transform=ax1.transAxes)
        ax1.text2D(0.90, 0.90, "------------", fontsize=16, transform=ax1.transAxes)
        ax1.text2D(0.90, 0.75, "Blue: rest", fontsize=16, transform=ax1.transAxes)
        ax1.text2D(0.90, 0.60, "Black: swim ", fontsize=16, transform=ax1.transAxes)
        ax1.text2D(0.90, 0.45, "Red: lat. line.", fontsize=16, transform=ax1.transAxes)

        plot_functions.plot_tank(ax1)
        plot_functions.plot_flow(current, ax2)
        plot_functions.plot_leak(ax3)

        plot_functions.plot_flow_field("none", ax4)

        self.line1 = Line3D([], [], [], color="black")
        self.line1a = Line3D([], [], [], color="red", linewidth=2)
        self.line1e = Line3D([], [], [], color="red", marker="o", markeredgecolor="k", markersize=8)

        self.line2 = Line2D([], [], color="black")
        self.line2e = Line2D([], [], color="red", marker="o", markeredgecolor="k", markersize=8)

        self.line3 = Line2D([], [], color="red", linewidth=2)
        self.line3e = Line2D([], [], color="red", marker="o", markeredgecolor="k", markersize=8)

        self.line4 = Line2D([], [], color="red", marker="o", markeredgewidth=2, markeredgecolor="w", markersize=11)

        ax1.add_line(self.line1)
        ax1.add_line(self.line1a)
        ax1.add_line(self.line1e)

        ax2.add_line(self.line2)
        ax2.add_line(self.line2e)

        ax3.add_line(self.line3)
        ax3.add_line(self.line3e)

        ax4.add_line(self.line4)

        ax1.set_xlim(0, 68)
        ax1.set_ylim(0, 15)
        ax1.set_zlim(0, 15)
        ax1.set_title(FROG1NAME)
        ax1.set_aspect("equal")

        ax2.set_xlim(0, len(frog1["time"]) * binsize * DOWNSAMPLE_RATE)
        ax2.set_ylim(-0.25, 1.05 * current)
        ax2.axis("off")

        ax3.set_xlim(0, len(frog1["time"]) * binsize * DOWNSAMPLE_RATE)
        ax3.set_ylim(-0.05, 1.05)
        ax3.axis("off")

        ax4.set_title("current field")
        ax4.set_aspect("equal")

        ax1.set_xticks([0, 68])
        ax1.set_yticks([])
        ax1.set_zticks([0, 15])

        ax2.set_xticks([])
        ax2.set_yticks([])

        ax3.set_xticks([])
        ax3.set_yticks([])

        ax4.set_xticks([])
        ax4.set_yticks([])

        plt.rc("xtick", labelsize=16)
        # plt.rc('title', labelsize=18)
        plt.tight_layout()

        self.axis4 = ax4
        animation.TimedAnimation.__init__(self, fig, interval=10, blit=False)
    def __init__(self):
        fig = plt.figure(facecolor = 'w', figsize = [12, 6])
        fig.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
        
        ax1 = fig.add_subplot(2, 1, 1,projection='3d')
        ax2 = fig.add_subplot(2, 1, 2,projection='3d')
        
        self.t = np.arange(0,len(frog1['track']))
        self.x = frog1['track'][self.t,0]
        self.y = frog1['track'][self.t,1]
        self.z = frog1['track'][self.t,2]
        
        self.x2 = frog2['track'][self.t,0]
        self.y2 = frog2['track'][self.t,1]
        self.z2 = frog2['track'][self.t,2]
        self.flow = flow[self.t]
        self.state1 = frog1['state']
        self.state2 = frog2['state']

        
        self.flowtexta1 = ax1.text2D(0.001, 0.65, 'Flow 0 cm/s', fontsize=18, transform=ax1.transAxes)
        self.flowtexta2 = ax2.text2D(0.001, 0.65, 'Flow 0 cm/s', fontsize=18, transform=ax2.transAxes)
        if REAL_DATA == 0:
            self.statetexta1 = ax1.text2D(0.001, 0.50, 'State 0', fontsize=18, transform=ax1.transAxes)
        self.statetexta2 = ax2.text2D(0.001, 0.50, 'State 0', fontsize=18, transform=ax2.transAxes)
        self.framerate = ax1.text2D(0.90, 0.85, str(DOWNSAMPLE_RATE) + 'x speed', fontsize = 18, transform=ax1.transAxes)
        self.info1 = ax2.text2D(0.90,0.95,'State key',fontsize = 18,transform=ax2.transAxes)
        self.info2 = ax2.text2D(0.90,0.90,'------------',fontsize = 18, transform=ax2.transAxes)
        self.info2 = ax2.text2D(0.90,0.75,'Blue: rest',fontsize = 18, transform=ax2.transAxes, color = 'blue')
        self.info3 = ax2.text2D(0.90,0.60,'Black: swim ', fontsize = 18, transform=ax2.transAxes, color = 'black')
        self.info4 = ax2.text2D(0.90,0.45,'Red: L.L. orientation.', fontsize = 18, transform=ax2.transAxes, color = 'red')


        plot_functions.plot_tank(ax1)
        plot_functions.plot_tank(ax2)

        #ax1.set_xlabel('x')
        #ax1.set_ylabel('y')
        #ax1.set_zlabel('z')

        #ax2.set_xlabel('x')
        #ax2.set_ylabel('y')
        #ax2.set_zlabel('z')
        
        self.line1 = Line3D([], [], [], color='black')
        self.line1a = Line3D([], [], [], color='green', linewidth=2)
        self.line1e = Line3D([], [], [], color='green', marker='o')

        self.line2 = Line3D([], [], [], color='black')
        self.line2a = Line3D([], [], [], color='red', linewidth=2)
        self.line2e = Line3D([], [], [], color='red', marker='o')

        
        ax1.add_line(self.line1)
        ax1.add_line(self.line1a)
        ax1.add_line(self.line1e)
        
        ax2.add_line(self.line2)
        ax2.add_line(self.line2a)
        ax2.add_line(self.line2e)
        
        ax1.set_xlim(0, 68)
        ax1.set_ylim(0, 15)
        ax1.set_zlim(0, 15)
        ax1.set_title(FROG1NAME)
        ax1.set_aspect('equal')

        ax2.set_xlim(0, 68)
        ax2.set_ylim(0, 15)
        ax2.set_zlim(0, 15)
        ax2.set_title('Lateral Line Model')
        ax2.set_aspect('equal')
        
        ax1.set_xticks([0, 68])
        ax1.set_yticks([])
        ax1.set_zticks([0, 15])

        ax2.set_xticks([0, 68])
        ax2.set_yticks([])
        ax2.set_zticks([0, 15])

        plt.rc('xtick', labelsize=20)

        animation.TimedAnimation.__init__(self, fig, interval=10, blit=False)
        orientation[bincount] = orient_angle(np.cos(theta)*np.sin(phi),np.sin(theta)*np.sin(phi)) # record orientation angle

    # pack output data
    data = {'time': time,
            'track': position,
            'velocity': velocity,
            'orientation': orientation,
            'lateral_line': Vll,
            'flow_rate': flow_rate,
            'state': state_record}

    return data


# script to execute example
if __name__ == "__main__":
    latline = True
    flow = 'JEB'
    data = randwalk(300, 0.1, 0, np.array([0.37, 0.075, 0.15]), latline = latline, flow_version = flow)
    data = randwalk(300, 0.1, 2, data, latline = latline, flow_version = flow)
    import plot_functions
    axes = plot_functions.plot_tank()
    plot_functions.plot_track3d(data, axes = axes)
    plot_functions.plot_xdata(data)
    plot_functions.plot_kineticdata(data)
    plot_functions.plt.show()