Skip to content

Commit

Permalink
Merge pull request #189 from kinverarity1/issue-17-comma-decimal-mark
Browse files Browse the repository at this point in the history
Automatically recognise commas as decimal marks
  • Loading branch information
kinverarity1 committed Nov 12, 2017
2 parents 10c95e5 + 2372dff commit b5762d1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lasio/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ def get_default_items():
}

READ_POLICIES = {
'default': ['run-on(-)', 'run-on(.)', 'run-on(NaN.)'],
'default': ['comma-decimal-mark', 'run-on(-)', 'run-on(.)', 'run-on(NaN.)'],
}

READ_SUBS = {
'comma-decimal-mark': [(re.compile(r'(\d),(\d)'), r'\1.\2'), ],
'run-on(-)': [(re.compile(r'(\d)-(\d)'), r'\1 -\2'), ],
'run-on(.)': [(re.compile(r'-?\d*\.\d*\.\d*'), ' NaN NaN '), ],
'run-on(NaN.)': [(re.compile(r'NaN[\.-]\d+'), ' NaN NaN '), ],
Expand Down
8 changes: 8 additions & 0 deletions lasio/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,14 @@ def num(self, x, default=None):
'''
if default is None:
default = x

# in case it is a string.
try:
pattern, sub = defaults.READ_SUBS['comma-decimal-mark'][0]
x = re.sub(pattern, sub, x)
except:
pass

try:
return np.int(x)
except:
Expand Down
46 changes: 46 additions & 0 deletions tests/examples/comma_decimal_mark.las
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
~VERSION INFORMATION
VERS. 1.2: CWLS LOG ASCII STANDARD -VERSION 1.2
WRAP. NO: ONE LINE PER DEPTH STEP
~WELL INFORMATION BLOCK
#MNEM.UNIT DATA TYPE INFORMATION
#--------- ------------- ------------------------------
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
#MNEM.UNIT API CODE CURVE DESCRIPTION
#--------- ------------- ------------------------------
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
ILM .OHMM : 7 MEDIUM RESISTIVITY
ILD .OHMM : 8 DEEP RESISTIVITY
~PARAMETER INFORMATION
#MNEM.UNIT VALUE DESCRIPTION
#--------- ------------- ------------------------------
BHT .DEGC 35.5000: BOTTOM HOLE TEMPERATURE
BS .MM 200.0000: BIT SIZE
FD .K/M3 1000.0000: FLUID DENSITY
MATR. 0.0000: NEUTRON MATRIX(0=LIME,1=SAND,2=DOLO)
MDEN. 2710,1000: LOGGING MATRIX DENSITY
RMF .OHMM 0.2160: MUD FILTRATE RESISTIVITY
DFD .K/M3 1525.0000: 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.
~A DEPTH DT RHOB NPHI SFLU SFLA ILM ILD
1670.000 123.450 2550.000 0.450 123.450 123.450 110.200 105.600
1669.875 123.450 2550.000 0.450 123,420 123.450 110.200 105.600
1669.750 123.450 2550.000 0.450 123.450 123.450 110.200 105.600
8 changes: 8 additions & 0 deletions tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,11 @@ def test_barebones_missing_all_sections():
def test_not_a_las_file():
with pytest.raises(KeyError):
las = read(egfn('not_a_las_file.las'))

def test_comma_decimal_mark_data():
las = read(egfn('comma_decimal_mark.las'))
assert las['SFLU'][1] == 123.42

def test_comma_decimal_mark_params():
las = read(egfn('comma_decimal_mark.las'))
assert las.params['MDEN'].value == 2710.1

0 comments on commit b5762d1

Please sign in to comment.