In [1]:
!head -24 ../data/core_analysis_example.spwla
In [205]:
s = """10 2
9999/9-9 Norway 9Sep99
Weatherford-Labs
15 10 10
1507 1602 2031 0Weatherford-Labs Nitrogen Permeability, Hor.
1512 1602 2031 0Weatherford-Labs Klinkenberg corrected gas perm, Hor.
1510 1602 2031 0Weatherford-Labs Nitrogen Permeability, Vert.
1515 1602 2031 0Weatherford-Labs Klinkenberg corrected gas perm, Vert.
1402 1211 3084 0Weatherford-Labs Porosity, Horizontal PLUG
1403 1211 3084 0Weatherford-Labs Porosity, Vertical PLUG
1401 1212 3084 0Weatherford-Labs Porosity, Summation
1302 1103 3085 0Weatherford-Labs CORE Oil Saturation
1301 1103 3085 0Weatherford-Labs CORE Water Saturation
2451 1201 1086 0Weatherford-Labs Grain Density, Hor.
20 1
0.00 0.00 1918.00 1983.72 0.0 1
30 1
1918.95 0.00 1.11
40 1 10
-1002.00000 -1002.00000 -1002.00000 -1002.00000 -1002.00000 18.44722 -1002.00000 14.78718 -1002.00000 -1002.00000
30 1
1919.95 0.00 2.11
40 1 10
-1002.00000 -1002.00000 -1002.00000 -1002.00000 -1002.00000 17.06246 -1002.00000 18.06427 -1002.00000 -1002.00000
"""
In [207]:
import re
# Not using this one.
# rx_fields = re.compile(r'''
# ^
# 15\s+?\d+?\s+?\d+?\n
# (?P<fields>[\s\S]+?)
# (?=^[^1]|\Z)
# ''', re.MULTILINE | re.VERBOSE)
rx_fields = re.compile(r'''
^
\s+?\d+?\s+?\d+?\s+?\d+?\s+?0\S+?\s+?(?P<field>[\w\d][- ,.\w\d]+?)\n
''', re.MULTILINE | re.VERBOSE)
rx_depth = re.compile(r'''
^
30\s+?1\n
\s+?(?P<depth>[.\d]+?)[ \t]+?[.\d]+?[ \t]+?(?P<seq>[.\d]+?)\n
(?P<record>[\s\S]+?)
(?=^30|\Z)
''', re.MULTILINE | re.VERBOSE)
rx_data = re.compile(r'''
^
(?:36\s+?1\s+?1\n
\s+?(?P<descr>.+?)\n)?
40\s+?1\s+?\d+?\n
\s+?(?P<data>[- .\d]+?)\n
''', re.MULTILINE | re.VERBOSE)
In [208]:
import pandas as pd
import numpy as np
def parse(s, null=-999.25):
records = (field.group('field') for field in rx_fields.finditer(s))
result = (
(
float(record.group('depth')),
record.group('seq'),
data.group('descr'),
*[float(x) for x in data.group('data').split()]
)
for record in rx_depth.finditer(s)
for data in rx_data.finditer(record.group('record'))
)
columns = ['depth', 'seq', 'descr'] + list(records)
df = pd.DataFrame(result, columns=columns)
df = df.replace(null, np.nan)
return df
In [209]:
parse(data, null=-1002)
Out[209]:
This has been dropped into ../gio/gio.py as read_spwla().
In [ ]: