-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelperFunctions.py
72 lines (62 loc) · 2.78 KB
/
helperFunctions.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import settings as sett
import numpy as np
import math
# ------------------------------------------------------------------------------------------------------------
#initialize global variables
sett.init()
# ST Kernel density estimation
#--------------------------------------------------------------------------------------
def densityF(x, y, t, xi, yi, ti, hs, ht):
u = (x-xi) / hs
v = (y-yi) / hs
w = (t-ti) / ht
Ks = (2/math.pi)*(1 - pow(u, 2) - pow(v, 2))
Kt = 0.75*(1 - pow(w, 2))
STKDE = [Ks,Kt]
return STKDE
#--------------------------------------------------------------------------------------
# function to convert coordinates to index for inArr
#--------------------------------------------------------------------------------------
def coordToIndex(x,y,t):
xIndex = int((x-sett.xmin) / sett.xyRes)
yIndex = int((y-sett.ymin) / sett.xyRes)
tIndex = int((t-sett.tmin) / sett.tRes)
return [xIndex, yIndex, tIndex]
#--------------------------------------------------------------------------------------
# function to create list of x,y,t coords witin hs, ht of data point
#--------------------------------------------------------------------------------------
def xytWithin(x,y,t):
#minimum coords of neighborhood around data point
xLo = x - sett.hs_max
xHi = x + sett.hs_max
yLo = y - sett.hs_max
yHi = y + sett.hs_max
tLo = t - sett.ht_max
tHi = t + sett.ht_max
#difference between xmin, ymin, tmin and closest grid point
xminDiff = xLo % sett.xyRes
xmaxDiff = xHi % sett.xyRes
yminDiff = yLo % sett.xyRes
ymaxDiff = yHi % sett.xyRes
tminDiff = tLo % sett.tRes
tmaxDiff = tHi % sett.tRes
#first
xminP = max(xLo - xminDiff + sett.xyRes, sett.xmin)
xmaxP = min(xHi - xmaxDiff + sett.xyRes, sett.xmax)
yminP = max(yLo - yminDiff + sett.xyRes, sett.ymin)
ymaxP = min(yHi - ymaxDiff + sett.xyRes, sett.ymax)
tminP = max(tLo - tminDiff + sett.tRes, sett.tmin)
tmaxP = min(tHi - tmaxDiff + sett.tRes, sett.tmax)
#grids
xytGrid = []
for i in np.arange(int(xminP),int(xmaxP),sett.xyRes):
for j in np.arange(int(yminP),int(ymaxP),sett.xyRes):
for k in np.arange(int(tminP), int(tmaxP), sett.tRes):
xytGrid.append(coordToIndex(i,j,k))
return xytGrid
# --------------------------------------------------------------------------------------
#distance function
#------------------------------------------------------------------------------------------------------------
def dist(p1,p2):
return [pow(pow(p1[0]-p2[0],2)+pow(p1[1]-p2[1],2),0.5), abs(p1[2] - p2[2])]
#------------------------------------------------------------------------------------------------------------