-
Notifications
You must be signed in to change notification settings - Fork 0
/
TSLDataReader.py
73 lines (62 loc) · 2.63 KB
/
TSLDataReader.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright © 2022 Yauhen Tratsiak. All rights reserved.
# Authors: Yauhen Tratsiak <ytratsia@utk.edu>
# License: GPLv3 (GNU General Public License Version 3)
# https://www.gnu.org/licenses/quick-guide-gplv3.html
#
# This file is part of TSL deconvolute software.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
'''
This file contains small class for reading TSL data files. If should be replaced in accordance with your needs.
'''
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
class TSLDataReader():
def __init__(self, filename, mult = 10):
self.fname = filename
self.mult = mult
def read_data(self, mult = True):
data = []
with open(self.fname, 'r') as f:
for lines in f.readlines():
elements = lines[:-1].split('\t')
data.append(np.array(elements))
data = np.array(data)
f.close()
mod_data = []
for i, rows in enumerate(data):
mod_data.append([])
for element in rows:
if len(element) > 1:
if ('PM' in element) or ('AM' in element):
dt = datetime.strptime(element,'%m/%d/%Y %I:%M:%S %p')
mod_data[i].append(np.datetime64(dt))
else:
mod_data[i].append(float(element))
mod_data = np.array(mod_data)
init_time = mod_data[0][-1]
for i in range(len(mod_data)):
mod_data[i][-1] = ((mod_data[i][-1] - init_time)/1e+6).astype(np.float64)
if mult:
mod_data[:, 3] = mod_data[:, 3] + np.abs(min(mod_data[:, 3]))
maxval = max(mod_data[:, 3])
mod_data[:, 3] = mod_data[:, 3] * self.mult/maxval
return np.array(mod_data, dtype=np.float64)
if __name__ == "__main__":
print('Not for individual use')