{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "`lasio` uses the [`logging` module](https://docs.python.org/3.6/howto/logging.html) to log warnings and other information when manipulating LAS files." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import logging\n", "import lasio" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sometimes you may want more or less information shown to you when you are reading LAS files with `lasio`. \n", "\n", "By default the logging level is set to `WARNING`, so you will only see a certain class of messages:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Header section Parameter regexp=~P was not found.\n" ] } ], "source": [ "l = lasio.read('../tests/examples/logging_levels.las')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see, the logger shows a warning that the Parmeter section was not found in the LAS file.\n", "\n", "To get more information when loading a file, you can set the logging level to `INFO`. First, instantiate the root logger with a basic configuration:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "logging.basicConfig()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then get the `lasio` logger object and set the logging level to `INFO`:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:lasio.reader:Opening ../tests/examples/logging_levels.las as ascii and treating errors with \"replace\"\n", "WARNING:lasio.las:Header section Parameter regexp=~P was not found.\n" ] } ], "source": [ "logger = logging.getLogger(lasio.__name__)\n", "logger.setLevel(logging.INFO)\n", "\n", "l = lasio.read('../tests/examples/logging_levels.las')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To get even _more_ information, you can set the logging level to `DEBUG`:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "DEBUG:lasio.reader:get_encoding Using chardet\n", "DEBUG:lasio.reader:chardet method detected encoding of ascii at confidence 1.0\n", "INFO:lasio.reader:Opening ../tests/examples/logging_levels.las as ascii and treating errors with \"replace\"\n", "DEBUG:lasio.reader:using read policy of \"default\"\n", "DEBUG:lasio.reader:adding substitution comma-decimal-mark\n", "DEBUG:lasio.reader:adding substitution run-on(-)\n", "DEBUG:lasio.reader:adding substitution run-on(.)\n", "DEBUG:lasio.reader:adding substitution run-on(NaN.)\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('(\\\\d),(\\\\d)') substr=\"\\1.\\2\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('(\\\\d)-(\\\\d)') substr=\"\\1 -\\2\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('-?\\\\d*\\\\.\\\\d*\\\\.\\\\d*') substr=\" NaN NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('NaN[\\\\.-]\\\\d+') substr=\" NaN NaN \"\n", "DEBUG:lasio.reader:using null policy of \"common\"\n", "DEBUG:lasio.reader:adding substitution NULL\n", "DEBUG:lasio.reader:located substition for LAS.version.NULL as True\n", "DEBUG:lasio.reader:adding substitution (null)\n", "DEBUG:lasio.reader:adding substitution -\n", "DEBUG:lasio.reader:adding substitution 9999.25\n", "DEBUG:lasio.reader:adding substitution 999.25\n", "DEBUG:lasio.reader:adding substitution NA\n", "DEBUG:lasio.reader:adding substitution INF\n", "DEBUG:lasio.reader:adding substitution IO\n", "DEBUG:lasio.reader:adding substitution IND\n", "DEBUG:lasio.reader:added numerical substitution: None\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile(' \\\\(null\\\\)') substr=\" NaN\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('\\\\(null\\\\) ') substr=\"NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile(' \\\\(NULL\\\\)') substr=\" NaN\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('\\\\(NULL\\\\) ') substr=\"NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile(' null') substr=\" NaN\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('null ') substr=\"NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile(' NULL') substr=\" NaN\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('NULL ') substr=\"NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile(' -+ ') substr=\" NaN \"\n", "DEBUG:lasio.reader:added numerical substitution: -9999.25\n", "DEBUG:lasio.reader:added numerical substitution: 9999.25\n", "DEBUG:lasio.reader:added numerical substitution: -999.25\n", "DEBUG:lasio.reader:added numerical substitution: 999.25\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('(#N/A)[ ]') substr=\"NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('[ ](#N/A)') substr=\" NaN\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('(-?1\\\\.#INF)[ ]') substr=\"NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('[ ](-?1\\\\.#INF[0-9]*)') substr=\" NaN\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('(-?1\\\\.#IO)[ ]') substr=\"NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('[ ](-?1\\\\.#IO)') substr=\" NaN\"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('(-?1\\\\.#IND)[ ]') substr=\"NaN \"\n", "DEBUG:lasio.reader:added regexp substitution: pattern=re.compile('[ ](-?1\\\\.#IND[0-9]*)') substr=\" NaN\"\n", "DEBUG:lasio.reader:Data section [\"array\"].shape = (523710,)\n", "WARNING:lasio.las:Header section Parameter regexp=~P was not found.\n", "DEBUG:lasio.las:~A data.shape (523710,)\n", "DEBUG:lasio.las:~A after NULL replacement data.shape (523710,)\n", "DEBUG:lasio.las:n_curves=18 ncols=18\n", "DEBUG:lasio.las:set_data data.shape = (29095, 18)\n", "DEBUG:lasio.las:set_data self.data.shape = (29095, 18)\n" ] } ], "source": [ "logger.setLevel(logging.DEBUG)\n", "\n", "l = lasio.read('../tests/examples/logging_levels.las')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One strategy for suppressing logging messages is to set the logger level to a very high level, such that only messages with a `CRITICAL` designation are shown:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "logger.setLevel(logging.CRITICAL)\n", "\n", "l = lasio.read('../tests/examples/logging_levels.las')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In that case, no messages were logged since no CRITICAL level issues were encountered.\n", "\n", "Just to prove that the LAS file loaded, even though no messages were shown, here's a header item:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "HeaderItem(mnemonic=SRVC, unit=, value=Baker Hughes Inc., descr=Service, original_mnemonic=SRVC)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.header['Well'].SRVC" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda root]", "language": "python", "name": "conda-root-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.3" } }, "nbformat": 4, "nbformat_minor": 2 }