-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from kif/539_big-endian
This should fix the decoding of CBF files on big-endian computer.
- Loading branch information
Showing
1 changed file
with
5 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ | |
__author__ = "Jérôme Kieffer" | ||
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__date__ = "06/04/2020" | ||
__date__ = "20/10/2023" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
|
||
import sys | ||
|
@@ -205,6 +205,7 @@ def decByteOffset_numpy(stream, size=None, dtype="int64"): | |
:param size: the size of the output array (of longInts) | ||
:return: 1D-ndarray | ||
Nota: data are always stored as little endian. | ||
""" | ||
logger.debug("CBF decompression using Numpy") | ||
listnpa = [] | ||
|
@@ -222,23 +223,19 @@ def decByteOffset_numpy(stream, size=None, dtype="int64"): | |
if stream[idx + 1:idx + 3] == key32: | ||
if stream[idx + 3:idx + 7] == key64: | ||
# 64 bits int | ||
res = numpy.frombuffer(stream[idx + 7:idx + 15], dtype=numpy.int64) | ||
res = numpy.frombuffer(stream[idx + 7:idx + 15], dtype="<q") | ||
listnpa.append(res) | ||
shift = 15 | ||
else: | ||
# 32 bits int | ||
res = numpy.frombuffer(stream[idx + 3:idx + 7], dtype=numpy.int32) | ||
res = numpy.frombuffer(stream[idx + 3:idx + 7], dtype="<i") | ||
listnpa.append(res) | ||
shift = 7 | ||
else: # int16 | ||
res = numpy.frombuffer(stream[idx + 1:idx + 3], dtype=numpy.int16) | ||
res = numpy.frombuffer(stream[idx + 1:idx + 3], dtype="<h") | ||
listnpa.append(res) | ||
shift = 3 | ||
stream = stream[idx + shift:] | ||
if not numpy.little_endian: | ||
for res in listnpa: | ||
if res.dtype != numpy.int8: | ||
res.byteswap(True) | ||
return numpy.ascontiguousarray(numpy.hstack(listnpa), dtype).cumsum() | ||
|
||
|
||
|