| |
- builtins.object
-
- FilterABC
class FilterABC(builtins.object) |
|
Abstract base class for making spectral filter plugins
Example:
from filterabc import FilterABC
from umetrics import SimcaApp
class CompleteCommand(FilterABC):
def __init__(self):
";
self.name = My filter
self.prefix = MF
self.generates_new_variables = False
def transform(self, data, options, settings):
transformed_data ...........(data)
return transformed_data |
|
Methods defined here:
- get_variable_name(self, options, column)
- Optional
if generates_new_variables returns True, simca will call this function to enable setting a custom name for each column.
options are the same values as returned by the setup function.
column is the column index 0, 1,.....
ex;
mean = options; #in the setup example we stored averages in option, we can use that as names
return str(mean[column])
- settings(self)
- Optional
A function to retrieve the filter properties the end of this file for mor information on fthe xml format, this function should return the default settings.
and the modified string is then passed to the transform function.
more information is available on wwww.umetrics.com in the knowledgebase artickle Q638 SIMCA extensible spectral filter support.
ex;
root = ET.Element('PluginSettings')
b = ET.SubElement(root, 'Categories')
c = ET.SubElement(b, 'Category',{'text':'Cathegory1', 'description': 'Cathergory1 description', 'expanded': 'true'})
d = ET.SubElement(c, 'Settings')
e = ET.SubElement(d, 'Setting',{'text':'Setting1', 'description':'Setting1 description', 'default':'2', 'min':'1', 'max':'10', 'value':""})
return ET.tostring(root)
- setup(self, data, names, xml_settings='')
- Optional
setup is called when the filter is created so the script can setup custom options,
the options are then saved in the project and passed as arguments to the transform function both for predictions and for workset.
the return values must either be 'bytes' objects or be possible to pickle.
data_collection: the input, an object of type umetrics.simca.DataCollection
names: the variable names before transformation
xml_settings: the string returned by settings and then modified by the filter wizard in simca, see settings(...)
ex;
data = data_collection.get_data()
meanrow1 = float(sum(data[0])) / max(len(data[0])]
return meanrow1
- summary(self, options)
- Optional
Return a html formatted string with information of the performed transform
- transform(self, data, options, predicting)
- The function that performs the actual transform
data_collection: the input, an object of type umetrics.simca.DataCollection
options: the values returned by the "setup".
predicting: False when creating the dataset for the first time and True when creating predictions for a model.
the function should return a matrix with transformed data for example a list of lists [][] or a UmPyMat with the same size as the input matrix (the number of columns can be different if you return true in generates_new_variables)
parse the settings for example like this
in this case we have options as an xml string but it can be anything that is possible to pickle
import xml.etree.ElementTree as ET
root = ET.fromstring(xml_settings)
Value = 2
Setting = root.find(".Categories/Category/Settings/Setting")
if Setting is not None:
try:
Value = int(Setting.get('value'))
except:
try:
Value = int(Setting.get('default'))
except:
pass
data = data_collection.get_data()
filtered_data = [[x+value for x in row] for row in data]
return filtered_data
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes defined here:
- __abstractmethods__ = frozenset({'transform'})
- generates_new_variables = False
- name = 'MyPlugin'
- prefix = ''
- requirements = ''
| |