Crates.io | delfi |
lib.rs | delfi |
version | 0.1.0 |
source | src |
created_at | 2022-12-04 13:11:31.562452 |
updated_at | 2023-01-26 21:26:52.472323 |
description | Conveniently writing data to csv-files |
homepage | |
repository | https://github.com/skogseth/delfi |
max_upload_size | |
id | 729595 |
size | 98,475 |
Rust crate for conveniently writing data to csv-files. The crate aims to be a minimal interface for saving data to csv such that this is not a considerable part of your program, preferably only taking up a few lines of code.
A basic use of delfi is shown below:
use delfi::Dataset;
let t = vec![0.0, 1.0, 2.0];
let x = vec![0.0, 2.0, 6.0];
let dataset = Dataset::columns([t, x], ["time", "length"]);
dataset.save("./path/to/file.csv").unwrap();
Alternatively you can use the macro for slightly longer, but perhaps more readable, code:
use delfi::dataset;
let t = vec![0.0, 1.0, 2.0];
let x = vec![0.0, 2.0, 6.0];
let dataset = dataset!{
"time" => t,
"length" => x,
};
dataset.save("./path/to/file.csv").unwrap();
It works with anything iterable, so long as they are the same type. Here is an example using ndarray:
use delfi::dataset;
use ndarray::Array;
const N: usize = 1000;
let t = Array::linspace(0., 10., N+1);
let x = Array::logspace(10., 0., 2., N+1);
let dataset = dataset!{
"time" => t,
"length" => x,
};
dataset.save("./path/to/file.csv").unwrap();
Work is currently being done to allow custom datastructures which combine multiple types. The current state allows patterns such as this (named structs are also supported):
use delfi::{Datapoint, Dataset};
#[derive(Datapoint)]
struct MyDatapoint(String, usize, f64);
let dp1 = MyDatapoint("Hello".to_owned(), 4, 10.2);
let dp2 = MyDatapoint("World".to_owned(), 5, 3.14);
let dataset = Dataset::from_datapoints([dp1, dp2]);
dataset.save("./path/to/file.csv").unwrap();
Hopefully this will be expanded upon in the future to allow for more ergonomic constructors.