Completed
Push — master ( 61816f...4cbf24 )
by Kent
9s
created

test_lasfile_setitem_data()   A

Complexity

Conditions 2

Size

Total Lines 4

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 4
rs 10
1
import os, sys; sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
2
3
import fnmatch
4
from pprint import pformat
5
6
import numpy
7
import pytest
8
import math
9
10
import lasio
11
import lasio.las_items
12
from lasio import las, read, exceptions
13
14
15
test_dir = os.path.dirname(__file__)
16
17
egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)
18
stegfn = lambda vers, fn: os.path.join(
19
    os.path.dirname(__file__), "examples", vers, fn)
20
21
22
def test_autodepthindex():
23
    m = read(egfn("autodepthindex_M.las"))
24
    f = read(egfn("autodepthindex_F.las"))
25
    ft = read(egfn("autodepthindex_FT.las"))
26
    err = read(egfn("autodepthindex_M_FT.las"))
27
28
29
def test_autodepthindex_inconsistent():
30
    err = read(egfn("autodepthindex_M_FT.las"))
31
    with pytest.raises(exceptions.LASUnknownUnitError):
32
        print(err.depth_m)
33
34
35
def test_autodepthindex_m():
36
    l = read(egfn("autodepthindex_M.las"))
37
    assert (l.depth_ft[-1] * 0.3048 == l.index[-1])
38
39
40
def test_autodepthindex_f():
41
    l = read(egfn("autodepthindex_F.las"))
42
    assert (l.depth_m[-1] / 0.3048 == l.index[-1])
43
44
45
def test_autodepthindex_ft():
46
    l = read(egfn("autodepthindex_FT.las"))
47
    assert (l.depth_m[-1] / 0.3048 == l.index[-1])
48
49
def test_autodepthindex_feet():
50
    l = read(egfn("autodepthindex_FEET.las"))
51
    assert (l.depth_m[-1] / 0.3048 == l.index[-1])
52
53
def test_df_indexing():
54
    l = read(egfn("6038187_v1.2.las"))
55
    metres = 9.05
56
    spacing = l.well["STEP"].value
57
    calc_index = math.floor((metres / spacing) - (l.well["STRT"].value / spacing))
58
    calc_index = int(calc_index)
59
    assert l["GAMN"][calc_index] == l.df()["GAMN"][metres]
60
61
62
# TODO: make above test in reverse-ordered LAS (e.g. STRT > STOP)
63
64
def test_df_reverse():
65
    l = read(egfn("sample_rev.las"))
66
    metres = 1667
67
    spacing = l.well["STEP"].value
68
    calc_index = math.floor((metres // spacing) - (l.well["STRT"].value // spacing))
69
    calc_index = int(calc_index)
70
    assert l["DT"][calc_index] == l.df()["DT"][metres]
71
72
def test_df_curve_names():
73
    l = read(egfn("sample_rev.las"))
74
    assert l.keys()[1:] == list(l.df().columns.values)
75
76
def test_non_standard_section():
77
    l = read(egfn("non-standard-header-section.las"))
78
    assert "SPECIAL INFORMATION" in l.sections.keys()
79
80
def test_non_standard_sections():
81
    l = read(egfn("non-standard-header-sections.las"))
82
    assert "SPECIAL INFORMATION" in l.sections.keys()
83
    assert "extra special information" in l.sections.keys()
84
85
def test_repr():
86
    h = lasio.las_items.HeaderItem('MN', unit='m', value=20, descr='test testing')
87
    assert h.__repr__() == pformat(h)
88
89
def test_mnemonic_case_preserved():
90
    las = lasio.read(egfn('mnemonic_case.las'), mnemonic_case='preserve')
91
    assert [c.mnemonic for c in las.curves] == ['Dept', 'Sflu', 'NPHI', 'SFLU:1', 'SFLU:2', 'sflu', 'SfLu']
92
93
def test_mnemonic_case_upper():
94
    las = lasio.read(egfn('mnemonic_case.las'), mnemonic_case='upper')
95
    assert [c.mnemonic for c in las.curves] == ['DEPT', 'SFLU:1', 'NPHI', 'SFLU:2', 'SFLU:3', 'SFLU:4', 'SFLU:5']
96
97
def test_mnemonic_case_lower():
98
    las = lasio.read(egfn('mnemonic_case.las'), mnemonic_case='lower')
99
    assert [c.mnemonic for c in las.curves] == ['dept', 'sflu:1', 'nphi', 'sflu:2', 'sflu:3', 'sflu:4', 'sflu:5']
100
101
def test_duplicate_append_curve():
102
    las = lasio.read(egfn('sample.las'))
103
    las.append_curve('TEST', data=[1,2,3])
104
    las.append_curve('TEST', data=[4,5,6])
105
    assert [c.mnemonic for c in las.curves[-2:]] == ['TEST:1', 'TEST:2']
106
    
107
def test_lasfile_setitem_data():
108
    las = lasio.read(egfn('sample.las'))
109
    las['EXTRA'] = las['ILD'] / 2
110
    assert (las.curves['EXTRA'].data == [52.8, 52.8, 52.8]).all()
111
112
def test_lasfile_setitem_curveitem():
113
    las = lasio.read(egfn('sample.las'))
114
    las['EXTRA'] = lasio.las_items.CurveItem('EXTRA', data=las['ILD'] / 2)
115
    assert (las.curves['EXTRA'].data == [52.8, 52.8, 52.8]).all()
116
117
def test_lasfile_setitem_curveitem_mnemonic_mismatch():
118
    las = lasio.read(egfn('sample.las'))
119
    with pytest.raises(KeyError):
120
        las['EXTRA'] = lasio.las_items.CurveItem('EXTRA2', data=las['ILD'] / 2)
121
122