Docstrings for the lasio package

Reading LAS files

lasio.read(file_ref, **kwargs)[source]

Read a LAS file.

Note that only versions 1.2 and 2.0 of the LAS file specification are fully supported. There is partial support for reading LAS 3.0 files.

Parameters:

file_ref (file-like object or str) – either a filename, an open file object, or a string containing the contents of a file.

Keyword Arguments:
 
  • ignore_header_errors (bool) – ignore LASHeaderErrors (False by default)
  • ignore_comments (sequence/str) – ignore lines beginning with these characters e.g. ("#", '"') in header sections.
  • ignore_data_comments (str) – ignore lines beginning with this character in data sections only.
  • mnemonic_case (str) – ‘preserve’: keep the case of HeaderItem mnemonics ‘upper’: convert all HeaderItem mnemonics to uppercase ‘lower’: convert all HeaderItem mnemonics to lowercase
  • ignore_data (bool) – if True, do not read in any of the actual data, just the header metadata. False by default.
  • engine (str) – “normal”: parse data section with normal Python reader (quite slow); “numpy”: parse data section with numpy.genfromtxt (fast). By default the engine is “numpy”.
  • use_normal_engine_for_wrapped (bool) – if header metadata indicates that the file is wrapped, always use the ‘normal’ engine. Default is True. The only reason you should use False is if speed is a very high priority and you had files with metadata that incorrectly indicates they are wrapped.
  • read_policy (str or list) – Apply regular expression substitutions for common errors in fixed-width formatted data sections. If you do not want any such substitutions to applied, pass read_policy=().
  • null_policy (str or list) – see https://lasio.readthedocs.io/en/latest/data-section.html#handling-invalid-data-indicators-automatically
  • accept_regexp_sub_recommendations (bool) – Accept recommendations to auto- matically remove read substitutions (applied by the default read_policy) which look for numeric run-on errors involving hyphens. This avoids incorrect parsing of dates such as ‘2018-05-22’ as three separate columns containing ‘2018’, ‘-5’ and ‘-22’. The read substitutions are applied only if the inspection code of the data section finds a hyphen in every line. The only circumstance where this should be manually set to False is where you have very problematic fixed-column-width data sections involving negative values.
  • index_unit (str) – Optionally force-set the index curve’s unit to “m” or “ft”
  • dtypes ("auto", dict or list) – specify the data types for each curve in the ~ASCII data section. If “auto”, each curve will be converted to floats if possible and remain as str if not. If a dict you can specify only the curve mnemonics you want to convert as a key. If a list, please specify data types for each curve in order. Note that the conversion currently only occurs via numpy.ndarray.astype() and therefore only a few simple casts will work e.g. int, float, str.
  • encoding (str) – character encoding to open file_ref with, using io.open() (this is handled by lasio.reader.open_with_codecs())
  • encoding_errors (str) – ‘strict’, ‘replace’ (default), ‘ignore’ - how to handle errors with encodings (see this section of the standard library’s codecs module for more information) (this is handled by lasio.reader.open_with_codecs())
  • autodetect_encoding (str or bool) – default True to use chardet to detect encoding. Note if set to False several common encodings will be tried but chardet won’t be used. (this is handled by lasio.reader.open_with_codecs())
  • autodetect_encoding_chars (int/None) – number of chars to read from LAS file for auto-detection of encoding. (this is handled by lasio.reader.open_with_codecs())
Returns:

a lasio.LASFile object representing the file

The documented arguments above are combined from these methods:

class lasio.LASFile(file_ref=None, **read_kwargs)[source]

LAS file object.

Keyword Arguments:
 
  • file_ref (file-like object or str) – either a filename, an open file object, or a string containing the contents of a file.
  • ignore_header_errors (bool) – ignore LASHeaderErrors (False by default)
  • ignore_comments (sequence/str) – ignore lines beginning with these characters e.g. ("#", '"') in header sections.
  • ignore_data_comments (str) – ignore lines beginning with this character in data sections only.
  • mnemonic_case (str) – ‘preserve’: keep the case of HeaderItem mnemonics ‘upper’: convert all HeaderItem mnemonics to uppercase ‘lower’: convert all HeaderItem mnemonics to lowercase
  • ignore_data (bool) – if True, do not read in any of the actual data, just the header metadata. False by default.
  • engine (str) – “normal”: parse data section with normal Python reader (quite slow); “numpy”: parse data section with numpy.genfromtxt (fast). By default the engine is “numpy”.
  • use_normal_engine_for_wrapped (bool) – if header metadata indicates that the file is wrapped, always use the ‘normal’ engine. Default is True. The only reason you should use False is if speed is a very high priority and you had files with metadata that incorrectly indicates they are wrapped.
  • read_policy (str or list) – Apply regular expression substitutions for common errors in fixed-width formatted data sections. If you do not want any such substitutions to applied, pass read_policy=().
  • null_policy (str or list) – see https://lasio.readthedocs.io/en/latest/data-section.html#handling-invalid-data-indicators-automatically
  • accept_regexp_sub_recommendations (bool) – Accept recommendations to auto- matically remove read substitutions (applied by the default read_policy) which look for numeric run-on errors involving hyphens. This avoids incorrect parsing of dates such as ‘2018-05-22’ as three separate columns containing ‘2018’, ‘-5’ and ‘-22’. The read substitutions are applied only if the inspection code of the data section finds a hyphen in every line. The only circumstance where this should be manually set to False is where you have very problematic fixed-column-width data sections involving negative values.
  • index_unit (str) – Optionally force-set the index curve’s unit to “m” or “ft”
  • dtypes ("auto", dict or list) – specify the data types for each curve in the ~ASCII data section. If “auto”, each curve will be converted to floats if possible and remain as str if not. If a dict you can specify only the curve mnemonics you want to convert as a key. If a list, please specify data types for each curve in order. Note that the conversion currently only occurs via numpy.ndarray.astype() and therefore only a few simple casts will work e.g. int, float, str.
  • encoding (str) – character encoding to open file_ref with, using io.open() (this is handled by lasio.reader.open_with_codecs())
  • encoding_errors (str) – ‘strict’, ‘replace’ (default), ‘ignore’ - how to handle errors with encodings (see this section of the standard library’s codecs module for more information) (this is handled by lasio.reader.open_with_codecs())
  • autodetect_encoding (str or bool) – default True to use chardet to detect encoding. Note if set to False several common encodings will be tried but chardet won’t be used. (this is handled by lasio.reader.open_with_codecs())
  • autodetect_encoding_chars (int/None) – number of chars to read from LAS file for auto-detection of encoding. (this is handled by lasio.reader.open_with_codecs())

The documented arguments above are combined from these methods:

encoding

the character encoding used when reading the file in from disk

Type:str or None
LASFile.read(file_ref, ignore_header_errors=False, ignore_comments=('#', ), ignore_data_comments='#', mnemonic_case='upper', ignore_data=False, engine='numpy', use_normal_engine_for_wrapped=True, read_policy='default', null_policy='strict', accept_regexp_sub_recommendations=True, index_unit=None, dtypes='auto', **kwargs)[source]

Read a LAS file.

Parameters:

file_ref (file-like object or str) – either a filename, an open file object, or a string containing the contents of a file.

Keyword Arguments:
 
  • ignore_header_errors (bool) – ignore LASHeaderErrors (False by default)
  • ignore_comments (sequence/str) – ignore lines beginning with these characters e.g. ("#", '"') in header sections.
  • ignore_data_comments (str) – ignore lines beginning with this character in data sections only.
  • mnemonic_case (str) – ‘preserve’: keep the case of HeaderItem mnemonics ‘upper’: convert all HeaderItem mnemonics to uppercase ‘lower’: convert all HeaderItem mnemonics to lowercase
  • ignore_data (bool) – if True, do not read in any of the actual data, just the header metadata. False by default.
  • engine (str) – “normal”: parse data section with normal Python reader (quite slow); “numpy”: parse data section with numpy.genfromtxt (fast). By default the engine is “numpy”.
  • use_normal_engine_for_wrapped (bool) – if header metadata indicates that the file is wrapped, always use the ‘normal’ engine. Default is True. The only reason you should use False is if speed is a very high priority and you had files with metadata that incorrectly indicates they are wrapped.
  • read_policy (str or list) – Apply regular expression substitutions for common errors in fixed-width formatted data sections. If you do not want any such substitutions to applied, pass read_policy=().
  • null_policy (str or list) – see https://lasio.readthedocs.io/en/latest/data-section.html#handling-invalid-data-indicators-automatically
  • accept_regexp_sub_recommendations (bool) – Accept recommendations to auto- matically remove read substitutions (applied by the default read_policy) which look for numeric run-on errors involving hyphens. This avoids incorrect parsing of dates such as ‘2018-05-22’ as three separate columns containing ‘2018’, ‘-5’ and ‘-22’. The read substitutions are applied only if the inspection code of the data section finds a hyphen in every line. The only circumstance where this should be manually set to False is where you have very problematic fixed-column-width data sections involving negative values.
  • index_unit (str) – Optionally force-set the index curve’s unit to “m” or “ft”
  • dtypes ("auto", dict or list) – specify the data types for each curve in the ~ASCII data section. If “auto”, each curve will be converted to floats if possible and remain as str if not. If a dict you can specify only the curve mnemonics you want to convert as a key. If a list, please specify data types for each curve in order. Note that the conversion currently only occurs via numpy.ndarray.astype() and therefore only a few simple casts will work e.g. int, float, str.
  • encoding (str) – character encoding to open file_ref with, using io.open() (this is handled by lasio.reader.open_with_codecs())
  • encoding_errors (str) – ‘strict’, ‘replace’ (default), ‘ignore’ - how to handle errors with encodings (see this section of the standard library’s codecs module for more information) (this is handled by lasio.reader.open_with_codecs())
  • autodetect_encoding (str or bool) – default True to use chardet to detect encoding. Note if set to False several common encodings will be tried but chardet won’t be used. (this is handled by lasio.reader.open_with_codecs())
  • autodetect_encoding_chars (int/None) – number of chars to read from LAS file for auto-detection of encoding. (this is handled by lasio.reader.open_with_codecs())
lasio.open_file(file_ref, **encoding_kwargs)[source]

Open a file if necessary.

If autodetect_encoding=True then chardet needs to be installed, or else an ImportError will be raised.

Parameters:file_ref (file-like object, str) – either a filename, an open file object, or a string containing the contents of a file.

See lasio.reader.open_with_codecs() for keyword arguments that can be used here.

Returns:tuple of an open file-like object, and the encoding that was used to decode it (if it were read from disk).
lasio.reader.open_with_codecs(filename, encoding=None, encoding_errors='replace', autodetect_encoding=True, autodetect_encoding_chars=4000)[source]

Read Unicode data from file.

Parameters:

filename (str) – path to file

Keyword Arguments:
 
  • encoding (str) – character encoding to open file_ref with, using io.open().
  • encoding_errors (str) – ‘strict’, ‘replace’ (default), ‘ignore’ - how to handle errors with encodings (see this section of the standard library’s codecs module for more information)
  • autodetect_encoding (str or bool) – default True to use chardet to detect encoding. Note if set to False several common encodings will be tried but chardet won’t be used.
  • autodetect_encoding_chars (int/None) – number of chars to read from LAS file for auto-detection of encoding.
Returns:

a unicode or string object

This function is called by lasio.reader.open_file().

lasio.reader.get_encoding(auto, raw)[source]

Automatically detect character encoding.

Parameters:
  • auto (str) – auto-detection of character encoding - can be one of ‘chardet’, False, or True (the latter will pick the fastest available option)
  • raw (bytes) – array of bytes to detect from
Returns:

A string specifying the character encoding.

LASFile.match_raw_section(pattern, re_func='match', flags=<RegexFlag.IGNORECASE: 2>)[source]

Find raw section with a regular expression.

Parameters:

pattern (str) – regular expression (you need to include the tilde)

Keyword Arguments:
 
  • re_func (str) – either “match” or “search”, see python re module.
  • flags (int) – flags for re.compile()
Returns:

dict

Intended for internal use only.

lasio.reader.read_data_section_iterative_normal_engine(file_obj, line_nos, regexp_subs, value_null_subs, ignore_data_comments, n_columns, dtypes, line_splitter)[source]

Read data section into memory.

Parameters:
  • file_obj – file-like object open for reading at the beginning of the section
  • line_nos (tuple) – the first and last line no of the section to read
  • regexp_subs (list) – each item should be a tuple of the pattern and substitution string for a call to re.sub() on each line of the data section. See defaults.py READ_SUBS and NULL_SUBS for examples.
  • value_null_subs (list) – list of numerical values to be replaced by numpy.nan values.
  • ignore_data_comments (str) – lines beginning with this character will be ignored
  • n_columns (int) – expected number of columns
  • dtypes (list, "auto", False) – list of expected data types for each column, (each data type can be specified as e.g. int, float, str, datetime). If you specify ‘auto’, then this function will attempt to convert each column to a float and if that fails, the column will be returned as a string. If you specify False, no conversion of data types will be attempt at all.
  • line_splitter (function) – This function is dynamically configured to split data lines on the configured delimiter

Returns: generator which yields the data as a 1D ndarray for each column at a time.

lasio.reader.read_data_section_iterative_numpy_engine(file_obj, line_nos)[source]

Read data section into memory.

Parameters:
  • file_obj – file-like object open for reading at the beginning of the section
  • line_nos (tuple) – the first and last line no of the section to read
Returns:

A numpy ndarray.

lasio.reader.get_substitutions(read_policy, null_policy)[source]

Parse read and null policy definitions into a list of regexp and value substitutions.

Parameters:
  • read_policy (str, list, or substitution) – either (1) a string defined in defaults.READ_POLICIES; (2) a list of substitutions as defined by the keys of defaults.READ_SUBS; or (3) a list of actual substitutions similar to the values of defaults.READ_SUBS. You can mix (2) and (3) together if you want.
  • null_policy (str, list, or sub) – as for read_policy but for defaults.NULL_POLICIES and defaults.NULL_SUBS
Returns:

regexp_subs, value_null_subs, version_NULL - two lists and a bool. The first list is pairs of regexp patterns and substrs, and the second list is just a list of floats or integers. The bool is whether or not ‘NULL’ was located as a substitution.

The default READ_POLICIES are

  • comma-decimal-mark : in numbers replace a comma divider with a decimal
  • run-on(-) : separate 2 numbers that run together on the negative sign
  • run-on(.) : replace numbers with 2 or more decimals or a NaN and a decimal with 2 NaNs
class lasio.reader.SectionParser(title, version=1.2)[source]

Parse lines from header sections.

Parameters:title (str) – title line of section. Used to understand different order formatting across the special sections ~C, ~P, ~W, and ~V, depending on version 1.2 or 2.0.
Keyword Arguments:
 version (float) – version to parse according to. Default is 1.2.
lasio.reader.read_header_line(line, pattern=None, section_name=None)[source]

Read a line from a LAS header section.

The line is parsed with a regular expression – see LAS file specs for more details, but it should basically be in the format:

name.unit       value : descr
Parameters:
  • line (str) – line from a LAS header section
  • section_name (str) – Name of the section the ‘line’ is from. The default
  • is None. (value) –
Returns:

A dictionary with keys ‘name’, ‘unit’, ‘value’, and ‘descr’, each containing a string as value.

class lasio.HeaderItem(mnemonic='', unit='', value='', descr='', data=None)[source]

Dictionary/namedtuple-style object for a LAS header line.

Parameters:
  • mnemonic (str) – the mnemonic
  • unit (str) – the unit (no whitespace!)
  • value (str) – value
  • descr (str) – description

These arguments are available for use as either items or attributes of the object.

HeaderItem.set_session_mnemonic_only(value)[source]

Set the mnemonic for session use.

See source comments for lasio.HeaderItem.__init__ for a more in-depth explanation.

class lasio.CurveItem(mnemonic='', unit='', value='', descr='', data=None)[source]

Dictionary/namedtuple-style object for a LAS curve.

See lasio.HeaderItem` for the (keyword) arguments.

Keyword Arguments:
 data (array-like, 1-D) – the curve’s data.
class lasio.SectionItems(*args, **kwargs)[source]

Variant of a list which is used to represent a LAS section.

Reading data

LASFile.__getitem__(key)[source]

Provide access to curve data.

Parameters:key (str, int) – either a curve mnemonic or the column index.
Returns:1D numpy.ndarray (the data for the curve)
LASFile.__setitem__(key, value)[source]

Append a curve.

Parameters:
  • key (str) – the curve mnemonic
  • value (1D data or CurveItem) – either the curve data, or a CurveItem

See lasio.LASFile.append_curve_item() or lasio.LASFile.append_curve() for more details.

LASFile.get_curve(mnemonic)[source]

Return CurveItem object.

Parameters:mnemonic (str) – the name of the curve
Returns:lasio.CurveItem (not just the data array)
LASFile.keys()[source]

Return curve mnemonics.

LASFile.values()[source]

Return data for each curve.

LASFile.items()[source]

Return mnemonics and data for all curves.

LASFile.df()[source]

Return data as a pandas.DataFrame structure.

The first Curve of the LASFile object is used as the pandas DataFrame’s index.

LASFile.version

Header information from the Version (~V) section.

Returns:lasio.SectionItems object.
LASFile.well

Header information from the Well (~W) section.

Returns:lasio.SectionItems object.
LASFile.curves

Curve information and data from the Curves (~C) and data section..

Returns:lasio.SectionItems object.
LASFile.curvesdict

Curve information and data from the Curves (~C) and data section..

Returns:dict
LASFile.params

Header information from the Parameter (~P) section.

Returns:lasio.SectionItems object.
LASFile.other

Header information from the Other (~O) section.

Returns:str
LASFile.index

Return data from the first column of the LAS file data (depth/time).

LASFile.depth_m

Return the index as metres.

LASFile.depth_ft

Return the index as feet.

LASFile.data
LASFile.stack_curves(mnemonic, sort_curves=True)[source]

Stack multi-channel curve data to a numpy 2D ndarray.

Provide a stub name (prefix shared by all curves that will be stacked) or a list of curve mnemonic strings.

Keyword Arguments:
 
  • mnemonic (str or list) – Supply the first several characters of the channel set to be stacked. Alternatively, supply a list of the curve names (mnemonics strings) to be stacked.
  • sort_curves (bool) – Natural sort curves based on mnemonic prior to stacking.
Returns:

2-D numpy array

Reading and modifying header data

class lasio.SectionItems(*args, **kwargs)[source]

Variant of a list which is used to represent a LAS section.

keys()[source]

Return mnemonics of all the HeaderItems in the section.

values()[source]

Return HeaderItems in the section.

items()[source]

Return pairs of (mnemonic, HeaderItem) from the section.

get(mnemonic, default='', add=False)[source]

Get an item, with a default value for the situation when it is missing.

Parameters:
  • mnemonic (str) – mnemonic of item to retrieve
  • default (str, HeaderItem, or CurveItem) – default to provide if mnemonic is missing from the section. If a string is provided, it will be used as the value attribute of a new HeaderItem or the descr attribute of a new CurveItem.
  • add (bool) – if True, the returned HeaderItem/CurveItem will also be appended to the SectionItems. By default this is not done.
Returns:

item from the section, if it is in there, or a new item, if it is not. If a CurveItem is returned, the data attribute will contain numpy.nan values.

Return type:

lasio.HeaderItem/lasio.CurveItem

set_item(key, newitem)[source]

Replace an item by comparison of session mnemonics.

Parameters:
  • key (str) – the item mnemonic (or HeaderItem with mnemonic) you want to replace.
  • newitem (HeaderItem) – the new item

If key is not present, it appends newitem.

set_item_value(key, value)[source]

Set the value attribute of an item.

Parameters:
  • key (str) – the mnemonic of the item (or HeaderItem with the mnemonic) you want to edit
  • value (str, int, float) – the new value.
append(newitem)[source]

Append a new HeaderItem to the object.

insert(i, newitem)[source]

Insert a new HeaderItem to the object.

assign_duplicate_suffixes(test_mnemonic=None)[source]

Check and re-assign suffixes for duplicate mnemonics.

Parameters:test_mnemonic (str, optional) – check for duplicates of this mnemonic. If it is None, check all mnemonics.
dictview()[source]

View of mnemonics and values as a dict.

Returns:dict - keys are the mnemonics and the values are the value attributes.

Modifying data

LASFile.set_data(array_like, names=None, truncate=False)[source]

Set the data for the LAS; actually sets data on individual curves.

Parameters:

array_like (array_like or pandas.DataFrame) – 2-D data array

Keyword Arguments:
 
  • names (list, optional) – used to replace the names of the existing lasio.CurveItem objects.
  • truncate (bool) – remove any columns which are not included in the Curves (~C) section.

Note: you can pass a pandas.DataFrame to this method. If you do this, the index of the DataFrame will be used as the first curve in the LAS file (i.e. it will not be discarded).

LASFile.set_data_from_df(df, **kwargs)[source]

Set the LAS file data from a pandas.DataFrame.

Parameters:df (pandas.DataFrame) – curve mnemonics are the column names. The depth column for the curves must be the index of the DataFrame.

Keyword arguments are passed to lasio.LASFile.set_data().

LASFile.append_curve(mnemonic, data, unit='', descr='', value='')[source]

Add a curve.

Parameters:
  • mnemonic (str) – the curve mnemonic
  • data (1D ndarray) – the curve data
Keyword Arguments:
 
  • unit (str) – curve unit
  • descr (str) – curve description
  • value (int/float/str) – value e.g. API code.
LASFile.insert_curve(ix, mnemonic, data, unit='', descr='', value='')[source]

Insert a curve.

Parameters:
  • ix (int) – position to insert curve at i.e. 0 for start.
  • mnemonic (str) – the curve mnemonic
  • data (1D ndarray) – the curve data
Keyword Arguments:
 
  • unit (str) – curve unit
  • descr (str) – curve description
  • value (int/float/str) – value e.g. API code.
LASFile.delete_curve(mnemonic=None, ix=None)[source]

Delete a curve.

Keyword Arguments:
 
  • ix (int) – index of curve in LASFile.curves.
  • mnemonic (str) – mnemonic of curve.

The index takes precedence over the mnemonic.

LASFile.append_curve_item(curve_item)[source]

Add a CurveItem.

Parameters:curve_item (lasio.CurveItem) –
LASFile.insert_curve_item(ix, curve_item)[source]

Insert a CurveItem.

Parameters:
  • ix (int) – position to insert CurveItem i.e. 0 for start
  • curve_item (lasio.CurveItem) –
LASFile.update_start_stop_step(STRT=None, STOP=None, STEP=None, fmt='%.5f')[source]

Configure or change STRT, STOP, and STEP values on the LASFile object.

Keyword Arguments:
 
  • STOP, STEP (STRT,) – value to set on the relevant header item in the ~Well section - can be any data type.
  • fmt (str) – Python format string for formatting the STRT/STOP/STEP value in the situation where any of those keyword arguments are None

If STRT/STOP/STEP are not passed to this method, they will be automatically calculated from the index curve.

LASFile.update_units_from_index_curve()[source]

Align STRT/STOP/STEP header item units with the index curve’s units.

Writing data out

LASFile.write(file_ref, **kwargs)[source]

Write LAS file to disk.

Parameters:file_ref (open file-like object or str) – either a file-like object open for writing, or a filename.

All **kwargs are passed to lasio.writer.write() – please check the docstring of that function for more keyword arguments you can use here!

Examples

>>> import lasio
>>> las = lasio.read("tests/examples/sample.las")
>>> with open('test_output.las', mode='w') as f:
...     las.write(f, version=2.0)   # <-- this method
lasio.writer.write(las, file_object, version=None, wrap=None, STRT=None, STOP=None, STEP=None, fmt='%.5f', column_fmt=None, len_numeric_field=None, lhs_spacer=' ', spacer=' ', data_width=79, header_width=60, data_section_header='~ASCII', mnemonics_header=False)[source]

Write a LAS files.

Parameters:
  • las (lasio.LASFile) –
  • file_object (file-like object open for writing) – output
  • version (float or None) – version of written file, either 1.2 or 2. If this is None, las.version.VERS.value will be used.
  • wrap (bool or None) – whether to wrap the output data section. If this is None, las.version.WRAP.value will be used.
  • STRT (float or None) – value to use as STRT (note the data will not be clipped). If this is None, the data value in the first column, first row will be used.
  • STOP (float or None) – value to use as STOP (note the data will not be clipped). If this is None, the data value in the first column, last row will be used.
  • STEP (float or None) – value to use as STEP (note the data will not be resampled and/or interpolated). If this is None, the STEP will be estimated from the first two rows of the first column.
  • fmt (str) – Python string formatting operator for numeric data to be used.
  • column_fmt (dict or None) – use this to set a different format string for specific columns from the data ndarray. E.g. to use '%.3f' for the depth column and '%.2f' for all the other columns, you would use fmt='%.2f', column_fmt={0: '%.3f'}.
  • len_numeric_field (int) – width of each numeric field column (must be greater than than all the formatted numeric values in the file). If it is None, the maximum necessary value will be used automatically (i.e. all columns will have the same width). If it is -1, then the columns will not have consistent widths. You can combine -1 with the fmt keyword argument to control column widths closely.
  • data_width (79) – width of data field in characters
  • lhs_spacer (str) – string which goes on left hand side of data section - by default it is ” “.
  • spacer (str) – string which goes between each column of the data section
  • data_section_header (str) – default “~ASCII”
  • mnemonics_header (bool) – include mnemonic curve names in the data_section_header at the top of data section

Creating an output file is not the only side-effect of this function. It will also modify the STRT, STOP and STEP HeaderItems so that they correctly reflect the ~Data section’s units and the actual first, last, and interval values.

However, passing a version to this write() function only changes the version of the object written to. Example: las.write(myfile, version=2). Lasio’s internal-las-object version will remain separate and defined by las.version.VERS.value

You should avoid calling this function directly - instead use the lasio.LASFile.write() method.

lasio.writer.get_formatter_function(order, left_width=None, middle_width=None)[source]

Create function to format a LAS header item for output.

Parameters:

order – format of item, either ‘descr:value’ or ‘value:descr’

Keyword Arguments:
 
  • left_width (int) – number of characters to the left hand side of the first period
  • middle_width (int) – total number of characters minus 1 between the first period from the left and the first colon from the left.
Returns:

A function which takes a header item (e.g. lasio.HeaderItem) as its single argument and which in turn returns a string which is the correctly formatted LAS header line.

lasio.writer.get_section_order_function(section, version, order_definitions={1.2: {'Curves': ['value:descr'], 'Parameter': ['value:descr'], 'Version': ['value:descr'], 'Well': ['descr:value', ('value:descr', ['STRT', 'STOP', 'STEP', 'NULL', 'strt', 'stop', 'step', 'null'])]}, 2.0: {'Curves': ['value:descr'], 'Parameter': ['value:descr'], 'Version': ['value:descr'], 'Well': ['value:descr']}, 2.1: {'Curves': ['value:descr'], 'Parameter': ['value:descr'], 'Version': ['value:descr'], 'Well': ['value:descr']}, 3.0: {'Curves': ['value:descr'], 'Parameter': ['value:descr'], 'Version': ['value:descr'], 'Well': ['value:descr']}})[source]

Get a function that returns the order per the mnemonic and section.

Parameters:
  • section (str) – either ‘well’, ‘params’, ‘curves’, ‘version’
  • version (float) – either 1.2 and 2.0
Keyword Arguments:
 

order_definitions (dict) – see source of defaults.py for more information

Returns:

A function which takes a mnemonic (str) as its only argument, and in turn returns the order ‘value:descr’ or ‘descr:value’.

lasio.writer.get_section_widths(section_name, items, version, order_func)[source]

Find minimum section widths fitting the content in items.

Parameters:
LASFile.to_csv(file_ref, mnemonics=True, units=True, units_loc='line', **kwargs)[source]

Export to a CSV file.

Parameters:

file_ref (open file-like object or str) – either a file-like object open for writing, or a filename.

Keyword Arguments:
 
  • mnemonics (list, True, False) – write mnemonics as a header line at the start. If list, use the supplied items as mnemonics. If True, use the curve mnemonics.
  • units (list, True, False) – as for mnemonics.
  • units_loc (str or None) – either ‘line’, ‘[]’ or ‘()’. ‘line’ will put units on the line following the mnemonics (good for WellCAD). ‘[]’ and ‘()’ will put the units in either brackets or parentheses following the mnemonics, on the single header line (better for Excel)
  • **kwargs – passed to csv.writer. Note that if lineterminator is not specified here, then it will be sent to csv.writer as lineterminator='\\n'.
LASFile.to_excel(filename)[source]

Export LAS file to a Microsoft Excel workbook.

Parameters:filename (str) – a name for the file to be created and written to.
LASFile.to_json()[source]
lasio.convert_version.convert_version()[source]
lasio.convert_version.get_convert_version_parser()[source]

Defaults

Custom exceptions

class lasio.exceptions.LASDataError[source]

Error during reading of numerical data from LAS file.

class lasio.exceptions.LASHeaderError[source]

Error during reading of header data from LAS file.

class lasio.exceptions.LASUnknownUnitError[source]

Error of unknown unit in LAS file.

Test data

lasio.examples.open(filename, **kwargs)[source]

Open an example LAS file from lasio’s test suite.

Parameters:filename (str) – forward-slash separated filename of a LAS file from lasio’s test suite, starting from the “tests/examples” subfolder e.g. “1001178549.las” or “2.0/sample_2.0.las”

Other keyword arguments are passed to lasio.LASFile. If lasio has been installed locally from source, then the local version of the example file will be opened. If lasio has not been installed from source then the LAS file will be downloaded from GitHub.

Returns: LASFile object

lasio.examples.open_github_example(filename, url_prefix='https://raw.githubusercontent.com/kinverarity1/lasio/master/tests/examples/', **kwargs)[source]

Open an example LAS file from lasio’s test suite on GitHub

Parameters:filename (str) – forward-slash separated filename of a LAS file from lasio’s test suite, starting from the “tests/examples” subfolder e.g. “1001178549.las” or “2.0/sample_2.0.las”

Other keyword arguments are passed to lasio.LASFile.

Returns: LASFile object

lasio.examples.open_local_example(filename, **kwargs)[source]

Open an example LAS file from lasio’s test suite.

Parameters:filename (str) – forward-slash separated filename of a LAS file from lasio’s test suite, starting from the “tests/examples” subfolder e.g. “1001178549.las” or “2.0/sample_2.0.las”

Other keyword arguments are passed to lasio.LASFile. If lasio has not been installed from source then an exception will be raised.

Returns: LASFile object

lasio.examples.get_local_examples_path()[source]

Return the path to the examples from lasio’s test suite, if it is installed locally.

Returns: path as str.

Logging

lasio.add_logging_level(levelName, levelNum, methodName=None)[source]

Add a new logging level to current logger.

Comprehensively adds a new logging level to the logging module and the currently configured logging class.

levelName becomes an attribute of the logging module with the value levelNum. methodName becomes a convenience method for both logging itself and the class returned by logging.getLoggerClass() (usually just logging.Logger). If methodName is not specified, levelName.lower() is used.

To avoid accidental clobberings of existing attributes, this method will raise an AttributeError if the level name is already an attribute of the logging module or if the method name is already present

Example

>>> add_logging_level('TRACE', logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("TRACE")
>>> logging.getLogger(__name__).trace('that worked')
>>> logging.trace('so did this')
>>> logging.TRACE
5