-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData1D_PumpingCurve.py
224 lines (189 loc) · 6.75 KB
/
Data1D_PumpingCurve.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import numpy as np
import os
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
import pandas as pd
class Data1D_PumpingCurve:
"""
A class to represent 1D pumping curve data.
"""
def __init__(self, filename):
"""
Initialize the Data1D_PumpingCurve object by loading data from a npz file.
Parameters:
----------
filename : str
The path to the file containing the data.
"""
file_name = os.path.basename(filename)
self.filename = file_name
data_structure = np.load(filename, allow_pickle=True)
self.label = data_structure['label']
self.taxis = data_structure['taxis']
self.data = data_structure['value']
def gen_unit(self):
"""
Generate the unit of the data.
Returns:
----------
str
The unit of the data.
"""
# create a dictionary of units
unit_dict = {'Treating Pressure': 'psi', 'Slurry Rate': 'bpm', 'Proppant Concentration': 'lb/gal'}
# find the variable index
self.unit = []
for key in self.label:
self.unit.append(unit_dict[key])
def print_label(self):
"""
Print the label of the data.
"""
print(self.label)
def print_info(self):
"""
Print the information of the data.
"""
print('Filename:', self.filename)
print('Label:', self.label)
print('Time range:', self.taxis[0], "-", self.taxis[-1])
def get_start_time(self):
"""
Get the start time of the data.
Returns:
----------
datetime
The start time of the data.
"""
return self.taxis[0]
def get_end_time(self):
"""
Get the end time of the data.
Returns:
----------
datetime
The end time of the data.
"""
return self.taxis[-1]
def apply_timeshift(self, shift):
"""
Apply a time shift to the data.
Parameters:
----------
shift : timedelta
The time shift to apply.
"""
self.taxis = self.taxis + shift
def plot_single_var(self, key):
"""
Plot the data of a single variable.
Parameters:
----------
key : str
The name of the variable to plot.
"""
# find the variable index
var_index = np.where(self.label == key)[0][0]
# plot the variable
plt.figure()
plt.plot(self.taxis, self.data[var_index, :])
plt.xlabel('Time')
plt.ylabel(key)
plt.title(key)
plt.tight_layout()
plt.show()
def get_data_by_name(self, key):
"""
Get the data of a variable by name.
Parameters:
----------
key : str
The name of the variable to get.
Returns:
----------
np.array
The data of the variable.
"""
# find the variable index
var_index = np.where(self.label == key)[0][0]
return self.data[var_index, :]
def crop_data(self, start_time, end_time):
"""
Crop the data to a specific time range.
Parameters:
----------
start_time : datetime
The start time of the time range.
end_time : datetime
The end time of the time range.
"""
ind = (self.taxis >= start_time) & (self.taxis <= end_time)
self.data = self.data[:, ind]
self.taxis = self.taxis[ind]
def plot_all_vars_simple(self, figsize=(10, 6)):
"""
Plot the data of all variables.
"""
plt.figure(figsize=figsize)
self.gen_unit()
# Read the pumping curve data and plot it
ax3 = plt.subplot2grid((3,4), (2,0), colspan=4, rowspan=1)
color = 'blue'
ax3.set_xlabel('Time')
ax3.set_ylabel(f'{self.label[0]}/{self.unit[0]}', color=color)
ax3.plot(self.taxis, self.data[0,:], label=self.label[0], color=color)
ax3.tick_params(axis='y', labelcolor=color)
# Making a second axis for treating pressure
ax31 = ax3.twinx()
color = 'green'
ax31.set_ylabel(f'{self.label[1]}/{self.unit[1]}', color=color)
ax31.plot(self.taxis, self.data[1, :], label=self.label[1], color=color)
ax31.tick_params(axis='y', labelcolor=color)
# Making a third axis for proppant concentration
ax32 = ax3.twinx()
color = 'red'
ax32.spines["right"].set_position(("outward", 60)) # Offset the right spine of ax3
ax32.set_ylabel(f'{self.label[2]}/{self.unit[2]}', color=color)
ax32.plot(self.taxis, self.data[2,:], label=self.label[2], color=color)
ax32.tick_params(axis='y', labelcolor=color)
ax3.xaxis_date()
# set legend for ax 3
# generate legend
lines, labels = ax3.get_legend_handles_labels()
lines2, labels2 = ax31.get_legend_handles_labels()
lines3, labels3 = ax32.get_legend_handles_labels()
ax3.legend(lines + lines2 + lines3, labels + labels2 + labels3, loc='upper right')
plt.tight_layout()
plt.show()
def plot_all_vars(self, ax3):
"""
Plot the data of all variables. on ax.
"""
self.gen_unit()
# Read the pumping curve data and plot it
# ax3 = plt.subplot2grid((3,4), (2,0), colspan=4, rowspan=1)
color = 'blue'
ax3.set_xlabel('Time')
ax3.set_ylabel(f'{self.label[0]}/{self.unit[0]}', color=color)
ax3.plot(self.taxis, self.data[0,:], label=self.label[0], color=color)
ax3.tick_params(axis='y', labelcolor=color)
# Making a second axis for treating pressure
ax31 = ax3.twinx()
color = 'green'
ax31.set_ylabel(f'{self.label[1]}/{self.unit[1]}', color=color)
ax31.plot(self.taxis, self.data[1, :], label=self.label[1], color=color)
ax31.tick_params(axis='y', labelcolor=color)
# Making a third axis for proppant concentration
ax32 = ax3.twinx()
color = 'red'
ax32.spines["right"].set_position(("outward", 60)) # Offset the right spine of ax3
ax32.set_ylabel(f'{self.label[2]}/{self.unit[2]}', color=color)
ax32.plot(self.taxis, self.data[2,:], label=self.label[2], color=color)
ax32.tick_params(axis='y', labelcolor=color)
ax3.xaxis_date()
# set legend for ax 3
# generate legend
lines, labels = ax3.get_legend_handles_labels()
lines2, labels2 = ax31.get_legend_handles_labels()
lines3, labels3 = ax32.get_legend_handles_labels()
ax3.legend(lines + lines2 + lines3, labels + labels2 + labels3, loc='upper right')