|
1
|
|
|
import os, sys; sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) |
|
2
|
|
|
import glob |
|
3
|
|
|
import fnmatch |
|
4
|
|
|
import traceback |
|
5
|
|
|
import logging |
|
6
|
|
|
|
|
7
|
|
|
import numpy |
|
8
|
|
|
import pytest |
|
9
|
|
|
|
|
10
|
|
|
import lasio |
|
11
|
|
|
|
|
12
|
|
|
test_dir = os.path.dirname(__file__) |
|
13
|
|
|
|
|
14
|
|
|
egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn) |
|
15
|
|
|
stegfn = lambda vers, fn: os.path.join( |
|
16
|
|
|
os.path.dirname(__file__), "examples", vers, fn) |
|
17
|
|
|
|
|
18
|
|
|
logger = logging.getLogger(__name__) |
|
19
|
|
|
|
|
20
|
|
|
def test_read_v12_sample(): |
|
21
|
|
|
l = lasio.read(stegfn("1.2", "sample.las")) |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def test_read_v12_sample_curve_api(): |
|
25
|
|
|
l = lasio.read(stegfn("1.2", "sample_curve_api.las")) |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
def test_read_v12_sample_minimal(): |
|
29
|
|
|
l = lasio.read(stegfn("1.2", "sample_minimal.las")) |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
def test_read_v12_sample_wrapped(): |
|
33
|
|
|
l = lasio.read(stegfn("1.2", "sample_wrapped.las")) |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
def test_read_v2_sample(): |
|
37
|
|
|
l = lasio.read(stegfn("2.0", "sample_2.0.las")) |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
def test_read_v2_sample_based(): |
|
41
|
|
|
l = lasio.read(stegfn("2.0", "sample_2.0_based.las")) |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def test_read_v2_sample_minimal(): |
|
45
|
|
|
l = lasio.read(stegfn("2.0", "sample_2.0_minimal.las")) |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
def test_read_v2_sample_wrapped(): |
|
49
|
|
|
l = lasio.read(stegfn("2.0", "sample_2.0_wrapped.las")) |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
def test_dodgy_param_sect(): |
|
53
|
|
|
with pytest.raises(lasio.exceptions.LASHeaderError): |
|
54
|
|
|
l = lasio.read(egfn("dodgy_param_sect.las")) |
|
55
|
|
|
|
|
56
|
|
|
def test_ignore_header_errors(): |
|
57
|
|
|
l = lasio.read(egfn("dodgy_param_sect.las"), ignore_header_errors=True) |
|
58
|
|
|
|
|
59
|
|
|
def test_mnemonic_good(): |
|
60
|
|
|
l = lasio.read(egfn("mnemonic_good.las")) |
|
61
|
|
|
assert [c.mnemonic for c in l.curves] == [ |
|
62
|
|
|
"DEPT", "DT", "RHOB", "NPHI", "SFLU", "SFLA", "ILM", "ILD"] |
|
63
|
|
|
|
|
64
|
|
|
def test_mnemonic_duplicate(): |
|
65
|
|
|
l = lasio.read(egfn("mnemonic_duplicate.las")) |
|
66
|
|
|
assert [c.mnemonic for c in l.curves] == [ |
|
67
|
|
|
"DEPT", "DT", "RHOB", "NPHI", "SFLU:1", "SFLU:2", "ILM", "ILD"] |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
def test_mnemonic_leading_period(): |
|
71
|
|
|
l = lasio.read(egfn("mnemonic_leading_period.las")) |
|
72
|
|
|
assert [c.mnemonic for c in l.curves] == [ |
|
73
|
|
|
"DEPT", "DT", "RHOB", "NPHI", "SFLU", "SFLA", "ILM", "ILD"] |
|
74
|
|
|
|
|
75
|
|
|
def test_mnemonic_missing(): |
|
76
|
|
|
l = lasio.read(egfn("mnemonic_missing.las")) |
|
77
|
|
|
assert [c.mnemonic for c in l.curves] == [ |
|
78
|
|
|
"DEPT", "DT", "RHOB", "NPHI", "UNKNOWN", "SFLA", "ILM", "ILD"] |
|
79
|
|
|
|
|
80
|
|
|
def test_mnemonic_missing_multiple(): |
|
81
|
|
|
l = lasio.read(egfn("mnemonic_missing_multiple.las")) |
|
82
|
|
|
assert [c.mnemonic for c in l.curves] == [ |
|
83
|
|
|
"DEPT", "DT", "RHOB", "NPHI", "UNKNOWN:1", "UNKNOWN:2", "ILM", "ILD"] |
|
84
|
|
|
|
|
85
|
|
|
def test_multi_curve_mnemonics(): |
|
86
|
|
|
l = lasio.read(egfn('sample_issue105_a.las')) |
|
87
|
|
|
assert l.keys() == [c.mnemonic for c in l.curves] == ['DEPT', 'RHO:1', 'RHO:2', 'RHO:3', 'PHI'] |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
def test_multi_missing_curve_mnemonics(): |
|
91
|
|
|
l = lasio.read(egfn('sample_issue105_b.las')) |
|
92
|
|
|
assert l.keys() == [c.mnemonic for c in l.curves] == ['DEPT', 'UNKNOWN:1', 'UNKNOWN:2', 'UNKNOWN:3', 'PHI'] |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
def test_multi_curve_mnemonics_gr(): |
|
96
|
|
|
l = lasio.read(egfn('sample_issue105_c.las')) |
|
97
|
|
|
assert l.keys() == [c.mnemonic for c in l.curves] == ['DEPT', 'GR:1', 'GR:2', 'GR[0]', 'GR[1]', 'GR[2]', 'GR[3]', 'GR[4]', 'GR[5]'] |
|
98
|
|
|
|
|
99
|
|
|
# DEPT.M : 1 DEPTH |
|
100
|
|
|
# GR.gAPI: mean gamma ray value |
|
101
|
|
|
# GR.gAPI: corrected gamma ray value |
|
102
|
|
|
# GR[0].gAPI: gamma ray image at angle 0 dega |
|
103
|
|
|
# GR[1].gAPI: gamma ray image at angle 60 dega |
|
104
|
|
|
# GR[2].gAPI: gamma ray image at angle 120 dega |
|
105
|
|
|
# GR[3].gAPI: gamma ray image at angle 180 dega |
|
106
|
|
|
# GR[4].gAPI: gamma ray image at angle 240 dega |
|
107
|
|
|
# GR[5].gAPI: gamma ray image at angle 300 dega |
|
108
|
|
|
|
|
109
|
|
|
def test_inf_uwi(): |
|
110
|
|
|
l = lasio.read(stegfn('2.0', 'sample_2.0_inf_uwi.las')) |
|
111
|
|
|
assert l.well['UWI'].value == '300E074350061450' |
|
112
|
|
|
|
|
113
|
|
|
def test_missing_vers_loads(): |
|
114
|
|
|
l = lasio.read(egfn("missing_vers.las")) |
|
115
|
|
|
|
|
116
|
|
|
def test_missing_vers_missing_headeritem(): |
|
117
|
|
|
l = lasio.read(egfn("missing_vers.las")) |
|
118
|
|
|
assert not 'VERS' in l.version |
|
119
|
|
|
|
|
120
|
|
|
def test_missing_vers_write_version_none_fails(): |
|
121
|
|
|
l = lasio.read(egfn("missing_vers.las")) |
|
122
|
|
|
with pytest.raises(KeyError): |
|
123
|
|
|
l.write(sys.stdout, version=None) |
|
124
|
|
|
|
|
125
|
|
|
def test_missing_vers_write_version_specified_works(): |
|
126
|
|
|
l = lasio.read(egfn("missing_vers.las")) |
|
127
|
|
|
l.write(sys.stdout, version=1.2) |
|
128
|
|
|
|
|
129
|
|
|
def test_missing_wrap_loads(): |
|
130
|
|
|
l = lasio.read(egfn("missing_wrap.las")) |
|
131
|
|
|
|
|
132
|
|
|
def test_missing_wrap_missing_headeritem(): |
|
133
|
|
|
l = lasio.read(egfn("missing_wrap.las")) |
|
134
|
|
|
assert not 'WRAP' in l.version |
|
135
|
|
|
|
|
136
|
|
|
def test_missing_wrap_write_wrap_none_fails(): |
|
137
|
|
|
l = lasio.read(egfn("missing_wrap.las")) |
|
138
|
|
|
with pytest.raises(KeyError): |
|
139
|
|
|
l.write(sys.stdout, wrap=None) |
|
140
|
|
|
|
|
141
|
|
|
def test_missing_wrap_write_wrap_specified_works(): |
|
142
|
|
|
l = lasio.read(egfn("missing_wrap.las")) |
|
143
|
|
|
l.write(sys.stdout, wrap=True) |
|
144
|
|
|
|
|
145
|
|
|
def test_missing_null_loads(): |
|
146
|
|
|
l = lasio.read(egfn("missing_null.las")) |
|
147
|
|
|
|
|
148
|
|
|
def test_missing_null_missing_headeritem(): |
|
149
|
|
|
l = lasio.read(egfn("missing_null.las")) |
|
150
|
|
|
assert not 'NULL' in l.well |
|
151
|
|
|
|
|
152
|
|
|
def test_barebones(): |
|
153
|
|
|
las = lasio.read(egfn('barebones.las')) |
|
154
|
|
|
assert las['DEPT'][1] == 201 |
|
155
|
|
|
|
|
156
|
|
|
def test_barebones_missing_all_sections(): |
|
157
|
|
|
las = lasio.read(egfn('barebones2.las')) |
|
158
|
|
|
assert las.curves[-1].mnemonic == 'UNKNOWN:8' |
|
159
|
|
|
|
|
160
|
|
|
def test_not_a_las_file(): |
|
161
|
|
|
with pytest.raises(KeyError): |
|
162
|
|
|
las = lasio.read(egfn('not_a_las_file.las')) |
|
163
|
|
|
|
|
164
|
|
|
def test_comma_decimal_mark_data(): |
|
165
|
|
|
las = lasio.read(egfn('comma_decimal_mark.las')) |
|
166
|
|
|
assert las['SFLU'][1] == 123.42 |
|
167
|
|
|
|
|
168
|
|
|
def test_comma_decimal_mark_params(): |
|
169
|
|
|
las = lasio.read(egfn('comma_decimal_mark.las')) |
|
170
|
|
|
assert las.params['MDEN'].value == 2710.1 |
|
171
|
|
|
|
|
172
|
|
|
def test_missing_a_section(): |
|
173
|
|
|
las = lasio.read(egfn('missing_a_section.las')) |
|
174
|
|
|
assert not las.data |
|
175
|
|
|
|
|
176
|
|
|
def test_blank_line_in_header(): |
|
177
|
|
|
las = lasio.read(egfn('blank_line.las')) |
|
178
|
|
|
assert las.curves[0].mnemonic == 'DEPT' |
|
179
|
|
|
|
|
180
|
|
|
def test_duplicate_step(): |
|
181
|
|
|
las = lasio.read(egfn('duplicate_step.las')) |
|
182
|
|
|
|
|
183
|
|
|
def test_blank_line_at_start(): |
|
184
|
|
|
las = lasio.read(egfn('blank_line_start.las')) |
|
185
|
|
|
|
|
186
|
|
|
def test_missing_STRT_STOP(): |
|
187
|
|
|
las = lasio.read(egfn('sample_TVD.las')) |
|
188
|
|
|
assert len(las.well) == 12 |
|
189
|
|
|
|
|
190
|
|
|
def test_UWI_API_leading_zero(): |
|
191
|
|
|
las = lasio.read(egfn('UWI_API_leading_zero.las')) |
|
192
|
|
|
assert las.well['UWI'].value == '05123370660000' |
|
193
|
|
|
|
|
194
|
|
|
def test_sparse_curves(): |
|
195
|
|
|
las = lasio.read(egfn('sparse_curves.las')) |
|
196
|
|
|
assert las.curves.keys() == ['DEPT', 'DT', 'RHOB', 'NPHI', 'SFLU', 'SFLA', 'ILM', 'ILD'] |
|
197
|
|
|
|
|
198
|
|
|
def test_issue92(): |
|
199
|
|
|
las = lasio.read(egfn('issue92.las'), ignore_header_errors=True) |
|
200
|
|
|
|