Fixed writing of nodepos to assert ds type + added subdata function
This commit is contained in:
parent
56a572c4ee
commit
9e4f86c557
|
@ -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):
|
||||||
|
|
Reference in New Issue