ST-DBSCAN application to detect#
new density-based clustering algorithm which takes into account spatial and temporal characteristics of the observations.
ST-DBSCAN is a spatio-temporal density-based clustering.
Reference: Birant, D., & Kut, A. (2007). ST-DBSCAN: An algorithm for clustering spatial–temporal data. Data & Knowledge Engineering, 60(1), 208-221. https://doi.org/10.1016/j.datak.2006.01.013
Exemple: détection des zones plates en montagne#
[1]:
import matplotlib.pyplot as plt
import os
import sys
#-------------------------------------------------------
# Import de tracklib
module_path = os.path.abspath(os.path.join('../../..'))
if module_path not in sys.path:
sys.path.append(module_path)
import tracklib as trk
[2]:
#
trk.ObsTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
resource_path = './'
filepath = os.path.join(resource_path, '../../../data/XYZBRAVOSANSFIDOUTEST.txt')
param = trk.TrackFormat({'ext': 'CSV', 'id_E': 0, 'id_N': 1, 'id_U': 2, 'id_T': -1, 'header': 1})
track = trk.TrackReader.readFromFile(filepath, param)
[3]:
kernel = trk.GaussianKernel(3)
track.operate(trk.Operator.FILTER, "z", kernel, "z_filtered")
track.operate("z=z_filtered")
trk.computeAbsCurv(track)
track.plotProfil('SPATIAL_ALTI_PROFIL')
plt.show()

[4]:
trk.stdbscan(track, 'z', 500, 5, 20, 25)
X1 = []
Y1 = []
X2 = []
Y2 = []
C2 = []
for i in range(len(track)):
o = track[i]
ac = track.getObsAnalyticalFeature('abs_curv', i)
noise = track.getObsAnalyticalFeature('noise', i)
cluster = track.getObsAnalyticalFeature('stdbscan', i)
if noise > 0:
X1.append(ac)
Y1.append(o.position.getZ())
if cluster > 0:
X2.append(ac)
Y2.append(o.position.getZ())
C2.append(cluster)
plt.figure(figsize=(5, 4))
ax1 = plt.gca()
track.plotProfil('SPATIAL_ALTI_PROFIL', append=ax1)
from collections import Counter
print (len(X2), track.size(), len(Counter(C2).keys()))
plt.plot(X2, Y2, 'bo', markersize=1)
plt.show()
249 1105 6
