Coder Social home page Coder Social logo

kinverarity1 / lasio Goto Github PK

View Code? Open in Web Editor NEW
338.0 33.0 153.0 5.12 MB

Python library for reading and writing well data using Log ASCII Standard (LAS) files

Home Page: https://lasio.readthedocs.io/en/latest/

License: MIT License

Jupyter Notebook 21.69% Python 22.66% Dockerfile 0.02% Lasso 55.63%
las-files geophysics geology data-format io petroleum geotechnical-engineering groundwater data-management data-mining

lasio's People

Contributors

adamwulf avatar ae3e avatar bgschaid avatar connortann avatar dagrha avatar dbhart avatar dcslagel avatar ejschoen avatar fry484 avatar justingosses avatar jwildman135 avatar jyhess avatar kinverarity1 avatar kwinkunks avatar ltbrizolara avatar mandarjkulkarni avatar nasedil avatar oliveirarodolfo avatar roliveira avatar trqmorgan avatar velizarvesselinov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lasio's Issues

ValueError: total size of new array must be unchanged

D:\study\2015\las_kgs_test\1999\1999\1001179028.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 131, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 156, in read
    data = reader.read_data(len(self.curves))
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 445, in read_data
    arr = numpy.reshape(arr, (-1, number_of_curves))
  File "C:\Users\kent\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 221, in reshape
    return reshape(newshape, order=order)
ValueError: total size of new array must be unchanged

LASHeaderError: Failed in ~W section on line: Sec. 14

D:\study\2015\las_kgs_test\2006_2011\1043562819.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 149, in read
    self.well = reader.read_section('~W')
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 411, in read_section
    section_name, line, traceback.format_exc()))
LASHeaderError: Failed in ~W section on line:
Sec.           14
Traceback (most recent call last):
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 408, in read_section
    values = read_line(line)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 529, in read_line
    for key, value in m.groupdict().items():
AttributeError: 'NoneType' object has no attribute 'groupdict'

With big LAS files potential memory error

With some of the big LAS files numpy.loadtxt(StringIO(s)) is crashing due to not enough memory.

In the past I was using the solution described here http://stackoverflow.com/questions/8956832/python-out-of-memory-on-large-csv-file-numpy

I can generate a big las file, but depends on the memory available in my docker container can crash the parser.

This is an example even before during replace is crashing.

Line by line of chunk by chunk should be used to optimize the memory footprint.

Wrap exampled #1: the STRT is wrongly setup (above Everest altitude) in this example, but is not strange to have files with a lot of rows :)

~Well Information Block
STRT.FT           -178957.0000: START DEPTH
STOP.FT              8372.0000: STOP DEPTH
STEP.FT                 0.5000: STEP
~Curve Information Block
DEPT.FT            0 000 00 00: Depth
R01.IN                        : 
R02.IN                        : 
R03.IN                        : 
R04.IN                        : 
R05.IN                        : 
R06.IN                        : 
R07.IN                        : 
R08.IN                        : 
R09.IN                        : 
R10.IN                        : 
R11.IN                        : 
R12.IN                        : 
R13.IN                        : 
R14.IN                        : 
R15.IN                        : 
R16.IN                        : 
R17.IN                        : 
R18.IN                        : 
R19.IN                        : 
R20.IN                        : 
R21.IN                        : 
R22.IN                        : 
R23.IN                        : 
R24.IN                        : 
R25.IN                        : 
R26.IN                        : 
R27.IN                        : 
R28.IN                        : 
R29.IN                        : 
R30.IN                        : 
R31.IN                        : 
R32.IN                        : 
R33.IN                        : 
R34.IN                        : 
R35.IN                        : 
R36.IN                        : 
R37.IN                        : 
R38.IN                        : 
R39.IN                        : 
R40.IN                        : 
R41.IN                        : 
R42.IN                        : 
R43.IN                        : 
R44.IN                        : 
R45.IN                        : 
R46.IN                        : 
R47.IN                        : 
R48.IN                        : 
R49.IN                        : 
R50.IN                        : 
R51.IN                        : 
R52.IN                        : 
R53.IN                        : 
R54.IN                        : 
R55.IN                        : 
R56.IN                        : 
R57.IN                        : 
R58.IN                        : 
R59.IN                        : 
R60.IN                        : 
idmx.IN                       : 
idmn.IN                       : 
idav.IN                       : 
idmd.IN                       : 
DEVI.IN                       : 
MINR.IN                       :  
~Parameter Information Block
~A  Depth   
#    R01         R02         R03         R04         R05         R06     
#    R07         R08         R09         R10         R11         R12     
#    R13         R14         R15         R16         R17         R18     
#    R19         R20         R21         R22         R23         R24     
#    R25         R26         R27         R28         R29         R30     
#    R31         R32         R33         R34         R35         R36     
#    R37         R38         R39         R40         R41         R42     
#    R43         R44         R45         R46         R47         R48     
#    R49         R50         R51         R52         R53         R54     
#    R55         R56         R57         R58         R59         R60     
#    idmx        idmn        idav        idmd        DEVI        MINR    
#
-178957.0000
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
-178956.5000
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
...

Example 2:

~Well Information Block
STRT.FT           -178956.5000: START DEPTH
STOP.FT             11541.7500: STOP DEPTH
STEP.FT                 0.0500: STEP
~Curve Information Block
DEPT.FT            0 000 00 00: Depth
GR.GAPI                       : Gamma Ray
CCL.                          : Casing Collar Locator
AMP3FT.MV                     : AMP3FT Amplitude
TT3FT.USEC                    : 3FT Travel Time
AMPCAL.MV                     : AMPCAL Amplitude
AMP5FT.MV                     : AMP5FT Amplitude
~Parameter Information Block
PPT.USEC                0.0000: Predicted Pipe Time
CASEWGHT.LB/FT         29.0000: Casing Weight
MAXAMPL.MV             62.2000: Maximum Amplitude
MINAMPL.MV              3.3000: Minimum Amplitude
MINATTN.DB/FT           0.8000: Minimum Attenuation
CASEOD.IN               7.0000: Casing O.D.
~A  Depth        GR         CCL        AMP3FT      TT3FT       AMPCAL      AMP5FT   
-178956.5000   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
-178956.4500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500
...

Exception example:

CRITICAL - Exception Information
CRITICAL - Type: <class 'MemoryError'>
CRITICAL - Value: 
CRITICAL - Traceback:
    l = read(f, autodetect_encoding=True)
  File "/usr/local/lib/python3.4/site-packages/lasio/__init__.py", line 26, in read
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/usr/local/lib/python3.4/site-packages/lasio/las.py", line 156, in __init__
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/usr/local/lib/python3.4/site-packages/lasio/las.py", line 211, in read
    data = reader.read_data(len(self.curves))
  File "/usr/local/lib/python3.4/site-packages/lasio/las.py", line 517, in read_data
    s = re.sub(eol_chars, " ", s)
  File "/usr/local/lib/python3.4/re.py", line 179, in sub
    return _compile(pattern, flags).sub(repl, string, count)

Another exception example in numpy this time:

ERROR    - Failed to read wrapped data: MemoryError
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/lasio/las.py", line 519, in read_data
    arr = numpy.loadtxt(StringIO(s))
MemoryError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
    l = read(f, autodetect_encoding=True)
  File "/usr/local/lib/python3.4/site-packages/lasio/__init__.py", line 26, in read
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/usr/local/lib/python3.4/site-packages/lasio/las.py", line 156, in __init__
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/usr/local/lib/python3.4/site-packages/lasio/las.py", line 211, in read
    data = reader.read_data(len(self.curves))
  File "/usr/local/lib/python3.4/site-packages/lasio/las.py", line 522, in read_data
    traceback.format_exc().splitlines()[-1]))
lasio.las.LASDataError: Failed to read wrapped data: MemoryError

TypeError parsing file with missing ~A section

File example:

~VERSION INFORMATION 
VERS  .    2.0                                     :CWLS Log ASCII Standard - VERSION 2.0
WRAP  .    NO                                      :One Line per Depth step
~WELL INFORMATION 
#MNEM           .UNIT                      DATA            :DESCRIPTION
#----            ------          --------------            -----------------------------
STRT            .ft                     -999.25            :START DEPTH
STOP            .ft                     -999.25            :STOP DEPTH
STEP            .ft              0.0833333333333333        :STEP

#--------------------------------------------------
~CURVE INFORMATION
#MNEM           .UNIT                  API CODE            :DESCRIPTION
#----            ------          --------------            -----------------------------
DEPT            .ft                                        :                                                        Depth Index
#-------------------------------------------------------------
#            DEPT 
#                 
#                 
#                 
~ASCII

Exception:

>>> l = read(f, autodetect_encoding=True)
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/lib/npyio.py:823: UserWarning: loadtxt: Empty input file: "<_io.StringIO object at 0x1021804c8>"
  warnings.warn('loadtxt: Empty input file: "%s"' % fname)
No data present.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/__init__.py", line 26, in read
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/las.py", line 146, in __init__
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/las.py", line 201, in read
    d = data[:, i]
TypeError: tuple indices must be integers, not tuple

Support reading and writing all LAS 3.0 features

LAS 3 specification: https://github.com/kinverarity1/lasio/blob/main/standards/LAS_3_File_Structure.pdf

Tasks:

  • PR #327 Re-arrange LASFile.read so that header sections are parsed before touching any data sections (see comments in #1)
  • Issue #265 Write a reader to handle comma separated data sections and strings -> numpy record array (refer to discussion in #1)
    • partly completed - see comment below
  • PR #424: Ensure LASFile can handle different data types per CurveItem (possible partial solution PR in #424 which uses pd.DataFrame, although not pd.read_csv) - Update 26th April: resolved by #461
  • Issue #446: Use an accelerated pandas reader e.g. pd.read_csv/pd.read_fwf where it is not needed for substitutions etc (refer to discussion in #1) - Update 26th April: being worked on in #452
  • Issue #513: Compile set of real-world LAS 3 files to provide targets for tests and feature implementation.
  • Issue #514: Finalize the API on LASFile for multiple linked Data + Definition sections (e.g. refer to discussion in this issue)
  • Issue #515: Add format to HeaderItem
  • Issue TBA Add association to HeaderItem
  • Issue TBA: Figure out how to handle runs (needs discussion)

Update May 2020: I will start to sketch out a roadmap for how to achieve this. I think once this is reasonably well tested we can do a version 1 release.

Goals:

  • Assume all LAS files are version 3 for parsing, even if they have a VERS code of 2.0. Only avoid this if we have to for performance.
  • Aim to improve reading performance times, it's really bad at the moment

Because I expect this work might require a broken branch for a while, let's merge into the las3-develop branch if we need to.

las_reader.read error management?

I added on my side several exceptions checks to avoid crash of noncompliants LAS files.

    try:
        l = las_reader.read(f)
    except ValueError as e:
        return False, {}, "las_reader.read({}) parsing value error : {}".format(f, e)
    except IndexError as e:
        return False, {}, "las_reader.read({}) index error: {}".format(f, e)

I found some files that are not fully LAS "certified" with strange values like -1.#IND, etc.

Let me know if you if you are interested by these problematic files.
In general will be good that these exceptions are identified in the library and receive output like the file is not readable, etc.

Update PYPI description of the package

Still no mention about writing on PyPI: https://pypi.python.org/pypi/lasio/0.6. Probably you need to update it.

lasio 0.6
Read borehole data from Log ASCII Standard (LAS) files
A library for reading borehole data from log standard ASCII (LAS) files (only specifications 1.2 and 2.0 are supported for now).
Keywords: science geophysics io

When you think (or what it is needed) the package will move from Beta to Production/Stable?

Auto null detection

Repeated values at the top or bottom or both ends of a curve are probably null values. e.g.

-999.25
-999.25
231.64
231.64
231.64
231.64
231.64
101.1
147.2
132.4
...
151.5
150.3
231.64

In the above case -999.25 might be defined as the NULL value but lasio -- given a particular keyword argument -- should autodetect and replace 231.64 by the desired null value (nan by default) in addition to -999.25 (NULL).

This is a particular problem with one piece of software that writes LAS files.

Missing value management on the reference curve

If NULL is setup as 0, and the LAS file have reference DEPTH with value 0, today the library is replacing the value with nan for all the Curves, I know some other software packages that do this only for curves that are not reference.

LAS specification document is not very clear about how should be managed reference with NULL value, but I found it more logical to keep the reference without NULL replacement.

What do you think?

LAS conformity checkup

A lot of people would like to have good working LAS certify solution.

If you can add a function that read the file and strictly check all the readings and return True or False will be a great addition for all the data managers.

If you can push the dream of all data managers is to add LAS repair functionality take a LAS with some strange formatting and convert it to a LAS that can be readable by all the packages.

KeyError: 'No key VERS in ~V section'

Version is available but there is two lines of comments before VERS line.

~Version Information
 #MNEM.UNIT                                            DATA   DESCRIPTION
 #---------                                            ----   -----------
 VERS.                                                  3.0 : CWLS LOG ASCII STANDARD - VERSION 3.0
 WRAP.                                                   NO : ONE LINE PER DEPTH STEP
 DLM.                                                 SPACE : COLUMN DATA SECTION DELIMITER
 SWARE.           MPLOT Build 3199 on 12/10/13 - Production : SOFTWARE VERSION
~Well Information
 #MNEM.UNIT                                                           DATA   DESCRIPTION
 #---------                                                           ----   -----------
 STRT.FT                                                           10530.0 : START DEPTH
 STOP.FT                                                           11300.0 : STOP DEPTH
 STEP.FT                                                               1.0 : STEP
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/lasio/__init__.py", line 26, in read
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/lasio/las.py", line 156, in __init__
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/lasio/las.py", line 186, in read
    raise KeyError("No key VERS in ~V section")
KeyError: 'No key VERS in ~V section'

LASHeaderError: Failed in ~C section on line: .RILD.Ohm-m : DIL Deep Resistivity

D:\study\2015\las_kgs_test\2006_2011\1043994644.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 150, in read
    self.curves = reader.read_list_section('~C')
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 424, in read_list_section
    section_name, line, traceback.format_exc()))
LASHeaderError: Failed in ~C section on line:
.RILD.Ohm-m                   : DIL Deep Resistivity
Traceback (most recent call last):
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 421, in read_list_section
    values = read_line(line)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 529, in read_line
    for key, value in m.groupdict().items():
AttributeError: 'NoneType' object has no attribute 'groupdict'

PyPI 0.5.2 version AttributeError: 'Curve' object has no attribute 'name'

Looks like Curve 'name' attribute disappeared in 0.5 version, but still used in the function get_curve_name

Mac$ pip3 install las_reader --upgrade
Collecting las-reader
  Using cached las_reader-0.5.2-py2.py3-none-any.whl
Requirement already up-to-date: numpy in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from las-reader)
Requirement already up-to-date: namedlist in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from las-reader)
Installing collected packages: las-reader
  Found existing installation: las-reader 0.5
    Uninstalling las-reader-0.5:
      Successfully uninstalled las-reader-0.5
Successfully installed las-reader-0.5.2
Mac$ python3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from las_reader import read
>>> f = 'xxx.las'
>>> l = read(f, autodetect_encoding=True)
>>> for i in l:
...     print(i)
...     c = l.get_curve_name(i)
... 
DEPT
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/las.py", line 352, in get_curve_name
    if curve.name == curve_name:
AttributeError: 'Curve' object has no attribute 'name'
>>> 

write problem

I am reading in this file: http://www.kgs.ku.edu/software/PfEFFER-java/HELP/New_Session/12345b.las
which seems to work fine. then
l = las_reader.read("12345a.las")

Then i try to write it using:
l.write('foo.las',2)

but this gives me an error:
in ()
----> 1 l.write('foo.las')

/home/bdi/virtualenvs/p27/local/lib/python2.7/site-packages/las_reader/las.pyc in write(self, file, version)
251 l_value = len(str(vm.value))
252 for vm in list(self.version.values()):
--> 253 vm_d = vm.todict()
254 vm_d['mnemonic'] = vm_d['mnemonic'].rjust(l_mnem)
255 vm_d['value'] = str(vm_d['value']).rjust(l_value)

AttributeError: 'Metadata' object has no attribute 'todict'

Is there an example on how i should write a file?
Can this library actually write las 2.0 files?

LASDataError: Failed to read data: ValueError: invalid literal for float(): 2000.0:

D:\study\2015\las_kgs_test\1999\1999\1006347031.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 157, in read
    data = reader.read_data(len(self.curves))
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 436, in read_data
    traceback.format_exc()))
LASDataError: Failed to read data:
Traceback (most recent call last):
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 433, in read_data
    arr = numpy.loadtxt(StringIO(s))
  File "C:\Users\kent\Anaconda\lib\site-packages\numpy\lib\npyio.py", line 856, in loadtxt
    items = [conv(val) for (conv, val) in zip(converters, vals)]
ValueError: invalid literal for float(): 2000.0:

Comparison over 100 wells between version 0.3 and 0.5.2

version 0.5.2 is able to load "XXX" mnemonic when is defined in the LAS file as "**.**XXX" ๐Ÿ‘

~Curve Information Block
DEPT.FT            0 000 00 00: Depth
GR.GAPI                       : Gamma Ray
TT3.USEC                      : CBL 3' Travel Time
AMP3.MV                       : CBL 3' Amplitude
AMP5.MV                       : CBL 5' Amplitude
ATT3.DB/FT                    : CBL 3' Attenuation
BONDIX.                       : CBL Bond Index
.CCL.                         : Casing Collar Locator
~Parameter Information Block
~A  Depth        GR         TT3         AMP3        AMP5        ATT3       BONDIX       .CCL    
  4468.0000   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500

but version 0.5.2 is not able load several occurrences of "XXX" ๐Ÿ‘Ž I prefer the old way, and you?

~Curve Information Block
#MNEM.UNIT               :   Curve Description
#---------                   ------------------------------
 DEPTH.F                 :     1  MEASURED DEPTH
 CAL.INCH               :     2  X CALIPER
 CAL.INCH               :     3  Y CALIPER
~Parameter Information Block
#MNEM.UNIT       Value   :   Description
#---------      ----------   ------------------------------
 CS  .INCH          5.500:   CASING SIZE
 CW  .LB/F          20.00:   CASING WEIGHT
 CG  .               N-80:   CASING GRADE
~A   DEPTH      CAL       CAL 
  9159.2998    -999.25    -999.25
  9158.7998    -999.25    -999.25
  9158.2998    -999.25    -999.25

in version 0.3 the channels DEPT, ROP and TGAS was correctly loaded, but not any more parsed with version 0.5: ๐Ÿ‘Ž I prefer the old way, and you? I would even suggest to have default name, like "UNKNOWN" and when the mnemonic is empty you can replace it with "UNKNOWN" so you can load the last 3 channels with UNKNOWN[0-2].

~CURVE INFORMATION
#MNEM.UNIT           APICODE             CURVE DESCRIPTION
#---------         -----------           ------------------
DEPT.FT                     : 1 DEPTH
ROP.MIN/FT                  : 2 ROP
TGAS.UNITS                  : 3 TGAS
.                           : 4 WOB
.                           : 5 RPM
.                           : 6 BHF
~A DEPTH      ROP           TGAS                                                     
 7440          0             0             0             0             0             
 7442          0             0             0             0             0             
 7444          0             0             0             0             0             

Parameter block warning versus exception

LAS file extraction with bad ~P block:

~Curve Information Block
DEPT.FT            0 000 00 00: Depth
GR.CPS                        : Gamma Ray
AMP3FT.MV                     : AMP3FT Amplitude
TT3FT.USEC                    : 3FT Travel Time
AMP5FT.MV                     : AMP5FT Amplitude
TEMP.DEGF                     : Downhole Temperature
DTMP.DEGF                     : Delta Temperature
CCL.                          : Casing Collar Locator
~Parameter Information Block
    Depth        GR        AMP3FT      TT3FT       AMP5FT       TEMP        DTMP        CCL
~A     
  1966.5000   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500   -999.2500

in version 0.3:
output but no exception

Failed to read in NAME.UNIT VALUE:DESCR from:
    Depth        GR        AMP3FT      TT3FT       AMP5FT       TEMP        DTMP        CCL

in version 0.5.2

Type: <class 'las_reader.las.LASHeaderError'>
Value: Failed in ~P section on line:
Depth        GR        AMP3FT      TT3FT       AMP5FT       TEMP        DTMP        CCL
AttributeError: 'NoneType' object has no attribute 'groupdict'
  File "/usr/local/lib/python3.4/site-packages/las_reader/__init__.py", line 26, in read
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/usr/local/lib/python3.4/site-packages/las_reader/las.py", line 146, in __init__
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/usr/local/lib/python3.4/site-packages/las_reader/las.py", line 192, in read
    self.params = reader.read_section('~P')
  File "/usr/local/lib/python3.4/site-packages/las_reader/las.py", line 469, in read_section
    traceback.format_exc().splitlines()[-1]))

I prefer the 0.3 las_read behavior: receive a warning for parameter section bad reading and be able to read the data.

Do you agree?

Resurrect LAS > Excel converter script

I accidentally deleted this code. Need to put it back in and test it. Also pandas may be a better library choice than xlwt -- or I could write code to support both.

class ExcelConverter(object):
    def __init__(self, las):
        self.las = las

    def write_excel(self, xlsfn):
        import xlwt
        wb = xlwt.Workbook()
        md_sheet = wb.add_sheet('Metadata')
        curves_sheet = wb.add_sheet('Curves')

        for i, (key, value) in enumerate(self.las.metadata_list()):
            md_sheet.write(i, 0, key)
            md_sheet.write(i, 1, value)

        for i, (name, data) in enumerate(self.las.curves()):
            curves_sheet.write(0, i, name)
            for j, value in enumerate(data):
                curves_sheet.write(j + 1, i, value)

        wb.save(xlsfn)

ValueError: could not convert string to float: ********

D:\study\2015\las_kgs_test\1999\1999\1006346380.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 157, in read
    data = reader.read_data(len(self.curves))
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 436, in read_data
    traceback.format_exc()))
LASDataError: Failed to read data:
Traceback (most recent call last):
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 433, in read_data
    arr = numpy.loadtxt(StringIO(s))
  File "C:\Users\kent\Anaconda\lib\site-packages\numpy\lib\npyio.py", line 856, in loadtxt
    items = [conv(val) for (conv, val) in zip(converters, vals)]
ValueError: could not convert string to float: ********

Fails on LAS file spec version 2.1 (?)

D:\study\2015\las_kgs_test\LAS Files\E-E' LAS Files\Deem\A_Deem_B.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 149, in read
    self.well = reader.read_section('~W')
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 403, in read_section
    parser = SectionParser(section_name, version=self.version)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 487, in __init__
    section_orders = ORDER_DEFINITIONS[self.version][self.section_name2]
KeyError: 2.1

LASDataError: Failed to read data: ValueError: could not convert string to float: TR

D:\study\2015\las_kgs_test\2014\1044907419.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 157, in read
    data = reader.read_data(len(self.curves))
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 436, in read_data
    traceback.format_exc()))
LASDataError: Failed to read data:
Traceback (most recent call last):
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 433, in read_data
    arr = numpy.loadtxt(StringIO(s))
  File "C:\Users\kent\Anaconda\lib\site-packages\numpy\lib\npyio.py", line 856, in loadtxt
    items = [conv(val) for (conv, val) in zip(converters, vals)]
ValueError: could not convert string to float: TR

Cannot read from URL on python 3

See e.g. https://travis-ci.org/kinverarity1/lasio/jobs/74413612

$ py.test --cov=lasio
============================= test session starts ==============================
platform linux2 -- Python 3.2.5 -- py-1.4.26 -- pytest-2.6.4
plugins: cov
collected 10 items 

lasio/test_open_file.py F....
lasio/test_read.py ....
lasio/test_wrapped.py .

=================================== FAILURES ===================================
________________________________ test_open_url _________________________________

    def test_open_url():
        l = read(
>           "https://raw.githubusercontent.com/kinverarity1/lasio"
            "/master/standards/examples/1.2/sample_curve_api.las")

lasio/test_open_file.py:14: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
lasio/__init__.py:26: in read
    autodetect_encoding_chars=autodetect_encoding_chars)
lasio/las.py:156: in __init__
    autodetect_encoding_chars=autodetect_encoding_chars)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {}
file_ref = 'https://raw.githubusercontent.com/kinverarity1/lasio/master/standards/examples/1.2/sample_curve_api.las'
encoding = None, autodetect_encoding = False, autodetect_encoding_chars = 20000

    def read(self, file_ref, encoding=None,
             autodetect_encoding=False, autodetect_encoding_chars=20000):
        '''Read a LAS file.

            Args:
              file_ref: either a filename, an open file object, or a string of
                a LAS file contents.

            Kwargs:
              encoding (str): character encoding to open file_ref with
              autodetect_encoding (bool): use chardet/ccharet to detect encoding
              autodetect_encoding_chars (int/None): number of chars to read from LAS
                file for auto-detection of encoding.

            '''
        f = open_file(file_ref, encoding=encoding,
                      autodetect_encoding=autodetect_encoding,
                      autodetect_encoding_chars=autodetect_encoding_chars)

        self._text = str(f.read())
        reader = Reader(self._text, version=1.2)

        self.version = reader.read_section('~V')

        # Set version
        try:
            reader.version = self.version['VERS'].value
        except KeyError:
>           raise KeyError("No key VERS in ~V section")
E           KeyError: 'No key VERS in ~V section'

lasio/las.py:186: KeyError
--------------- coverage: platform linux2, python 3.2.5-final-0 ----------------
Name                   Stmts   Miss  Cover
------------------------------------------
lasio/__init__             3      0   100%
lasio/las                389    145    63%
lasio/las2excel           53     53     0%
lasio/test_encoding        2      0   100%
lasio/test_open_file      17      0   100%
lasio/test_read           15      0   100%
lasio/test_wrapped         6      0   100%
------------------------------------------
TOTAL                    485    198    59%
====================== 1 failed, 9 passed in 0.64 seconds ======================

The command "py.test --cov=lasio" exited with 1.

lasio.las.LASHeaderError: Failed in ~W section on line:

I would suggest you that you consider that the property name is 'UNKNOWN' and you accept the line.

Internal exception is converted to a warning for "~P" section, I would suggest you that you do the same for the other sections as well.

  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/lasio/__init__.py", line 26, in read
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/lasio/las.py", line 156, in __init__
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/lasio/las.py", line 200, in read
    self.well = reader.read_section('~W')
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/lasio/las.py", line 488, in read_section
    traceback.format_exc().splitlines()[-1]))
lasio.las.LASHeaderError: Failed in ~W section on line:
.                                                                                                                                            :AttributeError: 'NoneType' object has no attribute 'groupdict'

~Well Information
 #MNEM.UNIT                                                                                                                              DATA   DESCRIPTION
 #---------                                                                                                                              ----   -----------
 STRT.FT                                                                                                                               8860.0 : START DEPTH
 STOP.FT                                                                                                                              10280.0 : STOP DEPTH
 STEP.FT                                                                                                                                  1.0 : STEP
 NULL.                                                                                                                                -9999.0 : NULL VALUE
...
.                                                                                                                                            :
~Curve Information
 #MNEM.UNIT                   DATA   DESCRIPTION
 #---------                   ----   -----------
 DEPTH.FT                          :  {F}

ValueError: Wrong number of columns at line 15

D:\study\2015\las_kgs_test\2001_2005\1031902741.las Traceback (most recent call last):
  File ".\basic_read_test.py", line 19, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 121, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 143, in read
    data = reader.read_data(len(self.curves))
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 416, in read_data
    arr = numpy.loadtxt(StringIO(s))
  File "C:\Users\kent\Anaconda\lib\site-packages\numpy\lib\npyio.py", line 853, in loadtxt
    % line_num)
ValueError: Wrong number of columns at line 15

autodetect_encoding=True don't seem to work for me

Looks like the encoding is well detected by it is not correctly passed to the open function

            if autodetect_encoding:
                try:
                    import cchardet as chardet
                except ImportError:
                    try:
                        import chardet
                    except ImportError:
                        raise ImportError("chardet or cchardet is required for"
                                          " automatic detection of character"
                                          " encodings.")
                with open(file_ref, mode="rb") as test_file:
                    chunk = test_file.read(autodetect_encoding_chars)
                    result = chardet.detect(chunk)
                    encoding = result["encoding"]
            file_ref = codecs.open(file_ref, mode="r", encoding=None)

LASHeaderError: Failed in ~W section on line: INJUN 815.00

D:\study\2015\las_kgs_test\LAS Files\D-D' LAS Files\Birney\Birney_A.LAS
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 149, in read
    self.well = reader.read_section('~W')
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 411, in read_section
    section_name, line, traceback.format_exc()))
LASHeaderError: Failed in ~W section on line:
INJUN                  815.00
Traceback (most recent call last):
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 408, in read_section
    values = read_line(line)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 529, in read_line
    for key, value in m.groupdict().items():
AttributeError: 'NoneType' object has no attribute 'groupdict'

building las curve from scratch

Could you add an example where you start with an empty LAS object and then build a las object in code, and finally save it to the file?

Python 3 issue with version 0.5 was working with the previous version

This line from las_reader import read is creating exception as shown below:

Mac:~/GitHub/las-reader (original)/las_reader$ pip install las-reader --upgrade
Collecting las-reader
  Downloading las_reader-0.5-py2.py3-none-any.whl
Collecting namedlist (from las-reader)
  Downloading namedlist-1.7.tar.gz
Collecting numpy (from las-reader)
  Downloading numpy-1.9.2-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.7MB)
    100% |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 3.7MB 158kB/s 
Installing collected packages: namedlist, numpy, las-reader
  Running setup.py install for namedlist
  Found existing installation: las-reader 0.0.0
    DEPRECATION: Uninstalling a distutils installed project (las-reader) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling las-reader-0.0.0:
      Successfully uninstalled las-reader-0.0.0
Successfully installed las-reader-0.5 namedlist-1.7 numpy-1.9.2
Mac:~/GitHub/las-reader (original)/las_reader$ python3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from las_reader import read
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/__init__.py", line 3, in <module>
    from las import __version__, LASFile, Curve, HeaderItem
ImportError: cannot import name '__version__'
>>> 

I think there is something wrong with the latest Python 3 commit. It will be great to have some automatic tests before the version is pushed to pip.

Trying to read a file providing wrong file path gives a confusing VERS exception

Often when the file name path is badly setup, I got this kind of exception.
file_ref parameter is considered to be string content of the file path:
file_ref: either a filename, an open file object, or a string of a LAS file contents.

Suggestion: if file_ref is a single line string to be all the time consider as file path and if don't exist to have a clear message that file path doesn't exist instead of trying to parse the file path as LAS content as shown below:

Mac$ python3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from las_reader import read
>>> l = read('random/Text/Or/Bad/File/Name', autodetect_encoding=True)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/las.py", line 174, in read
    reader.version = self.version['VERS'].value
KeyError: 'VERS'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/__init__.py", line 26, in read
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/las.py", line 146, in __init__
    autodetect_encoding_chars=autodetect_encoding_chars)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/las_reader/las.py", line 176, in read
    raise KeyError("No key VERS in ~V section")
KeyError: 'No key VERS in ~V section'

IndexError: index 3 is out of bounds for axis 1 with size 3


D:\study\2015\las_kgs_test\2006_2011\1042437385.las Traceback (most recent call last):
  File ".\basic_read_test.py", line 19, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 121, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 161, in read
    d = data[:, i]
IndexError: index 3 is out of bounds for axis 1 with size 3

python 3 version

First of all, thanks for just really finally building a las-lib that is easy to install and easy to use.
Definitly the best las library i have seen.
I wanted to try and contribute by converting to python 3 (i am a p3 user) but when i cloned your repo i saw you already have a p2->p3 branch. so i checked that out, and it seems its just an older version.
Would there be an easy way to get the p3 version of you lib updated so its working with your v. 0.5 demos?

LASHeaderError: Failed in ~W section on line: COUNTY: RUSSELL

D:\study\2015\las_kgs_test\2012\1044094833.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 149, in read
    self.well = reader.read_section('~W')
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 411, in read_section
    section_name, line, traceback.format_exc()))
LASHeaderError: Failed in ~W section on line:
COUNTY: RUSSELL
Traceback (most recent call last):
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 408, in read_section
    values = read_line(line)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 529, in read_line
    for key, value in m.groupdict().items():
AttributeError: 'NoneType' object has no attribute 'groupdict'

ValueError: invalid literal for float(): 0,087

D:\study\2015\las_kgs_test\2001_2005\1031712032.las Traceback (most recent call last):
  File ".\basic_read_test.py", line 19, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 121, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 143, in read
    data = reader.read_data(len(self.curves))
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 416, in read_data
    arr = numpy.loadtxt(StringIO(s))
  File "C:\Users\kent\Anaconda\lib\site-packages\numpy\lib\npyio.py", line 856, in loadtxt
    items = [conv(val) for (conv, val) in zip(converters, vals)]
ValueError: invalid literal for float(): 0,087

Handle metadata values properly

At the moment metadata values are not handled very well at all:

  1. It doesn't properly or consistently have default values
  2. Although they can be consistently accessed via their mnemonics in the relevant sections, I haven't decided how to present them as top level properties -- via a "pretty" name or via their mnemonic? And does the library return only their value, or the parent mutable named tuple?

Warn/check for ~ASCII header row

Most software puts the curve names as column headers on the line beginning with "~A". We should have scripts to check for this, cross-check to see if they match the curve mnemonics in ~C, and create or delete the row.

PyLint code check

Please check your code with PyLint or PEP8.
A lot of potential issues can be identified by these tools and make the code more easy to maintain.
I'm using Atom as editor with Atom-linter & linter-pylint plugins installed and make me help to avoid stupid Python errors.

No config file found, using default configuration
************* Module las_reader
C:  1, 0: Missing module docstring (missing-docstring)
C:  4, 0: Missing function docstring (missing-docstring)
W:  4, 0: Unused argument 'kwargs' (unused-argument)
************* Module las_reader._logging
C: 23, 0: Trailing whitespace (trailing-whitespace)
C: 26, 0: Trailing whitespace (trailing-whitespace)
C:  6, 0: Missing function docstring (missing-docstring)
W:  6,21: Redefining name 'logger' from outer scope (line 26) (redefined-outer-name)
C: 26, 0: Invalid constant name "logger" (invalid-name)
W: 27, 0: Specify string format arguments as logging function parameters (logging-not-lazy)
************* Module las_reader.las
W:203, 0: TODO: Issue #5 (fixme)
C: 62, 0: Exactly one space required after comma
        ("VERS", Metadata("VERS", "", 2.0,   "CWLS log ASCII Standard -VERSION 2.0")),
                                         ^ (bad-whitespace)
C: 63, 0: Exactly one space required after comma
        ("WRAP", Metadata("WRAP", "", "NO",  "One line per depth step")),
                                          ^ (bad-whitespace)
C: 64, 0: Exactly one space required after comma
        ("DLM",  Metadata("DLM", "", "SPACE", "Column Data Section Delimiter"))]),
              ^ (bad-whitespace)
C: 66, 0: Exactly one space required after comma
        ("STRT", Metadata("STRT", "m", numpy.nan,   "START DEPTH")),
                                                ^ (bad-whitespace)
C: 67, 0: Exactly one space required after comma
        ("STOP", Metadata("STOP", "m", numpy.nan,   "STOP DEPTH")),
                                                ^ (bad-whitespace)
C: 68, 0: Exactly one space required after comma
        ("STEP", Metadata("STEP", "m", numpy.nan,   "STEP")),
                                                ^ (bad-whitespace)
C: 69, 0: Exactly one space required after comma
        ("COMP", Metadata("NULL", "", -9999.25,     "NULL VALUE")),
                                              ^ (bad-whitespace)
C: 70, 0: Exactly one space required after comma
        ("COMP", Metadata("NULL", "", -9999.25,     "COMPANY")),
                                              ^ (bad-whitespace)
C: 71, 0: Exactly one space required after comma
        ("WELL", Metadata("NULL", "", -9999.25,     "WELL")),
                                              ^ (bad-whitespace)
C: 72, 0: Exactly one space required after comma
        ("FLD",  Metadata("NULL", "", -9999.25,     "FIELD")),
              ^ (bad-whitespace)
C: 72, 0: Exactly one space required after comma
        ("FLD",  Metadata("NULL", "", -9999.25,     "FIELD")),
                                              ^ (bad-whitespace)
C: 73, 0: Exactly one space required after comma
        ("LOC",  Metadata("NULL", "", -9999.25,     "LOCATION")),
              ^ (bad-whitespace)
C: 73, 0: Exactly one space required after comma
        ("LOC",  Metadata("NULL", "", -9999.25,     "LOCATION")),
                                              ^ (bad-whitespace)
C: 74, 0: Exactly one space required after comma
        ("PROV", Metadata("NULL", "", -9999.25,     "PROVINCE")),
                                              ^ (bad-whitespace)
C: 75, 0: Exactly one space required after comma
        ("CNTY", Metadata("NULL", "", -9999.25,     "COUNTY")),
                                              ^ (bad-whitespace)
C: 76, 0: Exactly one space required after comma
        ("STAT", Metadata("NULL", "", -9999.25,     "STATE")),
                                              ^ (bad-whitespace)
C: 77, 0: Exactly one space required after comma
        ("CTRY", Metadata("NULL", "", -9999.25,     "COUNTRY")),
                                              ^ (bad-whitespace)
C: 78, 0: Exactly one space required after comma
        ("SRVC", Metadata("NULL", "", -9999.25,     "SERVICE COMPANY")),
                                              ^ (bad-whitespace)
C: 79, 0: Exactly one space required after comma
        ("DATE", Metadata("NULL", "", -9999.25,     "DATE")),
                                              ^ (bad-whitespace)
C: 80, 0: Exactly one space required after comma
        ("UWI",  Metadata("NULL", "", -9999.25,     "UNIQUE WELL ID")),
              ^ (bad-whitespace)
C: 80, 0: Exactly one space required after comma
        ("UWI",  Metadata("NULL", "", -9999.25,     "UNIQUE WELL ID")),
                                              ^ (bad-whitespace)
C: 81, 0: Exactly one space required after comma
        ("API",  Metadata("NULL", "", -9999.25,     "API NUMBER"))
              ^ (bad-whitespace)
C: 81, 0: Exactly one space required after comma
        ("API",  Metadata("NULL", "", -9999.25,     "API NUMBER"))
                                              ^ (bad-whitespace)
C:120, 0: Unnecessary parens after 'not' keyword (superfluous-parens)
C:122, 0: Trailing whitespace (trailing-whitespace)
C:182, 0: Line too long (132/100) (line-too-long)
C:197, 0: Line too long (101/100) (line-too-long)
C:204, 0: Exactly one space required after comma
        self.version['WRAP'] = Metadata('WRAP', '', 'NO',  'One line per depth step')
                                                        ^ (bad-whitespace)
C:205, 0: Trailing whitespace (trailing-whitespace)
C:238, 0: Wrong hanging indentation.
                            l_left - len(wm_leftmost))
                    |       ^ (bad-continuation)
C:242, 0: Wrong hanging indentation.
                            l_left - len(wm_leftmost))
                    |       ^ (bad-continuation)
C:258, 0: Wrong hanging indentation.
                        **cm.todict()).ljust(l_mnem_unit)
                |       ^ (bad-continuation)
C:275, 0: Wrong hanging indentation.
                        **pm.todict()).ljust(l_mnem_unit)
                |       ^ (bad-continuation)
C:385, 0: Trailing whitespace (trailing-whitespace)
C:493, 0: Trailing whitespace (trailing-whitespace)
C:530, 0: Final newline missing (missing-final-newline)
W:441, 0: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
W:441, 0: Anomalous backslash in string: '\.'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
W:441, 0: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
W:441, 0: Anomalous backslash in string: '\.'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
W:441, 0: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
W:442, 0: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
W: 17, 0: No exception type(s) specified (bare-except)
F: 16, 4: Unable to import 'cStringIO' (import-error)
F: 25, 4: Unable to import 'StringIO' (import-error)
F: 28, 0: Unable to import 'namedlist' (import-error)
F: 29, 0: Unable to import 'numpy' (import-error)
C: 32, 0: Invalid constant name "logger" (invalid-name)
C: 36, 0: Invalid constant name "Metadata" (invalid-name)
C: 37, 0: Invalid constant name "Curve" (invalid-name)
C: 38, 0: Invalid constant name "Parameter" (invalid-name)
C: 42, 0: Missing class docstring (missing-docstring)
C: 44, 8: Invalid variable name "l" (invalid-name)
C: 46,12: Invalid variable name "s" (invalid-name)
C: 48, 8: Invalid variable name "s" (invalid-name)
C: 52, 4: Invalid attribute name "_d" (invalid-name)
C: 52, 4: Missing method docstring (missing-docstring)
C:123, 4: Missing method docstring (missing-docstring)
C:124, 8: Invalid variable name "f" (invalid-name)
C:145, 8: Invalid variable name "n" (invalid-name)
E:146,23: Instance of 'tuple' has no 'name' member (no-member)
C:155,15: Invalid variable name "c" (invalid-name)
C:160,15: Invalid variable name "c" (invalid-name)
C:161,12: Invalid variable name "d" (invalid-name)
W:164,16: Specify string format arguments as logging function parameters (logging-not-lazy)
C:173, 4: Missing method docstring (missing-docstring)
E:174,29: Instance of 'tuple' has no 'data' member (no-member)
E:176, 4: Method should have "self" as first argument (no-self-argument)
E:185,58: Undefined variable 'unit' (undefined-variable)
E:188,58: Undefined variable 'unit' (undefined-variable)
C:190, 4: Missing method docstring (missing-docstring)
R:190, 4: Too many local variables (30/15) (too-many-locals)
C:209,12: Invalid variable name "vm" (invalid-name)
C:214,12: Invalid variable name "vm" (invalid-name)
E:218,25: Undefined variable 'VERS_FMT' (undefined-variable)
C:227,12: Invalid variable name "wm" (invalid-name)
E:228,30: Undefined variable 'WELL_REV_MNEMONICS' (undefined-variable)
C:234,12: Invalid variable name "wm" (invalid-name)
E:236,30: Undefined variable 'WELL_REV_MNEMONICS' (undefined-variable)
C:248, 8: Invalid variable name "l_API_code" (invalid-name)
C:249,12: Invalid variable name "cm" (invalid-name)
E:250,55: Instance of 'tuple' has no 'todict' member (no-member)
C:253,12: Invalid variable name "s_API_code" (invalid-name)
E:253,29: Instance of 'tuple' has no 'API_code' member (no-member)
C:255,16: Invalid variable name "l_API_code" (invalid-name)
C:256,12: Invalid variable name "cm" (invalid-name)
E:258,26: Instance of 'tuple' has no 'todict' member (no-member)
E:259,26: Instance of 'tuple' has no 'API_code' member (no-member)
E:260,57: Instance of 'tuple' has no 'descr' member (no-member)
C:266,12: Invalid variable name "pm" (invalid-name)
C:273,12: Invalid variable name "pm" (invalid-name)
E:287,39: Instance of 'tuple' has no 'data' member (no-member)
C:290, 8: Invalid argument name "n" (invalid-name)
C:290, 8: Invalid argument name "l" (invalid-name)
C:290, 8: Missing function docstring (missing-docstring)
R:190, 4: Too many branches (24/12) (too-many-branches)
C:302, 4: Missing method docstring (missing-docstring)
E:304,15: Instance of 'tuple' has no 'name' member (no-member)
E:308,17: Bad first argument 'OrderedDictionary' given to super() (bad-super-call)
C:317, 4: Missing method docstring (missing-docstring)
C:320, 4: Missing method docstring (missing-docstring)
C:323, 4: Missing method docstring (missing-docstring)
C:327, 4: Missing method docstring (missing-docstring)
C:328, 8: Invalid variable name "d" (invalid-name)
C:329,12: Invalid variable name "di" (invalid-name)
C:330,19: Invalid variable name "v" (invalid-name)
C:335, 4: Missing method docstring (missing-docstring)
W:335,23: Unused argument 'value' (unused-argument)
R:335, 4: Method could be a function (no-self-use)
C:339, 4: Missing method docstring (missing-docstring)
C:344, 0: Missing class docstring (missing-docstring)
C:349, 0: Missing class docstring (missing-docstring)
C:357, 4: Missing method docstring (missing-docstring)
C:367, 4: Missing method docstring (missing-docstring)
C:384, 4: Missing method docstring (missing-docstring)
C:388, 4: Missing method docstring (missing-docstring)
C:390, 8: Invalid variable name "d" (invalid-name)
W:395,12: No exception type(s) specified (bare-except)
C:401, 4: Missing method docstring (missing-docstring)
C:403, 8: Invalid variable name "l" (invalid-name)
W:407,12: No exception type(s) specified (bare-except)
C:413, 4: Missing method docstring (missing-docstring)
C:414, 8: Invalid variable name "s" (invalid-name)
C:418,12: Invalid variable name "s" (invalid-name)
W:420,12: Specify string format arguments as logging function parameters (logging-not-lazy)
W:421,12: Specify string format arguments as logging function parameters (logging-not-lazy)
W:427,12: Specify string format arguments as logging function parameters (logging-not-lazy)
W:428, 8: Specify string format arguments as logging function parameters (logging-not-lazy)
C:432, 4: Missing method docstring (missing-docstring)
C:439, 8: Invalid variable name "s" (invalid-name)
C:440, 8: Invalid variable name "s" (invalid-name)
C:441, 8: Invalid variable name "s" (invalid-name)
C:442, 8: Invalid variable name "s" (invalid-name)
C:447, 0: Missing class docstring (missing-docstring)
C:471, 8: Invalid variable name "r" (invalid-name)
C:474, 4: Invalid argument name "x" (invalid-name)
C:474, 4: Missing method docstring (missing-docstring)
W:479, 8: No exception type(s) specified (bare-except)
W:482,12: No exception type(s) specified (bare-except)
R:474, 4: Method could be a function (no-self-use)
C:485, 4: Missing method docstring (missing-docstring)
C:492, 4: Missing method docstring (missing-docstring)
R:492, 4: Method could be a function (no-self-use)
C:496, 4: Missing method docstring (missing-docstring)
C:501, 0: Missing function docstring (missing-docstring)
C:502, 4: Invalid variable name "d" (invalid-name)
C:504, 4: Invalid variable name "m" (invalid-name)
C:510, 0: Missing function docstring (missing-docstring)
C:517,12: Invalid variable name "f" (invalid-name)
C:521,12: Invalid variable name "f" (invalid-name)
C:523, 8: Invalid variable name "f" (invalid-name)
W:528, 8: No exception type(s) specified (bare-except)
************* Module las_reader.las2excel
C:  6, 0: Trailing whitespace (trailing-whitespace)
C: 24, 0: Trailing whitespace (trailing-whitespace)
C: 29, 0: Trailing whitespace (trailing-whitespace)
C: 35, 0: Trailing whitespace (trailing-whitespace)
C: 36, 0: Trailing whitespace (trailing-whitespace)
C: 38, 0: Final newline missing (missing-final-newline)
C:  1, 0: Missing module docstring (missing-docstring)
C: 10, 0: Missing function docstring (missing-docstring)
C: 25, 4: Invalid variable name "l" (invalid-name)
E: 26,16: Undefined variable 'core' (undefined-variable)
C: 30, 0: Missing function docstring (missing-docstring)


Report
======
396 statements analysed.

Statistics by type
------------------

+---------+-------+-----------+-----------+------------+---------+
|type     |number |old number |difference |%documented |%badname |
+=========+=======+===========+===========+============+=========+
|module   |4      |NC         |NC         |50.00       |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|class    |5      |NC         |NC         |20.00       |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|method   |31     |NC         |NC         |29.03       |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|function |7      |NC         |NC         |0.00        |0.00     |
+---------+-------+-----------+-----------+------------+---------+



External dependencies
---------------------
::

    las_reader 
      \-las (las_reader,las_reader.las2excel)



Raw metrics
-----------

+----------+-------+------+---------+-----------+
|type      |number |%     |previous |difference |
+==========+=======+======+=========+===========+
|code      |459    |84.38 |NC       |NC         |
+----------+-------+------+---------+-----------+
|docstring |39     |7.17  |NC       |NC         |
+----------+-------+------+---------+-----------+
|comment   |11     |2.02  |NC       |NC         |
+----------+-------+------+---------+-----------+
|empty     |35     |6.43  |NC       |NC         |
+----------+-------+------+---------+-----------+



Duplication
-----------

+-------------------------+------+---------+-----------+
|                         |now   |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines      |0     |NC       |NC         |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |NC       |NC         |
+-------------------------+------+---------+-----------+



Messages by category
--------------------

+-----------+-------+---------+-----------+
|type       |number |previous |difference |
+===========+=======+=========+===========+
|convention |125    |NC       |NC         |
+-----------+-------+---------+-----------+
|refactor   |5      |NC       |NC         |
+-----------+-------+---------+-----------+
|warning    |22     |NC       |NC         |
+-----------+-------+---------+-----------+
|error      |17     |NC       |NC         |
+-----------+-------+---------+-----------+



% errors / warnings by module
-----------------------------

+---------------------+------+--------+---------+-----------+
|module               |error |warning |refactor |convention |
+=====================+======+========+=========+===========+
|las_reader.las       |94.12 |86.36   |100.00   |87.20      |
+---------------------+------+--------+---------+-----------+
|las_reader.las2excel |5.88  |0.00    |0.00     |8.00       |
+---------------------+------+--------+---------+-----------+
|las_reader._logging  |0.00  |9.09    |0.00     |3.20       |
+---------------------+------+--------+---------+-----------+
|las_reader.__init__  |0.00  |4.55    |0.00     |1.60       |
+---------------------+------+--------+---------+-----------+



Messages
--------

+------------------------------+------------+
|message id                    |occurrences |
+==============================+============+
|invalid-name                  |46          |
+------------------------------+------------+
|missing-docstring             |35          |
+------------------------------+------------+
|bad-whitespace                |24          |
+------------------------------+------------+
|trailing-whitespace           |11          |
+------------------------------+------------+
|no-member                     |9           |
+------------------------------+------------+
|undefined-variable            |6           |
+------------------------------+------------+
|logging-not-lazy              |6           |
+------------------------------+------------+
|bare-except                   |6           |
+------------------------------+------------+
|anomalous-backslash-in-string |6           |
+------------------------------+------------+
|import-error                  |4           |
+------------------------------+------------+
|bad-continuation              |4           |
+------------------------------+------------+
|no-self-use                   |3           |
+------------------------------+------------+
|unused-argument               |2           |
+------------------------------+------------+
|missing-final-newline         |2           |
+------------------------------+------------+
|line-too-long                 |2           |
+------------------------------+------------+
|too-many-locals               |1           |
+------------------------------+------------+
|too-many-branches             |1           |
+------------------------------+------------+
|superfluous-parens            |1           |
+------------------------------+------------+
|redefined-outer-name          |1           |
+------------------------------+------------+
|no-self-argument              |1           |
+------------------------------+------------+
|fixme                         |1           |
+------------------------------+------------+
|bad-super-call                |1           |
+------------------------------+------------+



Global evaluation
-----------------
Your code has been rated at 4.02/10

Retain comment lines (e.g. `#`) so that they can be written out

This causes an error at the moment but should be accommodated:

#11/15/1999 13:29:44 Updated by the Kansas Geological Survey
# #KGS#ID: 30S30W/1006347516
# #KGS#INPUT_FILE: /home/crude2_3/WellLogs/Watney/sw-ne/Kohn119a.las.las
~VERSION INFORMATION
 VERS.                          2.0: CWLS LOG ASCII STANDARD - VERSION 2.0
 WRAP.                           NO: ONE LINE PER DEPTH STEP
#
#
~WELL INFORMATION BLOCK
#MNEM.UNIT   DATA TYPE        DESCRIPTION
#---------   ------------     -----------------------------
 STRT.FT                   1684.000: 
 STOP.FT                   5898.000: 
 STEP.FT                      0.500: 

STRT STOP STEP not updating

Using your example i am trying to set some header items.
It seems that some of them is writing fine to file while others are not updated when flushed to file.
Specifically STRT, STOP and STEP seem to keep the default values of 10, 49.5 and 0.5.
Is it somehow overwriting those values? I tried grepping for 49.5 in src code but nothing came up.
This is my code (based on your example):

import las_reader
print(las_reader.version)
import datetime
import numpy
import os

import matplotlib.pyplot as plt

depths = numpy.arange(10, 50, 0.5)
synth = numpy.log10(depths) * 10 + numpy.random.random(len(depths))
synth[15:25] = numpy.nan # Add some null values in the middle

l = las_reader.LASFile()
l.well["DATE"].value = str(datetime.datetime.today())
l.well["STRT"].value = "0.25"
l.well["STOP"].value = "5000.25"
l.well["STEP"].value = "1"
l.well["NULL"].value = "-9999"
l.well["FLD"].value = "MY WELL"
l.well["COMP"].value = "MY COMPANY"
print(l.well)

HeaderItem: mnemonic, unit, value, descr

l.other = "Example of how to create a LAS file from scratch using las_reader"

l.add_curve("DEPT", depths, unit="m")
l.add_curve("SYNTH", synth, descr="Synthetic data")

fn = "scratch_example_v2.las"
if os.path.exists(fn): # Remove file if it already exists
os.remove(fn)
with open(fn, mode="w") as f: # Write LAS file to disk
l.write(f,2)

Windows WRAP files not parsed correctly

For files with Windows (CRLF new line) '\r' should be also replaced.

    if not self.wrap:
            try:
                arr = numpy.loadtxt(StringIO(s))
            except:
                raise LASDataError("Failed to read data:\n%s" % (
                                   traceback.format_exc().splitlines()[-1]))
        else:
            s = s.replace('\n', ' ').replace('\t', ' ')

newline bug

D:\study\2015\las_kgs_test\2006_2011\1043960160.las
Traceback (most recent call last):
  File ".\basic_read_test.py", line 20, in <module>
    l = las_reader.read(fn)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\__init__.py", line 5, in read
    return las.LASFile(file)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 132, in __init__
    self.read(file, **kwargs)
  File "d:\work\dewnr\logging_software\las_reader\las_reader\las.py", line 146, in read
    raise KeyError("No key VERS in ~V (%s)" % (", ".join(self.version.keys())))
KeyError: 'No key VERS in ~V ()'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.