This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/bin/mat2ftsv
einarr ca51a0b382 Added mat2ftsv to naïvely convert matlab matrices to ftsv files. Works in at
least one case, but does not try to guess anything sensible for identifiers.
2007-10-31 17:43:02 +00:00

38 lines
947 B
Python
Executable File

#!/usr/bin/python
import sys
from getopt import getopt
def show_help():
print "mat2ftsv - Matlab matrix to fluents dataset converter."
print
print "Usage: mat2ftsv <mat-file> [<matfile> ...]"
print
print "Description: For each mat file given as input, a ftsv file"
print " will be created with the same name, but suffixed with.ftsv"
print " in addition to .mat or any other suffix already on the"
print " file name."
options, params = getopt(sys.argv[1:], 'h', ['help'])
for opt, val in options:
if opt in ['-h', '--help']:
show_help()
sys.exit(0)
if len(params) == 0:
show_help()
sys.exit(0)
from scipy import io
from numpy import ndarray
from fluents import dataset
fn_in = params[0]
data = io.loadmat(fn_in)
for key, value in data.items():
if isinstance(value, ndarray):
ds = dataset.Dataset(value, name=key)
dataset.write_ftsv(fn_in + '.ftsv', ds)