Source code for tvb.adapters.forms.equation_forms

# -*- coding: utf-8 -*-
# TheVirtualBrain-Framework Package. This package holds all Data Management, and
# Web-UI helpful to run brain-simulations. To use it, you also need to download
# TheVirtualBrain-Scientific Package (for simulators). See content of the
# documentation-folder for more details. See also
# (c) 2012-2024, Baycrest Centre for Geriatric Care ("Baycrest") and others
# This program is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.  See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this
# program.  If not, see <>.
# When using The Virtual Brain for scientific publications, please cite it as explained here:

from tvb.datatypes.equations import *
from tvb.core.neotraits.forms import Form, FloatField, LabelField
from tvb.basic.neotraits.api import Float

[docs] class SpatialEquationsEnum(EquationsEnum): GAUSSIAN = (Gaussian, "Gaussian") MEXICAN_HAT = (DoubleGaussian, "Mexican-hat") SIGMOID = (Sigmoid, "Sigmoid") DISCRETE = (DiscreteEquation, "Discrete Equation")
[docs] class TemporalEquationsEnum(EquationsEnum): LINEAR = (Linear, "Linear") GAUSSIAN = (Gaussian, "Gaussian") MEXICAN_HAT = (DoubleGaussian, "Mexican-hat") SIGMOID = (Sigmoid, "Sigmoid") GENERALIZEDSIGMOID = (GeneralizedSigmoid, "GeneralizedSigmoid") SINUSOID = (Sinusoid, "Sinusoid") COSINE = (Cosine, "Cosine") ALPHA = (Alpha, "Alpha") PULSETRAIN = (PulseTrain, "PulseTrain")
[docs] class SurfaceModelEquationsEnum(TupleEnum): GAUSSIAN = (Gaussian, "Gaussian") SIGMOID = (Sigmoid, "Sigmoid")
[docs] class BoldMonitorEquationsEnum(EquationsEnum): Gamma_KERNEL = (Gamma, "Hrf Kernel: Gamma Kernel") DOUBLE_EXPONENTIAL_KERNEL = (DoubleExponential, "Hrf Kernel: Difference of Exponential") VOLTERRA_KERNEL = (FirstOrderVolterra, "Hrf Kernel: Volterra Kernel") MOG_KERNEL = (MixtureOfGammas, "Hrf Kernel: Mixture Of Gammas")
[docs] class TransferVectorEquationsEnum(EquationsEnum): IDENTITY = (Identity, "Identity") LINEAR = (Linear, "Linear") LINEAR_INTERVAL = (RescaleInterval, "Rescale to Interval") ABSOLUTE = (Absolute, "Absolute") LOGARITHM = (Logarithm, "Logarithm")
[docs] def get_ui_name_to_monitor_equation_dict(): eq_name_to_class = { 'HRF kernel: Gamma kernel': Gamma, 'HRF kernel: Difference of Exponential': DoubleExponential, 'HRF kernel: Volterra Kernel': FirstOrderVolterra, 'HRF kernel: Mixture of Gammas': MixtureOfGammas } return eq_name_to_class
[docs] def get_equation_to_form_dict(): coupling_class_to_form = { Linear: LinearEquationForm, RescaleInterval: RescaleIntervalEquationForm, Absolute: AbsoluteEquationForm, Identity: IdentityEquationForm, Logarithm: LogarithmEquationForm, Gaussian: GaussianEquationForm, DoubleGaussian: DoubleGaussianEquationForm, Sigmoid: SigmoidEquationForm, GeneralizedSigmoid: GeneralizedSigmoidEquationForm, Sinusoid: SinusoidEquationForm, Cosine: CosineEquationForm, Alpha: AlphaEquationForm, PulseTrain: PulseTrainEquationForm, Gamma: GammaEquationForm, DoubleExponential: DoubleExponentialEquationForm, FirstOrderVolterra: FirstOrderVolterraEquationForm, MixtureOfGammas: MixtureOfGammasEquationForm } return coupling_class_to_form
[docs] def get_form_for_equation(equation_class): return get_equation_to_form_dict().get(equation_class)
[docs] class EquationForm(Form):
[docs] @staticmethod def get_subform_key(): return 'EQUATION'
[docs] def get_traited_equation(self): return Equation
def __init__(self): super(EquationForm, self).__init__() traited_equation = self.get_traited_equation().equation self.equation = LabelField(traited_equation, traited_equation.doc) for param_key, param in self.get_traited_equation().parameters.default().items(): setattr(self, param_key, FloatField(Float(label=param_key, default=param), name=param_key))
[docs] def fill_from_post(self, form_data): for field in self.fields: if in form_data: field.fill_from_post(form_data)
[docs] def fill_trait_partially(self, datatype, fields=None): if fields is None: fields = [] for field_str in fields: datatype.parameters[field_str] = getattr(self, field_str).value
[docs] def fill_trait(self, datatype): for param_key in datatype.parameters.keys(): datatype.parameters[param_key] = getattr(self, param_key).value
[docs] def fill_from_trait(self, trait): for param_key in self.get_traited_equation().parameters.default().keys(): getattr(self, param_key).data = trait.parameters[param_key]
[docs] class LinearEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Linear
[docs] class RescaleIntervalEquationForm(EquationForm):
[docs] def get_traited_equation(self): return RescaleInterval
[docs] class AbsoluteEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Absolute
[docs] class IdentityEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Identity
[docs] class LogarithmEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Logarithm
[docs] class GaussianEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Gaussian
[docs] class DoubleGaussianEquationForm(EquationForm):
[docs] def get_traited_equation(self): return DoubleGaussian
[docs] class SigmoidEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Sigmoid
[docs] class GeneralizedSigmoidEquationForm(EquationForm):
[docs] def get_traited_equation(self): return GeneralizedSigmoid
[docs] class SinusoidEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Sinusoid
[docs] class CosineEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Cosine
[docs] class AlphaEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Alpha
[docs] class PulseTrainEquationForm(EquationForm):
[docs] def get_traited_equation(self): return PulseTrain
[docs] class GammaEquationForm(EquationForm):
[docs] def get_traited_equation(self): return Gamma
[docs] class DoubleExponentialEquationForm(EquationForm):
[docs] def get_traited_equation(self): return DoubleExponential
[docs] class FirstOrderVolterraEquationForm(EquationForm):
[docs] def get_traited_equation(self): return FirstOrderVolterra
[docs] class MixtureOfGammasEquationForm(EquationForm):
[docs] def get_traited_equation(self): return MixtureOfGammas