def test_sensorsmeg(self): dt = sensors.SensorsMEG() dt.configure() self.assertTrue(dt.has_orientation) self.assertEqual(dt.labels.shape, (151,)) self.assertEqual(dt.locations.shape, (151, 3)) self.assertEqual(dt.number_of_sensors, 151) self.assertEqual(dt.orientations.shape, (151, 3)) self.assertEqual(dt.sensors_type, 'MEG')
def test_sensorsmeg(self): dt = sensors.SensorsMEG(load_default=True) dt.configure() self.assertTrue(isinstance(dt, sensors.SensorsMEG)) self.assertTrue(dt.has_orientation) self.assertEqual(dt.labels.shape, (151, )) self.assertEqual(dt.locations.shape, (151, 3)) self.assertEqual(dt.number_of_sensors, 151) self.assertEqual(dt.orientations.shape, (151, 3)) self.assertEqual(dt.sensors_type, MEG_POLYMORPHIC_IDENTITY)
def test_sensorsmeg(self): dt = sensors.SensorsMEG(load_file="meg_151.txt.bz2") dt.configure() assert isinstance(dt, sensors.SensorsMEG) assert dt.has_orientation assert dt.labels.shape == (151,) assert dt.locations.shape == (151, 3) assert dt.number_of_sensors == 151 assert dt.orientations.shape == (151, 3) assert dt.sensors_type == MEG_POLYMORPHIC_IDENTITY
if __name__ == "__main__": from tvb.tests.library import setup_test_console_env setup_test_console_env() # Third party python libraries import numpy import unittest import itertools # From "The Virtual Brain" import tvb.datatypes.sensors as sensors from tvb.tests.library.base_testcase import BaseTestCase from tvb.simulator.lab import * from tvb.basic.traits.parameters_factory import get_traited_subclasses sens_meg = sensors.SensorsMEG() sens_eeg = sensors.SensorsEEG() class Simulator(object): """ Simulator test class """ def __init__(self): """ Initialise the structural information, coupling function, and monitors. """ #Initialise some Monitors with period in physical time
class MEG(Projection): "Forward solution monitor for magnetoencephalography (MEG)." _ui_name = "MEG" projection = ProjectionSurfaceMEG( default=None, label='Projection matrix', order=2, doc='Projection matrix to apply to sources.') sensors = sensors_module.SensorsMEG( label = "MEG Sensors", default = None, required = True, order=1, doc = """The set of MEG sensors for which the forward solution will be calculated.""") @classmethod def from_file(cls, sensors_fname='meg_brainstorm_276.txt', projection_fname='projection_meg_276_surface_16k.npy', **kwargs): return Projection.from_file.im_func(cls, sensors_fname, projection_fname, **kwargs) def analytic(self, loc, ori): """Compute single sphere analytic form of MEG lead field. Equation 25 of [Sarvas_1987]_.""" # the magnetic constant = 1.25663706 × 10-6 m kg s-2 A-2 (H/m) mu_0 = 1.25663706e-6 #mH/mm # r => sensor positions # r_0 => source positions # a => vector from sources_to_sensor # Q => source unit vectors r_0, Q = loc, ori centre = numpy.mean(r_0, axis=0)[numpy.newaxis, :] radius = 1.01 * max(numpy.sqrt(numpy.sum((r_0 - centre)**2, axis=1))) sensor_locations = self.sensors.locations.copy() sen_dis = numpy.sqrt(numpy.sum((sensor_locations)**2, axis=1)) sensor_locations = sensor_locations / sen_dis[:, numpy.newaxis] sensor_locations = sensor_locations * radius sensor_locations = sensor_locations + centre B_r = numpy.zeros((sensor_locations.shape[0], r_0.shape[0], 3)) for sensor_k in numpy.arange(sensor_locations.shape[0]): a = sensor_locations[sensor_k,:] - r_0 na = numpy.sqrt(numpy.sum(a**2, axis=1))[:, numpy.newaxis] rsk = sensor_locations[sensor_k,:][numpy.newaxis, :] nr = numpy.sqrt(numpy.sum(rsk**2, axis=1))[:, numpy.newaxis] F = a * (nr * a + nr**2 - numpy.sum(r_0 * rsk, axis=1)[:, numpy.newaxis]) adotr = numpy.sum((a / na) * rsk, axis=1)[:, numpy.newaxis] delF = ((na**2 / nr + adotr + 2.0 * na + 2.0 * nr) * rsk - (a + 2.0 * nr + adotr * r_0)) B_r[sensor_k, :] = ((mu_0 / (4.0 * numpy.pi * F**2)) * (numpy.cross(F * Q, r_0) - numpy.sum(numpy.cross(Q, r_0) * (rsk * delF), axis=1)[:, numpy.newaxis])) return numpy.sqrt(numpy.sum(B_r**2, axis=2)) def create_time_series(self, storage_path, connectivity=None, surface=None, region_map=None, region_volume_map=None): return TimeSeriesMEG(storage_path=storage_path, sensors=self.sensors, sample_period=self.period, title=' ' + self.__class__.__name__, **self._transform_user_tags())
import os import numpy import unittest import itertools from tvb.simulator.common import get_logger from tvb.simulator import simulator, models, coupling, integrators, monitors, noise from tvb.datatypes import connectivity, sensors from tvb.datatypes.cortex import Cortex from tvb.datatypes.local_connectivity import LocalConnectivity from tvb.datatypes.region_mapping import RegionMapping from tvb.basic.traits.parameters_factory import get_traited_subclasses from tvb.tests.library.base_testcase import BaseTestCase LOG = get_logger(__name__) sens_meg = sensors.SensorsMEG(load_default=True) sens_eeg = sensors.SensorsEEG(load_default=True) AVAILABLE_MODELS = get_traited_subclasses(models.Model) AVAILABLE_METHODS = get_traited_subclasses(integrators.Integrator) MODEL_CLASSES = AVAILABLE_MODELS.values() METHOD_NAMES = AVAILABLE_METHODS.keys() METHOD_NAMES.append('RungeKutta4thOrderDeterministic') class Simulator(object): """ Simulator test class """ def __init__(self): """