Skip to content

Commit

Permalink
Apply endianness override if spec was provided (#191)
Browse files Browse the repository at this point in the history
* 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 <altay.sansal@tgs.com>
  • Loading branch information
tasansal and Altay Sansal authored Sep 25, 2024
1 parent 6347f56 commit 80b59cc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/segy/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 80b59cc

Please sign in to comment.