Skip to main content

Codes to perform Dynamic Time Warping Based Hierarchical Agglomerative Clustering of GPS data

Project description

Dynamic Time Warping based Hierarchical Agglomerative Clustering

Codes to perform Dynamic Time Warping Based Hierarchical Agglomerative Clustering of GPS data

Documentation

Installation and usage information can be obtained from the documentation: dtwhaclustering.pdf

Complete documentation at: dtwhaclustering-docs

Details

This package include codes for processing the GPS displacement data including least-square modelling for trend, co-seismic jumps, seasonal and tidal signals. Finally, it can be used to cluster the GPS displacements based on the similarity of the waveforms. The similarity among the waveforms will be obtained using the DTW distance.

Usage

Least-squares modeling

Load Pickle Data into Pandas DataFrame

from dtwhaclustering.leastSquareModeling import lsqmodeling
final_dU, final_dN, final_dE = lsqmodeling(dUU, dNN, dEE,stnlocfile="helper_files/stn_loc.txt",  plot_results=True, remove_trend=False, remove_seasonality=True, remove_jumps=False)

LSQ Model

Plot station map

from dtwhaclustering import plot_stations
plot_stations.plot_station_map(station_data = 'helper_files/selected_stations_info.txt', outfig=f'{outloc}/station_map.pdf')

Plot linear trend

slopeFile=f'stn_slope_res_U.txt'
df = pd.read_csv(slopeFile, names=['stn','lon','lat','slope'], delimiter='\s+')
plot_linear_trend_on_map(df, outfig=f"Maps/slope-plot_U.pdf")

Note: slopeFile is obtained from lsqmodeling.

Dynamic Time Warping Analysis

from dtwhaclustering.dtw_analysis import dtw_signal_pairs, dtw_clustering
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt

np.random.seed(0)
# sampling parameters
fs = 100   # sampling rate, in Hz
T = 1      # duration, in seconds
N = T * fs  # duration, in samples

# time variable
t = np.linspace(0, T, N)

SNR = 0.2 #noise

XX0 = np.sin(2 * np.pi * t * 7+np.pi/2) #+ np.random.randn(1, N) * SNR
XX1 = signal.sawtooth(2 * np.pi * t * 5+np.pi/2) #+ np.random.randn(1, N) * SNR
# XX1 = np.abs(np.cos(2 * np.pi * t * 3)) - 0.5
s1, s2 = XX0, XX1

dtwsig = dtw_signal_pairs(s1, s2, labels=['S1', 'S2'])

dtwsig.plot_signals()
plt.show()
dtwsig.plot_matrix(windowfrac=0.6, psi=None) #Only allow for shifts up to 60% of the minimum signal length away from the two diagonals.
plt.show()

References

  1. Kumar, U., Chao, B.F., Chang, E.T.-Y.Y., 2020. What Causes the Common‐Mode Error in Array GPS Displacement Fields: Case Study for Taiwan in Relation to Atmospheric Mass Loading. Earth Sp. Sci. 0–2. https://doi.org/10.1029/2020ea001159

License

© 2021 Utpal Kumar

Licensed under the Apache License, Version 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dtwhaclustering-1.0.14.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

dtwhaclustering-1.0.14-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file dtwhaclustering-1.0.14.tar.gz.

File metadata

  • Download URL: dtwhaclustering-1.0.14.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for dtwhaclustering-1.0.14.tar.gz
Algorithm Hash digest
SHA256 33f115ddeb57150ec97f09622c7bb89a832efaa0bd5ae283b5fa3d8c48e9e4e0
MD5 bec22482126bfbcc039bcd6395f58935
BLAKE2b-256 cbaf928dd525ae06a3136b0d2114b69fa4a2b23815d362e50f7346a358cc71c7

See more details on using hashes here.

File details

Details for the file dtwhaclustering-1.0.14-py3-none-any.whl.

File metadata

  • Download URL: dtwhaclustering-1.0.14-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for dtwhaclustering-1.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 4fcb3046faa1022f81b915cab587f0d573a33680d72f5e15f19ea3cdb3e016d8
MD5 867dc0424a2f3ed82bb647749e7ad316
BLAKE2b-256 5fa5141b056b0a45cf227f43f5d3ca1907db6933df09dcd90a5361a7a87ed6db

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page