forked from n-riesco/lastodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lastodash.py
376 lines (317 loc) · 8.99 KB
/
lastodash.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
import argparse
import os
import pandas
import dash
import dash_daq as daq
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import dash_table as dt
import base64
from plotly import tools
import plotly.graph_objs as go
import lasio
import re
app = dash.Dash(__name__)
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
server = app.server
def parse_args():
parser = argparse.ArgumentParser(
description="Launch a Dash app to view a LAS log."
)
parser.add_argument(
"lasfile",
type=argparse.FileType(mode="r"),
help="Log ASCII Standard (LAS) file"
)
parser.add_argument(
"--debug", "-d",
action="store_true",
help="enable debug mode"
)
args = parser.parse_args()
return args.lasfile, args.debug
if 'DASH_APP_NAME' in os.environ:
lasfile = open('./alcor1.las')
debug = True
else:
lasfile, debug = parse_args()
lf = lasio.read(lasfile)
def generate_frontpage():
filename = os.path.basename(lasfile.name)
frontpage = []
# get the header
frontpage.append(
html.Div(id='las-header', children=[
html.Img(
id='las-logo',
src='data:image/png;base64,{}'.format(
base64.b64encode(
open('assets/logo.png', 'rb').read()
).decode()
)
),
html.Div(
id='las-header-text',
children=[
html.H1("LAS Report"),
html.Div(id='las-file-info', children=[
html.Span(id='las-filename',
children=filename),
html.Span(' ({0})'.format(lf.version['VERS'].descr
if 'VERS' in lf.version
else 'Unknown version'))
])
])
])
)
return frontpage
def generate_axis_title(descr, unit):
title_words = descr.split(' ')
current_line = ''
lines = []
for word in title_words:
if len(current_line) + len(word) > 15:
lines.append(current_line[:-1])
current_line = ''
current_line += '{} '.format(word)
lines.append(current_line)
title = '<br>'.join(lines)
title += '<br>({})'.format(unit)
return title
def generate_curves(
height=950, width=800,
bg_color='white',
font_size=10,
tick_font_size=8,
line_width=0.5
):
# include one graph for all curves, since they have the same x axis
yvals = 'DEPT'
cols = list(lf.curves.keys())
plots = []
plots.append(['BTVPVS', 'DGRC'])
plots.append(list(filter(
lambda x: x == 'EWXT' or re.search(r'R[0-9][0-9]P', x),
cols)
))
plots.append(['ALCDLC', 'ALDCLC'])
plots.append(['TNPS'])
plots.append(['BTCSS', 'BTCS'])
fig = tools.make_subplots(rows=1, cols=len(plots),
shared_yaxes=True,
horizontal_spacing=0)
for i in range(len(plots)):
for column in plots[i]:
fig.append_trace(go.Scatter(
x=lf.curves[column].data,
y=lf.curves[yvals].data,
name=column,
line={'width': line_width,
'dash': 'dashdot' if column in plots[1] else 'solid'},
), row=1, col=i+1)
fig['layout']['xaxis{}'.format(i+1)].update(
title=generate_axis_title(
lf.curves[plots[i][0]]['descr'],
lf.curves[plots[i][0]]['unit']
),
type='log' if column in plots[1] else 'linear'
)
fig['data'][1]['xaxis'] = 'x6'
fig['data'][6]['xaxis'] = 'x7'
fig['data'][8]['xaxis'] = 'x8'
fig['data'][11]['xaxis'] = 'x9'
# DGRC on graph 1
fig['layout']['xaxis6'] = dict(
overlaying='x1',
anchor='y',
side='top',
title=generate_axis_title(
lf.curves['DGRC']['descr'],
lf.curves['DGRC']['unit']
)
)
# EWXT on graph 2
fig['layout']['xaxis7'] = dict(
overlaying='x2',
anchor='y',
side='top',
title=generate_axis_title(
lf.curves['EWXT']['descr'],
lf.curves['EWXT']['unit']
)
)
# ALDCLC on graph 3
fig['layout']['xaxis8'] = dict(
overlaying='x3',
anchor='y',
side='top',
title=generate_axis_title(
lf.curves['ALDCLC']['descr'],
lf.curves['ALDCLC']['unit']
)
)
# BTCS on graph 5
fig['layout']['xaxis9'] = dict(
overlaying='x5',
anchor='y',
side='top',
title=generate_axis_title(
lf.curves['BTCS']['descr'],
lf.curves['BTCS']['unit']
)
)
# y axis title
fig['layout']['yaxis'].update(
title=generate_axis_title(
lf.curves[yvals]['descr'],
lf.curves[yvals]['unit']
),
autorange='reversed'
)
for axis in fig['layout']:
if re.search(r'[xy]axis[0-9]*', axis):
fig['layout'][axis].update(
mirror='all',
automargin=True,
showline=True,
title=dict(
font=dict(
family='Arial, sans-serif',
size=font_size
)
),
tickfont=dict(
family='Arial, sans-serif',
size=tick_font_size
)
)
fig['layout'].update(
height=height,
width=width,
plot_bgcolor=bg_color,
paper_bgcolor=bg_color,
hovermode='y',
legend={
'font': {
'size': tick_font_size
}
},
margin=go.layout.Margin(
r=100
)
)
return dcc.Graph(figure=fig)
def generate_table():
cols = ['mnemonic', 'descr', 'unit', 'value']
data = {
lf.well[i]['mnemonic']: {
col: lf.well[i][col]
for col in cols
}
for i in range(len(lf.well))
}
df = pandas.DataFrame(
data=data
)
df = df.transpose()
df = df[cols]
return dt.DataTable(
id='table',
sorting=True,
filtering=True,
row_deletable=True,
style_cell={
'padding': '15px',
'width': 'auto',
'textAlign': 'center'
},
style_cell_conditional=[
{
'if': {'row_index': 'even'},
'backgroundColor': '#f9f9f9'
}
],
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict("rows")
)
app.layout = html.Div([
html.Div(
id='controls',
children=[
html.Button(
"Print",
id='las-print'
),
]
),
html.Div(
id='frontpage',
className='page',
children=generate_frontpage()
),
html.Div(className='section', children=[
html.Div(
className='section-title',
children="LAS well"
),
html.Div(
className='page',
children=[
html.Div(
id='las-table',
children=generate_table()
),
html.Div(
id='las-table-print'
)]
)
]),
html.Div(className='section', children=[
html.Div(
className='section-title',
children="LAS curves"
),
html.Div(
className='page',
children=[
html.Div(
id='las-curves',
children=generate_curves()
)
]
)
])
])
@app.callback(
Output('las-table-print', 'children'),
[Input('table', 'data')]
)
def update_table_print(data):
colwidths = {
'mnemonic': '100px',
'descr': '300px',
'unit': '25px',
'value': '300px'
}
tables_list = []
num_tables = int(len(data)/34) + 1 # 34 rows max per page
for i in range(num_tables):
table_rows = []
for j in range(34):
if i*34 + j >= len(data):
break
table_rows.append(html.Tr([
html.Td(
data[i*34 + j][key]
) for key in data[0].keys()]))
table_rows.insert(0, html.Tr([
html.Th(
key.title(),
style={'width': colwidths[key]}
) for key in data[0].keys()]))
tables_list.append(html.Div(className='tablepage', children=html.Table(table_rows)))
return tables_list
if __name__ == '__main__':
app.run_server(debug=debug)