Skip to content

Commit

Permalink
Add tests for null_policy=... (#49)
Browse files Browse the repository at this point in the history
Also fixed the (un)wrapped tests
  • Loading branch information
kinverarity1 committed Feb 2, 2016
1 parent 3ae70ed commit fe0e975
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 217 deletions.
314 changes: 157 additions & 157 deletions notebooks/issues/sample_wrapped.ipynb

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions tests/examples/null_policy_alphanumeric.las
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
~VERSION INFORMATION
VERS. 1.2: CWLS LOG ASCII STANDARD -VERSION 1.2
WRAP. NO: ONE LINE PER DEPTH STEP
~WELL INFORMATION BLOCK
STRT.M 1670.000000:
STOP.M 1660.000000:
STEP.M -0.1250:
NULL. -999.2500:
COMP. COMPANY: # ANY OIL COMPANY LTD.
WELL. WELL: ANY ET AL OIL WELL #12
FLD . FIELD: EDAM
LOC . LOCATION: A9-16-49-20W3M
PROV. PROVINCE: SASKATCHEWAN
SRVC. SERVICE COMPANY: ANY LOGGING COMPANY LTD.
DATE. LOG DATE: 25-DEC-1988
UWI . UNIQUE WELL ID: 100091604920W300
~CURVE INFORMATION
DEPT.M : 1 DEPTH
DT .US/M : 2 SONIC TRANSIT TIME
RHOB.K/M3 : 3 BULK DENSITY
NPHI.V/V : 4 NEUTRON POROSITY
SFLU.OHMM : 5 RXO RESISTIVITY
SFLA.OHMM : 6 SHALLOW RESISTIVITY
~PARAMETER INFORMATION
~Other
~A DEPTH DT RHOB NPHI SFLU SFLA
1.000 -999.25 -9999 0.450 123.450 1
2.000 -999.25 -9999 0.460 123.460 2
3.000 1 -9999 0.47 123.45 3
4.000 2 3 0.48 123.46 4
5.000 #N/A 4 231.2 123.45 5
6.000 4 1.#INF 231.2 1 6
7.000 5 6 231.2 1 7
8.000 6 7 231.2 1 1.#IND
9.000 6 32767 -1.#IO -999.25 9
35 changes: 35 additions & 0 deletions tests/examples/null_policy_numeric.las
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
~VERSION INFORMATION
VERS. 1.2: CWLS LOG ASCII STANDARD -VERSION 1.2
WRAP. NO: ONE LINE PER DEPTH STEP
~WELL INFORMATION BLOCK
STRT.M 1670.000000:
STOP.M 1660.000000:
STEP.M -0.1250:
NULL. -999.2500:
COMP. COMPANY: # ANY OIL COMPANY LTD.
WELL. WELL: ANY ET AL OIL WELL #12
FLD . FIELD: EDAM
LOC . LOCATION: A9-16-49-20W3M
PROV. PROVINCE: SASKATCHEWAN
SRVC. SERVICE COMPANY: ANY LOGGING COMPANY LTD.
DATE. LOG DATE: 25-DEC-1988
UWI . UNIQUE WELL ID: 100091604920W300
~CURVE INFORMATION
DEPT.M : 1 DEPTH
DT .US/M : 2 SONIC TRANSIT TIME
RHOB.K/M3 : 3 BULK DENSITY
NPHI.V/V : 4 NEUTRON POROSITY
SFLU.OHMM : 5 RXO RESISTIVITY
SFLA.OHMM : 6 SHALLOW RESISTIVITY
~PARAMETER INFORMATION
~Other
~A DEPTH DT RHOB NPHI SFLU SFLA
1.000 -999.25 -9999 0.450 123.450 1
2.000 -999.25 -9999 0.460 123.460 2
3.000 1 -9999 0.47 123.45 3
4.000 2 3 0.48 123.46 4
5.000 3 4 231.2 123.45 5
6.000 4 5 231.2 1 6
7.000 5 6 231.2 1 7
8.000 6 7 231.2 1 8
9.000 6 32767 231.2 -999.25 9
46 changes: 0 additions & 46 deletions tests/examples/null_subs.las

This file was deleted.

57 changes: 45 additions & 12 deletions tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import fnmatch

import numpy
import numpy as np
import pytest

from lasio import read
Expand All @@ -13,6 +13,8 @@
stegfn = lambda vers, fn: os.path.join(
os.path.dirname(__file__), "examples", vers, fn)

NaN = np.nan

def test_read_v12_sample():
l = read(stegfn("1.2", "sample.las"))

Expand Down Expand Up @@ -80,17 +82,48 @@ def test_mnemonic_missing_multiple():
assert [c.mnemonic for c in l.curves] == [
"DEPT", "DT", "RHOB", "NPHI", "UNKNOWN:1", "UNKNOWN:2", "ILM", "ILD"]

def test_null_subs_default():
l = read(egfn("null_subs.las"))
assert numpy.isnan(l['DT'][0])

def test_null_subs_True():
l = read(egfn("null_subs.las"), null_subs=True)
assert numpy.isnan(l['DT'][0])

def test_null_subs_False():
l = read(egfn("null_subs.las"), null_subs=False)
assert l['DT'][0] == -999.25
# ~A DEPTH DT RHOB NPHI SFLU SFLA
# 1.000 -999.25 -9999 0.450 123.450 1
# 2.000 -999.25 -9999 0.460 123.460 2
# 3.000 1 -9999 0.47 123.45 3
# 4.000 2 3 0.48 123.46 4
# 5.000 3 4 231.2 123.45 5
# 6.000 4 5 231.2 1 6
# 7.000 5 6 231.2 1 7
# 8.000 6 7 231.2 1 8
# 9.000 6 32767 231.2 -999.25 9

def test_null_policy_numeric_None():
l = read(egfn("null_policy_numeric.las"), null_policy=None)
assert np.all(l['DT'] == [-999.25, -999.25, 1, 2, 3, 4, 5, 6, 6])
assert np.all(l['RHOB'] == [-9999, -9999, -9999, 3, 4, 5, 6, 7, 32767])
assert np.all(l['NPHI'] == [.45, .46, .47, .48, 231.2, 231.2, 231.2, 231.2, 231.2])
assert np.all(l['SFLU'] == [123.45, 123.46, 123.45, 123.46, 123.45, 1, 1, 1, -999.25])
assert np.all(l['SFLA'] == [1, 2, 3, 4, 5, 6, 7, 8, 9])

def test_null_policy_numeric_NULL():
l = read(egfn("null_policy_numeric.las"), null_policy='NULL')
assert np.all(np.isnan(l['DT']) == [True, True, False, False, False, False, False, False, False])
assert np.isfinite(l['RHOB']).all()
assert np.isfinite(l['NPHI']).all()
assert np.all(np.isnan(l['SFLU']) == [False, False, False, False, False, False, False, False, True])
assert np.isfinite(l['SFLA']).all()

def test_null_policy_numeric_common():
l = read(egfn("null_policy_numeric.las"), null_policy='common')
assert np.all(np.isnan(l['DT']) == [True, True, False, False, False, False, False, False, False])
assert np.all(np.isnan(l['RHOB']) == [True, True, True, False, False, False, False, False, True])
assert np.isfinite(l['NPHI']).all()
assert np.all(np.isnan(l['SFLU']) == [False, False, False, False, False, False, False, False, True])
assert np.isfinite(l['SFLA']).all()

def test_null_policy_numeric_aggressive():
l = read(egfn("null_policy_numeric.las"), null_policy='aggressive')
assert np.all(np.isnan(l['DT']) == [True, True, False, False, False, False, False, True, True])
assert np.all(np.isnan(l['RHOB']) == [True, True, True, False, False, False, False, False, True])
assert np.all(np.isnan(l['NPHI']) == [False, False, False, False, True, True, True, True, True])
assert np.all(np.isnan(l['SFLU']) == [False, False, False, False, False, True, True, True, True])
assert np.isfinite(l['SFLA']).all()

def test_multi_curve_mnemonics():
l = read(egfn('sample_issue105_a.las'))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_wrapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_wrapped():

def test_write_wrapped():
fn = stegfn("1.2", "sample_wrapped.las")
l = read(fn)
l = read(fn, null_policy='NULL')
s = StringIO()
l.write(s, version=2.0, wrap=True, fmt="%.5f")
s.seek(0)
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_write_wrapped():

def test_write_unwrapped():
fn = stegfn("1.2", "sample_wrapped.las")
l = read(fn)
l = read(fn, null_policy='NULL')
s = StringIO()
l.write(s, version=2, wrap=False, fmt="%.5f")
s.seek(0)
Expand Down

0 comments on commit fe0e975

Please sign in to comment.