Skip to content

Working with Experimental Data

When working on scientific models, you rarely rely purely on analytical math. You often need to load empirical datasets (like thermodynamic tables, sensor logs, or material properties), interpolate them, and save your results.

Zigma has native, built-in support for reading, parsing, and interpolating CSV data while maintaining strict dimensional safety.


1. Interpolating Data Tables (CSV)

Zigma can import .csv files and automatically perform linear interpolation on the dataset.

Formatting the CSV

To ensure Zigma can attach physical dimensions to your data, your CSV headers must be strictly formatted as indicator [unit].

Let's create a sample thermodynamic dataset for steam and save it as steam.csv:

T [degC], P [bar], h_v [kJ/kg]
100, 1.013, 2256.5
110, 1.433, 2230.2
120, 1.985, 2202.6
130, 2.701, 2174.2

Loading and Querying the Table

You can load this table using the table keyword. Once loaded, use the in ... get ... as syntax to retrieve interpolated values. Zigma automatically understands the units defined in the CSV headers.

steam = table "steam.csv"

// T = 115 degC is not explicitly in the CSV, so Zigma interpolates it!
P_interp = in steam get P as T = 115 degC
h_interp = in steam get h_v as T = 115 degC

print "Pressure at 115°C: {P_interp}" // Outputs ~1.709 bar
print "Enthalpy at 115°C: {h_interp}" // Outputs ~2216.4 kJ/kg

Unit Safety

Because the header says P [bar], the variable P_interp is strictly typed as a Pressure dimension in bar. If you try to add P_interp to a Length variable, Zigma will throw a compile-time error!


2. Importing Raw Tensors

If you don't need headers or interpolation, and just want to load a raw matrix or vector of numbers, you can use the input keyword. You must explicitly declare the unit for the incoming data.

Formatting the input file

Raw tensor files use commas , to separate columns and semicolons ; to separate rows. Create a file named matrix.txt:

1, 2, 3, 4;
5, 6, 7, 8

Loading the tensor

// Loads a 2x4 matrix with the dimension of Length [meters]
m = input "matrix.txt" m

3. Exporting Results

Once your simulation is complete, you can easily dump the results of a tensor or scalar into a file using the output keyword.

results = [10.5, 12.2, 15.8] m/s

// Dumps the tensor to a text file
output results "output_velocities.txt"