def add_experimental_plot(self, project, undolist=None): if undolist is None: undolist = project.journal ul = UndoList().describe("Experimental Plot") ds = Dataset() ds.key = pdict.unique_key(project.datasets, "exp_ds") ds.data = Table(ncols=2, nrows=5) ds.data[0] = [1,2,3,4,5] ds.data[1] = [1,4,9,16,25] ds2 = Dataset() ds2.key = pdict.unique_key(project.datasets, "exp_ds2") ds2.data = Table(ncols=2, nrows=4) ds2.data[0] = [10,17,3,8] ds2.data[1] = [1,89,48,1] plot = Plot() plot.key = pdict.unique_key(project.plots, "exp_plot") layer1 = Layer(type="line2d", lines=[Line(source=ds,cx=0,cy=1), Line(source=ds2,cx=0,cy=1)], x=0.0, y=0.0, width=1.0, height=0.5) layer2 = Layer(type="line2d", lines=[Line(source=ds2,cx=0,cy=1)], x=0.0, y=0.5, width=1.0, height=0.5) plot.layers = [layer1, layer2] project.add_datasets([ds,ds2], undolist=ul) project.add_plot(plot, undolist=ul) undolist.append(ul)
def add_experimental_plot(project, undolist=None): if undolist is None: undolist = project.journal ul = UndoList().describe("Experimental Plot") a = numpy.array( [(1,1), (2,4), (3,9), (4,16), (5,25)], dtype = {'names':['col1','col2'], 'formats':['f4','f4']} ) ds = Table(a) ds.infos['col2'].designation = 'Y' ds.key = pdict.unique_key(project.datasets, "exp_ds") a = numpy.array( [(10,12), (11,14), (13,-5), (16,8), (18,0)], dtype = {'names':['col3','col4'], 'formats':['f4','f4']} ) ds2 = Table(a) ds2.infos['col4'].designation = 'Y' ds2.key = pdict.unique_key(project.datasets, "exp_ds2") plot = Plot() plot.key = pdict.unique_key(project.plots, "exp_plot") layer1 = Layer(type="line2d", lines=[Line(source=ds,cx=0,cy=1), Line(source=ds2,cx=0,cy=1)], x=0.0, y=0.0, width=1.0, height=0.5) # layer2 = Layer(type="line2d", # lines=[Line(source=ds2,cx=0,cy=1)], # x=0.0, y=0.5, width=1.0, height=0.5) # plot.layers = [layer1, layer2] plot.layers = [layer1] project.add_datasets([ds,ds2], undolist=ul) #project.add_dataset(ds, undolist=ul) project.add_plot(plot, undolist=ul) undolist.append(ul)
def create_spc(self, dataset, undolist=None): """ Create new Plot from given Dataset, treating the Dataset as a SPC dataset. Returns the new Plot. """ project = self.app.project if undolist is None: undolist = project.journal table = dataset.data # TODO: check for Table p = Plot( key = pdict.unique_key(project.plots, "Spectrum %s" % dataset.key), layers = [Layer(type='line2d', lines=[Line( label=dataset.key, source=dataset, cx=1, cy=2 ) ], axes={'y' : Axis(scale="log", label='SIMS intensity (cts/sec)', start=10, format='%2.1e'), 'x' : Axis(scale="linear", label='mass (amu)')}, title=u"SIMS mass spectrum of %s" % dataset.key, ) ] ) project.add_plot(p, undolist=undolist)
def new_dataset(self, key='dataset', undolist=None): """ Add a new Dataset object to the Project. The `data` field contains a nearly empty numarray (1 row, 2 columns, all zero). If no key is given, then one is created. If the key already exists, then the method assures that it is unique within the Project. Returns newly created Dataset. """ if undolist is None: undolist = self.journal key = pdict.unique_key(self.datasets, key) ds = Dataset() pdict.setitem(self.datasets, key, ds) ds.data = Table(nrows=1,ncols=2) ds.data.column(0).designation = 'X' ds.data.column(1).designation = 'Y' self.sig_emit("notify::datasets") ui = UndoInfo(self.remove_objects, [ds], False) ui.describe("Create new Dataset '%s'" % key) undolist.append(ui) return ds
def create_spc(dataset, undolist=None): """ Create new Plot from given Dataset, treating the Dataset as a SPC dataset. Returns the new Plot. """ project = globals.app.project if undolist is None: undolist = project.journal table = dataset.get_data() # TODO: check for Table (get_table?) p = Plot( key = pdict.unique_key(project.plots, "spectrum_%s" % dataset.key), layers = [Layer(type='line2d', lines=[Line( label=dataset.key, source=dataset, cx=0, cy=1 ) ], yaxis = Axis(scale="log", label='SIMS intensity (cts/sec)', start=10, format='%2.1e'), xaxis = Axis(scale="linear", label='mass (amu)'), title=u"SIMS mass spectrum of %s" % dataset.key, ) ] ) project.add_plot(p, undolist=undolist)
def new_table(spj, element): # Create field infos formats = [] info_dict = {} for eColumn in element.findall("Column"): # name try: name = eColumn.attrib["name"] except KeyError: logger.warn("Could not get column name; using default name instead.") name = utils.unique_names(["col"], info_dict.keys()) # format try: format = eColumn.attrib["format"] except KeyError: logger.warn("Could not get column type, using default type instead.") format = "f4" formats.append(format) # create info with attributes info = Table.Info() for eAttribute in eColumn.findall("Attribute"): key = eAttribute.attrib["key"] value = eAttribute.text if value is not None: info.set_value(key, value) info_dict[name] = info # create table with given format and infos, but w/o any rows a = numpy.zeros((0,), {"names": info_dict.keys(), "formats": formats}) tbl = Table(a, info_dict) # node info for eItem in element.findall("NodeInfo/Item"): key = eItem.attrib["key"] value = eItem.text if value is not None: tbl.node_info.set_value(key, value) for eItem in element.findall("NodeInfo/MetaItem"): key = eItem.attrib["key"] value = eItem.text if value is not None: tbl.node_info.metadata[key] = value # table key is essential try: key = element.attrib["key"] except KeyError: logger.warn("Could not get table key. Using generic key instead.") key = pdict.unique_key(spj.datasets, "dataset") tbl.key = key # Right now, the Table is still empty. By setting this callback # for the _import attribute, the dataset is loaded from the hard # disk on the next access. tbl._import = DatasetImporter(spj.get_filename(), tbl.key) return tbl
def create_plot_from_datasets(self, datasets, plot_label=None, undolist=None): """ Creates a new plot from the list of given Datasets. >>> create_plot_from_datasets([ds1,ds2], 'my dataset') The method tries to guess, which lines to use as X/Y pairs, using the 'designation' given in the Dataset's tables. Returns the new plot. """ if undolist is None: undolist = self.journal if len(datasets) == 0: return if plot_label is None: plot_key = pdict.unique_key(self.plots, datasets[0].key) plot_label = plot_key lines = [] for dataset in datasets: dataset = self.get_dataset(dataset) # TODO: dataset.get_table() table = dataset.get_data() if not isinstance(table, Table): raise TypeError("Dataset %s has data, which is not a Table object, but %s" % (dataset, type(table)) ) cx = None j = -1 for column in table.get_columns(): j += 1 if cx is None: # skip if this is no X value if column.designation != 'X': continue else: cx = j else: # skip if this is no Y value if column.designation != 'Y': continue else: lines.append( Line(source=dataset, cx=cx, cy=j) ) cx = None if len(lines) == 0: logger.error("The Dataset contains no X/Y column pair.") return layer = Layer(lines=lines) plot = Plot(title=plot_label, key=plot_key, layers=[layer]) ui = UndoList().describe("Create Plot from Datasets") self.add_plots( [plot], undolist=ui ) undolist.append(ui) return plot
def create_plot_from_datasets(project, datasets, plot_label=None, undolist=None): """ Creates a new plot from the list of given Datasets. >>> create_plot_from_datasets([ds1,ds2], 'my dataset') The method tries to guess, which lines to use as X/Y pairs, using the 'designation' given in the Dataset's tables. Returns the new plot or None if not dataset was given or if the Plot could not be constructed. """ if undolist is None: undolist = project.journal ul = UndoList().describe("Create plot from datasets") if len(datasets) == 0: logger.error("No datasets given!") return if plot_label is None: plot_key = pdict.unique_key(project.plots, datasets[0].key) plot_label = plot_key lines = [] for dataset in datasets: cx = None j = -1 for name in dataset.names: info = dataset.infos[name] j += 1 if cx is None: # skip if this is no X value if info.designation != 'X': continue else: cx = j else: # skip if this is no Y value if info.designation != 'Y': continue else: lines.append(Line(source=dataset, cx=cx, cy=j)) cx = None if len(lines) == 0: raise SloppyError("The Dataset contains no X/Y column pair.") layer = Layer(lines=lines) plot = Plot(title=plot_label, key=plot_key, layers=[layer]) project.add_plots([plot], undolist=ul) undolist.append(ul) return plot
def new_plot(self, undolist=None): " Returns a new Plot. " if undolist is None: undolist = self.journal new_plot = globals.app.core.new_lineplot2d() new_plot.key = pdict.unique_key(self.plots, "new lineplot2d") self.add_plot(new_plot) ui = UndoInfo(self.remove_plot, new_plot).describe("New Plot") undolist.append(ui) return new_plot
def rename_plot(self, xn_plot, new_key, undolist=None): " Analogon to `rename_dataset`. " if undolist is None: undolist = self.journal plotlist = [plot for plot in self.plots] plot = self.get_plot(xn_plot) plotlist.remove(plot) new_key = pdict.unique_key(plotlist, new_key) uwrap.set(plot, 'key', new_key, undolist=undolist) return plot
def add_experimental_plot(self, project, undolist=None): if undolist is None: undolist = project.journal ul = UndoList().describe("Experimental Plot") ds = Dataset() ds.key = pdict.unique_key(project.datasets, "exp_ds") ds.data = Table(colcount=2, rowcount=5) ds.data[0] = [1,2,3,4,5] ds.data[1] = [1,4,9,16,25] ds2 = Dataset() ds2.key = pdict.unique_key(project.datasets, "exp_ds2") ds2.data = Table(colcount=2, rowcount=4) ds2.data[0] = [10,17,3,8] ds2.data[1] = [1,89,48,1] ulist.append( project.datasets, ds, undolist=ul ) ulist.append( project.datasets, ds2, undolist=ul ) plot = Plot() plot.key = pdict.unique_key(project.plots, "exp_plot") layer1 = Layer(type="line2d", lines=[Line(source=ds,cx=0,cy=1), Line(source=ds2)], x=0.0, y=0.0, width=1.0, height=0.5) layer2 = Layer(type="line2d", lines=[Line(source=ds2,cx=0,cy=1)], x=0.0, y=0.5, width=1.0, height=0.5) plot.layers = [layer1, layer2] # plot.layers.arrange(rowcount=1, colcount=2) ulist.append( project.plots, plot, undolist=ul ) uwrap.emit_last(project.datasets, "changed") undolist.append(ul)
def create_pfc(dataset, undolist=None): """ Create new Plot from given Dataset, treating the Dataset as a PFC dataset, i.e. column 0 = time for Element 1 column 1 = intensity for Element 1 column 2 = time for Element 2 column 3 = intensity for Element 2 ... Returns the new Plot. """ project = globals.app.project if undolist is None: undolist = project.journal table = dataset.get_data() # TODO: check for Table if table is None: logger.info("No dataset selected.") return if table.ncols % 2 == 1: logger.error("action_plot_profile_plot: Dataset '%s' has wrong shape." % dataset.key) return None lines = [] for i in range(int(table.ncols/2.0)): l = Line( source=dataset, cx=i*2, cy=i*2+1 ) lines.append(l) p = Plot( key = pdict.unique_key(project.plots, "profile_%s" % dataset.key), layers = [Layer(type='line2d', lines=lines, yaxis = Axis(scale="log", label='log SIMS intensity (cts/sec)', start=10, format='%L'), xaxis = Axis(scale="linear", label='time (sec)'), title=u"SIMS depth profile of %s" % dataset.key, legend = Legend(border=True, position='outside') ) ] ) project.add_plot(p, undolist=undolist)
def rename_plot(self, xn_plot, new_key, undolist=None): " Analogon to `rename_dataset`. " if undolist is None: undolist = self.journal plotlist = [plot for plot in self.plots] plot = self.get_plot(xn_plot) plotlist.remove(plot) new_key = pdict.unique_key(plotlist, new_key) ui = UndoInfo(self.rename_plot, plot, plot.key) ui.describe("Rename Plot") plot.key = new_key undolist.append(ui) Signals.emit(self, "notify::plots") return plot
def rename_dataset(self, xn_dataset, new_key, undolist=None): """ Rename a Dataset and make sure that its key is unique. The name might be modified so if the key is important to you, you might want to check it afterwards. Returns the Dataset. """ if undolist is None: undolist = self.journal dataset = self.get_dataset(xn_dataset) dslist = [ds for ds in self.datasets] dslist.remove(dataset) new_key = pdict.unique_key(dslist, new_key) uwrap.set(dataset, 'key', new_key, undolist=undolist) return dataset
def add_plots(self, plots, undolist=None): if undolist is None: undolist = self.journal if len(plots) == 0: undolist.append(NullUndo()) ul = UndoList() ul.describe("Append Plots to Project") for plot in plots: new_key = pdict.unique_key(self.plots, plot.key) if new_key != plot.key: uwrap.set(plot, 'key', new_key, undolist=ul) ulist.append(self.plots, plot, undolist=ul) undolist.append(ul) cli_logger.info("Added %d plot(s)." % len(plots) )
def add_datasets(self, datasets, undolist=None): if undolist is None: undolist = self.journal if len(datasets) == 0: undolist.append(NullUndo()) ul = UndoList() ul.describe("Append Dataset to Project") for dataset in datasets: new_key = pdict.unique_key(self.datasets, dataset.key) if new_key != dataset.key: uwrap.set(dataset, "key", new_key, undolist=ul) ulist.append(self.datasets, dataset, undolist=ul) uwrap.emit_last(self.datasets, "changed", undolist=ul) undolist.append(ul) cli_logger.info("Added %d dataset(s)." % len(datasets))
def rename_plot(self, xn_plot, new_key, undolist=None): " Analogon to `rename_dataset`. " if undolist is None: undolist = self.journal plotlist = [plot for plot in self.plots] plot = self.get_plot(xn_plot) plotlist.remove(plot) new_key = pdict.unique_key(plotlist, new_key) ui = UndoInfo(self.rename_plot, plot, plot.key) ui.describe("Rename Plot") try: plot.key = new_key except ValueError: globals.app.error_msg(MSG['invalid_key'] % new_key) return undolist.append(ui) return plot
def rename_dataset(self, xn_dataset, new_key, undolist=None): """ Rename a Dataset and make sure that its key is unique. The name might be modified so if the key is important to you, you might want to check it afterwards. Returns the Dataset. """ if undolist is None: undolist = self.journal dataset = self.get_dataset(xn_dataset) dslist = [ds for ds in self.datasets] dslist.remove(dataset) new_key = pdict.unique_key(dslist, new_key) ui = UndoInfo(self.rename_dataset, dataset, dataset.key) ui.describe("Rename Dataset") try: dataset.key = new_key except ValueError, msg: self.app.error_msg(DC['invalid_key'] % new_key) return
def rename_dataset(self, xn_dataset, new_key, undolist=None): """ Rename a Dataset and make sure that its key is unique. The name might be modified so if the key is important to you, you might want to check it afterwards. Returns the Dataset. """ if undolist is None: undolist = self.journal dataset = self.get_dataset(xn_dataset) dslist = [ds for ds in self.datasets] dslist.remove(dataset) new_key = pdict.unique_key(dslist, new_key) ui = UndoInfo(self.rename_dataset, dataset, dataset.key) ui.describe("Rename Dataset") dataset.key = new_key undolist.append(ui) Signals.emit(self, "notify::datasets") return dataset