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

38 lines
947 B
Plaintext
Raw Normal View History

#!/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)