Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/kinverarity1/lasio
Browse files Browse the repository at this point in the history
  • Loading branch information
kinverarity1 committed Jul 19, 2017
2 parents 2426f55 + 76434cd commit 76d129b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
20 changes: 18 additions & 2 deletions lasio/las_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ def __init__(self, mnemonic='', unit='', value='', descr='', **kwargs):
# to them. The result of this will be stored in the below variable,
# which is what the user should actually see and use 99.5% of the time.

self.mnemonic = str(self.useful_mnemonic)
self.set_session_mnemonic_only(str(self.useful_mnemonic))

self.unit = unit
self.value = value
self.descr = descr

def set_session_mnemonic_only(self, value):
super(HeaderItem, self).__setattr__('mnemonic', value)

def __getitem__(self, key):
if key == 'mnemonic':
return self.mnemonic
Expand All @@ -63,6 +66,18 @@ def __getitem__(self, key):
raise KeyError(
'CurveItem only has restricted items (not %s)' % key)

# def __setitem__(self, key, value):
# # print('.__setitem__ key=%s value=%s' % (key, value))
# if key == 'mnemonic':
# super(HeaderItem, self).__setitem__('original_mnemonic', value)
# super(HeaderItem, self).__setitem__('mnemonic', value)

def __setattr__(self, key, value):
# print('.__setitem__ key=%s value=%s' % (key, value))
if key == 'mnemonic':
super(HeaderItem, self).__setattr__('original_mnemonic', value)
super(HeaderItem, self).__setattr__(key, value)

def __repr__(self):
return (
'%s(mnemonic=%s, unit=%s, value=%s, '
Expand Down Expand Up @@ -233,7 +248,8 @@ def append(self, newitem):
for i, loc in enumerate(locations):
item = self[loc]
# raise Exception('%s' % str(type(item)))
item.mnemonic = item.useful_mnemonic + ':%d' % (i + 1)
item.set_session_mnemonic_only(item.useful_mnemonic + ':%d' % (i + 1))
# item.mnemonic = item.useful_mnemonic + ':%d' % (i + 1)

def dictview(self):
return dict(zip(self.keys(), [i.value for i in self.values()]))
Expand Down
6 changes: 4 additions & 2 deletions tests/test_enhancements.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy
import pytest
import math

from lasio import las, read, exceptions

Expand Down Expand Up @@ -46,17 +47,18 @@ def test_df_indexing():
l = read(egfn("6038187_v1.2.las"))
metres = 9.05
spacing = l.well["STEP"].value
calc_index = (metres / spacing) - (l.well["STRT"].value / spacing)
calc_index = math.floor((metres / spacing) - (l.well["STRT"].value / spacing))
calc_index = int(calc_index)
assert l["GAMN"][calc_index] == l.df()["GAMN"][metres]


# TODO: make above test in reverse-ordered LAS (e.g. STRT > STOP)

def test_df_reverse():
l = read(egfn("sample_rev.las"))
metres = 1667
spacing = l.well["STEP"].value
calc_index = (metres / spacing) - (l.well["STRT"].value / spacing)
calc_index = math.floor((metres // spacing) - (l.well["STRT"].value // spacing))
calc_index = int(calc_index)
assert l["DT"][calc_index] == l.df()["DT"][metres]

Expand Down
65 changes: 65 additions & 0 deletions tests/test_rename_curve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os, sys; sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import pytest

from lasio import read
from lasio.excel import ExcelConverter

from lasio.reader import StringIO

test_dir = os.path.dirname(__file__)

egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)


def test_rename_and_write_curve_mnemonic():
l = read(egfn("sample.las"))
for curve in l.curves:
if curve.mnemonic != 'DEPT':
curve.mnemonic = "New_" + curve.mnemonic
for curve in l.curves:
print('mnemonic=%s original_mnemonic=%s' % (curve.mnemonic, curve.original_mnemonic))
s = StringIO()
l.write(s, version=2)
s.seek(0)
assert s.read() == '''~Version ---------------------------------------------------
VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
WRAP. NO : ONE LINE PER DEPTH STEP
~Well ------------------------------------------------------
STRT.M 1670.0 :
STOP.M 1669.75 :
STEP.M -0.125 :
NULL. -999.25 :
COMP. # ANY OIL COMPANY LTD. : COMPANY
WELL. ANY ET AL OIL WELL #12 : WELL
FLD . EDAM : FIELD
LOC . A9-16-49-20W3M : LOCATION
PROV. SASKATCHEWAN : PROVINCE
SRVC. ANY LOGGING COMPANY LTD. : SERVICE COMPANY
DATE. 25-DEC-1988 : LOG DATE
UWI . 100091604920W300 : UNIQUE WELL ID
~Curves ----------------------------------------------------
DEPT .M : 1 DEPTH
New_DT .US/M : 2 SONIC TRANSIT TIME
New_RHOB.K/M3 : 3 BULK DENSITY
New_NPHI.V/V : 4 NEUTRON POROSITY
New_SFLU.OHMM : 5 RXO RESISTIVITY
New_SFLA.OHMM : 6 SHALLOW RESISTIVITY
New_ILM .OHMM : 7 MEDIUM RESISTIVITY
New_ILD .OHMM : 8 DEEP RESISTIVITY
~Params ----------------------------------------------------
BHT .DEGC 35.5 : BOTTOM HOLE TEMPERATURE
BS .MM 200.0 : BIT SIZE
FD .K/M3 1000.0 : FLUID DENSITY
MATR. 0.0 : NEUTRON MATRIX(0=LIME,1=SAND,2=DOLO)
MDEN. 2710.0 : LOGGING MATRIX DENSITY
RMF .OHMM 0.216 : MUD FILTRATE RESISTIVITY
DFD .K/M3 1525.0 : DRILL FLUID DENSITY
~Other -----------------------------------------------------
Note: The logging tools became stuck at 625 meters causing the data
between 625 meters and 615 meters to be invalid.
~ASCII -----------------------------------------------------
1670 123.45 2550 0.45 123.45 123.45 110.2 105.6
1669.9 123.45 2550 0.45 123.45 123.45 110.2 105.6
1669.8 123.45 2550 0.45 123.45 123.45 110.2 105.6
'''

0 comments on commit 76d129b

Please sign in to comment.