Changed how the selection list works. CategoryDatasets can be dragged down to
the selection list, and will then be converted to Selections.
This commit is contained in:
@@ -136,20 +136,23 @@ class Dataset:
|
||||
return self._all_dims
|
||||
|
||||
def get_dim_name(self,axis=None):
|
||||
"""Returns dim name for an axis, if no axis is provided it returns a list of dims"""
|
||||
"""Returns dim name for an axis, if no axis is provided it
|
||||
returns a list of dims"""
|
||||
if type(axis)==int:
|
||||
return self._dims[axis]
|
||||
else:
|
||||
return [dim for dim in self]
|
||||
|
||||
def get_identifiers(self, dim, indices=None,sorted=False):
|
||||
"""Returns identifiers along dim, sorted by position (index) is optional.
|
||||
"""Returns identifiers along dim, sorted by position (index)
|
||||
is optional.
|
||||
|
||||
You can optionally provide a list/ndarray of indices to get only the
|
||||
identifiers of a given position.
|
||||
You can optionally provide a list/ndarray of indices to get
|
||||
only the identifiers of a given position.
|
||||
|
||||
Identifiers are the unique names (strings) for a variable in a given dim.
|
||||
Index (Indices) are the Identifiers position in a matrix in a given dim.
|
||||
Identifiers are the unique names (strings) for a variable in a
|
||||
given dim. Index (Indices) are the Identifiers position in a
|
||||
matrix in a given dim.
|
||||
"""
|
||||
try:
|
||||
if len(indices)==0:# if empty list or empty array
|
||||
@@ -170,18 +173,22 @@ class Dataset:
|
||||
def get_indices(self, dim, idents=None):
|
||||
"""Returns indices for identifiers along dimension.
|
||||
|
||||
You can optionally provide a list of identifiers to retrieve a index subset.
|
||||
You can optionally provide a list of identifiers to retrieve a
|
||||
index subset.
|
||||
|
||||
|
||||
Identifiers are the unique names (strings) for a variable in a given dim.
|
||||
Index (Indices) are the Identifiers position in a matrix in a given dim.
|
||||
If none of the input identifiers are found an empty index is returned
|
||||
Identifiers are the unique names (strings) for a variable in a
|
||||
given dim. Index (Indices) are the Identifiers position in a
|
||||
matrix in a given dim. If none of the input identifiers are
|
||||
found an empty index is returned
|
||||
"""
|
||||
if idents==None:
|
||||
index = array_sort(self._map[dim].values())
|
||||
else:
|
||||
index = [self._map[dim][key] for key in idents if self._map[dim].has_key(key)]
|
||||
index = [self._map[dim][key]
|
||||
for key in idents if self._map[dim].has_key(key)]
|
||||
return asarray(index)
|
||||
|
||||
|
||||
class CategoryDataset(Dataset):
|
||||
"""The category dataset class.
|
||||
@@ -216,7 +223,8 @@ class CategoryDataset(Dataset):
|
||||
"""
|
||||
data={}
|
||||
for name,ind in self._map[self.get_dim_name(0)].items():
|
||||
data[name] = self.get_identifiers(self.get_dim_name(1),list(self._array[ind,:].nonzero()))
|
||||
data[name] = self.get_identifiers(self.get_dim_name(1),
|
||||
list(self._array[ind,:].nonzero()))
|
||||
self._dictlists = data
|
||||
self.has_dictlists = True
|
||||
return data
|
||||
@@ -226,9 +234,10 @@ class CategoryDataset(Dataset):
|
||||
"""
|
||||
ret_list = []
|
||||
for cat_name,ind in self._map[self.get_dim_name(1)].items():
|
||||
ids = self.get_identifiers(self.get_dim_name(0),self._array[:,ind].nonzero())
|
||||
ids = self.get_identifiers(self.get_dim_name(0),
|
||||
self._array[:,ind].nonzero()[0])
|
||||
selection = Selection(cat_name)
|
||||
selection.select(cat_name,ids)
|
||||
selection.select(self.get_dim_name(0), ids)
|
||||
ret_list.append(selection)
|
||||
return ret_list
|
||||
|
||||
@@ -242,6 +251,7 @@ class GraphDataset(Dataset):
|
||||
If the library NetworkX is installed, there is support for
|
||||
representing the graph as a NetworkX.Graph, or NetworkX.XGraph structure.
|
||||
"""
|
||||
|
||||
def __init__(self,array=None,identifiers=None,shape=None,all_dims=[],**kwds):
|
||||
Dataset.__init__(self,array=array,identifiers=identifiers,name='A')
|
||||
self.has_graph = False
|
||||
@@ -256,9 +266,9 @@ class GraphDataset(Dataset):
|
||||
return G
|
||||
|
||||
def _graph_from_adj_matrix(self,A,labels=None,nx_type='graph'):
|
||||
"""Creates a networkx graph class from adjacency matrix and ordered labels.
|
||||
nx_type = ['graph',['xgraph']]
|
||||
labels = None, results in string-numbered labels
|
||||
"""Creates a networkx graph class from adjacency matrix and
|
||||
ordered labels. nx_type = ['graph',['xgraph']] labels = None,
|
||||
results in string-numbered labels
|
||||
|
||||
"""
|
||||
import networkx as nx
|
||||
|
Reference in New Issue
Block a user