Hello everyone,
I wrote a very simple dataset plugin which shifts a dataset so that the dataset
starts with 0. Mostly useful to shift a time axis (x axis) that doesn't start
with t=0 at the beginning of the measurement.
Notice that this can be done with builtin features, but it is not as easy:
- define a function "start = lambda x: x[0]", then
- create a new dataset "newdataset = olddataset - start(olddataset)").
------------ plugin start ------------
import veusz.plugins as plugins
class ZeroShiftDatasetPlugin(plugins.DatasetPlugin):
"""Dataset plugin to shift a dataset, so that it starts at 0."""
# tuple of strings to build position on menu
menu = ('Compute', 'Shift by first value...')
# internal name for reusing plugin later
name = 'ZeroShift'
# string which appears in status bar
description_short = 'Shift dataset by its first value'
# string goes in dialog box
description_full = ('Shift a dataset by its first value. '
'The new dataset starts with zero.')
def __init__(self):
"""Define input fields for plugin."""
self.fields = [
plugins.FieldDataset('ds_in', 'Input dataset'),
plugins.FieldDataset('ds_out', 'Output dataset name'),
]
def getDatasets(self, fields):
"""Returns single output dataset (self.dsout).
This method should return a list of Dataset objects, which can include
Dataset1D, Dataset2D and DatasetText
"""
# raise DatasetPluginException if there are errors
if fields['ds_out'] == '':
raise plugins.DatasetPluginException('Invalid output dataset name')
# make a new dataset with name in fields['ds_out']
self.ds_out = plugins.Dataset1D(fields['ds_out'])
# return list of datasets
return [self.ds_out]
def updateDatasets(self, fields, helper):
"""Do shifting of dataset.
This function should *update* the dataset(s) returned by getDatasets
"""
# get the input dataset - helper provides methods for getting other
# datasets from Veusz
ds_in = helper.getDataset(fields['ds_in'])
newdata = ds_in.data - ds_in.data[0]
# update output dataset with offset input dataset and errorbars
self.ds_out.update(data=newdata,
serr=ds_in.serr, perr=ds_in.perr, nerr=ds_in.nerr)
# add plugin classes to this list to get used
plugins.datasetpluginregistry.append(ZeroShiftDatasetPlugin)
------------ plugin end ------------
Cheers,
Gaël
_______________________________________________
Veusz-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/veusz-discuss