-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreaddata.py
64 lines (50 loc) · 1.49 KB
/
readdata.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
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
"""
Contains data from the Monash University Woodside Living Lab Building
recording of earthquakes
Basic data reading and plotting
"""
# pip install npTDMS for reading the NI TDMS file type
from nptdms import TdmsFile
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from pathlib import Path
# The 22 Sept 2021 Mansfield 5.8M earthquake
quake2021_file = "./quake2021/202109220920_SHM-6.tdms"
# The 28 May 2023 Sunbury quake
quake2023_file = "./quake2023/202305282340_SHM-6.tdms"
# Which quake?
quake_file = Path(quake2023_file)
# Reading the NI TDMS file
tdms_file = TdmsFile.read(quake_file)
channels = tdms_file.groups()[0].channels()
# Quick plot of the data
fig, ax = plt.subplots()
for c in channels:
data = c[:]
t = c.time_track(absolute_time=True)
ax.plot(t, data, label=c.name)
ax.legend()
plt.show()
# Sample rate and start time in UTC
c0 = channels[0]
t0 = c0.properties["wf_start_time"]
fs = 1 / c0.properties["wf_increment"]
print(f"Record start time {t0}")
print(f"Sample rate: {fs}")
# Export relevant zeroed data window to CSV (~81 MB file)
t0 = c0.properties["wf_start_time"]
ts = t0 + np.timedelta64(60, "s")
tf = t0 + np.timedelta64(6, "m")
t = c0.time_track(absolute_time=True)
idx = np.where((t > ts) & (t < tf))
tw = t[idx]
df = pd.DataFrame()
df["t"] = tw
for c in channels:
zero_data = c[: (t < ts).sum()]
data = c[idx] - zero_data.mean()
df[c.name] = data
df.to_csv("accels.csv", index=False)