From 80b59cc7ef9fe05b1a915ad0e8b7aae15aa0eac5 Mon Sep 17 00:00:00 2001 From: Altay Sansal Date: Wed, 25 Sep 2024 14:53:00 -0500 Subject: [PATCH] Apply endianness override if `spec` was provided (#191) * apply endianness override if spec is provided * 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. --------- Co-authored-by: Altay Sansal --- src/segy/file.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/segy/file.py b/src/segy/file.py index 433dad2..83aa9ea 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,14 @@ def __init__( # If spec is provided set to it and update endianness if its None. else: self.spec = spec + + # Override/Infer endianness if self.spec.endianness is None: - scan_result = infer_endianness(self.fs, self.url, self.spec) - self.spec.endianness = scan_result.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)