Code Monkey home page Code Monkey logo

tdms's Introduction

tdms

tdms is a LabVIEW TDMS file parser library written in Rust. This is meant to be a general purpose library for reading and performing any calculation work on data contained in those files.

Note: This library is a work in progress. While I do not expect the current function signatures and library structure to change, you could experience difficulties due to early adoption. Functionality is currently limited. Raw data channel iterators will be added slowly and a list will be kept indicating which are available and which are under construction

Current Features

  • Read both standard and big endian encoded files
  • Read files with DAQmx data and data indices
  • Read all segments in file, along with their groups and channels (per segment only)
  • Read all raw data contained in all segments in file (as a Vec<u8> only at the present time)
  • Logging using the log api - users of the library must choose and initialize the implementation, such as env-logger

Here is a list of all supported iterators for TDMS data types. If completely unlisted, then that type is not supported yet. Check back frequently as this list will grow quickly.

Data Type Standard Interleaved DAQmx
Double Float ✓ - untested
Single Float ✓ - untested ✓ - untested
Single Float with unit ✓ - untested ✓ - untested
Double Float with unit ✓ - untested ✓ - untested
Complex Single Float ✓ - untested ✓ - untested
Complex Double Float ✓ - untested ✓ - untested
I8 ✓ - untested ✓ - untested
I32 ✓ - untested ✓ - untested
I64 ✓ - untested ✓ - untested
U8 ✓ - untested ✓ - untested
U16 ✓ - untested ✓ - untested
U32 ✓ - untested ✓ - untested
U64 ✓ - untested ✓ - untested
Boolean ✓ - untested ✓ - untested
Timestamp (returns tuple) ✓ - untested ✓ - untested
Single Float ✓ - untested ✓ - untested
Single Float ✓ - untested ✓ - untested
Single Float ✓ - untested ✓ - untested
String ✓ - untested

Planned Features

  • Iterators for each channel type, return native Rust values from encoded data channels
  • DAQmx data channel iterator support
  • Searching on string channels

Usage

extern crate tdms;

use std::path::Path;
use tdms::data_type::TdmsDataType;
use tdms::TDMSFile;

fn main() {
    // open and parse the TDMS file, passing in metadata false will mean the entire file is
    // read into memory, not just the metadata
    let file = match TDMSFile::from_path(Path::new("data/standard.tdms")) {
        Ok(f) => f,
        Err(e) => panic!("{:?}", e),
    };

    // fetch groups
    let groups = file.groups();

    for group in groups {
        // fetch an IndexSet of the group's channels
        let channels = file.channels(&group);

        let mut i = 0;
        for (_, channel) in channels {
            // once you know the channel's full path (group + channel) you can ask for the full
            // channel object. In order to fetch a channel you must call the proper channel func
            // depending on your data type. Currently this feature is unimplemented but the method
            // of calling this is set down for future changes
            let full_channel = match channel.data_type {
                // the returned full channel is an iterator over raw data
                TdmsDataType::DoubleFloat(_) => file.clone().channel_data_double_float(channel),
                _ => {
                    panic!("{}", "channel for data type unimplemented")
                }
            };

            let mut full_channel_iterator = match full_channel {
                Ok(i) => i,
                Err(e) => {
                    panic!("{:?}", e)
                }
            };

            println!("{:?}", full_channel_iterator.count());

            i += 1;
        }
    }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

tdms's People

Contributors

dnoberon avatar mettekou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mettekou

tdms's Issues

Reading file in causes 'index out of bounds' error

I am attempting to read in a tdms file so I can perform calculations on the data contained within. The structure of the file is this:

test.tdms
    aux_data
        time [s] 
        distance [in]
        gps 
    mic_data
        time [s]
        mic 1
        mic 2 
        ... mic 12

Reading in this test.tdms file like so:

let file = match TDMSFile::from_path(Path::new("src/data/test.tdms")) {
        Ok(f) => f,
        Err(e) => panic!("{:?}", e),
    };

throws the following error. I fear that the error is due to the tiered structure of my data because reading in the provided (non-tiered) standard, raw, and big endian tdms files works fine.

thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 2', C:\...\.cargo\registry\src\github.com-1ecc6299db9ec823\tdms-0.2.5\src\segment.rs:114:75
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library\core\src\panicking.rs:142
   2: core::panicking::panic_bounds_check
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library\core\src\panicking.rs:84
   3: core::slice::index::impl$2::index<str>
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\slice\index.rs:250
   4: core::slice::index::impl$0::index
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\slice\index.rs:18
   5: alloc::vec::impl$16::index<str,usize,alloc::alloc::Global>
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\alloc\src\vec\mod.rs:2628
   6: tdms::segment::Segment::new<std::io::buffered::bufreader::BufReader<std::fs::File> >
             at C:\...\.cargo\registry\src\github.com-1ecc6299db9ec823\tdms-0.2.5\src\segment.rs:114
   7: tdms::TDMSFile::from_path
             at C:\...\.cargo\registry\src\github.com-1ecc6299db9ec823\tdms-0.2.5\src\lib.rs:124
   8: test::tdms_reader::open
             at .\src\tdms_reader.rs:11
   9: test::main
             at .\src\main.rs:15
  10: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\ops\function.rs:248

TDMSValue from_path method do not exist

Hi,

I am starting with rust and labview and I am trying out this library, thanks for the work men!

Just a question about how to extract a value from a TDMSValue. In this particular case I need to extract the date to send it to a .csv file. I have this function:

fn extract_date(tdms_file: &TDMSFile, file: &mut File) -> std::io::Result<()> {
    let name = tdms_file.segments.get(0).unwrap().metadata.clone().unwrap();
    let obj = name
        .objects
        .iter()
        .find(|obj| obj.object_path == "/")
        .unwrap();
    // .collect();
    let date = obj
        .properties
        .iter()
        .find(|n| n.name == "DateTime")
        .unwrap()
        .value
        .clone();
    println!("extract date ---------->>> {:?}", date);
    Ok(())
}

date is of type TDMSValue, reading the docs I found that this struct has a method pub fn from_reader(...)
that I supose that is to extract that value from value depending on each type, but It seems that this function does not exists. I am not able to call this function.

image

Do you know what can be happening? any help is welcome. 😃

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.