From de787350794fe779ae2e8086fe3c7b0ecc3cc94c Mon Sep 17 00:00:00 2001 From: Altay Sansal Date: Wed, 25 Sep 2024 14:33:55 -0500 Subject: [PATCH 1/2] apply endianness override if spec is provided --- src/segy/file.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/segy/file.py b/src/segy/file.py index 433dad2..81f3535 100644 --- a/src/segy/file.py +++ b/src/segy/file.py @@ -134,6 +134,7 @@ def __init__( self._info = self.fs.info(self.url) # Spec setting overrides. + # The control flow here is terrible; needs a refactor. if self.settings.binary.revision is not None: self.spec = get_segy_standard(self.settings.binary.revision) @@ -151,9 +152,13 @@ def __init__( # If spec is provided set to it and update endianness if its None. else: self.spec = spec - if self.spec.endianness is None: + + # Override/Infer endianness + if self.settings.endianness is None: scan_result = infer_endianness(self.fs, self.url, self.spec) self.spec.endianness = scan_result.endianness + else: + self.spec.endianness = self.settings.endianness self._update_spec() self.accessors = TraceAccessor(self.spec.trace) From 915fc670039c1eb069195938149cb6dabd9eede4 Mon Sep 17 00:00:00 2001 From: Altay Sansal Date: Wed, 25 Sep 2024 14:50:06 -0500 Subject: [PATCH 2/2] Fix endianness determination logic Updated the logic for determining endianness to correctly prioritize user settings. This ensures the inferred endianness is only used if both the provided specification and user settings do not specify it. --- src/segy/file.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/segy/file.py b/src/segy/file.py index 81f3535..83aa9ea 100644 --- a/src/segy/file.py +++ b/src/segy/file.py @@ -154,11 +154,12 @@ def __init__( self.spec = spec # Override/Infer endianness - if self.settings.endianness is None: - scan_result = infer_endianness(self.fs, self.url, self.spec) - self.spec.endianness = scan_result.endianness - else: - self.spec.endianness = self.settings.endianness + if self.spec.endianness is None: + if self.settings.endianness is None: + scan_result = infer_endianness(self.fs, self.url, self.spec) + self.spec.endianness = scan_result.endianness + else: + self.spec.endianness = self.settings.endianness self._update_spec() self.accessors = TraceAccessor(self.spec.trace)