Added dataset transpose option
This commit is contained in:
		| @@ -76,7 +76,7 @@ class Dataset: | ||||
|         """Return the identifers along the dimension dim.""" | ||||
|         return self._map[dim] | ||||
|  | ||||
|     def _create_identifiers(self,shape,all_dims): | ||||
|     def _create_identifiers(self, shape, all_dims): | ||||
|         """Creates dimension names and identifier names, and returns | ||||
|         identifiers.""" | ||||
|          | ||||
| @@ -141,7 +141,7 @@ class Dataset: | ||||
|         if type(axis)==int: | ||||
|             return self._dims[axis] | ||||
|         else: | ||||
|             return [dim for dim in self] | ||||
|             return [dim for dim in self._dims] | ||||
|  | ||||
|     def common_dims(self, ds): | ||||
|         """Returns a list of the common dimensions in the two datasets.""" | ||||
| @@ -220,6 +220,19 @@ class Dataset: | ||||
|         """ | ||||
|         return copy.deepcopy(self) | ||||
|  | ||||
|     def transpose(self): | ||||
|         """Returns a copy of transpose of a dataset. | ||||
|  | ||||
|         As for the moment: only support for 2D-arrays. | ||||
|         """ | ||||
|          | ||||
|         #assert(self._array==ndarray) | ||||
|         ds = self.copy() | ||||
|         ds._array = ds._array.T | ||||
|         ds._dims.reverse() | ||||
|         ds.shape = ds._array.shape | ||||
|         return ds | ||||
|      | ||||
|     def _validate_identifiers(self, identifiers): | ||||
|          | ||||
|         for dim_name, ids in identifiers:  | ||||
|   | ||||
| @@ -198,6 +198,11 @@ class NavigatorMenu(gtk.Menu): | ||||
|         self.append(self.save_item) | ||||
|         self.save_item.show() | ||||
|  | ||||
|         self.trans_item = gtk.MenuItem('Transpose') | ||||
|         self.trans_item.connect('activate', self.on_transpose, navigator) | ||||
|         self.append(self.trans_item) | ||||
|         self.trans_item.show() | ||||
|          | ||||
|         # Build plot menu | ||||
|         self.plot_menu = gtk.Menu() | ||||
|  | ||||
| @@ -286,4 +291,9 @@ class NavigatorMenu(gtk.Menu): | ||||
|         project.data_tree_insert(self.tree_iter, 'Histogram', plot, None, "black", icon) | ||||
|         plot.set_selection_listener(project.set_selection) | ||||
|         project._selection_observers.append(plot) | ||||
|          | ||||
|  | ||||
|     def on_transpose(self, item, navigator): | ||||
|         project = main.project | ||||
|         ds = self.dataset.transpose() | ||||
|         icon = fluents.icon_factory.get("dataset") | ||||
|         project.data_tree_insert(self.tree_iter, self.dataset.get_name()+".T", ds, None, "black", icon) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user