-
Notifications
You must be signed in to change notification settings - Fork 3
/
loadDLSdataHelpers.py
51 lines (34 loc) · 1.25 KB
/
loadDLSdataHelpers.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
import pandas as pd
import numpy as np
def is_float(element):
try:
float(element)
return True
except ValueError:
return False
def isBlank(myString):
return (not (myString and myString.strip())) or myString == "nan"
def readWyatFile(file):
"""
Input: CSV where the first column stores the time in microseconds
all subsequent columns store the measured autocorrelation
"""
df = pd.read_csv(file, sep=',',encoding=' latin-1')
df = df.sort_values(by=[df.columns[0]], ascending=True)
# Delete the first point
startIDx = 1
time = np.array(df.iloc[startIDx:,0]) / 1e6 # From microseconds to seconds
total_rows = len(df.index)
# Get columns with data (not too many NaNs)
selInds = []
sampleNames = []
for ind, column in enumerate(df.columns[1:]):
nas = df[column].isna().sum()
if nas < total_rows / 2:
selInds.append(ind)
sampleNames.append(column)
# add 1 if required to the autocorrelation curves
if np.min(np.abs(df[column])) < 0.01:
df[column] += 1
autocorrelation = np.array(df.iloc[startIDx:,1:])[:,selInds]
return time, autocorrelation, sampleNames