forked from RudgeLab/Inverters
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatemanage.py
More file actions
140 lines (107 loc) · 4.11 KB
/
platemanage.py
File metadata and controls
140 lines (107 loc) · 4.11 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 17 01:10:22 2017
@author: Prosimio
"""
import numpy as np
# import data management package
import pickle as pkl
# Functions to load the data
def sheet_size(sheet, rc0=[1,1]):
"""
This function aims to size the data present in a sheet. The sizing is performed in a fixed position given by the user (rc0).
It means if rc0=[1,1] the column counting will be done in the first row and the row counting will be done in the first column.
Parameters
----------
sheet: workbook sheet
sheet file to be sized
rc0: numeric list
[row number, colmun number] fixed positions where perform the count
Returns
-------
rows: integer
number of rows counted in the sheet
columns: integer
number of columns counted in the sheet
"""
rows = 1
columns = 1
while True:
if sheet.cell(row=rows+1, column=rc0[1]).value != None:
rows+=1
else:
break
while True:
if sheet.cell(row=rc0[0], column=columns+1).value != None:
columns+=1
else:
break
#print(str(rows) + ' rows')
#print(str(columns) + ' columns')
return(rows,columns)
def delimit_data():
start_row=input('Enter the data starting row number (e.g. 2) ')
print('data start in row '+ start_row)
start_column=input('Enter the data starting column number (e.g. 3)')
print('data start in column '+ start_column)
return(int(start_row), int(start_column))
def get_values(ws, row_start, column_start, time_column=1, header_row=1):
"""
To get the wells data from a worksheet
Parameters
----------
ws: worksheet
sheet file to get the data
row_start: int
row where wells data started
Returns
-------
data: numpy array
wells experimental measurements
time: numpy vector
time points values in hours units
header: str
header of each well data (usually 'A1','A2', etc)
"""
rows, columns=sheet_size(ws)
data= np.zeros((rows-row_start+1,columns-column_start+1))
time = np.zeros((rows-row_start+1))
headers = []
for i in range(rows-row_start+1):
time_aux = ws.cell(row=i+row_start, column=time_column).value
#transform time values in hour fractions units
if type(time_aux)==float:
time[i] = time_aux*24
else:
time[i] =time_aux.hour + time_aux.minute/60 + time_aux.second/3600
for j in range(columns-column_start+1):
data[i,j]=ws.cell(row=i+row_start, column=j+column_start).value
if i==0:
headers.append(ws.cell(row=header_row, column=j+column_start).value) # list with the headers
#print(headers)
return(data,time,headers)
def delimit_label():
start_row=input('Enter the label starting row number (e.g. 2) ')
print('data start in row '+ start_row)
start_column=input('Enter the label starting column number (e.g. 2) ')
print('data start in column '+ start_column)
return(int(start_row), int(start_column))
def get_label_values(ws,row_start,column_start):
rows,columns=sheet_size(ws)
if type(ws.cell(row=row_start, column=column_start).value) == str:
values = []
for i in range(rows-row_start+1):
values_col=[]
for j in range(columns-column_start+1):
values_col.append(ws.cell(row=i+row_start, column=j+column_start).value)
values.append(values_col)
else: #in case data is not string
values= np.zeros((rows-row_start+1,columns-column_start+1))
for i in range(rows-row_start+1):
for j in range(columns-column_start+1):
values[i,j]=ws.cell(row=i+row_start, column=j+column_start).value
return(values)
def save_obj(obj, name, folder ):
with open(folder+'/'+ name + '.pkl', 'wb') as f:
pkl.dump(obj, f, pkl.HIGHEST_PROTOCOL)
#####