Skip to content

Commit

Permalink
Merge 2d8f2b5 into bf4276c
Browse files Browse the repository at this point in the history
  • Loading branch information
kinverarity1 committed Aug 11, 2015
2 parents bf4276c + 2d8f2b5 commit 4d5c493
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 35 deletions.
47 changes: 12 additions & 35 deletions lasio/las.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,6 @@ def write(self, file_object, version=None,

# ~Version
lines.append("~Version ".ljust(60, "-"))
# section_widths = {
# "left_width": None,
# "middle_width": None
# }
order_func = get_section_order_function("version", version)
section_widths = get_section_widths("version", self.version, version)
for mnemonic, header_item in self.version.items():
Expand All @@ -319,10 +315,6 @@ def write(self, file_object, version=None,

# ~Well
lines.append("~Well ".ljust(60, "-"))
# section_widths = {
# "left_width": None,
# "middle_width": None
# }
order_func = get_section_order_function("well", version)
section_widths = get_section_widths("well", self.well, version)
for mnemonic, header_item in self.well.items():
Expand All @@ -333,10 +325,6 @@ def write(self, file_object, version=None,

# ~Curves
lines.append("~Curves ".ljust(60, "-"))
# section_widths = {
# "left_width": None,
# "middle_width": None
# }
order_func = get_section_order_function("curves", version)
section_widths = get_section_widths("curves", self.curves, version)
for header_item in self.curves:
Expand All @@ -347,10 +335,6 @@ def write(self, file_object, version=None,

# ~Params
lines.append("~Params ".ljust(60, "-"))
# section_widths = {
# "left_width": None,
# "middle_width": None
# }
order_func = get_section_order_function("params", version)
section_widths = get_section_widths("params", self.params, version)
for mnemonic, header_item in self.params.items():
Expand Down Expand Up @@ -783,29 +767,22 @@ def get_section_widths(section_name, section, version, middle_padding=5):
version (float): either 1.2 or 2.0
'''
section_widths = {}
section_widths = {
"left_width": None,
"middle_width": None
}
if isinstance(section, dict):
items = section.values()
elif isinstance(section, list):
items = list(section)

section_widths["left_width"] = max([len(i.mnemonic) for i in items])

if section_name == "well" and version == 1.2:
mw = max([len(str(i.unit)) + len(str(i.descr)) for i in items])
section_widths["middle_width"] = mw + middle_padding
# descr_widths = [len(i.descr) for i in items]
# value_widths = [len(str(i.unit)) + len(str(i.value))
# for i in items]
# middle_widths = []
# for i in range(len(descr_widths)):
# middle_widths.append(
# max([descr_widths[i], value_widths[i]]) + middle_padding)
# section_widths["middle_width"] = max(middle_widths)
else:
mw = max([len(str(i.unit)) + len(str(i.value)) for i in items])
section_widths["middle_width"] = mw + middle_padding

if len(items) > 0:
section_widths["left_width"] = max([len(i.mnemonic) for i in items])
if section_name == "well" and version == 1.2:
mw = max([len(str(i.unit)) + len(str(i.descr)) for i in items])
section_widths["middle_width"] = mw + middle_padding
else:
mw = max([len(str(i.unit)) + len(str(i.value)) for i in items])
section_widths["middle_width"] = mw + middle_padding
return section_widths


Expand Down
35 changes: 35 additions & 0 deletions lasio/test_examples/sample_write_empty_params.las
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
~VERSION INFORMATION
VERS . 1.2: CWLS LOG ASCII STANDARD -VERSION 1.2
WRAP . NO: ONE LINE PER DEPTH STEP
~WELL INFORMATION BLOCK
#MNEM.UNIT DATA TYPE INFORMATION
#--------- ------------- ------------------------------
STRT.M 1670.000000:
STOP.M 1660.000000:
STEP.M -0.1250:
NULL. -999.2500:
COMP. COMPANY: # ANY OIL COMPANY LTD.
WELL. WELL: ANY ET AL OIL WELL #12
FLD . FIELD: EDAM
LOC . LOCATION: A9-16-49-20W3M
PROV. PROVINCE: SASKATCHEWAN
SRVC. SERVICE COMPANY: ANY LOGGING COMPANY AT ALL!!!!
DATE. LOG DATE: 25-DEC-1988
UWI . UNIQUE WELL ID: 100091604920W300
~CURVE INFORMATION
#MNEM.UNIT API CODE CURVE DESCRIPTION
#--------- ------------- ------------------------------
DEPT.M : 1 DEPTH
DT .US/M : 2 SONIC TRANSIT TIME
RHOB.K/M3 : 3 BULK DENSITY
NPHI.V/V : 4 NEUTRON POROSITY
SFLU.OHMM : 5 RXO RESISTIVITY
SFLA.OHMM : 6 SHALLOW RESISTIVITY
ILM .OHMM : 7 MEDIUM RESISTIVITY
ILD .OHMM : 8 DEEP RESISTIVITY
~PARAMETER INFORMATION
~Other
~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
8 changes: 8 additions & 0 deletions lasio/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

egfn = lambda fn: os.path.join(os.path.dirname(__file__), "test_examples", fn)


def test_write_sect_widths_12():
l = read(egfn("sample_write_sect_widths_12.las"))
s = StringIO()
Expand Down Expand Up @@ -52,6 +53,7 @@ def test_write_sect_widths_12():
1669.8 123.45 2550 0.45
"""


def test_write_sect_widths_12_curves():
l = read(egfn("sample_write_sect_widths_12.las"))
s = StringIO()
Expand All @@ -60,6 +62,7 @@ def test_write_sect_widths_12_curves():
s.seek(0)
assert "\n" + start in s.read()


def test_write_sect_widths_20_narrow():
l = read(egfn("sample_write_sect_widths_20_narrow.las"))
s = StringIO()
Expand Down Expand Up @@ -108,6 +111,7 @@ def test_write_sect_widths_20_narrow():
1669.8 123.45 2550 0.45 123.45 123.45 110.2 105.6
"""


def test_write_sect_widths_20_wide():
l = read(egfn("sample_write_sect_widths_20_wide.las"))
s = StringIO()
Expand Down Expand Up @@ -156,3 +160,7 @@ def test_write_sect_widths_20_wide():
1669.8 123.45 2550 0.45 123.45 123.45 110.2 105.6
"""


def test_write_sample_empty_params():
l = read(egfn("sample_write_empty_params.las"))
l.write(StringIO(), version=2)
124 changes: 124 additions & 0 deletions notebooks/issues/issue #67.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import lasio\n",
"\n",
"from cStringIO import StringIO"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"\n",
"def test_write_sample_empty_params(s):\n",
" l = lasio.read(\"/home/dewnrgeophysics/software/lasio/lasio/test_examples/sample_write_empty_params.las\")\n",
" l.write(s, version=2)\n",
" return s"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"s = test_write_sample_empty_params(StringIO())"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"~Version ---------------------------------------------------\n",
"VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0\n",
"WRAP. NO : ONE LINE PER DEPTH STEP\n",
"~Well ------------------------------------------------------\n",
"STRT.M 1670.0 : \n",
"STOP.M 1669.75 : \n",
"STEP.M -0.125 : \n",
"NULL. -999.25 : \n",
"COMP. # ANY OIL COMPANY LTD. : COMPANY\n",
"WELL. ANY ET AL OIL WELL #12 : WELL\n",
"FLD . EDAM : FIELD\n",
"LOC . A9-16-49-20W3M : LOCATION\n",
"PROV. SASKATCHEWAN : PROVINCE\n",
"SRVC. ANY LOGGING COMPANY AT ALL!!!! : SERVICE COMPANY\n",
"DATE. 25-DEC-1988 : LOG DATE\n",
"UWI . 100091604920W300 : UNIQUE WELL ID\n",
"~Curves ----------------------------------------------------\n",
"DEPT.M : 1 DEPTH\n",
"DT .US/M : 2 SONIC TRANSIT TIME\n",
"RHOB.K/M3 : 3 BULK DENSITY\n",
"NPHI.V/V : 4 NEUTRON POROSITY\n",
"SFLU.OHMM : 5 RXO RESISTIVITY\n",
"SFLA.OHMM : 6 SHALLOW RESISTIVITY\n",
"ILM .OHMM : 7 MEDIUM RESISTIVITY\n",
"ILD .OHMM : 8 DEEP RESISTIVITY\n",
"~Params ----------------------------------------------------\n",
"~Other -----------------------------------------------------\n",
"~ASCII -----------------------------------------------------\n",
" 1670 123.45 2550 0.45 123.45 123.45 110.2 105.6\n",
" 1669.9 123.45 2550 0.45 123.45 123.45 110.2 105.6\n",
" 1669.8 123.45 2550 0.45 123.45 123.45 110.2 105.6\n",
"\n"
]
}
],
"source": [
"s.seek(0)\n",
"print s.read()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 4d5c493

Please sign in to comment.