Writing LAS files

Any LASFile object can be written to a new LAS file using the lasio.LASFile.write() method.

Converting between v1.2 and v2.0

Take this sample LAS 2.0 file:

 1~VERSION INFORMATION
 2 VERS.                          2.0 :   CWLS LOG ASCII STANDARD -VERSION 2.0
 3 WRAP.                          NO  :   ONE LINE PER DEPTH STEP
 4~WELL INFORMATION
 5#MNEM.UNIT              DATA                       DESCRIPTION
 6#----- -----            ----------               -------------------------
 7STRT    .M              1670.0000                :START DEPTH
 8STOP    .M              1660.0000                :STOP DEPTH
 9STEP    .M              -0.1250                  :STEP
10NULL    .               -999.25                  :NULL VALUE
11COMP    .       ANY OIL COMPANY INC.             :COMPANY
12WELL    .       AAAAA_2            :WELL
13FLD     .       WILDCAT                          :FIELD
14LOC     .       12-34-12-34W5M                   :LOCATION
15PROV    .       ALBERTA                          :PROVINCE
16SRVC    .       ANY LOGGING COMPANY INC.         :SERVICE COMPANY
17DATE    .       13-DEC-86                        :LOG DATE
18UWI     .       100123401234W500                 :UNIQUE WELL ID
19~CURVE INFORMATION
20#MNEM.UNIT              API CODES                   CURVE DESCRIPTION
21#------------------     ------------              -------------------------
22 DEPT   .M                                       :  1  DEPTH
23 DT     .US/M           60 520 32 00             :  2  SONIC TRANSIT TIME
24 RHOB   .K/M3           45 350 01 00             :  3  BULK DENSITY
25 NPHI   .V/V            42 890 00 00             :  4  NEUTRON POROSITY
26 SFLU   .OHMM           07 220 04 00             :  5  SHALLOW RESISTIVITY
27 SFLA   .OHMM           07 222 01 00             :  6  SHALLOW RESISTIVITY
28 ILM    .OHMM           07 120 44 00             :  7  MEDIUM RESISTIVITY
29 ILD    .OHMM           07 120 46 00             :  8  DEEP RESISTIVITY
30~PARAMETER INFORMATION
31#MNEM.UNIT              VALUE             DESCRIPTION
32#--------------     ----------------      -----------------------------------------------
33 MUD    .               GEL CHEM        :   MUD TYPE
34 BHT    .DEGC           35.5000         :   BOTTOM HOLE TEMPERATURE
35 BS     .MM             200.0000        :   BIT SIZE
36 FD     .K/M3           1000.0000       :   FLUID DENSITY
37 MATR   .               SAND            :   NEUTRON MATRIX
38 MDEN   .               2710.0000       :   LOGGING MATRIX DENSITY
39 RMF    .OHMM           0.2160          :   MUD FILTRATE RESISTIVITY
40 DFD    .K/M3           1525.0000       :   DRILL FLUID DENSITY
41~OTHER
42     Note: The logging tools became stuck at 625 metres causing the data
43     between 625 metres and 615 metres to be invalid.
44~A  DEPTH     DT    RHOB        NPHI   SFLU    SFLA      ILM      ILD
451670.000   123.450 2550.000    0.450  123.450  123.450  110.200  105.600
461669.875   123.450 2550.000    0.450  123.450  123.450  110.200  105.600
471669.750   123.450 2550.000    0.450  123.450  123.450  110.200  105.600

And we can use lasio to convert it to LAS 1.2:

>>> las = lasio.examples.open("2.0/sample_2.0.las")
>>> las.write('example-as-v1.2.las', version=1.2)
 1~Version ---------------------------------------------------
 2VERS. 1.2 : CWLS LOG ASCII STANDARD - VERSION 1.2
 3WRAP.  NO : ONE LINE PER DEPTH STEP
 4~Well ------------------------------------------------------
 5STRT.M         1670.0 : START DEPTH
 6STOP.M        1669.75 : STOP DEPTH
 7STEP.M         -0.125 : STEP
 8NULL.         -999.25 : NULL VALUE
 9COMP.         COMPANY : ANY OIL COMPANY INC.
10WELL.            WELL : AAAAA_2
11FLD .           FIELD : WILDCAT
12LOC .        LOCATION : 12-34-12-34W5M
13PROV.        PROVINCE : ALBERTA
14SRVC. SERVICE COMPANY : ANY LOGGING COMPANY INC.
15DATE.        LOG DATE : 13-DEC-86
16UWI .  UNIQUE WELL ID : 100123401234W500
17~Curves ----------------------------------------------------
18DEPT.M                 : 1  DEPTH
19DT  .US/M 60 520 32 00 : 2  SONIC TRANSIT TIME
20RHOB.K/M3 45 350 01 00 : 3  BULK DENSITY
21NPHI.V/V  42 890 00 00 : 4  NEUTRON POROSITY
22SFLU.OHMM 07 220 04 00 : 5  SHALLOW RESISTIVITY
23SFLA.OHMM 07 222 01 00 : 6  SHALLOW RESISTIVITY
24ILM .OHMM 07 120 44 00 : 7  MEDIUM RESISTIVITY
25ILD .OHMM 07 120 46 00 : 8  DEEP RESISTIVITY
26~Params ----------------------------------------------------
27MUD .   GEL CHEM : MUD TYPE
28BHT .DEGC   35.5 : BOTTOM HOLE TEMPERATURE
29BS  .MM    200.0 : BIT SIZE
30FD  .K/M3 1000.0 : FLUID DENSITY
31MATR.       SAND : NEUTRON MATRIX
32MDEN.     2710.0 : LOGGING MATRIX DENSITY
33RMF .OHMM  0.216 : MUD FILTRATE RESISTIVITY
34DFD .K/M3 1525.0 : DRILL FLUID DENSITY
35~Other -----------------------------------------------------
36Note: The logging tools became stuck at 625 metres causing the data
37between 625 metres and 615 metres to be invalid.
38~ASCII -----------------------------------------------------
39       1670     123.45       2550       0.45     123.45     123.45      110.2      105.6
40     1669.9     123.45       2550       0.45     123.45     123.45      110.2      105.6
41     1669.8     123.45       2550       0.45     123.45     123.45      110.2      105.6

Converting between wrapped/unwrapped

Here is an example using this file to convert a wrapped data section to unwrapped.

 1~Version Information
 2 VERS.                1.20:   CWLS log ASCII Standard -VERSION 1.20
 3 WRAP.                 YES:   Multiple lines per depth step
 4~Well Information
 5#MNEM.UNIT       Data Type    Information
 6#---------    -------------   ------------------------------
 7 STRT.M            910.000:
 8 STOP.M            901.000:
 9 STEP.M            -0.1250:
10 NULL.           -999.2500:   Null value
11 COMP.             COMPANY:   ANY OIL COMPANY INC.
12 WELL.                WELL:   ANY ET AL XX-XX-XX-XX
13 FLD .               FIELD:   WILDCAT
14 LOC .            LOCATION:   XX-XX-XX-XXW3M
15 PROV.            PROVINCE:   SASKATCHEWAN
16 SRVC.     SERVICE COMPANY:   ANY LOGGING COMPANY INC.
17 SON .     SERVICE ORDER :   142085
18 DATE.            LOG DATE:   13-DEC-86
19 UWI .      UNIQUE WELL ID:
20~Curve Information
21#MNEM.UNIT      API CODE      Curve Description
22#---------    -------------   ------------------------------
23 DEPT.M                       :    Depth
24 DT  .US/M                    :  1 Sonic Travel Time
25 RHOB.K/M                     :  2 Density-Bulk Density
26 NPHI.V/V                     :  3 Porosity -Neutron
27 RX0 .OHMM                    :  4 Resistivity -Rxo
28 RESS.OHMM                    :  5 Resistivity -Shallow
29 RESM.OHMM                    :  6 Resistivity -Medium
30 RESD.OHMM                    :  7 Resistivity -Deep
31 SP  .MV                      :  8 Spon. Potential
32 GR  .GAPI                    :  9 Gamma Ray
33 CALI.MM                      : 10 Caliper
34 DRHO.K/M3                    : 11 Delta-Rho
35 EATT.DBM                     : 12 EPT Attenuation
36 TPL .NS/M                    : 13 TP -EPT
37 PEF .                        : 14 PhotoElectric Factor
38 FFI .V/V                     : 15 Porosity -NML FFI
39 DCAL.MM                      : 16 Caliper-Differential
40 RHGF.K/M3                    : 17 Density-Formation
41 RHGA.K/M3                    : 18 Density-Apparent
42 SPBL.MV                      : 19 Baselined SP
43 GRC .GAPI                    : 20 Gamma Ray BHC
44 PHIA.V/V                     : 21 Porosity -Apparent
45 PHID.V/V                     : 22 Porosity -Density
46 PHIE.V/V                     : 23 Porosity -Effective
47 PHIN.V/V                     : 24 Porosity -Neut BHC
48 PHIC.V/V                     : 25 Porosity -Total HCC
49 R0  .OHMM                    : 26 Ro
50 RWA .OHMM                    : 27 Rfa
51 SW   .                       : 28 Sw -Effective
52 MSI .                        : 29 Sh Idx -Min
53 BVW .                        : 30 BVW
54 FGAS.                        : 31 Flag -Gas Index
55 PIDX.                        : 32 Prod Idx
56 FBH .                        : 33 Flag -Bad Hole
57 FHCC.                        : 34 Flag -HC Correction
58 LSWB.                        : 35 Flag -Limit SWB
59~A Log data section
60910.000000
61  -999.2500  2692.7075     0.3140    19.4086    19.4086    13.1709    12.2681
62    -1.5010    96.5306   204.7177    30.5822  -999.2500  -999.2500     3.2515
63  -999.2500     4.7177  3025.0264  3025.0264    -1.5010    93.1378     0.1641
64     0.0101     0.1641     0.3140     0.1641    11.1397     0.3304     0.9529
65     0.0000     0.1564     0.0000    11.1397     0.0000     0.0000     0.0000
66909.875000
67  -999.2500  2712.6460     0.2886    23.3987    23.3987    13.6129    12.4744
68    -1.4720    90.2803   203.1093    18.7566  -999.2500  -999.2500     3.7058
69  -999.2500     3.1093  3004.6050  3004.6050    -1.4720    86.9078     0.1456
70    -0.0015     0.1456     0.2886     0.1456    14.1428     0.2646     1.0000
71     0.0000     0.1456     0.0000    14.1428     0.0000     0.0000     0.0000
72909.750000
73  -999.2500  2692.8137     0.2730    22.5909    22.5909    13.6821    12.6146
74    -1.4804    89.8492   201.9287     3.1551  -999.2500  -999.2500     4.3124
75  -999.2500     1.9287  2976.4451  2976.4451    -1.4804    86.3465     0.1435
76     0.0101     0.1435     0.2730     0.1435    14.5674     0.2598     1.0000
77     0.0000     0.1435     0.0000    14.5674     0.0000     0.0000     0.0000
78909.625000
79  -999.2500  2644.3650     0.2765    18.4831    18.4831    13.4159    12.6900
80    -1.5010    93.3999   201.5826    -6.5861  -999.2500  -999.2500     4.3822
81  -999.2500     1.5826  2955.3528  2955.3528    -1.5010    89.7142     0.1590
82     0.0384     0.1590     0.2765     0.1590    11.8600     0.3210     0.9667
83     0.0000     0.1538     0.0000    11.8600     0.0000     0.0000     0.0000
84909.500000
85  -999.2500  2586.2822     0.2996    13.9187    13.9187    12.9195    12.7016
86    -1.4916    98.1214   201.7126    -4.5574  -999.2500  -999.2500     3.5967
87  -999.2500     1.7126  2953.5940  2953.5940    -1.4916    94.2670     0.1880
88     0.0723     0.1880     0.2996     0.1880     8.4863     0.4490     0.8174
89     0.0000     0.1537     0.0000     8.4863     0.0000     0.0000     0.0000

We will change the wrap by adjusting the relevant header section in the LASFile header:

>>> las.version
[HeaderItem(mnemonic="VERS", unit="", value="1.2", descr="CWLS log ASCII Standa"),
 HeaderItem(mnemonic="WRAP", unit="", value="YES", descr="Multiple lines per de")]

>>> las.version.WRAP = 'NO'
>>> las.version.WRAP
HeaderItem(mnemonic="WRAP", unit="", value="NO", descr="Multiple lines per dep")
>>> las.write('example-unwrapped.las')
WARNING:lasio.writer:[v1.2] line #58 has 396 chars (>256)
WARNING:lasio.writer:[v1.2] line #59 has 396 chars (>256)
WARNING:lasio.writer:[v1.2] line #60 has 396 chars (>256)
WARNING:lasio.writer:[v1.2] line #61 has 396 chars (>256)
WARNING:lasio.writer:[v1.2] line #62 has 396 chars (>256)

We get warnings because the LAS 1.2 standard doesn’t allow writing lines longer than 256 characters. lasio provides the warning but still produces the long lines:

 1~Version ---------------------------------------------------
 2VERS. 1.2 : CWLS LOG ASCII STANDARD - VERSION 1.2
 3WRAP.  NO : Multiple lines per depth step
 4~Well ------------------------------------------------------
 5STRT.M          910.0 :
 6STOP.M          909.5 :
 7STEP.M         -0.125 :
 8NULL.         -999.25 : Null value
 9COMP.         COMPANY : ANY OIL COMPANY INC.
10WELL.            WELL : ANY ET AL XX-XX-XX-XX
11FLD .           FIELD : WILDCAT
12LOC .        LOCATION : XX-XX-XX-XXW3M
13PROV.        PROVINCE : SASKATCHEWAN
14SRVC. SERVICE COMPANY : ANY LOGGING COMPANY INC.
15SON .   SERVICE ORDER : 142085
16DATE.        LOG DATE : 13-DEC-86
17UWI .  UNIQUE WELL ID :
18~Curves ----------------------------------------------------
19DEPT.M     : Depth
20DT  .US/M  : 1 Sonic Travel Time
21RHOB.K/M   : 2 Density-Bulk Density
22NPHI.V/V   : 3 Porosity -Neutron
23RX0 .OHMM  : 4 Resistivity -Rxo
24RESS.OHMM  : 5 Resistivity -Shallow
25RESM.OHMM  : 6 Resistivity -Medium
26RESD.OHMM  : 7 Resistivity -Deep
27SP  .MV    : 8 Spon. Potential
28GR  .GAPI  : 9 Gamma Ray
29CALI.MM    : 10 Caliper
30DRHO.K/M3  : 11 Delta-Rho
31EATT.DBM   : 12 EPT Attenuation
32TPL .NS/M  : 13 TP -EPT
33PEF .      : 14 PhotoElectric Factor
34FFI .V/V   : 15 Porosity -NML FFI
35DCAL.MM    : 16 Caliper-Differential
36RHGF.K/M3  : 17 Density-Formation
37RHGA.K/M3  : 18 Density-Apparent
38SPBL.MV    : 19 Baselined SP
39GRC .GAPI  : 20 Gamma Ray BHC
40PHIA.V/V   : 21 Porosity -Apparent
41PHID.V/V   : 22 Porosity -Density
42PHIE.V/V   : 23 Porosity -Effective
43PHIN.V/V   : 24 Porosity -Neut BHC
44PHIC.V/V   : 25 Porosity -Total HCC
45R0  .OHMM  : 26 Ro
46RWA .OHMM  : 27 Rfa
47SW  .      : 28 Sw -Effective
48MSI .      : 29 Sh Idx -Min
49BVW .      : 30 BVW
50FGAS.      : 31 Flag -Gas Index
51PIDX.      : 32 Prod Idx
52FBH .      : 33 Flag -Bad Hole
53FHCC.      : 34 Flag -HC Correction
54LSWB.      : 35 Flag -Limit SWB
55~Params ----------------------------------------------------
56~Other -----------------------------------------------------
57~ASCII -----------------------------------------------------
58        910    -999.25     2692.7      0.314     19.409     19.409     13.171     12.268     -1.501     96.531     204.72     30.582    -999.25    -999.25     3.2515    -999.25     4.7177       3025       3025     -1.501     93.138     0.1641     0.0101     0.1641      0.314     0.1641      11.14     0.3304     0.9529          0     0.1564          0      11.14          0          0          0
59     909.88    -999.25     2712.6     0.2886     23.399     23.399     13.613     12.474     -1.472      90.28     203.11     18.757    -999.25    -999.25     3.7058    -999.25     3.1093     3004.6     3004.6     -1.472     86.908     0.1456    -0.0015     0.1456     0.2886     0.1456     14.143     0.2646          1          0     0.1456          0     14.143          0          0          0
60     909.75    -999.25     2692.8      0.273     22.591     22.591     13.682     12.615    -1.4804     89.849     201.93     3.1551    -999.25    -999.25     4.3124    -999.25     1.9287     2976.4     2976.4    -1.4804     86.347     0.1435     0.0101     0.1435      0.273     0.1435     14.567     0.2598          1          0     0.1435          0     14.567          0          0          0
61     909.62    -999.25     2644.4     0.2765     18.483     18.483     13.416      12.69     -1.501       93.4     201.58    -6.5861    -999.25    -999.25     4.3822    -999.25     1.5826     2955.4     2955.4     -1.501     89.714      0.159     0.0384      0.159     0.2765      0.159      11.86      0.321     0.9667          0     0.1538          0      11.86          0          0          0
62      909.5    -999.25     2586.3     0.2996     13.919     13.919     12.919     12.702    -1.4916     98.121     201.71    -4.5574    -999.25    -999.25     3.5967    -999.25     1.7126     2953.6     2953.6    -1.4916     94.267      0.188     0.0723      0.188     0.2996      0.188     8.4863      0.449     0.8174          0     0.1537          0     8.4863          0          0          0

If we decide to write the file in LAS 2.0 format, the warnings will go away:

>>> las.write('example-version-2.0.las', version=2.0)
 1~Version ---------------------------------------------------
 2VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0
 3WRAP.  NO : Multiple lines per depth step
 4~Well ------------------------------------------------------
 5STRT.M                   910.0 :
 6STOP.M                   909.5 :
 7STEP.M                  -0.125 :
 8NULL.                  -999.25 : Null value
 9COMP.     ANY OIL COMPANY INC. : COMPANY
10WELL.    ANY ET AL XX-XX-XX-XX : WELL
11FLD .                  WILDCAT : FIELD
12LOC .           XX-XX-XX-XXW3M : LOCATION
13PROV.             SASKATCHEWAN : PROVINCE
14SRVC. ANY LOGGING COMPANY INC. : SERVICE COMPANY
15SON .                   142085 : SERVICE ORDER
16DATE.                13-DEC-86 : LOG DATE
17UWI .                          : UNIQUE WELL ID
18~Curves ----------------------------------------------------
19DEPT.M     : Depth
20DT  .US/M  : 1 Sonic Travel Time
21RHOB.K/M   : 2 Density-Bulk Density
22NPHI.V/V   : 3 Porosity -Neutron
23RX0 .OHMM  : 4 Resistivity -Rxo
24RESS.OHMM  : 5 Resistivity -Shallow
25RESM.OHMM  : 6 Resistivity -Medium
26RESD.OHMM  : 7 Resistivity -Deep
27SP  .MV    : 8 Spon. Potential
28GR  .GAPI  : 9 Gamma Ray
29CALI.MM    : 10 Caliper
30DRHO.K/M3  : 11 Delta-Rho
31EATT.DBM   : 12 EPT Attenuation
32TPL .NS/M  : 13 TP -EPT
33PEF .      : 14 PhotoElectric Factor
34FFI .V/V   : 15 Porosity -NML FFI
35DCAL.MM    : 16 Caliper-Differential
36RHGF.K/M3  : 17 Density-Formation
37RHGA.K/M3  : 18 Density-Apparent
38SPBL.MV    : 19 Baselined SP
39GRC .GAPI  : 20 Gamma Ray BHC
40PHIA.V/V   : 21 Porosity -Apparent
41PHID.V/V   : 22 Porosity -Density
42PHIE.V/V   : 23 Porosity -Effective
43PHIN.V/V   : 24 Porosity -Neut BHC
44PHIC.V/V   : 25 Porosity -Total HCC
45R0  .OHMM  : 26 Ro
46RWA .OHMM  : 27 Rfa
47SW  .      : 28 Sw -Effective
48MSI .      : 29 Sh Idx -Min
49BVW .      : 30 BVW
50FGAS.      : 31 Flag -Gas Index
51PIDX.      : 32 Prod Idx
52FBH .      : 33 Flag -Bad Hole
53FHCC.      : 34 Flag -HC Correction
54LSWB.      : 35 Flag -Limit SWB
55~Params ----------------------------------------------------
56~Other -----------------------------------------------------
57~ASCII -----------------------------------------------------
58        910    -999.25     2692.7      0.314     19.409     19.409     13.171     12.268     -1.501     96.531     204.72     30.582    -999.25    -999.25     3.2515    -999.25     4.7177       3025       3025     -1.501     93.138     0.1641     0.0101     0.1641      0.314     0.1641      11.14     0.3304     0.9529          0     0.1564          0      11.14          0          0          0
59     909.88    -999.25     2712.6     0.2886     23.399     23.399     13.613     12.474     -1.472      90.28     203.11     18.757    -999.25    -999.25     3.7058    -999.25     3.1093     3004.6     3004.6     -1.472     86.908     0.1456    -0.0015     0.1456     0.2886     0.1456     14.143     0.2646          1          0     0.1456          0     14.143          0          0          0
60     909.75    -999.25     2692.8      0.273     22.591     22.591     13.682     12.615    -1.4804     89.849     201.93     3.1551    -999.25    -999.25     4.3124    -999.25     1.9287     2976.4     2976.4    -1.4804     86.347     0.1435     0.0101     0.1435      0.273     0.1435     14.567     0.2598          1          0     0.1435          0     14.567          0          0          0
61     909.62    -999.25     2644.4     0.2765     18.483     18.483     13.416      12.69     -1.501       93.4     201.58    -6.5861    -999.25    -999.25     4.3822    -999.25     1.5826     2955.4     2955.4     -1.501     89.714      0.159     0.0384      0.159     0.2765      0.159      11.86      0.321     0.9667          0     0.1538          0      11.86          0          0          0
62      909.5    -999.25     2586.3     0.2996     13.919     13.919     12.919     12.702    -1.4916     98.121     201.71    -4.5574    -999.25    -999.25     3.5967    -999.25     1.7126     2953.6     2953.6    -1.4916     94.267      0.188     0.0723      0.188     0.2996      0.188     8.4863      0.449     0.8174          0     0.1537          0     8.4863          0          0          0

Formatting data section columns

The keyword parameters that control the column spacing in the data section are, the left-hand spacer, lhs_spacer, and the in-between column spacer, spacer. They are both set to one space by default.

Use the len_numeric_field parameter to configure the padding within the numeric data fields.

The following examples will use lasio/tests/examples/2.0/sample_2.0.las. It’s data section looks like this:

~A  DEPTH     DT    RHOB        NPHI   SFLU    SFLA      ILM      ILD
1670.000   123.450 2550.000    0.450  123.450  123.450  110.200  105.600
1669.875   123.450 2550.000    0.450  123.450  123.450  110.200  105.600
1669.750   123.450 2550.000    0.450  123.450  123.450  110.200  105.600

Default data section formatting

If this file is read in and then written, the data section is formatted like this by default:

import lasio.examples
from lasio.reader import StringIO

las = lasio.examples.open("2.0/sample_2.0.las")
s = StringIO()

las.write(s)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
 1670.00000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
 1669.87500  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
 1669.75000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000

The default settings are:

  • len_numeric_field defaults to 10 characters

    • 5 digits to the right of the decimal

    • 1 character for the decimal

    • 4 digits for the number to the left of the decimal

      • if there are less than 4 digits, the field is padded with blank spaces

      • if there are more than 4 digits, the field is expanded to include all the digits

  • lhs_spacer defaults to 1 space. So the data is indented by one space.

  • spacer defaults to 1 space. So data columns will have one space dividing them

    • if a number is padded with blanks there will be more spaces seen for that number’s field

Examples: len_numeric_field

Turn off data column left-padding, set len_numeric_field to -1

This removes the padding of the numeric fields and leaves the lhs_spacer and spacer defaults of one space columns.

remove_padding=-1
las.write(s, len_numeric_field=remove_padding)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
 1670.00000 123.45000 2550.00000 0.45000 123.45000 123.45000 110.20000 105.60000
 1669.87500 123.45000 2550.00000 0.45000 123.45000 123.45000 110.20000 105.60000
 1669.75000 123.45000 2550.00000 0.45000 123.45000 123.45000 110.20000 105.60000

Set column width to less than the default: > 0 & < 10

Note in this example that only column 4 is 8 characters wide the other columns are 9 or more characters and expand to fit all their characters.

col_width = 8
las.write(s, len_numeric_field=col_width)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
 1670.00000 123.45000 2550.00000  0.45000 123.45000 123.45000 110.20000 105.60000
 1669.87500 123.45000 2550.00000  0.45000 123.45000 123.45000 110.20000 105.60000
 1669.75000 123.45000 2550.00000  0.45000 123.45000 123.45000 110.20000 105.60000

Set column width to more than the default: > 10

In this example all the columns are padded with space to make them wider. The lhs_spacer, left hand spacer, is still one space wide. The additional space on the left hand side is from the padding of the first data column to the requested col_width of 12 characters.

col_width = 12
las.write(s, len_numeric_field=col_width)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
   1670.00000    123.45000   2550.00000      0.45000    123.45000    123.45000    110.20000    105.60000
   1669.87500    123.45000   2550.00000      0.45000    123.45000    123.45000    110.20000    105.60000
   1669.75000    123.45000   2550.00000      0.45000    123.45000    123.45000    110.20000    105.60000

Examples: lhs_spacer

Remove the left most space, set lhs_spacer to an empty string

The output here removes the default 1 space column from the left hand side. Otherwise, it is the same as the initial default example.

empty_space = ""
las.write(s, lhs_spacer=empty_space)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
1670.00000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
1669.87500  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
1669.75000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000

Increase the left hand space, set lhs_spacer to a string with more spaces

In this example, there are 3 columns of space at the left hand side.

three_spaces = "   "
las.write(s, lhs_spacer=three_spaces)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
   1670.00000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
   1669.87500  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000
   1669.75000  123.45000 2550.00000    0.45000  123.45000  123.45000  110.20000  105.60000

Examples: spacer

Increase the space between columns, set spacer to as string with more spaces

In this example, there are 3 columns of space separating the data columns from each other. In addition some of the columns have more space due to space-padding of their digits to the right of the decimal.

Note that the left hand side only has the 1 space, because it is not in between the columns and is set by the default lhs_spacer setting of one space.

three_spaces = "   "
las.write(s, spacer=three_spaces)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
 1670.00000    123.45000   2550.00000      0.45000    123.45000    123.45000    110.20000    105.60000
 1669.87500    123.45000   2550.00000      0.45000    123.45000    123.45000    110.20000    105.60000
 1669.75000    123.45000   2550.00000      0.45000    123.45000    123.45000    110.20000    105.60000

Use a different character as the spacer character

This example demonstrates using a comma as the column separator. This outputs a set of comma separated data values.

comma_spacer = ","
las.write(s, spacer=comma_spacer)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
 1670.00000, 123.45000,2550.00000,   0.45000, 123.45000, 123.45000, 110.20000, 105.60000
 1669.87500, 123.45000,2550.00000,   0.45000, 123.45000, 123.45000, 110.20000, 105.60000
 1669.75000, 123.45000,2550.00000,   0.45000, 123.45000, 123.45000, 110.20000, 105.60000

Examples: a combined example

This example shows that these options can be combined to produce a variety of output formats. Here the data section is output as a tight comma separated data set.

empty_lhs_spacer = ""
comma_spacer = ","
no_padding = -1
las.write(s, lhs_spacer=empty_lhs_spacer, spacer=comma_spacer, len_numeric_field=no_padding)
s.seek(1665)
print(s.read())
~ASCII -----------------------------------------------------
1670.00000,123.45000,2550.00000,0.45000,123.45000,123.45000,110.20000,105.60000
1669.87500,123.45000,2550.00000,0.45000,123.45000,123.45000,110.20000,105.60000
1669.75000,123.45000,2550.00000,0.45000,123.45000,123.45000,110.20000,105.60000