#parser #radio-astronomy #astronomy

sigproc_filterbank

A parser and serializer for SIGPROC pulsar filterbank files

6 releases (3 breaking)

0.4.0 Apr 5, 2024
0.3.0 Feb 26, 2023
0.2.1 Aug 12, 2022
0.1.1 Aug 11, 2022

#658 in Parser implementations

Download history 3/week @ 2024-06-14 7/week @ 2024-07-19 19/week @ 2024-07-26 7/week @ 2024-09-13 8/week @ 2024-09-20 114/week @ 2024-09-27

129 downloads per month

Apache-2.0 OR MIT

51KB
1K SLoC

sigproc_filterbank

license docs rustc build status Codecov

This crate provides a simple, fast, and robust interface to the SIGPROC filterbank binary format. This format contains dynamic spectra, used commonly in pulsar and radio transient science in radio astronomy. This implementation is pure-rust with few dependencies and denies any unsafe code.

Description

There are two main interfaces to filterbank files, reading and writing. These exists as separate data structures as the way you interact with them is fundamentally different.

Reading

To read from a filterbank file, you simply need a slice of bytes. This can come from a memory-mapped file, an incoming stream, etc. Then, there are getter methods for the header data and a single get method for accessing points in the dynamic spectra. Every filterbank will return f32s as the largest integer value supported by the format (u16) fits losslessly in an f32. get indexes as IF channel, Sample number, frequency channel.

use std::{fs::File, io::Read};

use sigproc_filterbank::read::ReadFilterbank;

let mut file = File::open("tests/small.fil").unwrap();
let mut bytes = vec![];
file.read_to_end(&mut bytes).unwrap();
let fb = ReadFilterbank::from_bytes(&bytes).unwrap();
let my_spec_val = fb.get(0,0,0);

Writing

To build a filterbank file, you push time-series data, just as you would receive them in a live telescope. You must declare the number of IFs and number of channels, and then the sample number is implied by how much data you write. Additionally, the number of bits of the filterbank is implied by the type of data you push. You get a compile error if you try to push different types. For data less than 8 bits, use the ux crate. We support, u1, u2, and u4.

Then to write the file, you simply dump the bytes and write to a file, stream, etc.

use sigproc_filterbank::write::WriteFilterbank;

// Two frequency channels, one IF
let mut fb = WriteFilterbank::new(2, 1);
fb.push(&[1u8, 2u8]);
fb.push(&[3u8, 4u8]);
// Serialize to bytes
let bytes = fb.bytes();

License

sigproc_filterbank is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Dependencies

~1.2–1.8MB
~38K SLoC