Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Move strt/stop/step config to its own function #447

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lasio/las.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,33 @@ def read(
logger.warning("Conflicting index units found: {}".format(matches))
self.index_unit = None

def update_start_stop_step(self, STRT=None, STOP=None, STEP=None, fmt="%.5f"):
"""Configure or Change STRT, STOP, and STEP values
"""
if STRT is None:
STRT = self.index[0]
if STOP is None:
STOP = self.index[-1]
if STEP is None:
# prevents an error being thrown in the case of only a single sample being written
if STOP != STRT:
raw_step = self.index[1] - self.index[0]
STEP = fmt % raw_step

self.well["STRT"].value = STRT
self.well["STOP"].value = STOP
self.well["STEP"].value = STEP

# Check units
if self.curves[0].unit:
unit = self.curves[0].unit
else:
unit = self.well["STRT"].unit
self.well["STRT"].unit = unit
self.well["STOP"].unit = unit
self.well["STEP"].unit = unit
self.curves[0].unit = unit

def write(self, file_ref, **kwargs):
"""Write LAS file to disk.

Expand Down
24 changes: 1 addition & 23 deletions lasio/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,7 @@ def write(
"VERS", "", 2.0, "CWLS log ASCII Standard -VERSION 2.0"
)

if STRT is None:
STRT = las.index[0]
if STOP is None:
STOP = las.index[-1]
if STEP is None:
# prevents an error being thrown in the case of only a single sample being written
if STOP != STRT:
raw_step = las.index[1] - las.index[0]
STEP = fmt % raw_step

las.well["STRT"].value = STRT
las.well["STOP"].value = STOP
las.well["STEP"].value = STEP

# Check units
if las.curves[0].unit:
unit = las.curves[0].unit
else:
unit = las.well["STRT"].unit
las.well["STRT"].unit = unit
las.well["STOP"].unit = unit
las.well["STEP"].unit = unit
las.curves[0].unit = unit
las.update_start_stop_step()

# Write each section.
# get_formatter_function ( ** get_section_widths )
Expand Down