-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadData.py
93 lines (81 loc) · 2.94 KB
/
LoadData.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
'''
Author: Ahmed Ammar, [email protected]
Purpose: Load NarrowBand data
Inputs: - - -
Outputs: - - -
Date Created: Sat Mar 10 19:10:30 2018
Date Modified: M D, Y
Date Released: M D, Y
Versions:
V0.01: ---
'''
import scipy.io as mat
import numpy as np
import glob
import matplotlib.pyplot as plt
global DataLoaded
DataLoaded_list=[]
DataError_List=[]
def Load_DAQ_Data(path="",fname=""):
"""
Load DAQ Data from raw files
"""
FileList=glob.glob(path+fname)
Data=[]
StartTimes=[]
for filename in FileList:
LoadData = mat.loadmat(filename, struct_as_record=False,
squeeze_me=True)
file=filename.split("\\")
# Add loaded filenames into DataLoaded_list
DATA_NAME=file[-1]
DataLoaded_list.append(DATA_NAME)
print("Data Loaded:", DATA_NAME)
data = LoadData['data']
data_type= LoadData['is_amp']
station_lat= LoadData['latitude']
station_lon= LoadData['longitude']
direction=LoadData['adc_channel_number']
fs = LoadData['Fs']
year = LoadData['start_year']
month= LoadData['start_month']
day = LoadData['start_day']
hr = LoadData['start_hour']
mn = LoadData['start_minute']
sec= LoadData['start_second']
StationInfo={'data_type':data_type, 'station_lat':station_lat,
'station_lon':station_lon, 'direction':direction, 'fs':fs}
Tstart = [float(year),float(month),float(day),float(hr),float(mn),float(sec)] # vector of time.
# print("Tstart: ", Tstart)
S= np.array([1, 1/60., 1/3600.]) * Tstart[3:6]
startTime =S.sum(axis=0) # star time in hours
# print("startTime", startTime)
Data.append(data)
StartTimes.append(startTime)
try:
# Data= np.concatenate(Data) # all the input arrays must have same number of dimensions!
Data= np.hstack(Data) # Stack all Data horizontally
except ValueError:
# if error in file name
DataError_List.append("No filename like " +fname +" in this directory: " + path)
print("No filename like " +fname +" in this directory: " + path)
# Time axis
time= []
for i in range(0, len(Data)):
t1= StartTimes[0] + (i/float(fs)/3600)
# print (t1)
time.append(t1)
time=np.array(time)
return time, Data, StationInfo
if __name__ == "__main__":
# FOR TEST
time, Data, StationInfo =Load_DAQ_Data("F:\\NarrowbandData\\Algeria\\2015\\03\\20\\", "*150320*NRK_000B.mat")
#print(len(Data))
#for large data
plt.rcParams['agg.path.chunksize'] = 10000
# solution given by: Serenity,
#link: https://stackoverflow.com/questions/37470734/matplotlib-giving-error-overflowerror-in-draw-path-exceeded-cell-block-limit
plt.plot(time, Data, lw=.5, color='r')
plt.show()
print("Done!")