Completed
Pull Request — master (#118)
by Kent
04:16
created

tests.test_null_policy_alphanumeric_aggressive()   B

Complexity

Conditions 6

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 6
dl 0
loc 7
rs 8
1
import os, sys; sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
2
3
import fnmatch
4
5
import numpy as np
6
import pytest
7
8
from lasio import read, las
9
10
test_dir = os.path.dirname(__file__)
11
12
egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)
13
stegfn = lambda vers, fn: os.path.join(
14
    os.path.dirname(__file__), "examples", vers, fn)
15
16
NaN = np.nan
17
18
def test_read_v12_sample():
19
    l = read(stegfn("1.2", "sample.las"))
20
21
22
def test_read_v12_sample_big():
23
    l = read(stegfn("1.2", "sample_big.las"))
24
25
26
def test_read_v12_sample_curve_api():
27
    l = read(stegfn("1.2", "sample_curve_api.las"))
28
29
30
def test_read_v12_sample_minimal():
31
    l = read(stegfn("1.2", "sample_minimal.las"))
32
33
34
def test_read_v12_sample_wrapped():
35
    l = read(stegfn("1.2", "sample_wrapped.las"))
36
37
38
def test_read_v2_sample():
39
    l = read(stegfn("2.0", "sample_2.0.las"))
40
41
42
def test_read_v2_sample_based():
43
    l = read(stegfn("2.0", "sample_2.0_based.las"))
44
45
46
def test_read_v2_sample_minimal():
47
    l = read(stegfn("2.0", "sample_2.0_minimal.las"))
48
49
50
def test_read_v2_sample_wrapped():
51
    l = read(stegfn("2.0", "sample_2.0_wrapped.las"))
52
53
54
def test_dodgy_param_sect():
55
    l = read(egfn("dodgy_param_sect.las"))
56
57
58
def test_mnemonic_good():
59
    l = read(egfn("mnemonic_good.las"))
60
    assert [c.mnemonic for c in l.curves] == [
61
        "DEPT", "DT", "RHOB", "NPHI", "SFLU", "SFLA", "ILM", "ILD"]
62
63
64
def test_mnemonic_duplicate():
65
    l = 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 = 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 = 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 = 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
# ~A DEPTH     DT  RHOB    NPHI     SFLU   SFLA
86
# 1.000   -999.25 -9999    0.450  123.450  1
87
# 2.000   -999.25 -9999    0.460  123.460  2
88
# 3.000   1       -9999    0.47   123.45   3
89
# 4.000   2       3        0.48   123.46   4
90
# 5.000   3       4        231.2  123.45   5
91
# 6.000   4       5        231.2  1        6
92
# 7.000   5       6        231.2  1        7
93
# 8.000   6       7        231.2  1        8
94
# 9.000   6       32767    231.2  -999.25  9
95
96
def test_null_policy_numeric_None():
97
    l = read(egfn("null_policy_numeric.las"), null_policy=None)
98
    assert np.all(l['DT'] == [-999.25, -999.25, 1, 2, 3, 4, 5, 6, 6])
99
    assert np.all(l['RHOB'] == [-9999, -9999, -9999, 3, 4, 5, 6, 7, 32767])
100
    assert np.all(l['NPHI'] == [.45, .46, .47, .48, 231.2, 231.2, 231.2, 231.2, 231.2])
101
    assert np.all(l['SFLU'] == [123.45, 123.46, 123.45, 123.46, 123.45, 1, 1, 1, -999.25])
102
    assert np.all(l['SFLA'] == [1, 2, 3, 4, 5, 6, 7, 8, 9])
103
104
def test_null_policy_numeric_NULL():
105
    l = read(egfn("null_policy_numeric.las"), null_policy='NULL')
106
    assert np.all(np.isnan(l['DT']) == [True, True, False, False, False, False, False, False, False])
107
    assert np.isfinite(l['RHOB']).all()
108
    assert np.isfinite(l['NPHI']).all()
109
    assert np.all(np.isnan(l['SFLU']) == [False, False, False, False, False, False, False, False, True])
110
    assert np.isfinite(l['SFLA']).all()
111
112
def test_null_policy_numeric_common():
113
    l = read(egfn("null_policy_numeric.las"), null_policy='common')
114
    assert np.all(np.isnan(l['DT']) == [True, True, False, False, False, False, False, False, False])
115
    assert np.all(np.isnan(l['RHOB']) == [True, True, True, False, False, False, False, False, True])
116
    assert np.isfinite(l['NPHI']).all()
117
    assert np.all(np.isnan(l['SFLU']) == [False, False, False, False, False, False, False, False, True])
118
    assert np.isfinite(l['SFLA']).all()
119
120
def test_null_policy_numeric_aggressive():
121
    l = read(egfn("null_policy_numeric.las"), null_policy='aggressive')
122
    assert np.all(np.isnan(l['DT']) == [True, True, False, False, False, False, False, True, True])
123
    assert np.all(np.isnan(l['RHOB']) == [True, True, True, False, False, False, False, False, True])
124
    assert np.all(np.isnan(l['NPHI']) == [False, False, False, False, True, True, True, True, True])
125
    assert np.all(np.isnan(l['SFLU']) == [False, False, False, False, False, True, True, True, True])
126
    assert np.isfinite(l['SFLA']).all()
127
128
# ~A DEPTH     DT  RHOB    NPHI     SFLU   SFLA
129
# 1.000   -999.25 -9999    0.450  123.450  1
130
# 2.000   -999.25 -9999    0.460  123.460  2
131
# 3.000   1       -9999    0.47   123.45   3
132
# 4.000   2       3        0.48   123.46   4
133
# 5.000   #N/A    4        231.2  123.45   5
134
# 6.000   4       1.#INF   231.2  1        6
135
# 7.000   5       6        231.2  1        7
136
# 8.000   6       7        231.2  1        1.#IND
137
# 9.000   6       32767    -1.#IO -999.25  9
138
139
def test_null_policy_alphanumeric_None():
140
    with pytest.raises(las.LASDataError):
141
        l = read(egfn("null_policy_alphanumeric.las"), null_policy=None)
142
143
def test_null_policy_alphanumeric_NULL():
144
    with pytest.raises(las.LASDataError):
145
        l = read(egfn("null_policy_alphanumeric.las"), null_policy='NULL')
146
147
def test_null_policy_alphanumeric_common():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148
    l = read(egfn("null_policy_alphanumeric.las"), null_policy='common')
149
    assert np.all(np.isnan(l['DT']) == [True, True, False, False, True, False, False, False, False])
150
    assert np.all(np.isnan(l['RHOB']) == [True, True, True, False, False, True, False, False, True])
151
    assert np.all(np.isnan(l['NPHI']) == [False, False, False, False, False, False, False, False, True])
152
    assert np.all(np.isnan(l['SFLU']) == [False, False, False, False, False, False, False, False, True])
153
    assert np.all(np.isnan(l['SFLA']) == [False, False, False, False, False, False, False, True, False])
154
155
def test_null_policy_alphanumeric_aggressive():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
156
    l = read(egfn("null_policy_alphanumeric.las"), null_policy='aggressive')
157
    assert np.all(np.isnan(l['DT']) == [True, True, False, False, True, False, False, True, True])
158
    assert np.all(np.isnan(l['RHOB']) == [True, True, True, False, False, True, False, False, True])
159
    assert np.all(np.isnan(l['NPHI']) == [False, False, False, False, True, True, True, True, True])
160
    assert np.all(np.isnan(l['SFLU']) == [False, False, False, False, False, True, True, True, True])
161
    assert np.all(np.isnan(l['SFLA']) == [False, False, False, False, False, False, False, True, False])
162
163
def test_multi_curve_mnemonics():
164
    l = read(egfn('sample_issue105_a.las'))
165
    assert l.keys() == [c.mnemonic for c in l.curves] == ['DEPT', 'RHO:1', 'RHO:2', 'RHO:3', 'PHI']
166
167
168
def test_multi_missing_curve_mnemonics():
169
    l = read(egfn('sample_issue105_b.las'))
170
    assert l.keys() == [c.mnemonic for c in l.curves] == ['DEPT', 'UNKNOWN:1', 'UNKNOWN:2', 'UNKNOWN:3', 'PHI']
171
172
173
def test_multi_curve_mnemonics_gr():
174
    l = read(egfn('sample_issue105_c.las'))
175
    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]']
176
177
#  DEPT.M                      :  1  DEPTH
178
# GR.gAPI: mean gamma ray value
179
# GR.gAPI: corrected gamma ray value
180
# GR[0].gAPI: gamma ray image at angle 0 dega
181
# GR[1].gAPI: gamma ray image at angle 60 dega
182
# GR[2].gAPI: gamma ray image at angle 120 dega
183
# GR[3].gAPI: gamma ray image at angle 180 dega
184
# GR[4].gAPI: gamma ray image at angle 240 dega
185
# GR[5].gAPI: gamma ray image at angle 300 dega