/
Mlas2rsf.py
executable file
·79 lines (68 loc) · 2.32 KB
/
Mlas2rsf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
'Convert LAS-2 well logs to RSF'
## Copyright (C) 2010 University of Texas at Austin
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from __future__ import print_function
import os, sys
import numpy, m8r
from las import LASReader
def las2rsf(lasf,rsff):
las = LASReader(lasf)
rsf = m8r.Output(rsff)
data = las.data2d
data = data.astype('float32')
shape = data.shape
rsf.put('n1',shape[1])
rsf.put('n2',shape[0])
rsf.put('o2',las.start)
rsf.put('d2',las.step)
rsf.put('null',las.null)
k = 0
for name in las.curves.names:
k += 1
key = 'key%d' % k
rsf.put(key,name)
item = las.curves.items[name]
rsf.put(key+'_units',item.units)
if sys.version_info[0] >= 3:
desc = ' '.join(item.descr.translate(str.maketrans('','','"')).split()[1:])
else:
desc = ' '.join(item.descr.translate(None,'"').split()[1:])
rsf.put(name,desc)
for name in las.well.names:
item = las.well.items[name]
if sys.version_info[0] >= 3:
desc = item.data.translate(str.maketrans('','','"'))
else:
desc = item.data.translate(None,'"')
rsf.put(name,desc)
rsf.write(data)
rsf.close()
if __name__ == "__main__":
usage = '''
Usage: %s file.las [file.rsf]
Check the output using sfheaderattr < file.rsf segy=n
'''
if len(sys.argv) < 2:
print(usage)
sys.exit(1)
lasfile = sys.argv[1]
if len(sys.argv) < 3:
rsffile=os.path.splitext(lasfile)[0]+'.rsf'
else:
rsffile = sys.argv[2]
las2rsf(lasfile,rsffile)
sys.exit(0)