pybrainsim-activity Mailing List for PyBrainSim - The Brain Phantom Project
Status: Planning
Brought to you by:
rgoj
You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(123) |
Aug
(114) |
Sep
(44) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(9) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <rg...@us...> - 2010-08-05 17:36:07
|
Revision: 146 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=146&view=rev Author: rgoj Date: 2010-08-05 17:35:58 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Minor corrections so that lead field is calculated only once Modified Paths: -------------- trunk/src/Head.py trunk/src/HeadModelDipoleSphere.py Modified: trunk/src/Head.py =================================================================== --- trunk/src/Head.py 2010-06-30 08:42:36 UTC (rev 145) +++ trunk/src/Head.py 2010-08-05 17:35:58 UTC (rev 146) @@ -80,7 +80,7 @@ recording = [] for i in range(len(self.registrationSiteList)): recording.append([]) - + # Preparing a variable where the output of each of the generators will # be stored generatorOutput = [] Modified: trunk/src/HeadModelDipoleSphere.py =================================================================== --- trunk/src/HeadModelDipoleSphere.py 2010-06-30 08:42:36 UTC (rev 145) +++ trunk/src/HeadModelDipoleSphere.py 2010-08-05 17:35:58 UTC (rev 146) @@ -67,7 +67,7 @@ # How many generators and electrodes do we have? nGenerators = len(self.head.generatorSiteList) nElectrodes = len(self.head.registrationSiteList) - + # Assuming ideal conductivity sigma = 1.0 @@ -79,6 +79,7 @@ for iElectrode in range(nElectrodes): # Calculating the coordinates of the electrode in the Cartesian coordinates associated with the head + # The X axis points towards the right ear, while the Y axis points towards the front electrodeTheta = self.head.registrationSiteList[iElectrode][0] electrodePhi = self.head.registrationSiteList[iElectrode][1] xyzElectrodeHead = zeros(3); @@ -204,30 +205,37 @@ self.leadFieldFrank1952[iElectrode, iGenerator] = cosPsi * (( 1-pow(f,2.0) )/pow( 1+pow(f,2.0)-2*f*cosTheta, 3/2)-1) self.leadFieldFrank1952[iElectrode, iGenerator] += sinPsi*cosPhi/sinTheta* ( ( 3*f - 3*pow(f,2.0)*cosTheta + pow(f,3.0) - cosTheta )/pow(1+pow(f,2.0)-2*f*cosTheta,3/2) + cosTheta ) self.leadFieldFrank1952[iElectrode, iGenerator] = self.leadFieldFrank1952[iElectrode, iGenerator] / 4 /pi / sigma / self.radius / b + + # This is a nasty trick to make runHeadModel aware that the lead field has already been calculated + self.leadField = 1 def runHeadModel(self, generatorOutput, recording): # Calculating the lead field - self.calculateLeadField() + if self.leadField == 0: + self.calculateLeadField() # Calculating the recording by multyplying the lead field by the generator output - newRecording = dot(self.leadField, (array([generatorOutput])).transpose()) - newRecordingInfinite = dot(self.leadFieldInfinite, (array([generatorOutput])).transpose()) - newRecordingBrody1973 = dot(self.leadFieldBrody1973, (array([generatorOutput])).transpose()) - newRecordingFrank1952 = dot(self.leadFieldFrank1952, (array([generatorOutput])).transpose()) + #newRecording = dot(self.leadField, (array([generatorOutput])).transpose()) + #newRecordingInfinite = dot(self.leadFieldInfinite, (array([generatorOutput])).transpose()) + newRecordingBrody1973 = dot( self.leadFieldBrody1973, (array([generatorOutput])).transpose()) + #newRecordingFrank1952 = dot(self.leadFieldFrank1952, (array([generatorOutput])).transpose()) # Converting the new recording to list format for compatibility with rest of the code - newRecording = list(newRecording[:,0]) - newRecordingInfinite = list(newRecordingInfinite[:,0]) + #newRecording = list(newRecording[:,0]) + #newRecordingInfinite = list(newRecordingInfinite[:,0]) newRecordingBrody1973 = list(newRecordingBrody1973[:,0]) - newRecordingFrank1952 = list(newRecordingFrank1952[:,0]) + #newRecordingFrank1952 = list(newRecordingFrank1952[:,0]) - for i in range(len(newRecording)): + # Brody1973 rules, see comments below... + newRecording = newRecordingBrody1973 + + #for i in range(len(newRecording)): # All three of the lead field calculation methods implemented above can be used, however # only Brody1973 and Frank1952 give results in a bounded homogeneous conducting sphere, # and of these only Brody1973 gives results for all combinations of angles, etc. # Additionally, due to and arccos in my implementation above, Frank1952 for now gives even # worse results than it should for many angles... - newRecording[i] = newRecordingBrody1973[i] + #newRecording[i] = newRecordingBrody1973[i] #newRecording[i] = newRecordingFrank1952[i] #newRecording[i] = newRecordingInfinite[i] #newRecording[i] = (newRecordingBrody1973[i])/(newRecordingFrank1952[i]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-30 08:42:46
|
Revision: 145 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=145&view=rev Author: rgoj Date: 2010-06-30 08:42:36 +0000 (Wed, 30 Jun 2010) Log Message: ----------- * Modyfying the example of the use of the spherical head model to showcase it a little better. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-30 08:36:31 UTC (rev 144) +++ trunk/src/PyBrainSim.py 2010-06-30 08:42:36 UTC (rev 145) @@ -296,22 +296,25 @@ head3.setSamplingFrequency(1) # Adding registration sites - nElectrodes = 200 + nElectrodes = 201 angles = [] for i in range(nElectrodes): angles.append(i*numpy.pi/(nElectrodes-1) - numpy.pi/2) - head1.addRegistrationSite([angles[-1],numpy.pi/2]) - head2.addRegistrationSite([angles[-1],numpy.pi/2]) - head3.addRegistrationSite([angles[-1],numpy.pi/2]) + head1.addRegistrationSite([angles[-1],0]) + head2.addRegistrationSite([angles[-1],0]) + head3.addRegistrationSite([angles[-1],0]) # Adding a generator orientation1= 0; orientation2= numpy.pi/2; orientation3= numpy.pi/4; - generator1 = GeneratorNoisy('Gen', head1, position = [ 0.3, 0, orientation1, 0, 0], mean=1, stddev=0.1) - generator2 = GeneratorNoisy('Gen', head2, position = [ 0.3, 0, orientation2, 0, 0], mean=1, stddev=0.1) - generator3 = GeneratorNoisy('Gen', head3, position = [ 0.3, 0, orientation3, 0, 0], mean=1, stddev=0.1) + generator1 = GeneratorNoisy('Gen', head1, position = [ 4.0, 0, 0, orientation1, numpy.pi/2], mean=1, stddev=0.0) + generator2 = GeneratorNoisy('Gen', head2, position = [ 4.0, numpy.pi/4, 0, orientation2, numpy.pi/2], mean=1, stddev=0.0) + generator30 = GeneratorNoisy('Gen', head3, position = [ 4.0, 0, 0, orientation1, numpy.pi/2], mean=1, stddev=0.5) + generator31 = GeneratorNoisy('Gen', head3, position = [ 4.0, numpy.pi/4, 0, orientation2, numpy.pi/2], mean=3, stddev=0.5) + generator32 = GeneratorNoisy('Gen', head3, position = [ 4.0, -numpy.pi/4, 0, orientation3, numpy.pi/2], mean=2, stddev=0.5) + # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) simulatedData1 = numpy.array(head1.runSimulation(1)) simulatedData2 = numpy.array(head2.runSimulation(1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-30 08:36:37
|
Revision: 144 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=144&view=rev Author: rgoj Date: 2010-06-30 08:36:31 +0000 (Wed, 30 Jun 2010) Log Message: ----------- * Adding implementations of a dipole in a spherical head model ** First, and implementation of a lead field for a homogeneous infinite conductor ** Implementation of formulas from Brody 1973 ** Implementation of formulas from Frank 1952 (with problems, however!) ** Implementation can be selected by commenting out appropriate lines of code ** Brody 1973 is selected as the default implementation ** WARNING: All formulas are now being calculated each time a lead field is calculated - this is extremely resource consuming, something should be done about it. Modified Paths: -------------- trunk/src/HeadModelDipoleSphere.py Modified: trunk/src/HeadModelDipoleSphere.py =================================================================== --- trunk/src/HeadModelDipoleSphere.py 2010-06-27 19:43:32 UTC (rev 143) +++ trunk/src/HeadModelDipoleSphere.py 2010-06-30 08:36:31 UTC (rev 144) @@ -15,7 +15,7 @@ # PyBrainSim. If not, see <http://www.gnu.org/licenses/>. from __future__ import division -from numpy import arange, array, ones, identity, dot, zeros, sin, cos, pi, sqrt +from numpy import arange, array, ones, identity, dot, zeros, sin, cos, pi, sqrt, sum, arccos __metaclass__ = type # New style classes. Is this necessary? """ @@ -73,6 +73,9 @@ # The number of electrodes and generators defines the size of the lead field matrix self.leadField = zeros((nElectrodes,nGenerators)) + self.leadFieldInfinite = zeros((nElectrodes,nGenerators)) + self.leadFieldBrody1973 = zeros((nElectrodes,nGenerators)) + self.leadFieldFrank1952 = zeros((nElectrodes,nGenerators)) for iElectrode in range(nElectrodes): # Calculating the coordinates of the electrode in the Cartesian coordinates associated with the head @@ -84,6 +87,10 @@ xyzElectrodeHead[2] = self.radius * cos(electrodeTheta); for iGenerator in range(nGenerators): + # + # Infinite homogeneous conductor + # + # Calculating the coordinates of the dipole in the Cartesian coordinates associated with the head dipoleRadius = self.radius - self.head.generatorSiteList[iGenerator][0] dipoleTheta = self.head.generatorSiteList[iGenerator][1] @@ -102,24 +109,129 @@ distance += pow(xyzElectrodeDipole[1],2.0) distance += pow(xyzElectrodeDipole[2],2.0) distance = sqrt(distance) + + # Rotation matrix for translating the coordinates of the electrode in the dipole coordinates parallel + # to the reference coordinates at the center of the head to dipole coordinates where the dipole is specified + # i.e. where the z axis is radial. + rotationMatrix = zeros((3,3)); + dipoleTheta = self.head.generatorSiteList[iGenerator][1] + dipolePhi = self.head.generatorSiteList[iGenerator][2] + # Row 1 + rotationMatrix[0,0] = sin(dipolePhi) + rotationMatrix[0,1] = -cos(dipolePhi) + rotationMatrix[0,2] = 0 + # Row 2 + rotationMatrix[1,0] = cos(dipoleTheta) * cos(dipolePhi) + rotationMatrix[1,1] = cos(dipoleTheta) * sin(dipolePhi) + rotationMatrix[1,2] = -sin(dipoleTheta) + # Row 3 + rotationMatrix[2,0] = sin(dipoleTheta) * cos(dipolePhi) + rotationMatrix[2,1] = sin(dipoleTheta) * sin(dipolePhi) + rotationMatrix[2,2] = cos(dipoleTheta) + + rotationMatrixHeadToDipole = rotationMatrix - self.leadField[iElectrode, iGenerator] = 1.0 + # The Electrode coordinates in the dipole rotated frame of reference and scaleda + xyzElectrodeDipoleRotatedScaled = dot(rotationMatrix, xyzElectrodeDipole) / distance + # The Orientation vector + orientationTheta = self.head.generatorSiteList[iGenerator][3] + orientationPhi = self.head.generatorSiteList[iGenerator][4] + xyzOrientationDipoleRotated = zeros(3); + xyzOrientationDipoleRotated[0] = sin(orientationTheta) * cos(orientationPhi); + xyzOrientationDipoleRotated[1] = sin(orientationTheta) * sin(orientationPhi); + xyzOrientationDipoleRotated[2] = cos(orientationTheta); + + # The cosine of the angle between the dipole orientation and the electrode + cosAngleOrientationElectrode = sum(xyzElectrodeDipoleRotatedScaled * array(xyzOrientationDipoleRotated)) + + # Homogeneous conductor without boundaries + self.leadFieldInfinite[iElectrode, iGenerator] = cosAngleOrientationElectrode/distance/distance/4/pi/sigma + + # + # Bounded spherical conductor + # Brody 1973 + # + rCosPhi = dot(xyzElectrodeHead, xyzDipoleHead) / self.radius + #print rCosPhi + + fieldVector = zeros(3); + for i in range(3): + fieldVector[i] = 2*(xyzElectrodeHead[i] - xyzDipoleHead[i])/pow(distance,2.0) + fieldVector[i] += (1/pow(self.radius,2.0)) * (xyzElectrodeHead[i] + (xyzElectrodeHead[i] * rCosPhi - self.radius * xyzDipoleHead[i])/(distance + self.radius - rCosPhi)) + fieldVector[i] = fieldVector[i] / 4 / pi / sigma / distance + + # Rotation matrix for translating the coordinates in the dipole frame of reference to the + # coordinates associated with the dipole parallel to the head coordinates. + rotationMatrix = zeros((3,3)); + dipoleTheta = self.head.generatorSiteList[iGenerator][1] + dipolePhi = self.head.generatorSiteList[iGenerator][2] + # Row 1 + rotationMatrix[0,0] = sin(dipolePhi) + rotationMatrix[0,1] = cos(dipoleTheta) * cos(dipolePhi) + rotationMatrix[0,2] = sin(dipoleTheta) * cos(dipolePhi) + # Row 2 + rotationMatrix[1,0] = -cos(dipolePhi) + rotationMatrix[1,1] = cos(dipoleTheta) * sin(dipolePhi) + rotationMatrix[1,2] = sin(dipoleTheta) * sin(dipolePhi) + # Row 3 + rotationMatrix[2,0] = 0 + rotationMatrix[2,1] = -sin(dipoleTheta) + rotationMatrix[2,2] = cos(dipoleTheta) + + rotationMatrixDipoleToHead = rotationMatrix + + # Rotating Orientation to translated dipole coordinates + xyzOrientationDipole = dot(rotationMatrixDipoleToHead, xyzOrientationDipoleRotated) + + self.leadFieldBrody1973[iElectrode, iGenerator] = dot(fieldVector, xyzOrientationDipole) + + # + # Bounded spherical conductor + # Frank 1952 + # + xyzElectrodeDipoleRotated = dot(rotationMatrixHeadToDipole, xyzElectrodeHead) + # The below line causes problems because of arccos! + phi = arccos(xyzElectrodeDipoleRotated[0] / xyzElectrodeDipoleRotated[1]) - orientationPhi + cosPhi = cos(phi) + psi = orientationTheta + cosPsi = cos(psi) + sinPsi = sin(psi) + cosTheta = dot(xyzDipoleHead,xyzElectrodeHead) / sqrt(dot( xyzDipoleHead, xyzDipoleHead )) / sqrt(dot( xyzElectrodeHead, xyzElectrodeHead)) + sinTheta = sqrt(1-pow(cosTheta,2.0)) + b = self.radius - self.head.generatorSiteList[iGenerator][0] + f = b/self.radius + self.leadFieldFrank1952[iElectrode, iGenerator] = cosPsi * (( 1-pow(f,2.0) )/pow( 1+pow(f,2.0)-2*f*cosTheta, 3/2)-1) + self.leadFieldFrank1952[iElectrode, iGenerator] += sinPsi*cosPhi/sinTheta* ( ( 3*f - 3*pow(f,2.0)*cosTheta + pow(f,3.0) - cosTheta )/pow(1+pow(f,2.0)-2*f*cosTheta,3/2) + cosTheta ) + self.leadFieldFrank1952[iElectrode, iGenerator] = self.leadFieldFrank1952[iElectrode, iGenerator] / 4 /pi / sigma / self.radius / b + def runHeadModel(self, generatorOutput, recording): # Calculating the lead field self.calculateLeadField() - print self.leadField - print (array([generatorOutput])).transpose() - # Calculating the recording by multyplying the lead field by the generator output newRecording = dot(self.leadField, (array([generatorOutput])).transpose()) + newRecordingInfinite = dot(self.leadFieldInfinite, (array([generatorOutput])).transpose()) + newRecordingBrody1973 = dot(self.leadFieldBrody1973, (array([generatorOutput])).transpose()) + newRecordingFrank1952 = dot(self.leadFieldFrank1952, (array([generatorOutput])).transpose()) # Converting the new recording to list format for compatibility with rest of the code newRecording = list(newRecording[:,0]) + newRecordingInfinite = list(newRecordingInfinite[:,0]) + newRecordingBrody1973 = list(newRecordingBrody1973[:,0]) + newRecordingFrank1952 = list(newRecordingFrank1952[:,0]) - print newRecording - + for i in range(len(newRecording)): + # All three of the lead field calculation methods implemented above can be used, however + # only Brody1973 and Frank1952 give results in a bounded homogeneous conducting sphere, + # and of these only Brody1973 gives results for all combinations of angles, etc. + # Additionally, due to and arccos in my implementation above, Frank1952 for now gives even + # worse results than it should for many angles... + newRecording[i] = newRecordingBrody1973[i] + #newRecording[i] = newRecordingFrank1952[i] + #newRecording[i] = newRecordingInfinite[i] + #newRecording[i] = (newRecordingBrody1973[i])/(newRecordingFrank1952[i]) + for channel in range(len(recording)): recording[channel].append(newRecording[channel]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 19:43:38
|
Revision: 143 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=143&view=rev Author: rgoj Date: 2010-06-27 19:43:32 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Preparing for the presentation of dipoles with different rotations in the dipolar model example. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-27 17:14:44 UTC (rev 142) +++ trunk/src/PyBrainSim.py 2010-06-27 19:43:32 UTC (rev 143) @@ -281,33 +281,51 @@ def menuButton9(self, control): # head will hold sources, registrations sites and the head model - head = Head() + head1 = Head() + head2 = Head() + head3 = Head() # headModel will be our single sphere head model - headModel = HeadModelDipoleSphere(head, 10.0) + headModel1 = HeadModelDipoleSphere(head1, 10.0) + headModel2 = HeadModelDipoleSphere(head2, 10.0) + headModel3 = HeadModelDipoleSphere(head3, 10.0) # We need only one data point per simulation - head.setSamplingFrequency(1) + head1.setSamplingFrequency(1) + head2.setSamplingFrequency(1) + head3.setSamplingFrequency(1) # Adding registration sites nElectrodes = 200 angles = [] for i in range(nElectrodes): angles.append(i*numpy.pi/(nElectrodes-1) - numpy.pi/2) - head.addRegistrationSite([angles[-1],numpy.pi/2]) + head1.addRegistrationSite([angles[-1],numpy.pi/2]) + head2.addRegistrationSite([angles[-1],numpy.pi/2]) + head3.addRegistrationSite([angles[-1],numpy.pi/2]) # Adding a generator - orientation = 0; - generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, orientation, 0, 0], mean=1, stddev=0.1) + orientation1= 0; + orientation2= numpy.pi/2; + orientation3= numpy.pi/4; + generator1 = GeneratorNoisy('Gen', head1, position = [ 0.3, 0, orientation1, 0, 0], mean=1, stddev=0.1) + generator2 = GeneratorNoisy('Gen', head2, position = [ 0.3, 0, orientation2, 0, 0], mean=1, stddev=0.1) + generator3 = GeneratorNoisy('Gen', head3, position = [ 0.3, 0, orientation3, 0, 0], mean=1, stddev=0.1) # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) - simulatedData = numpy.array(head.runSimulation(1)) + simulatedData1 = numpy.array(head1.runSimulation(1)) + simulatedData2 = numpy.array(head2.runSimulation(1)) + simulatedData3 = numpy.array(head3.runSimulation(1)) - print(simulatedData) - pylab.plot(angles,simulatedData) + pylab.subplot(311) + pylab.plot(angles,simulatedData1) + pylab.title("Potential from superficial dipoles of different orientations") + pylab.subplot(312) + pylab.plot(angles,simulatedData2) + pylab.subplot(313) + pylab.plot(angles,simulatedData3) pylab.xlabel("Location of measurement on scalp [radians]") - pylab.ylabel("Potential on scalp [arbitrary units]") - pylab.title("Potential from superficial dipole of orientation " + str(orientation)) + pylab.ylabel("Scalp potential [relative]") pylab.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 17:14:50
|
Revision: 142 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=142&view=rev Author: rgoj Date: 2010-06-27 17:14:44 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Added a plot to the dipole spherical head model example. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-27 16:41:28 UTC (rev 141) +++ trunk/src/PyBrainSim.py 2010-06-27 17:14:44 UTC (rev 142) @@ -290,17 +290,25 @@ head.setSamplingFrequency(1) # Adding registration sites - nElectrodes = 20 + nElectrodes = 200 + angles = [] for i in range(nElectrodes): - head.addRegistrationSite([i*numpy.pi/(nElectrodes-1),numpy.pi/2]) + angles.append(i*numpy.pi/(nElectrodes-1) - numpy.pi/2) + head.addRegistrationSite([angles[-1],numpy.pi/2]) - # Adding generators - generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) + # Adding a generator + orientation = 0; + generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, orientation, 0, 0], mean=1, stddev=0.1) # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) simulatedData = numpy.array(head.runSimulation(1)) print(simulatedData) + pylab.plot(angles,simulatedData) + pylab.xlabel("Location of measurement on scalp [radians]") + pylab.ylabel("Potential on scalp [arbitrary units]") + pylab.title("Potential from superficial dipole of orientation " + str(orientation)) + pylab.show() def menuButtonQuit(self, control): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 16:41:35
|
Revision: 141 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=141&view=rev Author: rgoj Date: 2010-06-27 16:41:28 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Changes to dipole source example: ** No noise at level of electrode ** Easy to specify number of evenly spaced electrodes Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-27 16:33:45 UTC (rev 140) +++ trunk/src/PyBrainSim.py 2010-06-27 16:41:28 UTC (rev 141) @@ -290,24 +290,16 @@ head.setSamplingFrequency(1) # Adding registration sites - head.addRegistrationSite([-numpy.pi/2, numpy.pi/2]) - head.addRegistrationSite([-numpy.pi/4, numpy.pi/2]) - head.addRegistrationSite([0, numpy.pi/2]) - head.addRegistrationSite([numpy.pi/4, numpy.pi/2]) - head.addRegistrationSite([numpy.pi/2, numpy.pi/2]) + nElectrodes = 20 + for i in range(nElectrodes): + head.addRegistrationSite([i*numpy.pi/(nElectrodes-1),numpy.pi/2]) # Adding generators generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) - generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) - generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) - simulatedData = numpy.array(head.runSimulation(5)) + simulatedData = numpy.array(head.runSimulation(1)) - # Add Gaussian noise with mean 0 and variance 1 - electrodeNoise = numpy.random.normal(0, 0.0000001, simulatedData.shape); - simulatedData = simulatedData + electrodeNoise - print(simulatedData) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 16:33:51
|
Revision: 140 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=140&view=rev Author: rgoj Date: 2010-06-27 16:33:45 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Added an example usage of the work in progress dipole single sphere head model. This example will be modified later to actually show something interesting. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-27 15:56:09 UTC (rev 139) +++ trunk/src/PyBrainSim.py 2010-06-27 16:33:45 UTC (rev 140) @@ -38,11 +38,13 @@ from Head import Head from HeadModel import HeadModel from HeadModelHalfSphere import HeadModelHalfSphere +from HeadModelDipoleSphere import HeadModelDipoleSphere from Experiment import Experiment from Stimulus import Stimulus from StimulusDummy import StimulusDummy from GeneratorDummy import GeneratorDummy from GeneratorNumberIncrementing import GeneratorNumberIncrementing +from GeneratorNoisy import GeneratorNoisy from GeneratorSine import GeneratorSine from Connection import Connection from ConnectionDummy import ConnectionDummy @@ -61,6 +63,7 @@ self.frame.Bind(wx.EVT_BUTTON, self.menuButton6, id=xrc.XRCID("menuButton6")) self.frame.Bind(wx.EVT_BUTTON, self.menuButton7, id=xrc.XRCID("menuButton7")) self.frame.Bind(wx.EVT_BUTTON, self.menuButton8, id=xrc.XRCID("menuButton8")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton9, id=xrc.XRCID("menuButton9")) self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) self.frame.Show() @@ -276,6 +279,38 @@ pylab.plot(recording[i][firstPointToDisplay:]) pylab.show() + def menuButton9(self, control): + # head will hold sources, registrations sites and the head model + head = Head() + + # headModel will be our single sphere head model + headModel = HeadModelDipoleSphere(head, 10.0) + + # We need only one data point per simulation + head.setSamplingFrequency(1) + + # Adding registration sites + head.addRegistrationSite([-numpy.pi/2, numpy.pi/2]) + head.addRegistrationSite([-numpy.pi/4, numpy.pi/2]) + head.addRegistrationSite([0, numpy.pi/2]) + head.addRegistrationSite([numpy.pi/4, numpy.pi/2]) + head.addRegistrationSite([numpy.pi/2, numpy.pi/2]) + + # Adding generators + generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) + generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) + generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) + + # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) + simulatedData = numpy.array(head.runSimulation(5)) + + # Add Gaussian noise with mean 0 and variance 1 + electrodeNoise = numpy.random.normal(0, 0.0000001, simulatedData.shape); + simulatedData = simulatedData + electrodeNoise + + print(simulatedData) + + def menuButtonQuit(self, control): self.Exit() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 15:56:15
|
Revision: 139 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=139&view=rev Author: rgoj Date: 2010-06-27 15:56:09 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Adding a new menu button to the PyBrainSim.py script for showcasing the new work in progress dipole model, this doesn't do anything yet. Modified Paths: -------------- trunk/src/PyBrainSimGUI1.xrc Modified: trunk/src/PyBrainSimGUI1.xrc =================================================================== --- trunk/src/PyBrainSimGUI1.xrc 2010-06-27 15:31:45 UTC (rev 138) +++ trunk/src/PyBrainSimGUI1.xrc 2010-06-27 15:56:09 UTC (rev 139) @@ -1,103 +1,113 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1"> - <object class="wxFrame" name="menuFrame"> - <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style> - <size>450,390</size> - <title>PyBrainSim: Choose example simulation</title> - <object class="wxPanel" name="menuPanel"> - <style>wxTAB_TRAVERSAL</style> - <object class="wxBoxSizer"> - <orient>wxVERTICAL</orient> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton1"> - <label>Example dummy simulation</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton2"> - <label>Number generator and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton3"> - <label>Two number generators and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton4"> - <label>Sine generator and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton5"> - <label>Random sine generators and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton6"> - <label>Two sine generators, two recording sites and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton7"> - <label>Dummy 3D head model</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton8"> - <label>Neural mass model of a single cortical area</label> - <default>1</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxEXPAND | wxALL</flag> - <border>5</border> - <object class="wxStaticLine" name="m_staticline2"> - <style>wxLI_HORIZONTAL</style> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL</flag> - <border>5</border> - <object class="wxButton" name="menuButtonQuit"> - <label>Quit</label> - <default>0</default> - </object> - </object> - </object> - </object> - </object> + <object class="wxFrame" name="menuFrame"> + <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style> + <size>449,450</size> + <title>PyBrainSim: Choose example simulation</title> + <object class="wxPanel" name="menuPanel"> + <style>wxTAB_TRAVERSAL</style> + <object class="wxBoxSizer"> + <orient>wxVERTICAL</orient> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton1"> + <label>Example dummy simulation</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton2"> + <label>Number generator and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton3"> + <label>Two number generators and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton4"> + <label>Sine generator and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton5"> + <label>Random sine generators and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton6"> + <label>Sine generator, stimuli and two recording sites</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton7"> + <label>Dummy 3D head model</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton8"> + <label>Neural mass model of a single cortical area</label> + <default>1</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton9"> + <label>Dipole sources in a conducting sphere</label> + <default>1</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxEXPAND | wxALL</flag> + <border>5</border> + <object class="wxStaticLine" name="m_staticline2"> + <style>wxLI_HORIZONTAL</style> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL</flag> + <border>5</border> + <object class="wxButton" name="menuButtonQuit"> + <label>Quit</label> + <default>0</default> + </object> + </object> + </object> + </object> + </object> </resource> + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 15:31:51
|
Revision: 138 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=138&view=rev Author: rgoj Date: 2010-06-27 15:31:45 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Adding a work in progress of a single conducting sphere head model with generators as dipoles at last! Added Paths: ----------- trunk/src/HeadModelDipoleSphere.py Added: trunk/src/HeadModelDipoleSphere.py =================================================================== --- trunk/src/HeadModelDipoleSphere.py (rev 0) +++ trunk/src/HeadModelDipoleSphere.py 2010-06-27 15:31:45 UTC (rev 138) @@ -0,0 +1,126 @@ +# PyBrainSim Copyright 2009 Roman Goj +# +# This file is part of PyBrainSim. +# +# PyBrainSim 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. +# +# PyBrainSim 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 +# PyBrainSim. If not, see <http://www.gnu.org/licenses/>. + +from __future__ import division +from numpy import arange, array, ones, identity, dot, zeros, sin, cos, pi, sqrt +__metaclass__ = type # New style classes. Is this necessary? + +""" +This reimplemenation of the HeadModel class models the head as a single +conductant sphere containing dipolar sources. +""" + +from HeadModel import HeadModel + +class HeadModelDipoleSphere(HeadModel): + def __init__(self, head, radius): + HeadModel.__init__(self, head) + self.head = head + self.radius = radius # Radius of the head in [cm] + self.leadField = 0; + + def checkPosition(self,position): + # Checking if position is a list of two or five numbers + # The position of each registration site is given in spherical coordinates + # associated with the center of the spherical head. The radial coordinate of the electrode + # is always equal to the radius of the head, hence it doesn't need to be specified. + # The only two parameters that need to be specified are the angles theta and phi in this + # order. + # For each generator, all three cordinates must be given: the depth of the dipole and the + # theta and phi angles. Additionaly, angles specyfying the orientation of the dipole in + # the spherical coordinates of the dipole must also be given. The theta angle is then the + # orientation with respect to the surface of the head - i.e. theta = 0 means a radial + # dipole, while theta = pi/2 means a tangential dipole. Only values in this range are + # allowed! The specification of the phi angle is considered less important and should be + # explained more thoroughly in other documentation. + if not isinstance(position, list): + return False + if len(position) != 2 and len(position) != 5: + return False + # Check the radial coordinate (depth) of the dipole + if len(position) == 5 and (position[0] <= 0 or position[0] >= self.radius): + return False + # Check the theta angle of the orientation of the dipole + if len(position) == 5 and (position[3] < 0 or position[3] > pi/2): + return False + for i in range(len(position)): + if (not isinstance(position[i], float)) and (not isinstance(position[i], int)): + return False + + # If none of the conditions above fail, the position is correct + return True + + def calculateLeadField(self): + # How many generators and electrodes do we have? + nGenerators = len(self.head.generatorSiteList) + nElectrodes = len(self.head.registrationSiteList) + + # Assuming ideal conductivity + sigma = 1.0 + + # The number of electrodes and generators defines the size of the lead field matrix + self.leadField = zeros((nElectrodes,nGenerators)) + + for iElectrode in range(nElectrodes): + # Calculating the coordinates of the electrode in the Cartesian coordinates associated with the head + electrodeTheta = self.head.registrationSiteList[iElectrode][0] + electrodePhi = self.head.registrationSiteList[iElectrode][1] + xyzElectrodeHead = zeros(3); + xyzElectrodeHead[0] = self.radius * sin(electrodeTheta) * cos(electrodePhi); + xyzElectrodeHead[1] = self.radius * sin(electrodeTheta) * sin(electrodePhi); + xyzElectrodeHead[2] = self.radius * cos(electrodeTheta); + + for iGenerator in range(nGenerators): + # Calculating the coordinates of the dipole in the Cartesian coordinates associated with the head + dipoleRadius = self.radius - self.head.generatorSiteList[iGenerator][0] + dipoleTheta = self.head.generatorSiteList[iGenerator][1] + dipolePhi = self.head.generatorSiteList[iGenerator][2] + xyzDipoleHead = zeros(3); + xyzDipoleHead[0] = dipoleRadius * sin(dipoleTheta) * cos(dipolePhi); + xyzDipoleHead[1] = dipoleRadius * sin(dipoleTheta) * sin(dipolePhi); + xyzDipoleHead[2] = dipoleRadius * cos(dipoleTheta); + + # Calculating the coordinates of the electrode in the coordinates associated with the dipole + xyzElectrodeDipole = xyzElectrodeHead - xyzDipoleHead; + + # Calculating the distance between the dipole and the electrode + distance = 0; + distance += pow(xyzElectrodeDipole[0],2.0) + distance += pow(xyzElectrodeDipole[1],2.0) + distance += pow(xyzElectrodeDipole[2],2.0) + distance = sqrt(distance) + + self.leadField[iElectrode, iGenerator] = 1.0 + + def runHeadModel(self, generatorOutput, recording): + # Calculating the lead field + self.calculateLeadField() + + print self.leadField + print (array([generatorOutput])).transpose() + + # Calculating the recording by multyplying the lead field by the generator output + newRecording = dot(self.leadField, (array([generatorOutput])).transpose()) + + # Converting the new recording to list format for compatibility with rest of the code + newRecording = list(newRecording[:,0]) + + print newRecording + + for channel in range(len(recording)): + recording[channel].append(newRecording[channel]) + + return recording This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 15:30:04
|
Revision: 137 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=137&view=rev Author: rgoj Date: 2010-06-27 15:29:58 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Added a Generator that returns a normally distributed number every time it is ran. Added Paths: ----------- trunk/src/GeneratorNoisy.py Added: trunk/src/GeneratorNoisy.py =================================================================== --- trunk/src/GeneratorNoisy.py (rev 0) +++ trunk/src/GeneratorNoisy.py 2010-06-27 15:29:58 UTC (rev 137) @@ -0,0 +1,45 @@ +# PyBrainSim +# Copyright 2009 Roman Goj +# +# This file is part of PyBrainSim. +# +# PyBrainSim 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. +# +# PyBrainSim 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 +# PyBrainSim. If not, see <http://www.gnu.org/licenses/>. + +__metaclass__ = type # New style classes. Is this necessary? + +""" +The GeneratorNoisy class is a reimplementation of the Generator class. It +provides a simple generator which, whenever required, generates a number +generated from a Gaussian distribution with specified mean and variance. +""" + +from numpy.random import normal + +from Generator import Generator + +class GeneratorNoisy(Generator): + def __init__(self, name, head, position = [0,0,0], mean = 0, stddev = 0): + Generator.__init__(self, name, head, position) + self.mean = mean + self.stddev = stddev + + def printInfo(self): + print(self.name + ": A GeneratorNoisy object") + + def runGenerator(self, time): + if self.stddev == 0: + self.activation = self.mean + else: + self.activation = normal(self.mean, self.stddev) + + return self.activation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: PyBrainSim - T. i. <no...@so...> - 2009-09-14 00:52:21
|
#109: Make the text displayed to standard output display in a graphical log -----------------------+---------------------------------------------------- Reporter: rgoj | Owner: rgoj Type: task | Status: closed Priority: major | Milestone: Simple graphical user interface Component: Interface | Resolution: fixed Keywords: | -----------------------+---------------------------------------------------- Changes (by rgoj): * status: new => closed * resolution: => fixed -- Ticket URL: <http://sourceforge.net/apps/trac/pybrainsim/ticket/109#comment:1> PyBrainSim <http://sourceforge.net/projects/pybrainsim/> An interactive tool for the simulation and visualization of the electromagnetic activity of the brain. |
From: <rg...@us...> - 2009-09-14 00:50:56
|
Revision: 136 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=136&view=rev Author: rgoj Date: 2009-09-14 00:50:41 +0000 (Mon, 14 Sep 2009) Log Message: ----------- * Simulations that presented their output via stdandard output, now print to the output log window. * Removed simulation progress information from the neural mass simulation, because somehow it just won't get displayed in the log window... Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-09-14 00:48:51 UTC (rev 135) +++ trunk/src/PyBrainSim.py 2009-09-14 00:50:41 UTC (rev 136) @@ -49,9 +49,10 @@ class PyBrainSimGUI(wx.App): def OnInit(self): - self.res = xrc.XmlResource("PyBrainSimGUI.xrc") + self.res1 = xrc.XmlResource("PyBrainSimGUI1.xrc") + self.res2 = xrc.XmlResource("PyBrainSimGUI2.xrc") - self.frame = self.res.LoadFrame(None, "menuFrame") + self.frame = self.res1.LoadFrame(None, "menuFrame") self.frame.Bind(wx.EVT_BUTTON, self.menuButton1, id=xrc.XRCID("menuButton1")) self.frame.Bind(wx.EVT_BUTTON, self.menuButton2, id=xrc.XRCID("menuButton2")) self.frame.Bind(wx.EVT_BUTTON, self.menuButton3, id=xrc.XRCID("menuButton3")) @@ -62,6 +63,10 @@ self.frame.Bind(wx.EVT_BUTTON, self.menuButton8, id=xrc.XRCID("menuButton8")) self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) self.frame.Show() + + self.logWindow = self.res2.LoadFrame(None, "outputWindow") + self.log = xrc.XRCCTRL(self.logWindow, "outputLog") + return True def menuButton1(self, control): @@ -75,8 +80,9 @@ exampleConnection = ConnectionDummy('Con', exampleHead, exampleStimulus, exampleGenerator) exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) - print("\nSimulations resulted in the following recording:") - print(exampleExperiment.getRecording()) + output = str(exampleExperiment.getRecording()) + self.log.SetValue(output) + self.logWindow.Show() def menuButton2(self, control): exampleHead = Head() @@ -90,8 +96,9 @@ exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() + output = str(exampleExperiment.getRecording()) + self.log.SetValue(output) + self.logWindow.Show() def menuButton3(self, control): exampleHead = Head() @@ -113,8 +120,9 @@ exampleConnection2 = Connection('Con2', exampleHead, exampleStimulus2, exampleGenerator2) exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() + output = str(exampleExperiment.getRecording()) + self.log.SetValue(output) + self.logWindow.Show() def menuButton4(self, control): exampleHead = Head() @@ -126,14 +134,11 @@ exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) exampleStimulus = Stimulus('Stim', exampleHead) - print exampleExperiment.getStimulusTimes()[0] exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) exampleGenerator = GeneratorSine('Gen', exampleHead) exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() exampleExperiment.plotRecording() def menuButton5(self, control): @@ -230,7 +235,6 @@ cC3=0.25*cC1 cC4=0.25*cC1 noise = noiseObject.getNoise(t) - #print("Time: " + str(t) + " Noise: " + str(noise)) return [y[1], cA*ca*( sigmoidFunction(y[2] - y[4]) ) - 2*ca*y[1] - ca**2*y[0], y[3], cA*ca*( noise + cC2*sigmoidFunction(cC1*y[0]) ) - 2*ca*y[3] - ca**2*y[2], y[5], cB*cb*( cC4*sigmoidFunction(cC3*y[0]) @@ -251,7 +255,7 @@ r = [] recording = [ [], [], [], [], [], [] ] parameter = [ 68, 128, 135, 270, 675, 1350 ] - + # Differential equation integration for i in range(len(parameter)): # Preparing the integration @@ -259,7 +263,6 @@ r[i].set_initial_value(y0, t0) r[i].set_f_params( someNoise, parameter[i] ) # Integrating - print("Performing simulation " + str(i+1) + "/" + str(len(parameter))) while r[i].successful() and r[i].t < timeSpan: r[i].integrate(r[i].t+dtime) recording[i].append(r[i].y[2] - r[i].y[4]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-14 00:48:58
|
Revision: 135 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=135&view=rev Author: rgoj Date: 2009-09-14 00:48:51 +0000 (Mon, 14 Sep 2009) Log Message: ----------- * Adding a renamed version of PyBrainSimGUI.xrc * Corrected description of one of the simulations Added Paths: ----------- trunk/src/PyBrainSimGUI1.xrc Added: trunk/src/PyBrainSimGUI1.xrc =================================================================== --- trunk/src/PyBrainSimGUI1.xrc (rev 0) +++ trunk/src/PyBrainSimGUI1.xrc 2009-09-14 00:48:51 UTC (rev 135) @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1"> + <object class="wxFrame" name="menuFrame"> + <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style> + <size>450,390</size> + <title>PyBrainSim: Choose example simulation</title> + <object class="wxPanel" name="menuPanel"> + <style>wxTAB_TRAVERSAL</style> + <object class="wxBoxSizer"> + <orient>wxVERTICAL</orient> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton1"> + <label>Example dummy simulation</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton2"> + <label>Number generator and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton3"> + <label>Two number generators and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton4"> + <label>Sine generator and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton5"> + <label>Random sine generators and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton6"> + <label>Two sine generators, two recording sites and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton7"> + <label>Dummy 3D head model</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton8"> + <label>Neural mass model of a single cortical area</label> + <default>1</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxEXPAND | wxALL</flag> + <border>5</border> + <object class="wxStaticLine" name="m_staticline2"> + <style>wxLI_HORIZONTAL</style> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL</flag> + <border>5</border> + <object class="wxButton" name="menuButtonQuit"> + <label>Quit</label> + <default>0</default> + </object> + </object> + </object> + </object> + </object> +</resource> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-14 00:48:01
|
Revision: 134 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=134&view=rev Author: rgoj Date: 2009-09-14 00:47:55 +0000 (Mon, 14 Sep 2009) Log Message: ----------- * Removing, because of name change. Removed Paths: ------------- trunk/src/PyBrainSimGUI.xrc Deleted: trunk/src/PyBrainSimGUI.xrc =================================================================== --- trunk/src/PyBrainSimGUI.xrc 2009-09-14 00:45:53 UTC (rev 133) +++ trunk/src/PyBrainSimGUI.xrc 2009-09-14 00:47:55 UTC (rev 134) @@ -1,104 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1"> - <object class="wxFrame" name="menuFrame"> - <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style> - <size>450,390</size> - <title>PyBrainSim: Choose example simulation</title> - <object class="wxPanel" name="menuPanel"> - <style>wxTAB_TRAVERSAL</style> - <object class="wxBoxSizer"> - <orient>wxVERTICAL</orient> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton1"> - <label>Example dummy simulation</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton2"> - <label>Number generator and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton3"> - <label>Two number generators and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton4"> - <label>Sine generator and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton5"> - <label>Random sine generators and stimuli</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton6"> - <label>Sine generator, stimuli and two recording sites</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton7"> - <label>Dummy 3D head model</label> - <default>0</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> - <border>5</border> - <object class="wxButton" name="menuButton8"> - <label>Neural mass model of a single cortical area</label> - <default>1</default> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxEXPAND | wxALL</flag> - <border>5</border> - <object class="wxStaticLine" name="m_staticline2"> - <style>wxLI_HORIZONTAL</style> - </object> - </object> - <object class="sizeritem"> - <option>0</option> - <flag>wxALL|wxALIGN_CENTER_HORIZONTAL</flag> - <border>5</border> - <object class="wxButton" name="menuButtonQuit"> - <label>Quit</label> - <default>0</default> - </object> - </object> - </object> - </object> - </object> -</resource> - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-14 00:45:58
|
Revision: 133 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=133&view=rev Author: rgoj Date: 2009-09-14 00:45:53 +0000 (Mon, 14 Sep 2009) Log Message: ----------- * Added XML resources for a second window, for the output log. Added Paths: ----------- trunk/src/PyBrainSimGUI2.xrc Added: trunk/src/PyBrainSimGUI2.xrc =================================================================== --- trunk/src/PyBrainSimGUI2.xrc (rev 0) +++ trunk/src/PyBrainSimGUI2.xrc 2009-09-14 00:45:53 UTC (rev 133) @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1"> + <object class="wxFrame" name="outputWindow"> + <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style> + <size>500,86</size> + <title>PyBrainSim: Simulation results</title> + <object class="wxPanel" name="outputWindowPanel"> + <style>wxTAB_TRAVERSAL</style> + <object class="wxBoxSizer"> + <orient>wxVERTICAL</orient> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxEXPAND</flag> + <border>5</border> + <object class="wxTextCtrl" name="outputLog"> + <style>wxTE_MULTILINE</style> + <value></value> + <maxlength>0</maxlength> + </object> + </object> + </object> + </object> + </object> +</resource> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-13 23:40:43
|
Revision: 132 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=132&view=rev Author: rgoj Date: 2009-09-13 23:40:34 +0000 (Sun, 13 Sep 2009) Log Message: ----------- * PyBrainSimGUI.py becomes PyBrainSim.py * We now have a graphical interface! Added Paths: ----------- trunk/src/PyBrainSim.py Removed Paths: ------------- trunk/src/PyBrainSimGUI.pyw Copied: trunk/src/PyBrainSim.py (from rev 130, trunk/src/PyBrainSimGUI.pyw) =================================================================== --- trunk/src/PyBrainSim.py (rev 0) +++ trunk/src/PyBrainSim.py 2009-09-13 23:40:34 UTC (rev 132) @@ -0,0 +1,281 @@ +#!/usr/bin/python + +# PyBrainSim +# Copyright 2009 Roman Goj +# +# This file is part of PyBrainSim. +# +# PyBrainSim 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. +# +# PyBrainSim 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 +# PyBrainSim. If not, see <http://www.gnu.org/licenses/>. + +""" +PyBrainSim is an interactive tool for the simulation and visualization of the +electromagnetic activity of the brain, currently under development. + +This script allows you to choose from a few example simulations, ranging from +adding numbers to neural mass models. + +pybrainsim.sourceforge.net +""" + +import wx +from wx import xrc + +import numpy +import pylab +from random import random +from scipy.integrate import ode + +from Head import Head +from HeadModel import HeadModel +from HeadModelHalfSphere import HeadModelHalfSphere +from Experiment import Experiment +from Stimulus import Stimulus +from StimulusDummy import StimulusDummy +from GeneratorDummy import GeneratorDummy +from GeneratorNumberIncrementing import GeneratorNumberIncrementing +from GeneratorSine import GeneratorSine +from Connection import Connection +from ConnectionDummy import ConnectionDummy + +class PyBrainSimGUI(wx.App): + def OnInit(self): + self.res = xrc.XmlResource("PyBrainSimGUI.xrc") + + self.frame = self.res.LoadFrame(None, "menuFrame") + self.frame.Bind(wx.EVT_BUTTON, self.menuButton1, id=xrc.XRCID("menuButton1")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton2, id=xrc.XRCID("menuButton2")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton3, id=xrc.XRCID("menuButton3")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton4, id=xrc.XRCID("menuButton4")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton5, id=xrc.XRCID("menuButton5")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton6, id=xrc.XRCID("menuButton6")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton7, id=xrc.XRCID("menuButton7")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton8, id=xrc.XRCID("menuButton8")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) + self.frame.Show() + return True + + def menuButton1(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleStimulus = StimulusDummy('Stim', exampleHead) + exampleGenerator = GeneratorDummy('Gen', exampleHead) + exampleConnection = ConnectionDummy('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) + print("\nSimulations resulted in the following recording:") + print(exampleExperiment.getRecording()) + + def menuButton2(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes([0.3, 0.6]) + exampleGenerator = GeneratorNumberIncrementing('Gen', exampleHead) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + + def menuButton3(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0) + exampleExperiment.setStimulusTimes([[0.3, 0.6], [0.5]]) + + exampleStimulus1 = Stimulus('Stim1', exampleHead) + exampleStimulus2 = Stimulus('Stim2', exampleHead) + exampleStimulus1.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleStimulus2.setStimulusTimes(exampleExperiment.getStimulusTimes()[1]) + + exampleGenerator1 = GeneratorNumberIncrementing('Gen1', exampleHead) + exampleGenerator2 = GeneratorNumberIncrementing('Gen2', exampleHead) + exampleConnection1 = Connection('Con1', exampleHead, exampleStimulus1, exampleGenerator1) + exampleConnection2 = Connection('Con2', exampleHead, exampleStimulus2, exampleGenerator2) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + + def menuButton4(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(128) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) + exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) + + exampleStimulus = Stimulus('Stim', exampleHead) + print exampleExperiment.getStimulusTimes()[0] + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleGenerator = GeneratorSine('Gen', exampleHead) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + exampleExperiment.plotRecording() + + def menuButton5(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(256) + exampleHead.addRegistrationSite([0, 0, 0]) + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 100.0) + + # Randomizing stimuli times + stimuli = [] + for i in range(100): + stimuli.append( i + 0.2 +random()/2 ) + exampleExperiment.setStimulusTimes([stimuli]) + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + + # Creating many generators with random frequencies in the range 2-20 Hz and + # random phases. Connecting some of them to the stimulus generator + exampleGenerators = [] + exampleConnections = [] + for i in range(100): + randomFrequency = 2.0 + random() * 18 + randomPhaseShift = random() + exampleGenerators.append(GeneratorSine('Gen', exampleHead, frequency=randomFrequency, phaseShift=randomPhaseShift)) + if(random() > 0.75): + exampleConnections.append(Connection('Con', exampleHead, exampleStimulus, exampleGenerators[i])) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + exampleExperiment.plotRecording() + + def menuButton6(self, control): + exampleHead = Head() + exampleHeadModel = HeadModelHalfSphere(exampleHead) + exampleHead.setSamplingFrequency(128) + exampleHead.addRegistrationSite([ 0.5, 0.0, 0.866]) + exampleHead.addRegistrationSite([ 0.0, 0.0, 0.866]) + exampleHead.addRegistrationSite([-0.5, 0.0, 0.866]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) + exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) + + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleGenerator = GeneratorSine('Gen', exampleHead, position = [0.5, 0, 0.366], frequency = 7) + exampleGenerator = GeneratorSine('Gen', exampleHead, position = [-0.5, 0, 0.366], frequency = 4) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + exampleExperiment.plotRecording() + + def menuButton7(self, control): + exampleHead = Head() + exampleHead.displayHead() + + def menuButton8(self, control): + # This class will produce noise that will be fed into the modelled + # cortical area as input. + class NeuralNoise: + def __init__(self, timeSpan, dtime): + self.noise = [] + self.dtime = dtime + self.timePoints = range( int(timeSpan//dtime+1) ) + # Random noise distributed evenly between 120 and 320 + for i in self.timePoints: + self.noise.append( 120+200*random() ) + def getNoise(self, time): + # Searching for the appropriate time point + for i in self.timePoints: + if time < self.timePoints[i]*self.dtime: + # Interpolating between the randomly generated values + return self.noise[i] + \ + (self.noise[i+1]-self.noise[i]) \ + * ((self.timePoints[i]*self.dtime-time)/self.dtime) + + # The sigmoid function + def sigmoidFunction(v): + """Constants taken from Jansen and Rit 1995, p. 360""" + cEzero = 2.5 + cR = 0.56 + cVzero = 6 + + """Sigmoid function taken from Jansen and Rit 1995, p. 360""" + return 2*cEzero / ( 1 + numpy.exp( cR*( cVzero - v ) ) ) + + # Defining the equations + def f(t, y, noiseObject, cC): + cA=3.25 + ca=100.0 + cB=22.0 + cb=50.0 + cC1=cC + cC2=0.8*cC1 + cC3=0.25*cC1 + cC4=0.25*cC1 + noise = noiseObject.getNoise(t) + #print("Time: " + str(t) + " Noise: " + str(noise)) + return [y[1], cA*ca*( sigmoidFunction(y[2] - y[4]) ) - 2*ca*y[1] - + ca**2*y[0], y[3], cA*ca*( noise + cC2*sigmoidFunction(cC1*y[0]) ) - + 2*ca*y[3] - ca**2*y[2], y[5], cB*cb*( cC4*sigmoidFunction(cC3*y[0]) + ) - 2*cb*y[5] - cb**2*y[4]] + + # How many seconds should be modelled and how accurately + timeSpan = 3 + dtime = 0.001 + firstPointToDisplay = 1000 + + # A noise object that will be used as input into the equations + someNoise = NeuralNoise(timeSpan+1, dtime*10) + + # Initial conditions + y0, t0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 0 + + # Preparing for simulations + r = [] + recording = [ [], [], [], [], [], [] ] + parameter = [ 68, 128, 135, 270, 675, 1350 ] + + # Differential equation integration + for i in range(len(parameter)): + # Preparing the integration + r.append(ode(f).set_integrator('vode', method='bdf')) + r[i].set_initial_value(y0, t0) + r[i].set_f_params( someNoise, parameter[i] ) + # Integrating + print("Performing simulation " + str(i+1) + "/" + str(len(parameter))) + while r[i].successful() and r[i].t < timeSpan: + r[i].integrate(r[i].t+dtime) + recording[i].append(r[i].y[2] - r[i].y[4]) + + # Show results of simulations + for i in range(len(parameter)): + pylab.subplot( len(parameter), 1, i+1) + if i==0: + pylab.title("Simulations based on Fig. 3 from Jansen and Rit 1995") + pylab.ylabel( "C = " + str(parameter[i]) ) + pylab.plot(recording[i][firstPointToDisplay:]) + pylab.show() + + def menuButtonQuit(self, control): + self.Exit() + +if __name__ == '__main__': + app = PyBrainSimGUI(0) + app.MainLoop() Property changes on: trunk/src/PyBrainSim.py ___________________________________________________________________ Added: svn:executable + * Added: svn:mergeinfo + Deleted: trunk/src/PyBrainSimGUI.pyw =================================================================== --- trunk/src/PyBrainSimGUI.pyw 2009-09-13 23:39:27 UTC (rev 131) +++ trunk/src/PyBrainSimGUI.pyw 2009-09-13 23:40:34 UTC (rev 132) @@ -1,281 +0,0 @@ -#!/usr/bin/python - -# PyBrainSim -# Copyright 2009 Roman Goj -# -# This file is part of PyBrainSim. -# -# PyBrainSim 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. -# -# PyBrainSim 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 -# PyBrainSim. If not, see <http://www.gnu.org/licenses/>. - -""" -PyBrainSim is an interactive tool for the simulation and visualization of the -electromagnetic activity of the brain, currently under development. - -This script allows you to choose from a few example simulations, ranging from -adding numbers to neural mass models. - -pybrainsim.sourceforge.net -""" - -import wx -from wx import xrc - -import numpy -import pylab -from random import random -from scipy.integrate import ode - -from Head import Head -from HeadModel import HeadModel -from HeadModelHalfSphere import HeadModelHalfSphere -from Experiment import Experiment -from Stimulus import Stimulus -from StimulusDummy import StimulusDummy -from GeneratorDummy import GeneratorDummy -from GeneratorNumberIncrementing import GeneratorNumberIncrementing -from GeneratorSine import GeneratorSine -from Connection import Connection -from ConnectionDummy import ConnectionDummy - -class PyBrainSimGUI(wx.App): - def OnInit(self): - self.res = xrc.XmlResource("PyBrainSimGUI.xrc") - - self.frame = self.res.LoadFrame(None, "menuFrame") - self.frame.Bind(wx.EVT_BUTTON, self.menuButton1, id=xrc.XRCID("menuButton1")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton2, id=xrc.XRCID("menuButton2")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton3, id=xrc.XRCID("menuButton3")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton4, id=xrc.XRCID("menuButton4")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton5, id=xrc.XRCID("menuButton5")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton6, id=xrc.XRCID("menuButton6")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton7, id=xrc.XRCID("menuButton7")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton8, id=xrc.XRCID("menuButton8")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) - self.frame.Show() - return True - - def menuButton1(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleStimulus = StimulusDummy('Stim', exampleHead) - exampleGenerator = GeneratorDummy('Gen', exampleHead) - exampleConnection = ConnectionDummy('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) - print("\nSimulations resulted in the following recording:") - print(exampleExperiment.getRecording()) - - def menuButton2(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes([0.3, 0.6]) - exampleGenerator = GeneratorNumberIncrementing('Gen', exampleHead) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() - - def menuButton3(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0) - exampleExperiment.setStimulusTimes([[0.3, 0.6], [0.5]]) - - exampleStimulus1 = Stimulus('Stim1', exampleHead) - exampleStimulus2 = Stimulus('Stim2', exampleHead) - exampleStimulus1.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleStimulus2.setStimulusTimes(exampleExperiment.getStimulusTimes()[1]) - - exampleGenerator1 = GeneratorNumberIncrementing('Gen1', exampleHead) - exampleGenerator2 = GeneratorNumberIncrementing('Gen2', exampleHead) - exampleConnection1 = Connection('Con1', exampleHead, exampleStimulus1, exampleGenerator1) - exampleConnection2 = Connection('Con2', exampleHead, exampleStimulus2, exampleGenerator2) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() - - def menuButton4(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(128) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) - exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) - - exampleStimulus = Stimulus('Stim', exampleHead) - print exampleExperiment.getStimulusTimes()[0] - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleGenerator = GeneratorSine('Gen', exampleHead) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() - exampleExperiment.plotRecording() - - def menuButton5(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(256) - exampleHead.addRegistrationSite([0, 0, 0]) - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 100.0) - - # Randomizing stimuli times - stimuli = [] - for i in range(100): - stimuli.append( i + 0.2 +random()/2 ) - exampleExperiment.setStimulusTimes([stimuli]) - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - - # Creating many generators with random frequencies in the range 2-20 Hz and - # random phases. Connecting some of them to the stimulus generator - exampleGenerators = [] - exampleConnections = [] - for i in range(100): - randomFrequency = 2.0 + random() * 18 - randomPhaseShift = random() - exampleGenerators.append(GeneratorSine('Gen', exampleHead, frequency=randomFrequency, phaseShift=randomPhaseShift)) - if(random() > 0.75): - exampleConnections.append(Connection('Con', exampleHead, exampleStimulus, exampleGenerators[i])) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - exampleExperiment.plotRecording() - - def menuButton6(self, control): - exampleHead = Head() - exampleHeadModel = HeadModelHalfSphere(exampleHead) - exampleHead.setSamplingFrequency(128) - exampleHead.addRegistrationSite([ 0.5, 0.0, 0.866]) - exampleHead.addRegistrationSite([ 0.0, 0.0, 0.866]) - exampleHead.addRegistrationSite([-0.5, 0.0, 0.866]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) - exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) - - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleGenerator = GeneratorSine('Gen', exampleHead, position = [0.5, 0, 0.366], frequency = 7) - exampleGenerator = GeneratorSine('Gen', exampleHead, position = [-0.5, 0, 0.366], frequency = 4) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - exampleExperiment.plotRecording() - - def menuButton7(self, control): - exampleHead = Head() - exampleHead.displayHead() - - def menuButton8(self, control): - # This class will produce noise that will be fed into the modelled - # cortical area as input. - class NeuralNoise: - def __init__(self, timeSpan, dtime): - self.noise = [] - self.dtime = dtime - self.timePoints = range( int(timeSpan//dtime+1) ) - # Random noise distributed evenly between 120 and 320 - for i in self.timePoints: - self.noise.append( 120+200*random() ) - def getNoise(self, time): - # Searching for the appropriate time point - for i in self.timePoints: - if time < self.timePoints[i]*self.dtime: - # Interpolating between the randomly generated values - return self.noise[i] + \ - (self.noise[i+1]-self.noise[i]) \ - * ((self.timePoints[i]*self.dtime-time)/self.dtime) - - # The sigmoid function - def sigmoidFunction(v): - """Constants taken from Jansen and Rit 1995, p. 360""" - cEzero = 2.5 - cR = 0.56 - cVzero = 6 - - """Sigmoid function taken from Jansen and Rit 1995, p. 360""" - return 2*cEzero / ( 1 + numpy.exp( cR*( cVzero - v ) ) ) - - # Defining the equations - def f(t, y, noiseObject, cC): - cA=3.25 - ca=100.0 - cB=22.0 - cb=50.0 - cC1=cC - cC2=0.8*cC1 - cC3=0.25*cC1 - cC4=0.25*cC1 - noise = noiseObject.getNoise(t) - #print("Time: " + str(t) + " Noise: " + str(noise)) - return [y[1], cA*ca*( sigmoidFunction(y[2] - y[4]) ) - 2*ca*y[1] - - ca**2*y[0], y[3], cA*ca*( noise + cC2*sigmoidFunction(cC1*y[0]) ) - - 2*ca*y[3] - ca**2*y[2], y[5], cB*cb*( cC4*sigmoidFunction(cC3*y[0]) - ) - 2*cb*y[5] - cb**2*y[4]] - - # How many seconds should be modelled and how accurately - timeSpan = 3 - dtime = 0.001 - firstPointToDisplay = 1000 - - # A noise object that will be used as input into the equations - someNoise = NeuralNoise(timeSpan+1, dtime*10) - - # Initial conditions - y0, t0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 0 - - # Preparing for simulations - r = [] - recording = [ [], [], [], [], [], [] ] - parameter = [ 68, 128, 135, 270, 675, 1350 ] - - # Differential equation integration - for i in range(len(parameter)): - # Preparing the integration - r.append(ode(f).set_integrator('vode', method='bdf')) - r[i].set_initial_value(y0, t0) - r[i].set_f_params( someNoise, parameter[i] ) - # Integrating - print("Performing simulation " + str(i+1) + "/" + str(len(parameter))) - while r[i].successful() and r[i].t < timeSpan: - r[i].integrate(r[i].t+dtime) - recording[i].append(r[i].y[2] - r[i].y[4]) - - # Show results of simulations - for i in range(len(parameter)): - pylab.subplot( len(parameter), 1, i+1) - if i==0: - pylab.title("Simulations based on Fig. 3 from Jansen and Rit 1995") - pylab.ylabel( "C = " + str(parameter[i]) ) - pylab.plot(recording[i][firstPointToDisplay:]) - pylab.show() - - def menuButtonQuit(self, control): - self.Exit() - -if __name__ == '__main__': - app = PyBrainSimGUI(0) - app.MainLoop() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-13 23:39:38
|
Revision: 131 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=131&view=rev Author: rgoj Date: 2009-09-13 23:39:27 +0000 (Sun, 13 Sep 2009) Log Message: ----------- * Removing the old text based PyBrainSim.py script to make room for PyBrainSimGUI. Removed Paths: ------------- trunk/src/PyBrainSim.py Deleted: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-09-13 23:37:32 UTC (rev 130) +++ trunk/src/PyBrainSim.py 2009-09-13 23:39:27 UTC (rev 131) @@ -1,265 +0,0 @@ -# PyBrainSim -# Copyright 2009 Roman Goj -# -# This file is part of PyBrainSim. -# -# PyBrainSim 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. -# -# PyBrainSim 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 -# PyBrainSim. If not, see <http://www.gnu.org/licenses/>. - -""" -PyBrainSim is an interactive tool for the simulation and visualization of the -electromagnetic activity of the brain, currently under development. - -This script can be executed to run an example simulation, using the Head and -GeneratorDummy classes. Currently it only generates a list of integer -numbers... but work is under way to make it simulate the brain... Have fun! - -pybrainsim.sourceforge.net -""" - -import numpy -from random import random -from scipy.integrate import ode - -from Head import Head -from HeadModel import HeadModel -from HeadModelHalfSphere import HeadModelHalfSphere -from Experiment import Experiment -from Stimulus import Stimulus -from StimulusDummy import StimulusDummy -from GeneratorDummy import GeneratorDummy -from GeneratorNumberIncrementing import GeneratorNumberIncrementing -from GeneratorSine import GeneratorSine -from Connection import Connection -from ConnectionDummy import ConnectionDummy - -welcomeMessage = "\n\ -Welcome to this early version of PyBrainSim\n\n\ -Choose the type of simulation you would like to perform:\n\ - 1. Example dummy simulation\n\ - 2. Incrementing numbers, one generator and a stimulus\n\ - 3. Incrementing numbers, two generators and a stimulus for one of them\n\ - 4. A single sinusoidal generator\n\ - 5. A hundred sinusoidal generators with random frequencies, some connected\ - to a stimulus\n\ - 6. A single sinusoidal generator but with two registration sites\n\ - 7. A presentation of the 3d head model\n\ - 8. A model of a cortical area, based on Jansen and Rit 1995." - -print(welcomeMessage) -userChoice = input("Your choice: ") -print("\n") - -if userChoice == 1: - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleStimulus = StimulusDummy('Stim', exampleHead) - exampleGenerator = GeneratorDummy('Gen', exampleHead) - exampleConnection = ConnectionDummy('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) - print("\nSimulations resulted in the following recording:") - print(exampleExperiment.getRecording()) -elif userChoice == 2: - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes([0.3, 0.6]) - exampleGenerator = GeneratorNumberIncrementing('Gen', exampleHead) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() -elif userChoice == 3: - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0) - exampleExperiment.setStimulusTimes([[0.3, 0.6], [0.5]]) - - exampleStimulus1 = Stimulus('Stim1', exampleHead) - exampleStimulus2 = Stimulus('Stim2', exampleHead) - exampleStimulus1.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleStimulus2.setStimulusTimes(exampleExperiment.getStimulusTimes()[1]) - - exampleGenerator1 = GeneratorNumberIncrementing('Gen1', exampleHead) - exampleGenerator2 = GeneratorNumberIncrementing('Gen2', exampleHead) - exampleConnection1 = Connection('Con1', exampleHead, exampleStimulus1, exampleGenerator1) - exampleConnection2 = Connection('Con2', exampleHead, exampleStimulus2, exampleGenerator2) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() -elif userChoice == 4: - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(128) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) - exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) - - exampleStimulus = Stimulus('Stim', exampleHead) - print exampleExperiment.getStimulusTimes()[0] - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleGenerator = GeneratorSine('Gen', exampleHead) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() - exampleExperiment.plotRecording() -elif userChoice == 5: - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(256) - exampleHead.addRegistrationSite([0, 0, 0]) - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 100.0) - - # Randomizing stimuli times - stimuli = [] - for i in range(100): - stimuli.append( i + 0.2 +random()/2 ) - exampleExperiment.setStimulusTimes([stimuli]) - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - - # Creating many generators with random frequencies in the range 2-20 Hz and - # random phases. Connecting some of them to the stimulus generator - exampleGenerators = [] - exampleConnections = [] - for i in range(100): - randomFrequency = 2.0 + random() * 18 - randomPhaseShift = random() - exampleGenerators.append(GeneratorSine('Gen', exampleHead, frequency=randomFrequency, phaseShift=randomPhaseShift)) - if(random() > 0.75): - exampleConnections.append(Connection('Con', exampleHead, exampleStimulus, exampleGenerators[i])) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - exampleExperiment.plotRecording() -elif userChoice == 6: - exampleHead = Head() - exampleHeadModel = HeadModelHalfSphere(exampleHead) - exampleHead.setSamplingFrequency(128) - exampleHead.addRegistrationSite([ 0.5, 0.0, 0.866]) - exampleHead.addRegistrationSite([ 0.0, 0.0, 0.866]) - exampleHead.addRegistrationSite([-0.5, 0.0, 0.866]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) - exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) - - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleGenerator = GeneratorSine('Gen', exampleHead, position = [0.5, 0, 0.366], frequency = 7) - exampleGenerator = GeneratorSine('Gen', exampleHead, position = [-0.5, 0, 0.366], frequency = 4) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - exampleExperiment.plotRecording() -elif userChoice == 7: - exampleHead = Head() - exampleHead.displayHead() -elif userChoice == 8: - # This class will produce noise that will be fed into the modelled - # cortical area as input. - class NeuralNoise: - def __init__(self, timeSpan, dtime): - self.noise = [] - self.dtime = dtime - self.timePoints = range( int(timeSpan//dtime+1) ) - # Random noise distributed evenly between 120 and 320 - for i in self.timePoints: - self.noise.append( 120+200*random() ) - def getNoise(self, time): - # Searching for the appropriate time point - for i in self.timePoints: - if time < self.timePoints[i]*self.dtime: - # Interpolating between the randomly generated values - return self.noise[i] + \ - (self.noise[i+1]-self.noise[i]) \ - * ((self.timePoints[i]*self.dtime-time)/self.dtime) - - # The sigmoid function - def sigmoidFunction(v): - """Constants taken from Jansen and Rit 1995, p. 360""" - cEzero = 2.5 - cR = 0.56 - cVzero = 6 - - """Sigmoid function taken from Jansen and Rit 1995, p. 360""" - return 2*cEzero / ( 1 + numpy.exp( cR*( cVzero - v ) ) ) - - # Defining the equations - def f(t, y, noiseObject, cC): - cA=3.25 - ca=100.0 - cB=22.0 - cb=50.0 - cC1=cC - cC2=0.8*cC1 - cC3=0.25*cC1 - cC4=0.25*cC1 - noise = noiseObject.getNoise(t) - #print("Time: " + str(t) + " Noise: " + str(noise)) - return [y[1], cA*ca*( sigmoidFunction(y[2] - y[4]) ) - 2*ca*y[1] - - ca**2*y[0], y[3], cA*ca*( noise + cC2*sigmoidFunction(cC1*y[0]) ) - - 2*ca*y[3] - ca**2*y[2], y[5], cB*cb*( cC4*sigmoidFunction(cC3*y[0]) - ) - 2*cb*y[5] - cb**2*y[4]] - - # How many seconds should be modelled and how accurately - timeSpan = 3 - dtime = 0.001 - firstPointToDisplay = 1000 - - # A noise object that will be used as input into the equations - someNoise = NeuralNoise(timeSpan+1, dtime*10) - - # Initial conditions - y0, t0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 0 - - # Preparing for simulations - r = [] - recording = [ [], [], [], [], [], [] ] - parameter = [ 68, 128, 135, 270, 675, 1350 ] - - # Differential equation integration - for i in range(len(parameter)): - # Preparing the integration - r.append(ode(f).set_integrator('vode', method='bdf')) - r[i].set_initial_value(y0, t0) - r[i].set_f_params( someNoise, parameter[i] ) - # Integrating - print("Performing simulation " + str(i+1) + "/" + str(len(parameter))) - while r[i].successful() and r[i].t < timeSpan: - r[i].integrate(r[i].t+dtime) - recording[i].append(r[i].y[2] - r[i].y[4]) - - # Show results of simulations - from pylab import * - for i in range(len(parameter)): - subplot( len(parameter), 1, i+1) - if i==0: - title("Simulations based on Fig. 3 from Jansen and Rit 1995") - ylabel( "C = " + str(parameter[i]) ) - plot(recording[i][firstPointToDisplay:]) - show() -else: - print("No such option unfortunately...") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: PyBrainSim - T. i. <no...@so...> - 2009-09-13 23:38:39
|
#108: Implement the main window allowing the user to graphically choose example simulations. -----------------------+---------------------------------------------------- Reporter: rgoj | Owner: rgoj Type: task | Status: closed Priority: major | Milestone: Simple graphical user interface Component: Interface | Resolution: fixed Keywords: | -----------------------+---------------------------------------------------- Changes (by rgoj): * status: new => closed * resolution: => fixed -- Ticket URL: <http://sourceforge.net/apps/trac/pybrainsim/ticket/108#comment:1> PyBrainSim <http://sourceforge.net/projects/pybrainsim/> An interactive tool for the simulation and visualization of the electromagnetic activity of the brain. |
From: <rg...@us...> - 2009-09-13 23:37:51
|
Revision: 130 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=130&view=rev Author: rgoj Date: 2009-09-13 23:37:32 +0000 (Sun, 13 Sep 2009) Log Message: ----------- * Added all the content from the PyBrainSim script, preparing PyBrainSimGUI one to be the main executable. * Removed all the left over code from wxPython tutorials. Modified Paths: -------------- trunk/src/PyBrainSimGUI.pyw Modified: trunk/src/PyBrainSimGUI.pyw =================================================================== --- trunk/src/PyBrainSimGUI.pyw 2009-09-13 23:11:44 UTC (rev 129) +++ trunk/src/PyBrainSimGUI.pyw 2009-09-13 23:37:32 UTC (rev 130) @@ -30,92 +30,252 @@ import wx from wx import xrc +import numpy +import pylab +from random import random +from scipy.integrate import ode + +from Head import Head +from HeadModel import HeadModel +from HeadModelHalfSphere import HeadModelHalfSphere +from Experiment import Experiment +from Stimulus import Stimulus +from StimulusDummy import StimulusDummy +from GeneratorDummy import GeneratorDummy +from GeneratorNumberIncrementing import GeneratorNumberIncrementing +from GeneratorSine import GeneratorSine +from Connection import Connection +from ConnectionDummy import ConnectionDummy + class PyBrainSimGUI(wx.App): def OnInit(self): self.res = xrc.XmlResource("PyBrainSimGUI.xrc") - #self.InitFrame() - #self.InitMenu() - #self.InitEverythingElse() self.frame = self.res.LoadFrame(None, "menuFrame") self.frame.Bind(wx.EVT_BUTTON, self.menuButton1, id=xrc.XRCID("menuButton1")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton2, id=xrc.XRCID("menuButton2")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton3, id=xrc.XRCID("menuButton3")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton4, id=xrc.XRCID("menuButton4")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton5, id=xrc.XRCID("menuButton5")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton6, id=xrc.XRCID("menuButton6")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton7, id=xrc.XRCID("menuButton7")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton8, id=xrc.XRCID("menuButton8")) self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) - #self.panel = xrc.XRCCTRL(self.frame, "MainPanel") - #self.first_arg = xrc.XRCCTRL(self.panel, "FirstArg") - #self.second_arg = xrc.XRCCTRL(self.panel, "SecondArg") - #self.result = xrc.XRCCTRL(self.panel, "Result") - #self.first_arg.SetValue("Hi") - #self.second_arg.SetValue("You") - #self.result.SetValue("man") - #self.menuBar = self.res.LoadMenuBar("MenuBar") - #self.frame.SetMenuBar(self.menuBar) - #sizer = self.panel.GetSizer() - #sizer.Fit(self.frame) - #sizer.SetSizeHints(self.frame) self.frame.Show() return True def menuButton1(self, control): - print "Hullo World!" + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleStimulus = StimulusDummy('Stim', exampleHead) + exampleGenerator = GeneratorDummy('Gen', exampleHead) + exampleConnection = ConnectionDummy('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) + print("\nSimulations resulted in the following recording:") + print(exampleExperiment.getRecording()) + def menuButton2(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes([0.3, 0.6]) + exampleGenerator = GeneratorNumberIncrementing('Gen', exampleHead) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + + def menuButton3(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0) + exampleExperiment.setStimulusTimes([[0.3, 0.6], [0.5]]) + + exampleStimulus1 = Stimulus('Stim1', exampleHead) + exampleStimulus2 = Stimulus('Stim2', exampleHead) + exampleStimulus1.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleStimulus2.setStimulusTimes(exampleExperiment.getStimulusTimes()[1]) + + exampleGenerator1 = GeneratorNumberIncrementing('Gen1', exampleHead) + exampleGenerator2 = GeneratorNumberIncrementing('Gen2', exampleHead) + exampleConnection1 = Connection('Con1', exampleHead, exampleStimulus1, exampleGenerator1) + exampleConnection2 = Connection('Con2', exampleHead, exampleStimulus2, exampleGenerator2) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + + def menuButton4(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(128) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) + exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) + + exampleStimulus = Stimulus('Stim', exampleHead) + print exampleExperiment.getStimulusTimes()[0] + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleGenerator = GeneratorSine('Gen', exampleHead) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + exampleExperiment.plotRecording() + + def menuButton5(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(256) + exampleHead.addRegistrationSite([0, 0, 0]) + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 100.0) + + # Randomizing stimuli times + stimuli = [] + for i in range(100): + stimuli.append( i + 0.2 +random()/2 ) + exampleExperiment.setStimulusTimes([stimuli]) + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + + # Creating many generators with random frequencies in the range 2-20 Hz and + # random phases. Connecting some of them to the stimulus generator + exampleGenerators = [] + exampleConnections = [] + for i in range(100): + randomFrequency = 2.0 + random() * 18 + randomPhaseShift = random() + exampleGenerators.append(GeneratorSine('Gen', exampleHead, frequency=randomFrequency, phaseShift=randomPhaseShift)) + if(random() > 0.75): + exampleConnections.append(Connection('Con', exampleHead, exampleStimulus, exampleGenerators[i])) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + exampleExperiment.plotRecording() + + def menuButton6(self, control): + exampleHead = Head() + exampleHeadModel = HeadModelHalfSphere(exampleHead) + exampleHead.setSamplingFrequency(128) + exampleHead.addRegistrationSite([ 0.5, 0.0, 0.866]) + exampleHead.addRegistrationSite([ 0.0, 0.0, 0.866]) + exampleHead.addRegistrationSite([-0.5, 0.0, 0.866]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) + exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) + + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleGenerator = GeneratorSine('Gen', exampleHead, position = [0.5, 0, 0.366], frequency = 7) + exampleGenerator = GeneratorSine('Gen', exampleHead, position = [-0.5, 0, 0.366], frequency = 4) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + exampleExperiment.plotRecording() + + def menuButton7(self, control): + exampleHead = Head() + exampleHead.displayHead() + + def menuButton8(self, control): + # This class will produce noise that will be fed into the modelled + # cortical area as input. + class NeuralNoise: + def __init__(self, timeSpan, dtime): + self.noise = [] + self.dtime = dtime + self.timePoints = range( int(timeSpan//dtime+1) ) + # Random noise distributed evenly between 120 and 320 + for i in self.timePoints: + self.noise.append( 120+200*random() ) + def getNoise(self, time): + # Searching for the appropriate time point + for i in self.timePoints: + if time < self.timePoints[i]*self.dtime: + # Interpolating between the randomly generated values + return self.noise[i] + \ + (self.noise[i+1]-self.noise[i]) \ + * ((self.timePoints[i]*self.dtime-time)/self.dtime) + + # The sigmoid function + def sigmoidFunction(v): + """Constants taken from Jansen and Rit 1995, p. 360""" + cEzero = 2.5 + cR = 0.56 + cVzero = 6 + + """Sigmoid function taken from Jansen and Rit 1995, p. 360""" + return 2*cEzero / ( 1 + numpy.exp( cR*( cVzero - v ) ) ) + + # Defining the equations + def f(t, y, noiseObject, cC): + cA=3.25 + ca=100.0 + cB=22.0 + cb=50.0 + cC1=cC + cC2=0.8*cC1 + cC3=0.25*cC1 + cC4=0.25*cC1 + noise = noiseObject.getNoise(t) + #print("Time: " + str(t) + " Noise: " + str(noise)) + return [y[1], cA*ca*( sigmoidFunction(y[2] - y[4]) ) - 2*ca*y[1] - + ca**2*y[0], y[3], cA*ca*( noise + cC2*sigmoidFunction(cC1*y[0]) ) - + 2*ca*y[3] - ca**2*y[2], y[5], cB*cb*( cC4*sigmoidFunction(cC3*y[0]) + ) - 2*cb*y[5] - cb**2*y[4]] + + # How many seconds should be modelled and how accurately + timeSpan = 3 + dtime = 0.001 + firstPointToDisplay = 1000 + + # A noise object that will be used as input into the equations + someNoise = NeuralNoise(timeSpan+1, dtime*10) + + # Initial conditions + y0, t0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 0 + + # Preparing for simulations + r = [] + recording = [ [], [], [], [], [], [] ] + parameter = [ 68, 128, 135, 270, 675, 1350 ] + + # Differential equation integration + for i in range(len(parameter)): + # Preparing the integration + r.append(ode(f).set_integrator('vode', method='bdf')) + r[i].set_initial_value(y0, t0) + r[i].set_f_params( someNoise, parameter[i] ) + # Integrating + print("Performing simulation " + str(i+1) + "/" + str(len(parameter))) + while r[i].successful() and r[i].t < timeSpan: + r[i].integrate(r[i].t+dtime) + recording[i].append(r[i].y[2] - r[i].y[4]) + + # Show results of simulations + for i in range(len(parameter)): + pylab.subplot( len(parameter), 1, i+1) + if i==0: + pylab.title("Simulations based on Fig. 3 from Jansen and Rit 1995") + pylab.ylabel( "C = " + str(parameter[i]) ) + pylab.plot(recording[i][firstPointToDisplay:]) + pylab.show() + def menuButtonQuit(self, control): self.Exit() - #def InitFrame(self): - # self.frame = self.res.LoadFrame(None, "MainFrame") - # self.panel = xrc.XRCCTRL(self.frame, "MainPanel") - # self.first_arg = xrc.XRCCTRL(self.panel, "FirstArg") - # self.second_arg = xrc.XRCCTRL(self.panel, "SecondArg") - # self.result = xrc.XRCCTRL(self.panel, "Result") - # self.first_arg.SetValue("Hi") - # self.second_arg.SetValue("You") - # self.result.SetValue("man") - #def InitMenu(self): - # self.menuBar = self.res.LoadMenuBar("MenuBar") - # self.frame.Bind(wx.EVT_MENU, self.Add, id=xrc.XRCID("AddMenuItem")) - # self.frame.Bind(wx.EVT_MENU, self.Subtract, id=xrc.XRCID("SubtractMenuItem")) - # self.frame.Bind(wx.EVT_MENU, self.Multiply, id=xrc.XRCID("MultiplyMenuItem")) - # self.frame.Bind(wx.EVT_MENU, self.Divide, id=xrc.XRCID("DivideMenuItem")) - # self.frame.SetMenuBar(self.menuBar) - #def InitEverythingElse(self): - # sizer = self.panel.GetSizer() - # sizer.Fit(self.frame) - # sizer.SetSizeHints(self.frame) - # self.frame.Show() - #def InitArgs(self): - # try: - # self.first = float(self.first_arg.GetValue()) - # except ValueError: - # return self.BadFloatValue(self.first_arg) - # try: - # self.second = float(self.second_arg.GetValue()) - # except ValueError: - # return self.BadFloatValue(self.second_arg) - # return True - #def BadFloatValue(self, control): - # dlg = wx.MessageDialog(self.frame, "I can't convert this to float.", - # 'Conversion error', wx.OK | wx.ICON_ERROR) - # dlg.ShowModal() - # dlg.Destroy() - # control.SetFocus() - # control.SetSelection(-1, -1) - # return False - #def Add(self, evt): - # if self.InitArgs(): - # self.result.SetValue(str(self.first + self.second)) - #def Subtract(self, evt): - # if self.InitArgs(): - # self.result.SetValue(str(self.first - self.second)) - #def Multiply(self, evt): - # if self.InitArgs(): - # self.result.SetValue(str(self.first * self.second)) - #def Divide(self, evt): - # if self.InitArgs(): - # if self.second != 0: - # self.result.SetValue(str(self.first / self.second)) - # else: - # self.result.SetValue("#ERROR") - if __name__ == '__main__': app = PyBrainSimGUI(0) app.MainLoop() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: PyBrainSim - T. i. <no...@so...> - 2009-09-13 23:29:10
|
#105: Write a simple test of the gui in a new source file -----------------------+---------------------------------------------------- Reporter: rgoj | Owner: rgoj Type: task | Status: closed Priority: major | Milestone: Simple graphical user interface Component: Interface | Resolution: fixed Keywords: | -----------------------+---------------------------------------------------- Changes (by rgoj): * status: new => closed * resolution: => fixed -- Ticket URL: <http://sourceforge.net/apps/trac/pybrainsim/ticket/105#comment:1> PyBrainSim <http://sourceforge.net/projects/pybrainsim/> An interactive tool for the simulation and visualization of the electromagnetic activity of the brain. |
From: <rg...@us...> - 2009-09-13 23:11:52
|
Revision: 129 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=129&view=rev Author: rgoj Date: 2009-09-13 23:11:44 +0000 (Sun, 13 Sep 2009) Log Message: ----------- * Adding a file that runs the GUI menu, that for now does only that, but will soon become the main PyBrainSim script overriding the old one. Added Paths: ----------- trunk/src/PyBrainSimGUI.pyw Added: trunk/src/PyBrainSimGUI.pyw =================================================================== --- trunk/src/PyBrainSimGUI.pyw (rev 0) +++ trunk/src/PyBrainSimGUI.pyw 2009-09-13 23:11:44 UTC (rev 129) @@ -0,0 +1,121 @@ +#!/usr/bin/python + +# PyBrainSim +# Copyright 2009 Roman Goj +# +# This file is part of PyBrainSim. +# +# PyBrainSim 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. +# +# PyBrainSim 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 +# PyBrainSim. If not, see <http://www.gnu.org/licenses/>. + +""" +PyBrainSim is an interactive tool for the simulation and visualization of the +electromagnetic activity of the brain, currently under development. + +This script allows you to choose from a few example simulations, ranging from +adding numbers to neural mass models. + +pybrainsim.sourceforge.net +""" + +import wx +from wx import xrc + +class PyBrainSimGUI(wx.App): + def OnInit(self): + self.res = xrc.XmlResource("PyBrainSimGUI.xrc") + #self.InitFrame() + #self.InitMenu() + #self.InitEverythingElse() + + self.frame = self.res.LoadFrame(None, "menuFrame") + self.frame.Bind(wx.EVT_BUTTON, self.menuButton1, id=xrc.XRCID("menuButton1")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) + #self.panel = xrc.XRCCTRL(self.frame, "MainPanel") + #self.first_arg = xrc.XRCCTRL(self.panel, "FirstArg") + #self.second_arg = xrc.XRCCTRL(self.panel, "SecondArg") + #self.result = xrc.XRCCTRL(self.panel, "Result") + #self.first_arg.SetValue("Hi") + #self.second_arg.SetValue("You") + #self.result.SetValue("man") + #self.menuBar = self.res.LoadMenuBar("MenuBar") + #self.frame.SetMenuBar(self.menuBar) + #sizer = self.panel.GetSizer() + #sizer.Fit(self.frame) + #sizer.SetSizeHints(self.frame) + self.frame.Show() + return True + + def menuButton1(self, control): + print "Hullo World!" + + def menuButtonQuit(self, control): + self.Exit() + + #def InitFrame(self): + # self.frame = self.res.LoadFrame(None, "MainFrame") + # self.panel = xrc.XRCCTRL(self.frame, "MainPanel") + # self.first_arg = xrc.XRCCTRL(self.panel, "FirstArg") + # self.second_arg = xrc.XRCCTRL(self.panel, "SecondArg") + # self.result = xrc.XRCCTRL(self.panel, "Result") + # self.first_arg.SetValue("Hi") + # self.second_arg.SetValue("You") + # self.result.SetValue("man") + #def InitMenu(self): + # self.menuBar = self.res.LoadMenuBar("MenuBar") + # self.frame.Bind(wx.EVT_MENU, self.Add, id=xrc.XRCID("AddMenuItem")) + # self.frame.Bind(wx.EVT_MENU, self.Subtract, id=xrc.XRCID("SubtractMenuItem")) + # self.frame.Bind(wx.EVT_MENU, self.Multiply, id=xrc.XRCID("MultiplyMenuItem")) + # self.frame.Bind(wx.EVT_MENU, self.Divide, id=xrc.XRCID("DivideMenuItem")) + # self.frame.SetMenuBar(self.menuBar) + #def InitEverythingElse(self): + # sizer = self.panel.GetSizer() + # sizer.Fit(self.frame) + # sizer.SetSizeHints(self.frame) + # self.frame.Show() + #def InitArgs(self): + # try: + # self.first = float(self.first_arg.GetValue()) + # except ValueError: + # return self.BadFloatValue(self.first_arg) + # try: + # self.second = float(self.second_arg.GetValue()) + # except ValueError: + # return self.BadFloatValue(self.second_arg) + # return True + #def BadFloatValue(self, control): + # dlg = wx.MessageDialog(self.frame, "I can't convert this to float.", + # 'Conversion error', wx.OK | wx.ICON_ERROR) + # dlg.ShowModal() + # dlg.Destroy() + # control.SetFocus() + # control.SetSelection(-1, -1) + # return False + #def Add(self, evt): + # if self.InitArgs(): + # self.result.SetValue(str(self.first + self.second)) + #def Subtract(self, evt): + # if self.InitArgs(): + # self.result.SetValue(str(self.first - self.second)) + #def Multiply(self, evt): + # if self.InitArgs(): + # self.result.SetValue(str(self.first * self.second)) + #def Divide(self, evt): + # if self.InitArgs(): + # if self.second != 0: + # self.result.SetValue(str(self.first / self.second)) + # else: + # self.result.SetValue("#ERROR") + +if __name__ == '__main__': + app = PyBrainSimGUI(0) + app.MainLoop() Property changes on: trunk/src/PyBrainSimGUI.pyw ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-13 23:09:36
|
Revision: 128 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=128&view=rev Author: rgoj Date: 2009-09-13 23:09:30 +0000 (Sun, 13 Sep 2009) Log Message: ----------- * Adding a wxWidgets XML Resource file, that describes the main menu for the new graphical PyBrainSim. Added Paths: ----------- trunk/src/PyBrainSimGUI.xrc Added: trunk/src/PyBrainSimGUI.xrc =================================================================== --- trunk/src/PyBrainSimGUI.xrc (rev 0) +++ trunk/src/PyBrainSimGUI.xrc 2009-09-13 23:09:30 UTC (rev 128) @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1"> + <object class="wxFrame" name="menuFrame"> + <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style> + <size>450,390</size> + <title>PyBrainSim: Choose example simulation</title> + <object class="wxPanel" name="menuPanel"> + <style>wxTAB_TRAVERSAL</style> + <object class="wxBoxSizer"> + <orient>wxVERTICAL</orient> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton1"> + <label>Example dummy simulation</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton2"> + <label>Number generator and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton3"> + <label>Two number generators and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton4"> + <label>Sine generator and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton5"> + <label>Random sine generators and stimuli</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton6"> + <label>Sine generator, stimuli and two recording sites</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton7"> + <label>Dummy 3D head model</label> + <default>0</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND</flag> + <border>5</border> + <object class="wxButton" name="menuButton8"> + <label>Neural mass model of a single cortical area</label> + <default>1</default> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxEXPAND | wxALL</flag> + <border>5</border> + <object class="wxStaticLine" name="m_staticline2"> + <style>wxLI_HORIZONTAL</style> + </object> + </object> + <object class="sizeritem"> + <option>0</option> + <flag>wxALL|wxALIGN_CENTER_HORIZONTAL</flag> + <border>5</border> + <object class="wxButton" name="menuButtonQuit"> + <label>Quit</label> + <default>0</default> + </object> + </object> + </object> + </object> + </object> +</resource> + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: PyBrainSim - T. i. <no...@so...> - 2009-09-13 23:04:39
|
#106: Design the main window for the graphical PyBrainSim interface --------------------+------------------------------------------------------- Reporter: rgoj | Owner: rgoj Type: task | Status: closed Priority: major | Milestone: Simple graphical user interface Component: Design | Resolution: fixed Keywords: | --------------------+------------------------------------------------------- Changes (by rgoj): * status: new => closed * resolution: => fixed -- Ticket URL: <http://sourceforge.net/apps/trac/pybrainsim/ticket/106#comment:1> PyBrainSim <http://sourceforge.net/projects/pybrainsim/> An interactive tool for the simulation and visualization of the electromagnetic activity of the brain. |
From: PyBrainSim - T. i. <no...@so...> - 2009-09-13 23:03:22
|
#104: Choose the libraries and method of creating the GUI --------------------+------------------------------------------------------- Reporter: rgoj | Owner: rgoj Type: task | Status: closed Priority: major | Milestone: Simple graphical user interface Component: Design | Resolution: fixed Keywords: | --------------------+------------------------------------------------------- Changes (by rgoj): * status: new => closed * resolution: => fixed Comment: wxWidgets, wxPython, XML Resources prepared with wxFormBuilder -- Ticket URL: <http://sourceforge.net/apps/trac/pybrainsim/ticket/104#comment:1> PyBrainSim <http://sourceforge.net/projects/pybrainsim/> An interactive tool for the simulation and visualization of the electromagnetic activity of the brain. |
From: PyBrainSim - T. i. <no...@so...> - 2009-09-13 19:28:18
|
#78: Test the differential equations solving on simple equations implemented in the Head class. -------------------------------------------+-------------------------------- Reporter: rgoj | Type: task Status: closed | Priority: major Milestone: Neural mass model simulation | Component: Tests Resolution: fixed | Keywords: -------------------------------------------+-------------------------------- Changes (by rgoj): * status: new => closed * resolution: => fixed -- Ticket URL: <http://sourceforge.net/apps/trac/pybrainsim/ticket/78#comment:4> PyBrainSim <http://sourceforge.net/projects/pybrainsim/> An interactive tool for the simulation and visualization of the electromagnetic activity of the brain. |