Kaitai Struct runtime for Awkward Arrays
Project description
Kaitai Struct: runtime library for Awkward
This library building Awkward Arrays using Kaitai Struct API for Awkward using C++/STL.
Steps
1. Write a .ksy file for your custom file format. Refer to the Kaitai User Guide for more details.
Here, we take an example of animal.ksy
meta:
id: animal
endian: le
license: CC0-1.0
ks-version: 0.8
seq:
- id: entry
type: animal_entry
repeat: eos
types:
animal_entry:
seq:
- id: str_len
type: u1
- id: species
type: str
size: str_len
encoding: UTF-8
- id: age
type: u1
- id: weight
type: u2
2. Clone kaitai_struct_awkward_runtime repository:
git clone --recursive https://github.com/det-lab/kaitai_struct_awkward_runtime.git
cd kaitai_struct_awkward_runtime
git checkout ManasviGoyal/test
3. Update submodule and compile scala code (only the first time)
git submodule update --init
cd kaitai_struct_compiler
sbt package
cd ../
chmod u+x kaitai-struct-compiler
4. Generate the source and header files for Awkward target
./kaitai-struct-compiler -t awkward --outdir src-animal example_data/schemas/animal.ksy
5. Install the library
pip install awkward-kaitai
6. Build awkward-kaitai by passing the path of the main .cpp from the generated code.
If python gives a warning about the installation not being on the path, in order to get the file to build you may need to run:
echo "export PATH=$PATH:/whatever/path/python/says" >> ~/.bashrc
awkward-kaitai-build src-animal/animal.cpp -b build
Note:
awkward-kaitai-build [-h] [-d DEST] [-b BUILD] fileoptions:
-h, --help: shows help message-d DEST, --dest DEST: explicitly specify a destination for the build shared library.-b BUILD, --build BUILD: explicitly specify a build location.
7. Open python and print the returned ak.Array:
python
import awkward_kaitai
animal = awkward_kaitai.Reader("./src-animal/libanimal.so") # pass the path of the shared file
awkward_array = animal.load("example_data/data/animal.raw")
awkward_array.to_list()
Output
[{'animalA__Zentry': [{'animal_entryA__Zstr_len': 3, 'animal_entryA__Zspecies': 'cat', 'animal_entryA__Zage': 5, 'animal_entryA__Zweight': 12}, {'animal_entryA__Zstr_len': 3, 'animal_entryA__Zspecies': 'dog', 'animal_entryA__Zage': 3, 'animal_entryA__Zweight': 43}, {'animal_entryA__Zstr_len': 6, 'animal_entryA__Zspecies': 'turtle', 'animal_entryA__Zage': 10, 'animal_entryA__Zweight': 5}]}]
Related Papers and Talks
- Describe Data to get Science-Data-Ready Tooling: Awkward as a Target for Kaitai Struct YAML, Advanced Computing and Analysis Techniques for Physics Research Workshop 2024, New York, US.
- Awkward Target for Kaitai Struct, PyHEP Users Workshop 2023.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file awkward_kaitai-0.2.0.tar.gz.
File metadata
- Download URL: awkward_kaitai-0.2.0.tar.gz
- Upload date:
- Size: 14.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
309f848f85d87c54a5f74f0e3e54538c1c3a818213db1289f5929066e5c5805b
|
|
| MD5 |
a8d82052594d0f59f66d0d4c6aaeec7c
|
|
| BLAKE2b-256 |
1f6f2ef17194db53d70abc0bb6e2b962653326842b8cae721809e96836ac728a
|
File details
Details for the file awkward_kaitai-0.2.0-py3-none-any.whl.
File metadata
- Download URL: awkward_kaitai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8356d1d6791126eb1da632bdb0bb263b01bbce3b2aa8763075fe0cea0111c065
|
|
| MD5 |
35289db3e5beea411d030ef10b233415
|
|
| BLAKE2b-256 |
45219d36fb64d40cdf149a59641547ec21677e50cbabbc4dc4e4fc66e9fc1284
|