Skip to content

Commit

Permalink
Forward compatibility with littleEndianWords in Blob API
Browse files Browse the repository at this point in the history
We use Big Endian for Spectra and Little Endian for the rest.
To be consistent we'll need to fix one of them. We'll probably
change everything to Big Endian, but that would break this SDK
right away. So for forward compatibility the API will temporarily
handle littleEndianWords flag when we start switching.
  • Loading branch information
ctapobep committed Dec 30, 2024
1 parent 6f153aa commit 9ca5fca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "elsci-peaksel-sdk"
version = "1.0.0"
version = "1.0.1"
description = "SDK to upload and manage chromatographic injections and other data in Elsci Peaksel"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
10 changes: 6 additions & 4 deletions python/src/peakselsdk/blob/BlobClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ def get_spectra(self, blob_id: str) -> list[Spectrum]:
def get_peak_spectrum(self, blob_id: str) -> Floats2d:
return self._get_2d_floats(blob_id)

def get_blob(self, blob_id: str) -> bytes:
def get_blob(self, blob_id: str, little_endian = False) -> bytes:
if not blob_id:
raise Exception(f"You must pass a blob ID, got: {blob_id}")
return self.http.get_bytes(f"/api/blob/{blob_id}", headers={"Accept": "application/octet-stream"})
# Little Endian flag is passed for forward compatibility when we fix the endianness of signals and baseline
return self.http.get_bytes(f"/api/blob/{blob_id}?littleEndianWords={little_endian}",
headers={"Accept": "application/octet-stream"})

def _get_1d_floats(self, blob_id: str) -> tuple[float,...]:
return bytes_to_floats_le(self.get_blob(blob_id))
return bytes_to_floats_le(self.get_blob(blob_id, little_endian=True))

def _get_2d_floats(self, blob_id: str) -> Floats2d:
data = self.get_blob(blob_id)
data = self.get_blob(blob_id, little_endian=True)
half_len = (len(data)-4) // 2 # first 4 bytes is the length
x: tuple[float,...] = bytes_to_floats_le(data, 4, len_bytes=half_len)
y: tuple[float,...] = bytes_to_floats_le(data, 4+half_len)
Expand Down
2 changes: 1 addition & 1 deletion python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9ca5fca

Please sign in to comment.