From 706cdf7dbcd7cb50c9d18431ccbc6b02ce9d38ee Mon Sep 17 00:00:00 2001 From: dcslagel Date: Fri, 16 Apr 2021 10:57:51 -0600 Subject: [PATCH] Move strt/stop/step config to its own function Move strt/stop/step config/change from writer.py::write() to its own function as part of the LASFile class. For this checkin this new function is included in writer.py::write() so the overall behavior is the same. --- lasio/las.py | 27 +++++++++++++++++++++++++++ lasio/writer.py | 24 +----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/lasio/las.py b/lasio/las.py index 89f89e6..3c61cbc 100644 --- a/lasio/las.py +++ b/lasio/las.py @@ -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. diff --git a/lasio/writer.py b/lasio/writer.py index 23aa1df..a228fad 100644 --- a/lasio/writer.py +++ b/lasio/writer.py @@ -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 )