projectvectorabc
index
d:\um3\simca\releases\simca14dev\simca\projectvectorabc.py

Abstract base class and enums used to add new vector types to SIMCA written in Python.
Vectors implemented in Python will be available in the commands on the Plot/List tab and also for
coloring and sizing points in plots.
A Python vector is added to SIMCA by creating a python file containing a class that inherits ProjectVectorABC
that is placed in one of the directories that SIMCA searches for modules. To see which these directories are
or to add/remove directories, click 'Set paths' on the 'Developer tab'.
 
Example:
 
import projectvectorabc
import sys
import math
import umetrics
 
class SquareRootT(projectvectorabc.ProjectVectorABC):
    # Calculates the square root of the absolute value of t.
    def __init__(self):
        # \u221A is the unicode code point for the square root glyph
        self.name = "\u221A|t|"
        # The vector should be available when 'Variables and Scores' is selected in the Plot/List dialogs.
        self.vectortype = projectvectorabc.VectorType.variable_type
        self.help_string = "The square root of the absolute value of t."
        self.datasource = projectvectorabc.Datasource.model
 
    # See the ProjectVectorABC documentation for an explanation of the arguments
    def get_data(self, project, model, comp):
        # Get the scores (t) for the specified component and model.
        builder=project.data_builder()
        data=builder.create("t", model=model, comp=comp)
        m=data.matrix()
        # Calculate the square root of the absolute value
        for row in range(0, len(m)):
            for col in range(0, len(m[0])):
                m[row][col] = math.sqrt(math.fabs(m[row][col]))
        # The name of the series.
        names=["\u221A|" + name + "|" for name in data.series_names() ]
        # Return a new ProjectData with the transformed values.
        return umetrics.simca.ProjectData(m, data.get_value_ids(), names, project)
        
    # See the ProjectVectorABC documentation for an explanation of the arguments
    def get_ids(self, project, model, comp):
        # Since we just transform the values of t, we can use the same column identifiers as t.
        builder=project.data_builder()
        data=builder.create("t", model=model, comp=comp)
        return data.get_value_ids()

 
Classes
       
builtins.object
ProjectVectorABC
enum.Enum(builtins.object)
Datasource
VectorType

 
class Datasource(enum.Enum)
    Defines the source of a project vector. The source does not neccesarily indicate that the data
comes directly from that source, it can be a transformation of data from the source or data that
is associated with the source in some other way.
uninitialized  --- Only used to indicate that a variable hasn't been initialized to a valid value yet.
dataset        --- The source of the data is a dataset.
                   Project vectors with this source will be available in the plot/list dialogs when a
                   dataset is selected.
model          --- The source of the data is a model.
                   Project vectors with this source will be available in the plot/list dialogs when a
                   model is selected.
 
 
Method resolution order:
Datasource
enum.Enum
builtins.object

Data and other attributes defined here:
dataset = <Datasource.dataset: 1>
model = <Datasource.model: 2>
uninitialized = <Datasource.uninitialized: -1>

Data descriptors inherited from enum.Enum:
name
The name of the Enum member.
value
The value of the Enum member.

Data descriptors inherited from enum.EnumMeta:
__members__
Returns a mapping of member name->value.
 
This mapping lists all enum members, including aliases. Note that this
is a read-only view of the internal mapping.

 
class ProjectVectorABC(builtins.object)
    Abstract base class for project vectors.
 
Properties:
name        --- The short name of the data. This string will show up in the plot list dialog.
                The name should be short and can not contain blanks or comma (,).
                Must be set in the inherited class.
vectortype  --- See VectorType.
                Must be set in the inherited class.
datasource  --- See Datasource.
                Must be set in the inherited class.
help_string --- A short help string (one or two lines).
                Setting the help is optional.
 
  Methods defined here:
get_data(self, project)
This method must be implemented in the inherited class and must return a umetrics.simca.ProjectData object.
The inherited class can have other arguments than in the base class. SIMCA uses the names of the arguments
to evaluate what information the method needs to be able to produce the data.
 
Allowed argument names are:
self         --- This is mandatory and must be the first argument.
model        --- A model number.
comp         --- A (predictive) component number
comp_end     --- Used with 'comp' to specify a sequence of components from 'comp' to and including 'comp_end'.
comp_ortho_x --- An orthogonal component in the X block. Only available for OPLS and O2PLS models.
comp_ortho_y --- An orthogonal component in the Y block. Only available for OPLS and O2PLS models.
selcv        --- A cross validation group number.
variable     --- A variable name.
xvariable    --- The name of an X-variable in a model.
yvariable    --- The name of an Y-variabel in a model.
observation  --- An observation name.
project      --- The project associated with the data
dataset      --- A dataset number
 
Depending on what arguments the metod takes, controls in the Plot/List dialogs will be enabled to
select them.
 
Not all combinations of arguments are allowed:
model can not be combined with dataset.
comp_end must be used with comp.
observation and variable can not be used together.
xvariable and yvariable can only be used with models.
 
The order of the arguments are not important, just the names. get_data(model, project, comp)
and get_data(comp, model, project) will behave the same way.
get_ids(self, project)
This method must be implemented in the inherited class and must return a umetrics.simca.ValueIDs object.
See get_data for an explanation of the arguments. 
get_ids does not need to take all of the arguments of get_data, it can use a subset of them.
is_valid_dataset(self, project, dataset_info)
Override this method in the inherited class if the vector is only to be available
for certain datasets.
If the vector can be used with the dataset, return True, otherwise False.
is_valid_model(self, project, model_info)
Override this method in the inherited class if the vector is only to be available
for certain models.
If the vector can be used with the model, return True, otherwise False.
is_valid_project(self, project)
Override this method in the inherited class if the vector is only to be available
for certain projects.
If the vector can be used with the project, return True, otherwise False.

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(['get_data', 'get_ids'])
datasource = <Datasource.uninitialized: -1>
help_string = ''
name = ''
vectortype = <VectorType.uninitialized: -1>

 
class VectorType(enum.Enum)
    Defines the type of a project vector.
This determines what each value corresponds to.
uninitialized    --- Only used to indicate that a variable hasn't been initialized to a valid value yet.
variable_type    --- The vector will be available in the Plot/List dialogs if 'Variable and Scores'
                     is seelcted.
observation_type --- The vector will be available in the Plot/List dialogs if 'Observations and Loadings'
                     is selected.
 
 
Method resolution order:
VectorType
enum.Enum
builtins.object

Data and other attributes defined here:
observation_type = <VectorType.observation_type: 2>
uninitialized = <VectorType.uninitialized: -1>
variable_type = <VectorType.variable_type: 1>

Data descriptors inherited from enum.Enum:
name
The name of the Enum member.
value
The value of the Enum member.

Data descriptors inherited from enum.EnumMeta:
__members__
Returns a mapping of member name->value.
 
This mapping lists all enum members, including aliases. Note that this
is a read-only view of the internal mapping.