-
Notifications
You must be signed in to change notification settings - Fork 3
/
animals.py
39 lines (28 loc) · 1.43 KB
/
animals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
def displacement(file):
file = np.loadtxt(str(file),delimiter=',')
dis = np.sum(np.sqrt(np.sum(np.diff(file[:,1:],axis=0)**2,axis=1)))
return str(np.round(dis,2))
def time_center(x1,x2,y1,y2,file):
tc = 0
file = np.loadtxt(str(file),delimiter=',')
for i in range (file.shape[0]-1):
if (file[i,1] > x1 and file[i,1] < x2 and file[i,2] > y1 and file[i,2] < y2) and (file[i+1,1] > x1 and file[i+1,1] < x2
and file[i+1,2] > y1 and file[i+1,2] < y2):
tc += file[i+1,0] - file[i,0]
return str(np.round(tc,2))
def time_edges(x1,x2,y1,y2,file):
file = np.loadtxt(str(file),delimiter=',')
te = 0
for i in range(file.shape[0]-1):
if (file[i,1] < x1 or file[i,1] > x2):
if (file[i+1,1] < x1 or file[i+1,1] > x2):
te += file[i+1,0] - file[i,0]
elif (file[i+1,1] > x1 and file[i+1,1] < x2) and (file[i+1,2] < y1 or file[i+1,2] > y2):
te += file[i+1,0] - file[i,0]
elif (file[i,1] > x1 and file[i,1] < x2) and (file[i,2] < y1 or file[i,2] > y2):
if (file[i+1,1] < x1 or file[i+1,1] > x2):
te += file[i+1,0] - file[i,0]
elif (file[i+1,1] > x1 and file[i+1,1] < x2) and (file[i+1,2] < y1 or file[i+1,2] > y2):
te += file[i+1,0] - file[i,0]
return str(np.round(te,2))