#io #load #interface #save #file #metadata #thz-spectroscopy

dotthz

Crate to load and save dotThz files in rust

7 releases

0.2.4 Nov 30, 2024
0.2.3 Nov 25, 2024
0.1.2 Nov 15, 2024

#585 in Filesystem

Download history 354/week @ 2024-11-11 58/week @ 2024-11-18 417/week @ 2024-11-25 99/week @ 2024-12-02 131/week @ 2024-12-09

722 downloads per month

MIT license

4MB
418 lines

Interface with dotThz files using rust

This crate provides an easy way to interface with dotThz files in rust.

Load it in your cargo.toml

[dependencies]
dotthz-rs = "0.2.4"

and then use like specified in the following example:

use std::path::PathBuf;
use dotthz::{DotthzFile};

fn main() {
    // Load data from the original file
    let file_path = PathBuf::new("test_files/2_VariableTemperature.thz");
    let file = DotthzFile::create(&file_path);
    
    // Initialize test metadata
    let meta_data = DotthzMetaData {
        user: "Test User".to_string(),
        email: "test@example.com".to_string(),
        orcid: "0000-0001-2345-6789".to_string(),
        institution: "Test Institute".to_string(),
        description: "Test description".to_string(),
        md: [("Thickness (mm)".to_string(), "0.52".to_string())]
            .into_iter()
            .collect(),
        ds_description: vec!["ds1".to_string()],
        version: "1.0".to_string(),
        mode: "Test mode".to_string(),
        instrument: "Test instrument".to_string(),
        time: "12:34:56".to_string(),
        date: "2024-11-08".to_string(),
    };

    // create a group with metadata
    let mut original_dotthz = DotthzFile::create(&path)?;
    let group_name = "Measurement".to_string();
    original_dotthz.add_group(&group_name, &meta_data)?;

    // write data
    let dataset_name = "test_dataset".to_string();
    let dataset_data: Array2<f32> = array![[1.0, 2.0], [3.0, 4.0], [3.0, 4.0]];

    original_dotthz.add_dataset(&group_name, &dataset_name, dataset_data.view())?;
    
    // data is now already saved to the file.
    
    
    // Load data from the dotTHz file
    let file = DotthzFile::load(&file_path)?;

    for group in file
        .get_groups()?
    {
        // Compare the original and copied metadata
        let meta_data = file.get_meta_data(&group.name());
        
        for dataset in group.get_datasets() {
            // do stuff with the loaded dataset
            // ...
        }
        let data = file.get_dataset(&group.name(), &dataset_name);
    }

}

Use the hdf5-sys-static feature to compile hdf5 and statically link it. This requires cmake to be installed. Use the serde feature to derive Serialize and Deserialize for DotthzMetaData.

Dependencies

~4–14MB
~181K SLoC