|
1
|
|
|
import os, sys; sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) |
|
2
|
|
|
|
|
3
|
|
|
import fnmatch |
|
4
|
|
|
import logging |
|
5
|
|
|
|
|
6
|
|
|
import numpy as np |
|
7
|
|
|
import pytest |
|
8
|
|
|
|
|
9
|
|
|
import lasio |
|
10
|
|
|
|
|
11
|
|
|
logger = logging.getLogger(__name__) |
|
12
|
|
|
|
|
13
|
|
|
test_dir = os.path.dirname(__file__) |
|
14
|
|
|
|
|
15
|
|
|
egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn) |
|
16
|
|
|
stegfn = lambda vers, fn: os.path.join( |
|
17
|
|
|
os.path.dirname(__file__), "examples", vers, fn) |
|
18
|
|
|
|
|
19
|
|
|
def test_delete_curve(): |
|
20
|
|
|
las = lasio.read(egfn("sample.las")) |
|
21
|
|
|
del las.curves['DT'] |
|
22
|
|
|
assert las.curves.keys() == ['DEPT', 'RHOB', 'NPHI', 'SFLU', 'SFLA','ILM', 'ILD'] |
|
23
|
|
|
|
|
24
|
|
|
def test_delete_section_item_by_index(): |
|
25
|
|
|
las = lasio.read(egfn('sample.las')) |
|
26
|
|
|
del las.params[1] |
|
27
|
|
|
assert las.params.keys() == ['BHT', 'FD', 'MATR', 'MDEN', 'RMF', 'DFD'] |
|
28
|
|
|
|
|
29
|
|
|
def test_delete_section_item_by_mnemonic(): |
|
30
|
|
|
las = lasio.read(egfn('sample.las')) |
|
31
|
|
|
del las.params['MDEN'] |
|
32
|
|
|
assert las.params.keys() == ['BHT', 'BS', 'FD', 'MATR', 'RMF', 'DFD'] |
|
33
|
|
|
|
|
34
|
|
|
def test_section_items_slice(): |
|
35
|
|
|
las = lasio.read(egfn('sample.las')) |
|
36
|
|
|
sl = las.curves[slice(1, 4)] |
|
37
|
|
|
assert sl.keys() == ['DT', 'RHOB', 'NPHI'] |
|
38
|
|
|
|
|
39
|
|
|
def test_section_items_indices(): |
|
40
|
|
|
las = lasio.read(egfn('sample.las')) |
|
41
|
|
|
logger.debug('Type of las.curves = {}'.format(type(las.curves))) |
|
42
|
|
|
sl = las.curves[1:4] |
|
43
|
|
|
# logger.debug(str(sl)) |
|
44
|
|
|
assert sl.keys() == ['DT', 'RHOB', 'NPHI'] |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
def test_add_curve_duplicate(): |
|
|
|
|
|
|
47
|
|
|
las = lasio.LASFile() |
|
48
|
|
|
a = np.array([1, 2, 3, 4]) |
|
49
|
|
|
b1 = np.array([5, 9, 1, 4]) |
|
50
|
|
|
b2 = np.array([1, 2, 3, 2]) |
|
51
|
|
|
las.add_curve('DEPT', a) |
|
52
|
|
|
las.add_curve('B', b1, descr='b1') |
|
53
|
|
|
las.add_curve('B', b2, descr='b2') |
|
54
|
|
|
# assert l.keys == ['DEPT', 'B', 'B'] |
|
55
|
|
|
assert [c.descr for c in las.curves] == ['', 'b1', 'b2'] |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
View Code Duplication |
def test_append_curve_duplicate(): |
|
|
|
|
|
|
59
|
|
|
las = lasio.LASFile() |
|
60
|
|
|
a = np.array([1, 2, 3, 4]) |
|
61
|
|
|
b1 = np.array([5, 9, 1, 4]) |
|
62
|
|
|
b2 = np.array([1, 2, 3, 2]) |
|
63
|
|
|
las.append_curve('DEPT', a) |
|
64
|
|
|
las.append_curve('B', b1, descr='b1') |
|
65
|
|
|
las.append_curve('B', b2, descr='b2') |
|
66
|
|
|
assert [c.descr for c in las.curves] == ['', 'b1', 'b2'] |
|
67
|
|
|
|
|
68
|
|
|
def test_insert_curve_1(): |
|
69
|
|
|
las = lasio.LASFile() |
|
70
|
|
|
a = np.array([1, 2, 3, 4]) |
|
71
|
|
|
b1 = np.array([5, 9, 1, 4]) |
|
72
|
|
|
b2 = np.array([1, 2, 3, 2]) |
|
73
|
|
|
las.append_curve('DEPT', a) |
|
74
|
|
|
las.append_curve('B', b2, descr='b2') |
|
75
|
|
|
las.insert_curve(1, 'B', b1, descr='b1') |
|
76
|
|
|
assert [c.descr for c in las.curves] == ['', 'b1', 'b2'] |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
def test_insert_curve_2(): |
|
|
|
|
|
|
79
|
|
|
las = lasio.LASFile() |
|
80
|
|
|
a = np.array([1, 2, 3, 4]) |
|
81
|
|
|
b1 = np.array([5, 9, 1, 4]) |
|
82
|
|
|
b2 = np.array([1, 2, 3, 2]) |
|
83
|
|
|
las.append_curve('DEPT', a) |
|
84
|
|
|
las.append_curve('B', b2, descr='b2') |
|
85
|
|
|
las.insert_curve(2, 'B', b1, descr='b1') |
|
86
|
|
|
assert [c.descr for c in las.curves] == ['', 'b2', 'b1'] |
|
87
|
|
|
|
|
88
|
|
View Code Duplication |
def test_delete_curve_ix(): |
|
|
|
|
|
|
89
|
|
|
las = lasio.LASFile() |
|
90
|
|
|
a = np.array([1, 2, 3, 4]) |
|
91
|
|
|
b1 = np.array([5, 9, 1, 4]) |
|
92
|
|
|
b2 = np.array([1, 2, 3, 2]) |
|
93
|
|
|
las.append_curve('DEPT', a) |
|
94
|
|
|
las.append_curve('B', b2, descr='b2') |
|
95
|
|
|
las.insert_curve(2, 'B', b1, descr='b1') |
|
96
|
|
|
las.delete_curve(ix=0) |
|
97
|
|
|
assert [c.descr for c in las.curves] == ['b2', 'b1'] |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
def test_delete_curve_mnemonic(): |
|
101
|
|
|
las = lasio.LASFile() |
|
102
|
|
|
a = np.array([1, 2, 3, 4]) |
|
103
|
|
|
b1 = np.array([5, 9, 1, 4]) |
|
104
|
|
|
b2 = np.array([1, 2, 3, 2]) |
|
105
|
|
|
logger.info(str([c.mnemonic for c in las.curves])) |
|
106
|
|
|
las.append_curve('DEPT', a) |
|
107
|
|
|
logger.info(str([c.mnemonic for c in las.curves])) |
|
108
|
|
|
las.append_curve('B', b2, descr='b2') |
|
109
|
|
|
logger.info(str([c.mnemonic for c in las.curves])) |
|
110
|
|
|
las.insert_curve(2, 'B', b1, descr='b1') |
|
111
|
|
|
logger.info(str([c.mnemonic for c in las.curves])) |
|
112
|
|
|
las.delete_curve(mnemonic='DEPT') |
|
113
|
|
|
assert [c.descr for c in las.curves] == ['b2', 'b1'] |
|
114
|
|
|
|
|
115
|
|
|
def test_mnemonic_case_comparison_preserve_1(): |
|
116
|
|
|
las = lasio.read(egfn('mnemonic_case.las'), mnemonic_case='preserve') |
|
117
|
|
|
assert 'Dept' in las.curves |
|
118
|
|
|
|
|
119
|
|
|
def test_mnemonic_case_comparison_preserve_2(): |
|
120
|
|
|
las = lasio.read(egfn('mnemonic_case.las'), mnemonic_case='preserve') |
|
121
|
|
|
assert not 'DEPT' in las.curves |
|
122
|
|
|
|
|
123
|
|
|
def test_mnemonic_case_comparison_upper(): |
|
124
|
|
|
las = lasio.read(egfn('mnemonic_case.las'), mnemonic_case='upper') |
|
125
|
|
|
assert 'dept' in las.curves |
|
126
|
|
|
|
|
127
|
|
|
def test_mnemonic_case_comparison_lower(): |
|
128
|
|
|
las = lasio.read(egfn('mnemonic_case.las'), mnemonic_case='lower') |
|
129
|
|
|
assert 'DEPT' in las.curves |
|
130
|
|
|
|
|
131
|
|
|
def test_missing_sectionitems_mnemonic(): |
|
132
|
|
|
las = lasio.read(egfn('sample.las')) |
|
133
|
|
|
with pytest.raises(KeyError): |
|
134
|
|
|
las.curves['blahblahblah'] |
|
135
|
|
|
|
|
136
|
|
|
def test_mnemonic_rename_1(): |
|
137
|
|
|
las = lasio.read(egfn('sample.las')) |
|
138
|
|
|
las.curves[-1].mnemonic = '' |
|
139
|
|
|
assert las.curves[-1].mnemonic == 'UNKNOWN' |