Beispiel #1
0
 def evaluateSegments(self, nodeList, startStep=0):
     """Evaluate the list of nodes in nodeList.
     Args:
         nodeList: list of nodes to evaluate
         startStep: the step number at which evaluation starts
     Returns:
         startStep, sampleList: The step at which the next waveform begins, together with a list of samples
     """
     sampleList = numpy.array([])
     for node in nodeList:
         if node.enabled:
             if node.nodeType == nodeTypes.segment:
                 duration = self.settings.varDict[
                     node.duration]['value'] if isIdentifier(
                         node.duration
                     ) else self.expression.evaluateAsMagnitude(
                         node.duration)
                 startStep, newSamples = self.evaluateEquation(
                     node, duration, startStep)
                 sampleList = numpy.append(sampleList, newSamples)
             elif node.nodeType == nodeTypes.segmentSet:
                 repMag = self.settings.varDict[
                     node.repetitions]['value'] if isIdentifier(
                         node.repetitions
                     ) else self.expression.evaluateAsMagnitude(
                         node.repetitions)
                 repetitions = int(repMag.to_base_units().val
                                   )  #convert to float, then to integer
                 for n in range(repetitions):
                     startStep, newSamples = self.evaluateSegments(
                         node.children, startStep)  #recursive
                     sampleList = numpy.append(sampleList, newSamples)
     return startStep, sampleList
Beispiel #2
0
 def updateSegmentDependencies(self, nodeList):
     for node in nodeList:
         if node.nodeType==nodeTypes.segment:
             node.stack = node.expression._parse_expression(node.equation)
             nodeDependencies = node.expression.findDependencies(node.stack)
             self.dependencies.update(nodeDependencies)
             if isIdentifier(node.duration):
                 self.dependencies.add(node.duration)
         elif node.nodeType==nodeTypes.segmentSet:
             if isIdentifier(node.repetitions):
                 self.dependencies.add(node.repetitions)
             self.updateSegmentDependencies(node.children) #recursive
Beispiel #3
0
 def updateSegmentDependencies(self, nodeList):
     for node in nodeList:
         if node.nodeType == nodeTypes.segment:
             node.stack = node.expression._parse_expression(node.equation)
             nodeDependencies = node.expression.findDependencies(node.stack)
             self.dependencies.update(nodeDependencies)
             if isIdentifier(node.duration):
                 self.dependencies.add(node.duration)
         elif node.nodeType == nodeTypes.segmentSet:
             if isIdentifier(node.repetitions):
                 self.dependencies.add(node.repetitions)
             self.updateSegmentDependencies(node.children)  #recursive
Beispiel #4
0
 def addVariable(self, name, categories=None):
     """Add a new global variable"""
     if name == "":
         name = 'NewGlobalVariable'
     if name not in self._globalDict_ and isIdentifier(name):
         newGlobal = GlobalVariable(name, Q(0))
         newGlobal.categories = categories
         newGlobal.valueChanged.connect(self.onValueChanged)
         node = self.addNode(newGlobal)
         self._globalDict_[name] = newGlobal
         return node
 def addVariable(self, name, categories=None):
     """Add a new global variable"""
     if name=="":
         name = 'NewGlobalVariable'
     if name not in self._globalDict_ and isIdentifier(name):
         newGlobal = GlobalVariable(name, Q(0))
         newGlobal.categories = categories
         newGlobal.valueChanged.connect(self.onValueChanged)
         node = self.addNode(newGlobal)
         self._globalDict_[name] = newGlobal
         return node
Beispiel #6
0
 def evaluateSegments(self, nodeList, startStep=0):
     """Evaluate the list of nodes in nodeList.
     Args:
         nodeList: list of nodes to evaluate
         startStep: the step number at which evaluation starts
     Returns:
         startStep, sampleList: The step at which the next waveform begins, together with a list of samples
     """
     sampleList = numpy.array([])
     for node in nodeList:
         if node.enabled:
             if node.nodeType==nodeTypes.segment:
                 duration = self.settings.varDict[node.duration]['value'] if isIdentifier(node.duration) else self.expression.evaluateAsMagnitude(node.duration)
                 startStep, newSamples = self.evaluateEquation(node, duration, startStep)
                 sampleList = numpy.append(sampleList, newSamples)
             elif node.nodeType==nodeTypes.segmentSet:
                 repMag = self.settings.varDict[node.repetitions]['value'] if isIdentifier(node.repetitions) else self.expression.evaluateAsMagnitude(node.repetitions)
                 repetitions = int(repMag.to_base_units().val) #convert to float, then to integer
                 for n in range(repetitions):
                     startStep, newSamples = self.evaluateSegments(node.children, startStep) #recursive
                     sampleList = numpy.append(sampleList, newSamples)
     return startStep, sampleList
 def setValue(self, index, value, key):
     row = index.row()
     column = index.column()
     if value in self.globalDict:
         logging.getLogger(__name__).warning("'{0}' is already a global variable name".format(value))
         return False
     elif not isIdentifier(value):
         logging.getLogger(__name__).warning("'{0}' is not a valid variable name".format(value))
         return False
     else:
         self.segmentList[row][key] = value
         self.dataChanged.emit(index, index)
         self.segmentChanged.emit(self.channel, row, column, value)
         self.settings.saveIfNecessary()
         return True
Beispiel #8
0
 def setValue(self, index, value, key):
     row = index.row()
     column = index.column()
     if value in self.globalDict:
         logging.getLogger(__name__).warning(
             "'{0}' is already a global variable name".format(value))
         return False
     elif not isIdentifier(value):
         logging.getLogger(__name__).warning(
             "'{0}' is not a valid variable name".format(value))
         return False
     else:
         self.segmentList[row][key] = value
         self.dataChanged.emit(index, index)
         self.segmentChanged.emit(self.channel, row, column, value)
         self.settings.saveIfNecessary()
         return True
 def setName(self, index, value):
     """Change the name of a global variable"""
     node = self.nodeFromIndex(index)
     var = node.content
     newName = value.strip()
     if var.name != newName:
         if isIdentifier(newName):
             del self._globalDict_[var.name]
             try:
                 var.name = newName
             except HistoryException as e:
                 logging.getLogger(__name__).warning(str(e))
             self._globalDict_[newName] = var
             return True
         else:
             logging.getLogger(__name__).warning("'{0}' is not a valid identifier".format(newName))
             return False
     return True
 def setValue(self, index, value, key):
     node = self.nodeFromIndex(index)
     if (node.nodeType==nodeTypes.segment and (key=='equation' or key=='duration')) or \
             (node.nodeType==nodeTypes.segmentSet and key=='repetitions'):
         strvalue = str(value)
         if strvalue in self.globalDict:
             logging.getLogger(__name__).warning("'{0}' is already a global variable name".format(strvalue))
             return False
         elif (not isIdentifier(strvalue)) and (not isValueExpression(strvalue)) and index.column()!=self.column.equation:
             logging.getLogger(__name__).warning("'{0}' is not a valid variable name or value".format(strvalue))
             return False
         else:
             setattr(node, key, strvalue)
             self.dataChanged.emit(index, index)
             self.segmentChanged.emit()
             self.settings.saveIfNecessary()
             return True
     else:
         return False
Beispiel #11
0
 def setName(self, index, value):
     """Change the name of a global variable"""
     node = self.nodeFromIndex(index)
     var = node.content
     newName = value.strip()
     if var.name != newName:
         if isIdentifier(newName):
             del self._globalDict_[var.name]
             try:
                 var.name = newName
             except HistoryException as e:
                 logging.getLogger(__name__).warning(str(e))
             self._globalDict_[newName] = var
             return True
         else:
             logging.getLogger(__name__).warning(
                 "'{0}' is not a valid identifier".format(newName))
             return False
     return True
 def setValue(self, index, value, key):
     node = self.nodeFromIndex(index)
     if (node.nodeType==nodeTypes.segment and (key=='equation' or key=='duration')) or \
             (node.nodeType==nodeTypes.segmentSet and key=='repetitions'):
         strvalue = str(value)
         if strvalue in self.globalDict:
             logging.getLogger(__name__).warning(
                 "'{0}' is already a global variable name".format(strvalue))
             return False
         elif (not isIdentifier(strvalue)) and (not isValueExpression(
                 strvalue)) and index.column() != self.column.equation:
             logging.getLogger(__name__).warning(
                 "'{0}' is not a valid variable name or value".format(
                     strvalue))
             return False
         else:
             setattr(node, key, strvalue)
             self.dataChanged.emit(index, index)
             self.segmentChanged.emit()
             self.settings.saveIfNecessary()
             return True
     else:
         return False