Completed
Push — master ( 25abed...55d3cc )
by Kent
10s
created

test_write_large_depths()   A

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
1
import os, sys; sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
2
3
import pytest
4
import numpy as np
5
6
import lasio
7
from lasio import read
8
from lasio.excel import ExcelConverter
9
10
from lasio.reader import StringIO
11
12
test_dir = os.path.dirname(__file__)
13
14
egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)
15
16
17
def test_write_sect_widths_12(capsys):
18
    las = lasio.read(egfn("sample_write_sect_widths_12.las"))
19
    las.write(sys.stdout, version=1.2)
20
    assert capsys.readouterr()[0] == open(egfn('test_write_sect_widths_12.txt')).read()
21
22
def test_write_to_filename():
23
    las = read(egfn("sample_write_sect_widths_12.las"))
24
    las.write('test.las', version=1.2)
25
    assert os.path.isfile('test.las')
26
    os.remove('test.las')
27
28
29
def test_write_sect_widths_12_curves():
30
    l = read(egfn("sample_write_sect_widths_12.las"))
31
    s = StringIO()
32
    l.write(s, version=1.2)
33
    for start in ("D.M ", "A.US/M ", "B.K/M3 ", "C.V/V "):
34
        s.seek(0)
35
        assert "\n" + start in s.read()
36
37
38
def test_write_sect_widths_20_narrow():
39
    l = read(egfn("sample_write_sect_widths_20_narrow.las"))
40
    s = StringIO()
41
    l.write(s, version=2)
42
    s.seek(0)
43
    assert s.read() == """~Version ---------------------------------------------------
44
VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
45
WRAP.  NO : ONE LINE PER DEPTH STEP
46
~Well ------------------------------------------------------
47
STRT.M   1670.0 : START DEPTH
48
STOP.M  1669.75 : STOP DEPTH
49
STEP.M   -0.125 : STEP
50
NULL.   -999.25 : NULL VALUE
51
COMP.       ANY : COMPANY
52
WELL.   AAAAA_2 : WELL
53
FLD .   WILDCAT : FIELD
54
LOC .        12 : LOCATION
55
PROV.   ALBERTA : PROVINCE
56
SRVC.   LOGGING : SERVICE COMPANY ARE YOU KIDDING THIS IS A REALLY REALLY LONG STRING
57
DATE. 13-DEC-86 : LOG DATE
58
UWI .  10012340 : UNIQUE WELL ID
59
~Curves ----------------------------------------------------
60
DEPT.M                 : 1  DEPTH
61
DT  .US/M 60 520 32 00 : 2  SONIC TRANSIT TIME
62
RHOB.K/M3 45 350 01 00 : 3  BULK DENSITY
63
NPHI.V/V  42 890 00 00 : 4  NEUTRON POROSITY
64
SFLU.OHMM 07 220 04 00 : 5  SHALLOW RESISTIVITY
65
SFLA.OHMM 07 222 01 00 : 6  SHALLOW RESISTIVITY
66
ILM .OHMM 07 120 44 00 : 7  MEDIUM RESISTIVITY
67
ILD .OHMM 07 120 46 00 : 8  DEEP RESISTIVITY
68
~Params ----------------------------------------------------
69
MUD .   GEL CHEM : MUD TYPE
70
BHT .DEGC   35.5 : BOTTOM HOLE TEMPERATURE
71
BS  .MM    200.0 : BIT SIZE
72
FD  .K/M3 1000.0 : FLUID DENSITY
73
MATR.       SAND : NEUTRON MATRIX
74
MDEN.     2710.0 : LOGGING MATRIX DENSITY
75
RMF .OHMM  0.216 : MUD FILTRATE RESISTIVITY
76
DFD .K/M3 1525.0 : DRILL FLUID DENSITY
77
~Other -----------------------------------------------------
78
Note: The logging tools became stuck at 625 metres causing the data
79
between 625 metres and 615 metres to be invalid.
80
~ASCII -----------------------------------------------------
81
 1670.00000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
82
 1669.87500  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
83
 1669.75000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
84
"""
85
86
87
def test_write_sect_widths_20_wide():
88
    l = read(egfn("sample_write_sect_widths_20_wide.las"))
89
    s = StringIO()
90
    l.write(s, version=2)
91
    s.seek(0)
92
    assert s.read() == """~Version ---------------------------------------------------
93
VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
94
WRAP.  NO : ONE LINE PER DEPTH STEP
95
~Well ------------------------------------------------------
96
STRT.M                                                         1670.0 : START DEPTH
97
STOP.M                                                        1669.75 : STOP DEPTH
98
STEP.M                                                         -0.125 : STEP
99
NULL.                                                         -999.25 : NULL VALUE
100
COMP.                                            ANY OIL COMPANY INC. : COMPANY
101
WELL.                                                         AAAAA_2 : WELL
102
FLD .                                                         WILDCAT : FIELD
103
LOC .                                                  12-34-12-34W5M : LOCATION
104
PROV.                                                         ALBERTA : PROVINCE
105
SRVC. The company that did this logging has a very very long name.... : SERVICE COMPANY
106
DATE.                                                       13-DEC-86 : LOG DATE
107
UWI .                                                100123401234W500 : UNIQUE WELL ID
108
~Curves ----------------------------------------------------
109
DEPT.M                 : 1  DEPTH
110
DT  .US/M 60 520 32 00 : 2  SONIC TRANSIT TIME
111
RHOB.K/M3 45 350 01 00 : 3  BULK DENSITY
112
NPHI.V/V  42 890 00 00 : 4  NEUTRON POROSITY
113
SFLU.OHMM 07 220 04 00 : 5  SHALLOW RESISTIVITY
114
SFLA.OHMM 07 222 01 00 : 6  SHALLOW RESISTIVITY
115
ILM .OHMM 07 120 44 00 : 7  MEDIUM RESISTIVITY
116
ILD .OHMM 07 120 46 00 : 8  DEEP RESISTIVITY
117
~Params ----------------------------------------------------
118
MUD .   GEL CHEM : MUD TYPE
119
BHT .DEGC   35.5 : BOTTOM HOLE TEMPERATURE
120
BS  .MM    200.0 : BIT SIZE
121
FD  .K/M3 1000.0 : FLUID DENSITY
122
MATR.       SAND : NEUTRON MATRIX
123
MDEN.     2710.0 : LOGGING MATRIX DENSITY
124
RMF .OHMM  0.216 : MUD FILTRATE RESISTIVITY
125
DFD .K/M3 1525.0 : DRILL FLUID DENSITY
126
~Other -----------------------------------------------------
127
Note: The logging tools became stuck at 625 metres causing the data
128
between 625 metres and 615 metres to be invalid.
129
~ASCII -----------------------------------------------------
130
 1670.00000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
131
 1669.87500  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
132
 1669.75000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
133
"""
134
135
def test_write_sample_empty_params():
136
    l = read(egfn("sample_write_empty_params.las"))
137
    l.write(StringIO(), version=2)
138
139
def test_df_curve_addition_on_export():
140
    l = read(egfn("sample.las"))
141
    df = l.df()
142
    df["ILD_COND"] = 1000 / df.ILD
143
    l.set_data_from_df(df, truncate=False)
144
    s = StringIO()
145
    l.write(s, version=2, wrap=False, fmt="%.5f")
146
    s.seek(0)
147
    assert s.read() == """~Version ---------------------------------------------------
148
VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
149
WRAP.  NO : One line per depth step
150
~Well ------------------------------------------------------
151
STRT.M                  1670.0 : 
152
STOP.M                 1669.75 : 
153
STEP.M                  -0.125 : 
154
NULL.                  -999.25 : 
155
COMP.   # ANY OIL COMPANY LTD. : COMPANY
156
WELL.   ANY ET AL OIL WELL #12 : WELL
157
FLD .                     EDAM : FIELD
158
LOC .           A9-16-49-20W3M : LOCATION
159
PROV.             SASKATCHEWAN : PROVINCE
160
SRVC. ANY LOGGING COMPANY LTD. : SERVICE COMPANY
161
DATE.              25-DEC-1988 : LOG DATE
162
UWI .         100091604920W300 : UNIQUE WELL ID
163
~Curves ----------------------------------------------------
164
DEPT    .M     : 1  DEPTH
165
DT      .US/M  : 2  SONIC TRANSIT TIME
166
RHOB    .K/M3  : 3  BULK DENSITY
167
NPHI    .V/V   : 4   NEUTRON POROSITY
168
SFLU    .OHMM  : 5  RXO RESISTIVITY
169
SFLA    .OHMM  : 6  SHALLOW RESISTIVITY
170
ILM     .OHMM  : 7  MEDIUM RESISTIVITY
171
ILD     .OHMM  : 8  DEEP RESISTIVITY
172
ILD_COND.      : 
173
~Params ----------------------------------------------------
174
BHT .DEGC   35.5 : BOTTOM HOLE TEMPERATURE
175
BS  .MM    200.0 : BIT SIZE
176
FD  .K/M3 1000.0 : FLUID DENSITY
177
MATR.        0.0 : NEUTRON MATRIX(0=LIME,1=SAND,2=DOLO)
178
MDEN.     2710.0 : LOGGING MATRIX DENSITY
179
RMF .OHMM  0.216 : MUD FILTRATE RESISTIVITY
180
DFD .K/M3 1525.0 : DRILL FLUID DENSITY
181
~Other -----------------------------------------------------
182
Note: The logging tools became stuck at 625 meters causing the data
183
between 625 meters and 615 meters to be invalid.
184
~ASCII -----------------------------------------------------
185
 1670.00000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000    9.46970
186
 1669.87500  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000    9.46970
187
 1669.75000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000    9.46970
188
"""
189
190
def test_write_xlsx():
191
    l = read(egfn("sample.las"))
192
    e = ExcelConverter(l)
193
    xlsxfn = "test.xlsx"
194
    e.write(xlsxfn)
195
    os.remove(xlsxfn)
196
197
def test_export_xlsx():
198
    l = read(egfn("sample.las"))
199
    xlsxfn = "test2.xlsx"
200
    l.to_excel(xlsxfn)
201
    os.remove(xlsxfn)
202
203
def test_multi_curve_mnemonics_rewrite():
204
    l = read(egfn('sample_issue105_a.las'))
205
    s = StringIO()
206
    l.write(s, version=2, wrap=False, fmt="%.5f")
207
    s.seek(0)
208
    assert s.read() == '''~Version ---------------------------------------------------
209
VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
210
WRAP.  NO : One line per depth step
211
~Well ------------------------------------------------------
212
STRT.M                  1670.0 : 
213
STOP.M                 1669.75 : 
214
STEP.M                  -0.125 : 
215
NULL.                  -999.25 : 
216
COMP.   # ANY OIL COMPANY LTD. : COMPANY
217
WELL.   ANY ET AL OIL WELL #12 : WELL
218
FLD .                     EDAM : FIELD
219
LOC .           A9-16-49-20W3M : LOCATION
220
PROV.             SASKATCHEWAN : PROVINCE
221
SRVC. ANY LOGGING COMPANY LTD. : SERVICE COMPANY
222
DATE.              25-DEC-1988 : LOG DATE
223
UWI .         100091604920W300 : UNIQUE WELL ID
224
~Curves ----------------------------------------------------
225
DEPT.M     : 1  DEPTH
226
RHO .ohmm  : curve 1,2,3
227
RHO .ohmm  : curve 10,20,30
228
RHO .ohmm  : curve 100,200,300
229
PHI .      : porosity
230
~Params ----------------------------------------------------
231
BHT .DEGC   35.5 : BOTTOM HOLE TEMPERATURE
232
BS  .MM    200.0 : BIT SIZE
233
FD  .K/M3 1000.0 : FLUID DENSITY
234
MATR.        0.0 : NEUTRON MATRIX(0=LIME,1=SAND,2=DOLO)
235
MDEN.     2710.0 : LOGGING MATRIX DENSITY
236
RMF .OHMM  0.216 : MUD FILTRATE RESISTIVITY
237
DFD .K/M3 1525.0 : DRILL FLUID DENSITY
238
~Other -----------------------------------------------------
239
Note: The logging tools became stuck at 625 meters causing the data
240
between 625 meters and 615 meters to be invalid.
241
~ASCII -----------------------------------------------------
242
 1670.00000    1.00000   10.00000  100.00000    0.10000
243
 1669.87500    2.00000   20.00000  200.00000    0.20000
244
 1669.75000    3.00000   30.00000  300.00000    0.30000
245
'''
246
247
def test_multi_curve_missing_mnemonics_rewrite():
248
    l = read(egfn('sample_issue105_b.las'))
249
    s = StringIO()
250
    l.write(s, version=2, wrap=False, fmt="%.5f")
251
    s.seek(0)
252
    assert s.read() == '''~Version ---------------------------------------------------
253
VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
254
WRAP.  NO : One line per depth step
255
~Well ------------------------------------------------------
256
STRT.M                  1670.0 : 
257
STOP.M                 1669.75 : 
258
STEP.M                  -0.125 : 
259
NULL.                  -999.25 : 
260
COMP.   # ANY OIL COMPANY LTD. : COMPANY
261
WELL.   ANY ET AL OIL WELL #12 : WELL
262
FLD .                     EDAM : FIELD
263
LOC .           A9-16-49-20W3M : LOCATION
264
PROV.             SASKATCHEWAN : PROVINCE
265
SRVC. ANY LOGGING COMPANY LTD. : SERVICE COMPANY
266
DATE.              25-DEC-1988 : LOG DATE
267
UWI .         100091604920W300 : UNIQUE WELL ID
268
~Curves ----------------------------------------------------
269
DEPT.M     : 1  DEPTH
270
    .ohmm  : curve 1,2,3
271
    .ohmm  : curve 10,20,30
272
    .ohmm  : curve 100,200,300
273
PHI .      : porosity
274
~Params ----------------------------------------------------
275
BHT .DEGC   35.5 : BOTTOM HOLE TEMPERATURE
276
BS  .MM    200.0 : BIT SIZE
277
FD  .K/M3 1000.0 : FLUID DENSITY
278
MATR.        0.0 : NEUTRON MATRIX(0=LIME,1=SAND,2=DOLO)
279
MDEN.     2710.0 : LOGGING MATRIX DENSITY
280
RMF .OHMM  0.216 : MUD FILTRATE RESISTIVITY
281
DFD .K/M3 1525.0 : DRILL FLUID DENSITY
282
~Other -----------------------------------------------------
283
Note: The logging tools became stuck at 625 meters causing the data
284
between 625 meters and 615 meters to be invalid.
285
~ASCII -----------------------------------------------------
286
 1670.00000    1.00000   10.00000  100.00000    0.10000
287
 1669.87500    2.00000   20.00000  200.00000    0.20000
288
 1669.75000    3.00000   30.00000  300.00000    0.30000
289
'''
290
291
def test_write_units():
292
    l = read(egfn("sample.las"))
293
    l.curves[0].unit = 'FT'
294
    s = StringIO()
295
    l.write(s, version=2, wrap=False, fmt="%.5f")
296
    s.seek(0)
297
    assert s.read() == '''~Version ---------------------------------------------------
298
VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
299
WRAP.  NO : One line per depth step
300
~Well ------------------------------------------------------
301
STRT.FT                 1670.0 : 
302
STOP.FT                1669.75 : 
303
STEP.FT                 -0.125 : 
304
NULL.                  -999.25 : 
305
COMP.   # ANY OIL COMPANY LTD. : COMPANY
306
WELL.   ANY ET AL OIL WELL #12 : WELL
307
FLD .                     EDAM : FIELD
308
LOC .           A9-16-49-20W3M : LOCATION
309
PROV.             SASKATCHEWAN : PROVINCE
310
SRVC. ANY LOGGING COMPANY LTD. : SERVICE COMPANY
311
DATE.              25-DEC-1988 : LOG DATE
312
UWI .         100091604920W300 : UNIQUE WELL ID
313
~Curves ----------------------------------------------------
314
DEPT.FT    : 1  DEPTH
315
DT  .US/M  : 2  SONIC TRANSIT TIME
316
RHOB.K/M3  : 3  BULK DENSITY
317
NPHI.V/V   : 4   NEUTRON POROSITY
318
SFLU.OHMM  : 5  RXO RESISTIVITY
319
SFLA.OHMM  : 6  SHALLOW RESISTIVITY
320
ILM .OHMM  : 7  MEDIUM RESISTIVITY
321
ILD .OHMM  : 8  DEEP RESISTIVITY
322
~Params ----------------------------------------------------
323
BHT .DEGC   35.5 : BOTTOM HOLE TEMPERATURE
324
BS  .MM    200.0 : BIT SIZE
325
FD  .K/M3 1000.0 : FLUID DENSITY
326
MATR.        0.0 : NEUTRON MATRIX(0=LIME,1=SAND,2=DOLO)
327
MDEN.     2710.0 : LOGGING MATRIX DENSITY
328
RMF .OHMM  0.216 : MUD FILTRATE RESISTIVITY
329
DFD .K/M3 1525.0 : DRILL FLUID DENSITY
330
~Other -----------------------------------------------------
331
Note: The logging tools became stuck at 625 meters causing the data
332
between 625 meters and 615 meters to be invalid.
333
~ASCII -----------------------------------------------------
334
 1670.00000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
335
 1669.87500  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
336
 1669.75000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
337
'''
338
339
def test_to_csv_units_None():
340
    las = read(egfn("sample.las"))
341
    las.to_csv('test.csv', units_loc=None)
342
    csv_output = open('test.csv', 'r').readlines()
343
    proof_output = open(egfn('sample.las_units-none.csv'), 'r').readlines()
344
    os.remove('test.csv')
345
    assert csv_output[0] == proof_output[0]
346
    # assert csv_output[1] == proof_output[1]
347
348
def test_to_csv_units_line():
349
    las = read(egfn("sample.las"))
350
    las.to_csv('test.csv', units_loc='line')
351
    csv_output = open('test.csv', 'r').readlines()
352
    proof_output = open(egfn('sample.las_units-line.csv'), 'r').readlines()
353
    os.remove('test.csv')
354
    assert csv_output[0] == proof_output[0]
355
    assert csv_output[1] == proof_output[1]
356
357
def test_to_csv_units_parentheses():
358
    las = read(egfn("sample.las"))
359
    las.to_csv('test.csv', units_loc='()')
360
    csv_output = open('test.csv', 'r').readlines()
361
    proof_output = open(egfn('sample.las_units-parentheses.csv'), 'r').readlines()
362
    os.remove('test.csv')
363
    assert csv_output[0] == proof_output[0]
364
365
def test_to_csv_units_brackets():
366
    las = read(egfn("sample.las"))
367
    las.to_csv('test.csv', units_loc='[]')
368
    csv_output = open('test.csv', 'r').readlines()
369
    proof_output = open(egfn('sample.las_units-brackets.csv'), 'r').readlines()
370
    os.remove('test.csv')
371
    assert csv_output[0] == proof_output[0]
372
    # assert csv_output[1] == proof_output[1]
373
374
def test_to_csv_specify_mnemonics():
375
    las = read(egfn("sample.las"))
376
    las.to_csv('test.csv', mnemonics=[str(i) for i in range(len(las.curves))])
377
    csv_output = open('test.csv', 'r').readlines()
378
    assert csv_output[0] == '0,1,2,3,4,5,6,7\n'
379
    os.remove('test.csv')
380
381
def test_to_csv_specify_units():
382
    las = read(egfn("sample.las"))
383
    las.to_csv('test.csv', units=[str(i) for i in range(len(las.curves))])
384
    csv_output = open('test.csv', 'r').readlines()
385
    assert csv_output[1] == '0,1,2,3,4,5,6,7\n'
386
    os.remove('test.csv')
387
388
389
def test_rename_and_write_curve_mnemonic():
390
    l = read(egfn("sample.las"))
391
    for curve in l.curves:
392
        if curve.mnemonic != 'DEPT':
393
            curve.mnemonic = "New_" + curve.mnemonic
394
    for curve in l.curves:
395
        print('mnemonic=%s original_mnemonic=%s' % (curve.mnemonic, curve.original_mnemonic))
396
    s = StringIO()
397
    l.write(s, version=2)
398
    s.seek(0)
399
    assert s.read() == '''~Version ---------------------------------------------------
400
VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
401
WRAP.  NO : ONE LINE PER DEPTH STEP
402
~Well ------------------------------------------------------
403
STRT.M                  1670.0 : 
404
STOP.M                 1669.75 : 
405
STEP.M                  -0.125 : 
406
NULL.                  -999.25 : 
407
COMP.   # ANY OIL COMPANY LTD. : COMPANY
408
WELL.   ANY ET AL OIL WELL #12 : WELL
409
FLD .                     EDAM : FIELD
410
LOC .           A9-16-49-20W3M : LOCATION
411
PROV.             SASKATCHEWAN : PROVINCE
412
SRVC. ANY LOGGING COMPANY LTD. : SERVICE COMPANY
413
DATE.              25-DEC-1988 : LOG DATE
414
UWI .         100091604920W300 : UNIQUE WELL ID
415
~Curves ----------------------------------------------------
416
DEPT    .M     : 1  DEPTH
417
New_DT  .US/M  : 2  SONIC TRANSIT TIME
418
New_RHOB.K/M3  : 3  BULK DENSITY
419
New_NPHI.V/V   : 4   NEUTRON POROSITY
420
New_SFLU.OHMM  : 5  RXO RESISTIVITY
421
New_SFLA.OHMM  : 6  SHALLOW RESISTIVITY
422
New_ILM .OHMM  : 7  MEDIUM RESISTIVITY
423
New_ILD .OHMM  : 8  DEEP RESISTIVITY
424
~Params ----------------------------------------------------
425
BHT .DEGC   35.5 : BOTTOM HOLE TEMPERATURE
426
BS  .MM    200.0 : BIT SIZE
427
FD  .K/M3 1000.0 : FLUID DENSITY
428
MATR.        0.0 : NEUTRON MATRIX(0=LIME,1=SAND,2=DOLO)
429
MDEN.     2710.0 : LOGGING MATRIX DENSITY
430
RMF .OHMM  0.216 : MUD FILTRATE RESISTIVITY
431
DFD .K/M3 1525.0 : DRILL FLUID DENSITY
432
~Other -----------------------------------------------------
433
Note: The logging tools became stuck at 625 meters causing the data
434
between 625 meters and 615 meters to be invalid.
435
~ASCII -----------------------------------------------------
436
 1670.00000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
437
 1669.87500  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
438
 1669.75000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
439
'''
440
441
def test_write_large_depths():
442
    las = lasio.read(egfn("sample.las"))
443
    las.curves[0].data *= 10.5 + 0.1
444
    las.write('write_large_depths.las')
445
    las2 = lasio.read('write_large_depths.las')
446
    os.remove('write_large_depths.las')
447
    assert np.all(las.curves[0].data == las2.curves[0].data)
448