Reputation: 11
I hope you are all well.
I want to handle .las
files in python. These are specific ascii
files for geophysical profiling. They have a header and then a series of columns containing various information.
What is the best way to start?
The main objective would be to add new columns that would be mathematical operations of the other columns. And operations between values in the same column.
Below we have an example of a .las
file.
~Version Information
VERS. 2.00 : CWLS Log ASCII Standard - Version 2.00
WRAP. NO : One line per depth step
#
~Well Information
#MNEM.UNIT DATA : DESCRIPTION
#----.---- --------- : -----------------
STRT .M 25.000 : Start
STOP .M 251.000 : Stop
STEP .M 0.010 : Step increment
NULL . -999.250 : Null value
COMP . VALE DO RIO DOCE : Company
WELL . GAL-FD00033 : Well
FLD . PICO : Field
PROV . QUADRILATERO FERRIFERO : Province / County
CTRY . MINAS GERAIS : State / Country
LOC . BRASIL : Location
LOC2 . : Location 2
SRVC . Weatherford : Service company
UWI . : Unique Well ID
LATI . 7763458M : Latitude
LONG . 619198M : Longitude
DATE . 18-Sep-2014 : Logging date
#
~Curve Information
#MNEM.UNIT API CODES : CURVE DESCRIPTION
#----.---- --------- : -----------------
DEPT .M 00 001 00 00 : Logged depth
CADE .MM 45 280 01 00 : Caliper from DD6
BIT .MM 70 282 00 00 : Bit size
GRC1 .GAPI 45 310 1 00 : Gamma Ray from GC1-GC2
DD3L .CPS 00 000 00 00 : Long Spaced Density Raw
DD3B .CPS 00 000 00 00 : Short Spaced Density Raw
DENL .G/C3 45 350 02 00 : Density Long Spaced
DENB .G/C3 45 350 02 00 : Density Short Spaced
GRDE .API 45 310 01 00 : Gamma Ray from DD6
CCO1 .MM 42 280 1 00 : 3-Arm Caliper CO1-GC2
CO1C .CPS 0 0 0 00 : Caliper Raw
DD3G .CPS 00 000 00 00 : Gamma Ray Raw
GC1G .CPS 0 0 0 00 : Gamma Ray Raw
DD3C .CPS 00 000 00 00 : Caliper Raw
GTMP .DEGC 80 660 2 00 : Borehole Temperature
GRDO .API 45 310 01 00 : Gamma Ray from Density O
DNBO .G/C3 45 350 02 00 : Density Short Spaced OPE
DNLO .G/C3 45 350 02 00 : Density Long Spaced OPEN
CCLF .CPS 0 0 0 00 : Casing Collar Locator
#
~Parameter Information
#MNEM.UNIT VALUE : DESCRIPTION
#----.---- --------- : -----------------
RNID . MAIN LOG : Run ID
EREF .M 1512.610 : Elevation of depth reference
DREF . K.B. : Depth reference
GL .M 1511.000 : Ground elevation
RUN . 2 : Run number
TDD .M 255.000 : TD (driller)
TDL .M 226.000 : TD (logger)
CSGD .M 252.600 : Casing bottom (driller)
CSGL .M 251.000 : Casing bottom (logger)
BS .MM 77.80 : Bit size
MUD . WATER BASED : Mud type
MUDD .K/M3 : Mud density
MUDV .CP : Mud viscosity
PH . : Mud pH
FL .ML/30MIN : Mud fluid loss rate
MUDS . N/A : Mud sample source
TMAX .DEGC 20.12 : Max recorder temperature
TIMC .DAY/HR : Time circulation ended
TIML .DAY/HR : Time logger at bottom
UNIT . 11613 : Equipment ID
BASE . : Equipment base location
ENG . SIONEY/DEIVISON/HELBERT : Recording engineer
WIT . GEOSERVICE : Witnessed by
CSUP .FEET -999999.000 : Casing Stick Up GL
CSGS .MM 60.100 : Casing size
CSGW .KG/M 0.00 : Casing weight
CSGT . NQ : Casing Type
#
~Other Information
--------------------------------------------------------------------------------
TOOLS LOGGED IN CASED HOLE
HQ - 25.00M TO 147.00
NQ - 147.00 TO 251.00
GC2 TD @ 226.00M
DD6 TD @ 226.00M
ON SITE: 10:00
START: 10:15
FINISH:11:50
WATER LEVEL - 66.50M
LOGGING JOB REQUESTED BY WANDERSON PEREIRA / DIONISIO CARLOS
--------------------------------------------------------------------------------
~A DEPT CADE BIT GRC1 DD3L DD3B DENL DENB GRDE CCO1 CO1C DD3G GC1G DD3C GTMP GRDO DNBO DNLO CCLF
25.000 78.687 77.800 26.421 19.000 439.000 3.351 4.358 51.334 79.631 1461.000 22.000 13.000 2013.000 19.108 61.720 3.602 2.940 0.136
25.010 78.696 77.800 28.308 26.000 416.000 3.341 4.360 48.032 79.485 1451.000 23.000 13.000 2007.000 19.111 60.250 3.609 2.937 -0.009
25.020 78.682 77.800 28.151 26.000 420.000 3.337 4.368 40.077 79.654 1465.000 31.000 0.000 2011.000 19.098 58.926 3.618 2.933 -0.055
25.030 78.687 77.800 28.151 13.000 425.000 3.336 4.381 38.876 79.639 1455.000 30.000 13.000 2011.000 19.096 56.894 3.625 2.932 0.355
25.040 78.689 77.800 32.240 26.000 403.000 3.333 4.387 37.825 79.747 1467.000 23.000 26.000 2013.000 19.089 54.335 3.634 2.933 -0.136
25.050 78.684 77.800 34.284 25.000 412.000 3.338 4.401 34.523 79.774 1455.000 24.000 38.000 2006.000 19.104 51.650 3.643 2.936 -0.336
25.060 78.670 77.800 32.240 25.000 428.000 3.347 4.406 32.422 79.803 1461.000 23.000 38.000 2013.000 19.096 48.656 3.652 2.939 0.291
25.070 78.675 77.800 32.240 19.000 406.000 3.360 4.414 32.422 79.462 1458.000 0.000 25.000 2009.000 19.094 46.587 3.659 2.943 -0.100
25.080 78.618 77.800 34.284 13.000 377.000 3.373 4.423 27.769 79.401 1458.000 15.000 0.000 2008.000 19.098 45.753 3.665 2.950 0.145
25.090 78.642 77.800 34.284 33.000 392.000 3.384 4.430 26.718 79.341 1461.000 23.000 26.000 2009.000 19.109 45.063 3.670 2.958 0.518
25.100 78.648 77.800 32.240 13.000 388.000 3.405 4.421 26.718 79.285 1461.000 16.000 26.000 2011.000 19.118 44.356 3.676 2.966 0.018
25.110 78.602 77.800 26.264 19.000 424.000 3.425 4.429 26.568 79.421 1449.000 8.000 0.000 2011.000 19.096 44.446 3.679 2.973 0.482
25.120 78.603 77.800 24.377 13.000 390.000 3.444 4.435 30.921 79.738 1464.000 23.000 13.000 2009.000 19.098 45.335 3.680 2.983 0.000
25.130 78.678 77.800 28.466 19.000 396.000 3.460 4.443 33.172 79.551 1455.000 0.000 13.000 2011.000 19.111 46.769 3.681 2.991 -0.018
25.140 78.647 77.800 32.397 19.000 401.000 3.474 4.433 33.172 79.634 1468.000 23.000 13.000 2011.000 19.101 48.910 3.685 2.998 0.018
25.150 78.651 77.800 34.284 13.000 431.000 3.491 4.433 31.971 79.573 1452.000 23.000 13.000 2009.000 19.103 51.178 3.689 3.005 0.018
25.160 78.721 77.800 36.329 19.000 389.000 3.500 4.432 35.274 79.430 1462.000 23.000 0.000 2008.000 19.104 53.301 3.692 3.010 -0.509
25.170 78.693 77.800 38.373 19.000 409.000 3.507 4.450 39.777 79.266 1468.000 52.000 26.000 2013.000 19.108 55.587 3.696 3.017 -0.082
25.180 78.660 77.800 36.329 19.000 385.000 3.513 4.454 44.280 79.529 1451.000 15.000 51.000 2009.000 19.103 56.676 3.704 3.022 -0.482
25.190 78.653 77.800 36.329 13.000 405.000 3.520 4.459 45.480 79.572 1465.000 15.000 25.000 2011.000 19.119 57.637 3.711 3.025 -0.491
25.200 78.648 77.800 34.284 19.000 392.000 3.525 4.468 45.480 79.688 1452.000 15.000 38.000 2006.000 19.109 58.744 3.719 3.027 -0.400
25.210 78.619 77.800 32.240 13.000 389.000 3.522 4.486 44.280 79.696 1465.000 38.000 39.000 2011.000 19.088 59.851 3.722 3.031 -0.600
25.220 78.637 77.800 36.329 20.000 373.000 3.520 4.481 45.480 79.658 1459.000 38.000 13.000 2013.000 19.111 60.414 3.724 3.033 -0.345
25.230 78.646 77.800 36.329 13.000 379.000 3.521 4.484 39.927 79.580 1462.000 53.000 0.000 2009.000 19.101 60.160 3.723 3.034 -0.073
25.240 78.688 77.800 32.397 19.000 383.000 3.518 4.470 41.127 79.621 1456.000 8.000 13.000 2006.000 19.094 58.672 3.720 3.034 0.400
25.250 78.669 77.800 34.599 19.000 375.000 3.518 4.467 42.328 79.658 1458.000 23.000 0.000 2013.000 19.114 57.166 3.713 3.035 0.445
25.260 78.680 77.800 36.801 19.000 380.000 3.514 4.454 41.127 79.562 1458.000 15.000 0.000 2007.000 19.108 55.932 3.705 3.035 1.091
25.270 78.694 77.800 32.712 13.000 403.000 3.517 4.450 39.927 79.573 1462.000 31.000 26.000 2009.000 19.094 54.716 3.693 3.034 0.118
25.280 78.662 77.800 32.712 19.000 400.000 3.516 4.439 37.675 79.408 1456.000 15.000 26.000 2017.000 19.098 53.065 3.681 3.034 0.464
25.290 78.619 77.800 34.756 13.000 427.000 3.512 4.425 31.971 79.314 1459.000 23.000 26.000 2009.000 19.118 52.357 3.667 3.035 0.209
25.300 78.637 77.800 36.801 19.000 414.000 3.509 4.409 33.022 79.256 1459.000 23.000 39.000 2009.000 19.106 51.922 3.655 3.035 -0.109
25.310 78.645 77.800 38.845 19.000 428.000 3.509 4.389 35.274 79.499 1461.000 7.000 52.000 2009.000 19.088 51.613 3.642 3.035 -0.745
25.320 78.636 77.800 42.934 13.000 401.000 3.510 4.374 34.223 79.515 1452.000 30.000 13.000 2013.000 19.114
Upvotes: 1
Views: 1280
Reputation: 576
Try Kinverity's Lasio tool at https://github.com/kinverarity1/lasio. The current version as of June 2022 is v0.30. It is stable and in practical use.
Lasio has the capability to write a new las file from modified data. I am pretty sure you can add new columns as described in the question.
Use Python3 if possible because Python2 support ended August 2020.
See the full documentation at: https://lasio.readthedocs.io/en/latest/
Install instructions:
For the minimum working requirements, you'll need numpy installed. Install lasio with:
$ pip install lasio
To make sure you have everything, use this to ensure pandas, cchardet, and openpyxl are also installed:
$ pip install lasio[all]
Example session:
>>> import lasio
You can read the file using a filename, file-like object, or URL:
>>> las = lasio.read("sample_rev.las")
>>> las.keys()
['DEPT', 'DT', 'RHOB', 'NPHI', 'SFLU', 'SFLA', 'ILM', 'ILD']
>>> las['SFLU']
array([ 123.45, 123.45, 123.45, ..., 123.45, 123.45, 123.45])
>>> las['DEPT']
array([ 1670. , 1669.875, 1669.75 , ..., 1669.75 , 1670. ,
1669.875])
From there you can perform a various operations on the Log Ascii Standard data via the las
object.
Upvotes: 1
Reputation: 11
the best way is to import your las file using lasio and then utilize pandas and numpy to handle your data and do your calculations
import pandas as pd
import numpy as np
import lasio
#read the file
las = lasio.read("file.las")
once your file is read , you can utilize pandas by converting the las to pandas data framework
df=las.df()
to add a column or a calaulated cuve you can use the guide code below : let's say you want to create curve (NEW) which is equal to DD3L + DD3B of your dataset.
df_copy=df.copy() # Just create a copy of your data
df_copy['NEW'] = (df_copy.DD3L()) + (df_copy.DD3B())
Upvotes: 1