Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Fixed writing of nodepos to assert ds type + added subdata function

This commit is contained in:
Arnar Flatberg 2008-01-15 11:41:53 +00:00
parent 56a572c4ee
commit 9e4f86c557
1 changed files with 17 additions and 1 deletions

View File

@ -224,6 +224,22 @@ class Dataset(object):
""" """
return copy.deepcopy(self) return copy.deepcopy(self)
def subdata(self, dim, idents):
"""Returns a new dataset based on dimension and given identifiers.
"""
ds = self.copy()
indices = ds.get_indices(dim, idents)
ax = [i for i, name in enumerate(ds._dims) if name == dim][0]
subarr = ds._array.take(indices, ax)
for k, v in ds._map[dim].items():
if k not in idents:
del ds._map[dim][k]
ds.shape = tuple(len(ds._map[d]) for d in ds._dims)
ds.set_array(subarr)
return ds
def transpose(self): def transpose(self):
"""Returns a copy of transpose of a dataset. """Returns a copy of transpose of a dataset.
@ -569,7 +585,7 @@ def write_ftsv(fd, ds, decimals=7, sep='\t', fmt=None, sp_format=True):
fd.write("# name: %s" % ds.get_name() + '\n') fd.write("# name: %s" % ds.get_name() + '\n')
# xy-node-positions # xy-node-positions
if ds.nodepos != None: if type == 'network' and ds.nodepos != None:
fd.write("# nodepos:") fd.write("# nodepos:")
node_dim = ds.get_dim_name(0) node_dim = ds.get_dim_name(0)
for ident in ds.get_identifiers(node_dim, sorted=True): for ident in ds.get_identifiers(node_dim, sorted=True):