Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added function to save fluents tab separated values (ftsv) files.

This commit is contained in:
Einar Ryeng 2007-01-11 23:24:05 +00:00
parent e4d7f8e5a2
commit 08b7d8dd85
1 changed files with 30 additions and 0 deletions

View File

@ -383,6 +383,36 @@ class Selection(dict):
self[axis] = labels self[axis] = labels
def write_ftsv(fd, ds):
# Write header information
if isinstance(ds, CategoryDataset):
type = 'category'
elif isinstance(ds, GraphDataset):
type = 'network'
elif isinstance(ds, Dataset):
type = 'dataset'
else:
raise Exception("Unknown object")
print >> fd, "# type: %s" % type
for dim in ds.get_dim_name():
print >> fd, "# dimension: %s" % dim,
for id in ds.get_identifiers(dim, None, True):
print >> fd, id,
print >> fd
print >> fd, "# name: %s" % ds.get_name()
print >> fd
# Write data
m = ds.asarray()
y, x = m.shape
for j in range(y):
for i in range(x):
print >> fd, "%s\t" % m[j, i],
print >> fd
def read_ftsv(fd): def read_ftsv(fd):
split_re = re.compile('^#\s*(\w+)\s*:\s*(.+)') split_re = re.compile('^#\s*(\w+)\s*:\s*(.+)')
dimensions = [] dimensions = []