dotthz

Crates.iodotthz
lib.rsdotthz
version0.2.4
sourcesrc
created_at2024-11-14 16:38:48.063786
updated_at2024-11-30 14:43:16.756833
descriptionCrate to load and save dotThz files in rust.
homepagehttps://github.com/hacknus/dotthz-rs
repositoryhttps://github.com/hacknus/dotthz-rs
max_upload_size
id1448014
size7,746,145
(hacknus)

documentation

https://docs.rs/dotthz-rs

README

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.

Commit count: 27

cargo fmt