# ahkab.csvlib¶

The csvlib module contains common routines for handling Comma Separated Values (CSV) or Tab Separated Values (TSV) files.

Functions:

1. MISC utilities

The separator can be selected setting:

csvlib.SEPARATOR = '\t' # default value

get_headers(filename)[source]

Reads the signals inside a file.

The order of the signals in the list corresponds to the order of the signals in the file.

Parameters:

filename : string
the path to the file from which the header is to be read

Returns:

get_headers_index(headers, load_headers=None, verbose=3)[source]

Creates a list of integers. Each element in the list is the COLUMN index of the signal according to the supplied headers.

Parameters:

the signal names, as returned by get_headers().
The headers for the data to be loaded. If not provided, all indeces will be returned.

Returns:

the header indeces : a list of int.

load_csv(filename, load_headers=None, nsamples=None, skip=0, verbose=3)[source]

Reads data in CVS format from filename.

Supports:

• skipping to a certain line, to allow incremental reading of big files.

Parameters:

filename : string
the path to the file to be read.
Each one being a signal to be loaded. An empty list (or None) is interpreted as “read all signals”.
nsamples : int, optional
The number of samples to be read for each signal. If None, read all available samples.
skip : int, optional
The index of the first sample to be read. Default: 0

Returns:

data : ndarray
The data, ordered according to the order of load_headers (or the order on file if load_headers was empty),
the names of the signals read from file,
pos : int
position of the last sample read +1, referred to the sample #0 in the file.
EOF : bool
A flag set to true is all the data in the file were read.
write_csv(filename, data, headers, append=False)[source]

Writes data in CVS format to filename.

The headers have to be ordered according to the data order.

Parameters:

filename : string
the path to the file to be written. Use ‘stdout’ to write to stdout
data : ndarray
The data to be written. Notice that variables are swept across rows, time samples are swept along columns. Or equivalently: data[variable_index, sample_number]
the signal names, ordered so that headers[i] corresponds to data[i, :].
write_headers(filename, headers)[source]