{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0b85a598",
   "metadata": {},
   "outputs": [],
   "source": [
    "from brian2 import *\n",
    "\n",
    "from adex_sine import *\n",
    "\n",
    "defaultclock.dt = 10 * us\n",
    "\n",
    "\n",
    "class Model:\n",
    "    # Model type flags\n",
    "    SINE = 0\n",
    "    EXP2SYN = 1\n",
    "\n",
    "    # Noise flags\n",
    "    HIGH = 0\n",
    "    LOW = 1\n",
    "    OFF = -1\n",
    "\n",
    "    # Noise parameters\n",
    "    EXCITATORY_NOISE_VARIANCE = {HIGH: 0.5 * nS, LOW: 0.25 * nS, OFF: 0 * nS}\n",
    "    INHIBITORY_NOISE_VARIANCE = {HIGH: 1.25 * nS, LOW: 0.625 * nS, OFF: 0 * nS}\n",
    "\n",
    "    # Noise mean conductance\n",
    "    EXCITATORY_CONDUCTANCE = 1 * nS\n",
    "    INHIBITORY_CONDUCTANCE = 4 * nS\n",
    "\n",
    "    DEFAULT_PARAMETERS = {\n",
    "        \"sigma_flux\" : 6.75*pA,     \n",
    "        \"c\": 85 * pF,\n",
    "        \"tau_w\": 21.33510833 * ms,\n",
    "        \"b\": 0.25 * nA,\n",
    "        \"a\": 1.3 * nS,\n",
    "        \"v_T\": -45 * mV,\n",
    "        \"v_thresh\": 0 * mV,\n",
    "        \"DeltaT\": 0.2 * mV,\n",
    "        # EQUILIBRIUM POTENTIAL\n",
    "        \"e_l\": -65 * mV,\n",
    "        \"e_ex\": 0 * mV,\n",
    "        \"e_in\": -70 * mV,\n",
    "        # CONDUCTANCES\n",
    "        \"g_l\": 3 * nS,\n",
    "        \"mu_ex\": 0 * nS,\n",
    "        \"mu_in\": 0 * nS,\n",
    "        # EXCITATORY NOISE\n",
    "        \"sigma_ex\": 0 * nS,\n",
    "        \"tau_noise_ex\": 3 * ms,\n",
    "        # INHIBITORY NOISE\n",
    "        \"sigma_in\": 0 * nS,\n",
    "        \"tau_noise_in\": 10 * ms,\n",
    "        # SINE INPUT\n",
    "        \"f\": 100 * Hz,\n",
    "        \"A\": 0 * pA,\n",
    "        \"i_injected\": 0 * pA,\n",
    "        \"v_reset\": -70 * mV,\n",
    "        # m current\n",
    "        \"g_adapt\": 10 * nS,\n",
    "        \"e_k\": -90*mV,\n",
    "        \"beta_z\": -35*mV,\n",
    "        \"gamma_z\": 4*mV,     #5\n",
    "        \"tau_z\": 100*ms,\n",
    "    }\n",
    "\n",
    "    def __init__(\n",
    "        self, n, *, stim=None, noise=None, resistance=None, additional_vars=()\n",
    "    ):\n",
    "        if resistance is None:\n",
    "            raise ValueError(\"Resistance must be specified\")\n",
    "\n",
    "        if noise is None:\n",
    "            raise ValueError(\"Noise must be specified\")\n",
    "\n",
    "        self.stim_type = stim\n",
    "        self._input_resistance = None\n",
    "        self._noise_level = None\n",
    "        self._duration = 0\n",
    "        self.recorded_vars = (\"v\",) + additional_vars\n",
    "\n",
    "        self.neurons = self.set_default(n_neuron=n)\n",
    "        self.set_resistance(resistance)\n",
    "        self.set_noise(noise)\n",
    "\n",
    "        self.spikes = None\n",
    "        self.spiker = None\n",
    "        self.synapses = None\n",
    "        self.inhib_synapses = None\n",
    "        self.smon = None\n",
    "        self.network = None\n",
    "        self.build_network()\n",
    "\n",
    "    def create_model(self):\n",
    "        return ADEX_MODEL, self.DEFAULT_PARAMETERS\n",
    "\n",
    "    def set_default(self, n_neuron):\n",
    "        model, parameters = self.create_model()\n",
    "\n",
    "        neurons = NeuronGroup(\n",
    "            n_neuron,\n",
    "            model=model,\n",
    "            method=\"Euler\",\n",
    "            name=\"neurons\",\n",
    "            threshold=\"v > v_thresh\",\n",
    "            reset=\"v = v_reset; w += b\",\n",
    "        )\n",
    "\n",
    "        for parameter, value in parameters.items():\n",
    "            neurons.__setattr__(parameter, value)\n",
    "\n",
    "        neurons.v = neurons.e_l  # remove most of transient\n",
    "\n",
    "        return neurons\n",
    "\n",
    "    def set_resistance(self, level):\n",
    "        if level == self.LOW:\n",
    "            exc_conductance = self.EXCITATORY_CONDUCTANCE\n",
    "            inhib_conductance = self.INHIBITORY_CONDUCTANCE\n",
    "\n",
    "        else:\n",
    "            exc_conductance = inhib_conductance = 0\n",
    "\n",
    "        self._input_resistance = level\n",
    "        self._set_variable(\"mu_ex\", exc_conductance)\n",
    "        self._set_variable(\"mu_in\", inhib_conductance)\n",
    "\n",
    "    def set_noise(self, level):\n",
    "        if level == self.HIGH or level == self.LOW:\n",
    "            exc_noise = self.EXCITATORY_NOISE_VARIANCE[level]\n",
    "            inhib_noise = self.INHIBITORY_NOISE_VARIANCE[level]\n",
    "\n",
    "        else:\n",
    "            exc_noise = inhib_noise = 0\n",
    "\n",
    "        self._noise_level = level\n",
    "        self._set_variable(\"sigma_ex\", exc_noise)\n",
    "        self._set_variable(\"sigma_in\", inhib_noise)\n",
    "\n",
    "    def set_injected_current(self, amplitude):\n",
    "        self._set_variable(\"i_injected\", amplitude)\n",
    "        self._set_variable(\"A\", 0 * pA)\n",
    "\n",
    "    def set_stimulus_current(self, amplitude):\n",
    "        self._set_variable(\"A\", amplitude)\n",
    "        self._set_variable(\"i_injected\", 0 * pA)\n",
    "\n",
    "    @property\n",
    "    def f(self):\n",
    "        return self.neurons.f\n",
    "\n",
    "    @f.setter\n",
    "    def f(self, new_f):\n",
    "        self._set_variable(\"f\", new_f)  # this will reset smon\n",
    "        if self.stim_type == self.EXP2SYN:\n",
    "            self.spiker.T = 1 / new_f\n",
    "\n",
    "    def run(self, duration, report=\"stdout\"):\n",
    "        self._duration = duration\n",
    "        self.network.run(duration, report=report)\n",
    "\n",
    "    def build_network(self):\n",
    "        self.smon = StateMonitor(\n",
    "            self.neurons, self.recorded_vars, record=True, name=\"smon\"\n",
    "        )\n",
    "        self.spikes = SpikeMonitor(self.neurons, name=\"spikes\")\n",
    "\n",
    "        self.network = Network(self.neurons, self.smon, self.spikes)\n",
    "\n",
    "    def _set_variable(self, name, value):\n",
    "        self.neurons.__setattr__(name, value)\n",
    "        self.reset_recording()\n",
    "\n",
    "    def reset_recording(self):\n",
    "        try:\n",
    "            self.network\n",
    "        except AttributeError:\n",
    "            return  # network not yet initialized\n",
    "\n",
    "        self.network.remove(self.smon, self.spikes)\n",
    "\n",
    "        self.smon = StateMonitor(\n",
    "            self.neurons, self.recorded_vars, record=True, name=\"smon\"\n",
    "        )\n",
    "        self.spikes = SpikeMonitor(self.neurons, name=\"spikes\")\n",
    "\n",
    "        self.network.add(self.smon, self.spikes)\n",
    "\n",
    "    @property\n",
    "    def spike_train(self):\n",
    "        return self.spikes.spike_trains()\n",
    "\n",
    "    @property\n",
    "    def firing_rate(self):\n",
    "        return self.spikes.count / self.duration\n",
    "\n",
    "    @property\n",
    "    def duration(self):\n",
    "        return self._duration\n",
    "\n",
    "    @property\n",
    "    def input_resistance(self):\n",
    "        if self._input_resistance == self.HIGH:\n",
    "            return \"HIGH\"\n",
    "        else:\n",
    "            return \"LOW\"\n",
    "\n",
    "    @property\n",
    "    def noise_level(self):\n",
    "        if self._noise_level == self.HIGH:\n",
    "            return \"HIGH\"\n",
    "        elif self._noise_level == self.LOW:\n",
    "            return \"LOW\"\n",
    "        else:\n",
    "            return \"NO\"\n",
    "\n",
    "    def __repr__(self):\n",
    "        return f\"{self.neurons.N} Neurons with {self.input_resistance} input resistance and {self.noise_level} noise\"\n",
    "\n",
    "    def __str__(self):\n",
    "        return self.__repr__()\n",
    "\n",
    "    def store(self, name):\n",
    "        self.network.store(name)\n",
    "\n",
    "    def restore(self, name):\n",
    "        self.network.restore(name)\n",
    "\n",
    "    @property\n",
    "    def v(self):\n",
    "        return self.smon.v\n",
    "\n",
    "    @property\n",
    "    def t(self):\n",
    "        return self.smon.t\n",
    "\n",
    "    @property\n",
    "    def injected_current(self):\n",
    "        return self.neurons.i_injected\n",
    "\n",
    "    @property\n",
    "    def stimulus_amplitude(self):\n",
    "        return self.neurons.A\n",
    "\n",
    "\n",
    "class CurrentModel(Model):\n",
    "    def __init__(self, **kwargs):\n",
    "        super().__init__(stim=self.SINE, **kwargs)\n",
    "\n",
    "    def create_model(self):\n",
    "        model, parameters = super().create_model()\n",
    "        model += CURRENT_INPUT\n",
    "\n",
    "        return model, parameters\n",
    "\n",
    "\n",
    "class SineModel(CurrentModel):\n",
    "    def create_model(self):\n",
    "        model, parameters = super().create_model()\n",
    "        model += SINE_INPUT\n",
    "\n",
    "        return model, parameters\n",
    "\n",
    "\n",
    "class SawModel(CurrentModel):\n",
    "    def create_model(self):\n",
    "        model, parameters = super().create_model()\n",
    "        model += SAW_INPUT\n",
    "\n",
    "        return model, parameters\n",
    "\n",
    "\n",
    "class SynapticModel(Model):\n",
    "    def __init__(self, **kwargs):\n",
    "        super().__init__(stim=self.EXP2SYN, **kwargs)\n",
    "\n",
    "    SYNAPTIC_PARAMETERS = {\n",
    "        \"tau_input_1\": 0.4 * ms,\n",
    "        \"tau_input_2\": 4 * ms,\n",
    "        \"offset_A\": 1.48793507e-11,\n",
    "        \"offset_B\": -2.66359562e-08,\n",
    "        \"offset_C\": 1.77538800e-05,\n",
    "        \"offset_D\": -8.05925810e-04,\n",
    "        \"offset_E\": -3.51463644e-02,\n",
    "        \"offset_switch\": 0,\n",
    "    }\n",
    "\n",
    "    def create_model(self):\n",
    "        model, parameters = super().create_model()\n",
    "        model += EXP2SYN_WAVEFORM + SUMMATION_OFFSET\n",
    "        parameters = {**parameters, **self.SYNAPTIC_PARAMETERS}\n",
    "\n",
    "        return model, parameters\n",
    "\n",
    "    def build_network(self):\n",
    "        super().build_network()\n",
    "        self.spiker = NeuronGroup(\n",
    "            self.neurons.N,\n",
    "            \"\"\"T : second (constant)\n",
    "                                     lastspike : second\"\"\",\n",
    "            threshold=\"timestep(t-lastspike, dt)>=timestep(T, dt)\",\n",
    "            reset=\"lastspike=t\",\n",
    "        )\n",
    "        self.spiker.T = 1 / self.neurons.f\n",
    "        self.synapses = Synapses(\n",
    "            self.spiker, self.neurons, on_pre=\"input_aux += 1\"\n",
    "        )  # connect input to neurons\n",
    "        self.synapses.connect(\"i==j\")  # one synapse goes to one neuron\n",
    "\n",
    "        self.network.add(self.spiker, self.synapses)\n",
    "\n",
    "\n",
    "class SynapticCurrentModel(SynapticModel):\n",
    "    def __init__(self, offset=True, **kwargs):\n",
    "        self.offset = 1 if offset else 0\n",
    "        super().__init__(**kwargs)\n",
    "\n",
    "    def create_model(self):\n",
    "        model, parameters = super().create_model()\n",
    "        model += CURRENT_INPUT + SYNAPTIC_INPUT_CURRENT\n",
    "        parameters = {**parameters, **{\"offset_switch\": self.offset}}\n",
    "\n",
    "        return model, parameters\n",
    "\n",
    "\n",
    "class SynapticConductanceModel(SynapticModel):\n",
    "    FLAT = 0\n",
    "    ACTIVE = 1\n",
    "\n",
    "    CONDUCTANCE_PARAMETERS = {\n",
    "        \"A\": 0 * nS,  # overwrite A to be conductance\n",
    "        \"g_i\": 1 * nS,\n",
    "    }\n",
    "\n",
    "    INHIBITION_PARAMETERS = {\n",
    "        \"tau_inhibition_1\": 1 * ms,\n",
    "        \"tau_inhibition_2\": 10 * ms,\n",
    "    }\n",
    "\n",
    "    def __init__(self, offset=ACTIVE, **kwargs):\n",
    "        self.offset = offset\n",
    "        super().__init__(**kwargs)\n",
    "\n",
    "    def create_model(self):\n",
    "        model, parameters = super().create_model()\n",
    "        if self.offset == self.FLAT:\n",
    "            model += CONDUCTANCE_INPUT + SYNAPTIC_CONDUCTANCE_FLAT\n",
    "            parameters = {\n",
    "                **parameters,\n",
    "                **self.SYNAPTIC_PARAMETERS,\n",
    "                **self.CONDUCTANCE_PARAMETERS,\n",
    "                **{\"offset_switch\": 1},\n",
    "            }\n",
    "\n",
    "        elif self.offset == self.ACTIVE:\n",
    "            model += CONDUCTANCE_INPUT + SYNAPTIC_CONDUCTANCE_STIM\n",
    "            parameters = {\n",
    "                **parameters,\n",
    "                **self.SYNAPTIC_PARAMETERS,\n",
    "                **self.CONDUCTANCE_PARAMETERS,\n",
    "                **self.INHIBITION_PARAMETERS,\n",
    "            }\n",
    "\n",
    "        return model, parameters\n",
    "\n",
    "    def build_network(self):\n",
    "        super().build_network()\n",
    "        if self.offset != self.ACTIVE:\n",
    "            return\n",
    "\n",
    "        self.inhib_synapses = Synapses(\n",
    "            self.spiker, self.neurons, on_pre=\"input_inhib_aux += 1\", delay=2 * ms\n",
    "        )  # connect input to neurons\n",
    "        self.inhib_synapses.connect(\"i==j\")  # one synapse goes to one neuron\n",
    "\n",
    "        self.network.add(self.inhib_synapses)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c82769f2",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING    Cannot use Cython, a test compilation failed: Microsoft Visual C++ 14.0 or greater is required. Get it with \"Microsoft C++ Build Tools\": https://visualstudio.microsoft.com/visual-cpp-build-tools/ (DistutilsPlatformError) [brian2.codegen.runtime.cython_rt.cython_rt.failed_compile_test]\n",
      "INFO       Cannot use compiled code, falling back to the numpy code generation target. Note that this will likely be slower than using compiled code. Set the code generation to numpy manually to avoid this message:\n",
      "prefs.codegen.target = \"numpy\" [brian2.devices.device.codegen_fallback]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting simulation at t=0. s for a duration of 12. s\n",
      "0.59719 s (4%) simulated in 10s, estimated 3m 11s remaining.\n",
      "1.19334 s (9%) simulated in 20s, estimated 3m 1s remaining.\n",
      "1.66498 s (13%) simulated in 30s, estimated 3m 6s remaining.\n",
      "2.18947 s (18%) simulated in 40s, estimated 2m 59s remaining.\n",
      "2.71611 s (22%) simulated in 50s, estimated 2m 51s remaining.\n",
      "3.16604 s (26%) simulated in 1m 0s, estimated 2m 47s remaining.\n",
      "3.6722 s (30%) simulated in 1m 10s, estimated 2m 39s remaining.\n",
      "4.19371 s (34%) simulated in 1m 20s, estimated 2m 29s remaining.\n",
      "4.76632 s (39%) simulated in 1m 30s, estimated 2m 17s remaining.\n",
      "5.33492 s (44%) simulated in 1m 40s, estimated 2m 5s remaining.\n",
      "5.91136 s (49%) simulated in 1m 50s, estimated 1m 53s remaining.\n",
      "6.48644 s (54%) simulated in 2m 0s, estimated 1m 42s remaining.\n",
      "7.06363 s (58%) simulated in 2m 10s, estimated 1m 31s remaining.\n",
      "7.62235 s (63%) simulated in 2m 20s, estimated 1m 20s remaining.\n",
      "8.19532 s (68%) simulated in 2m 30s, estimated 1m 10s remaining.\n",
      "8.77246 s (73%) simulated in 2m 40s, estimated 59s remaining.\n",
      "9.35301 s (77%) simulated in 2m 50s, estimated 48s remaining.\n",
      "9.85757 s (82%) simulated in 3m 0s, estimated 39s remaining.\n",
      "10.42124 s (86%) simulated in 3m 10s, estimated 29s remaining.\n",
      "11.00183 s (91%) simulated in 3m 20s, estimated 18s remaining.\n",
      "11.56277 s (96%) simulated in 3m 30s, estimated 8s remaining.\n",
      "12. s (100%) simulated in 3m 37s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[<matplotlib.collections.EventCollection at 0x18cc1c85a30>]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAASi0lEQVR4nO3df6zdd33f8edrTtyONCMFX9IsdrCRrKneREJ25CYLgqQdmR3BrEpItUWhQ6A7ukRqu62Ts0qgbX9tTNVESTEWdTO2JmErCVjIkKCuWrrSUF+zkNgkprcmXe6czRdSBQqVUnfv/XG+pkc3597ztX3uvfaH50M6ut/v58e5n7eu9fL3fs8595OqQpLUrr+23guQJK0ug16SGmfQS1LjDHpJapxBL0mNu2K9FzDOpk2bauvWreu9DEm6bBw7duybVTUzru+SDPqtW7cyNze33suQpMtGkj9Zrs9bN5LUOINekhpn0EtS4wx6SWqcQS9JjZsY9Em2JPndJM8kOZH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3GM0VOOIadb0/TlVdRZ4CXjtqq18jFaCvvcm5JeqJD8CfBr4xar69kpDx7Sd10bsay3J24EzVXWs75QxbZd0jQyv1G4GPlZVbwK+y/BX/uVcdjV296n3MLxl8TeBq5L87EpTxrRd0jX2cCE1rXu9rQR9nw3ML1lJrmQY8r9VVQ93zf83yXVd/3XAma59uVoXuuOl7ZeC24B/mOQ54CHgJ5P8Z9qqcQFYqKovd+e/zTD4W6rx7wPfqKrFqvoL4GHg79FWjedMs6bvz0lyBfBq4MVVW/kYrQT9ZbsJeffK/G8Az1TVr450HQZ+rjv+OYb37s+17+1eyd8GbAf+sPv18jtJbume8z0jc9ZVVd1bVZuraivDn81/q6qfpa0a/w/wfJK/1TX9FPA1GqqR4S2bW5K8qlvbTwHP0FaN50yzptHneifDf/9r+xvMer4AMuUXU+5i+I6VPwZ+Zb3Xcx7rfjPDX+OeAp7sHncxvIf3O8AfdV9fMzLnV7o6TzLybgVgABzv+j7KGr/g07Pe2/mrF2ObqhG4CZjrfpafAX60wRr/FfBst77/xPDdJ5d1jcCDDF9z+AuGV9/vm2ZNwA8D/xWYZ/jOnDesdY3+CQRJalwrt24kScsw6CWpcQa9JDXOoJekxhn0ktQ4g16SGmfQS1Lj/j8L+QwV5oXFMAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#from models import Model, SynapticConductanceModel\n",
    "from brian2 import *\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "model = SynapticConductanceModel(resistance=Model.LOW, # Model.LOW, Model.HIGH\n",
    "                                 noise=Model.OFF, n=1, # Model.OFF, Model.LOW, Model,HIGH\n",
    "                                 offset=SynapticConductanceModel.ACTIVE)\n",
    "\n",
    "\n",
    "# model = SineModel(resistance=Model.LOW, # Model.LOW, Model.HIGH\n",
    "#                                   noise=Model.OFF, n=1, # Model.OFF, Model.LOW, Model,HIGH\n",
    "#                                 )\n",
    "\n",
    "\n",
    "model.f = 100 * Hz\n",
    "model.set_stimulus_current(400 * nS) # current should be scaled by 100x for Active Offset so (500nS is actually 5nS)\n",
    "model._set_variable(\"i_injected\", 65 * pA)\n",
    "\n",
    "\n",
    "model.run(12*second)\n",
    "\n",
    "spike_times = [s/ms for s in model.spike_train.values()]\n",
    "\n",
    "plt.eventplot(spike_times)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "20e3191c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy.io\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "file_path = 'data44.mat'\n",
    "scipy.io.savemat(file_path, {'data44': spike_times[0]})\n",
    "\n",
    "# file_path = 'data1.mat'\n",
    "# scipy.io.savemat(file_path, {'data1': spike_times[1]})\n",
    "\n",
    "# file_path = 'data2.mat'\n",
    "# scipy.io.savemat(file_path, {'data2': spike_times[2]})\n",
    "\n",
    "# file_path = 'data3.mat'\n",
    "# scipy.io.savemat(file_path, {'data3': spike_times[3]})\n",
    "\n",
    "# file_path = 'data4.mat'\n",
    "# scipy.io.savemat(file_path, {'data4': spike_times[4]})\n",
    "\n",
    "# file_path = 'data5.mat'\n",
    "# scipy.io.savemat(file_path, {'data5': spike_times[5]})\n",
    "\n",
    "# file_path = 'data6.mat'\n",
    "# scipy.io.savemat(file_path, {'data6': spike_times[6]})\n",
    "\n",
    "# file_path = 'data7.mat'\n",
    "# scipy.io.savemat(file_path, {'data7': spike_times[7]})\n",
    "\n",
    "# file_path = 'data8.mat'\n",
    "# scipy.io.savemat(file_path, {'data8': spike_times[8]})\n",
    "\n",
    "# file_path = 'data9.mat'\n",
    "# scipy.io.savemat(file_path, {'data9': spike_times[9]})\n",
    "\n",
    "# file_path = 'data10.mat'\n",
    "# scipy.io.savemat(file_path, {'data10': spike_times[10]})\n",
    "\n",
    "# file_path = 'data11.mat'\n",
    "# scipy.io.savemat(file_path, {'data11': spike_times[11]})\n",
    "\n",
    "# file_path = 'data12.mat'\n",
    "# scipy.io.savemat(file_path, {'data12': spike_times[12]})\n",
    "\n",
    "# file_path = 'data13.mat'\n",
    "# scipy.io.savemat(file_path, {'data13': spike_times[13]})\n",
    "\n",
    "# file_path = 'data14.mat'\n",
    "# scipy.io.savemat(file_path, {'data14': spike_times[14]})\n",
    "\n",
    "# file_path = 'data15.mat'\n",
    "# scipy.io.savemat(file_path, {'data15': spike_times[15]})\n",
    "\n",
    "# file_path = 'data16.mat'\n",
    "# scipy.io.savemat(file_path, {'data16': spike_times[16]})\n",
    "\n",
    "# file_path = 'data17.mat'\n",
    "# scipy.io.savemat(file_path, {'data17': spike_times[17]})\n",
    "\n",
    "# file_path = 'data18.mat'\n",
    "# scipy.io.savemat(file_path, {'data18': spike_times[18]})\n",
    "\n",
    "# file_path = 'data19.mat'\n",
    "# scipy.io.savemat(file_path, {'data19': spike_times[19]})\n",
    "\n",
    "# file_path = 'data20.mat'\n",
    "# scipy.io.savemat(file_path, {'data20': spike_times[20]})\n",
    "\n",
    "# file_path = 'data21.mat'\n",
    "# scipy.io.savemat(file_path, {'data21': spike_times[21]})\n",
    "\n",
    "# file_path = 'data22.mat'\n",
    "# scipy.io.savemat(file_path, {'data22': spike_times[22]})\n",
    "\n",
    "# file_path = 'data23.mat'\n",
    "# scipy.io.savemat(file_path, {'data23': spike_times[23]})\n",
    "\n",
    "# file_path = 'data24.mat'\n",
    "# scipy.io.savemat(file_path, {'data24': spike_times[24]})\n",
    "\n",
    "# file_path = 'data25.mat'\n",
    "# scipy.io.savemat(file_path, {'data25': spike_times[25]})\n",
    "\n",
    "# file_path = 'data26.mat'\n",
    "# scipy.io.savemat(file_path, {'data26': spike_times[26]})\n",
    "\n",
    "# file_path = 'data27.mat'\n",
    "# scipy.io.savemat(file_path, {'data27': spike_times[27]})\n",
    "\n",
    "# file_path = 'data28.mat'\n",
    "# scipy.io.savemat(file_path, {'data28': spike_times[28]})\n",
    "\n",
    "# file_path = 'data29.mat'\n",
    "# scipy.io.savemat(file_path, {'data29': spike_times[29]})\n",
    "\n",
    "# file_path = 'data30.mat'\n",
    "# scipy.io.savemat(file_path, {'data30': spike_times[30]})\n",
    "\n",
    "# file_path = 'data31.mat'\n",
    "# scipy.io.savemat(file_path, {'data31': spike_times[31]})\n",
    "\n",
    "# file_path = 'data32.mat'\n",
    "# scipy.io.savemat(file_path, {'data32': spike_times[32]})\n",
    "\n",
    "# file_path = 'data33.mat'\n",
    "# scipy.io.savemat(file_path, {'data33': spike_times[33]})\n",
    "\n",
    "# file_path = 'data34.mat'\n",
    "# scipy.io.savemat(file_path, {'data34': spike_times[34]})\n",
    "\n",
    "# file_path = 'data35.mat'\n",
    "# scipy.io.savemat(file_path, {'data35': spike_times[35]})\n",
    "\n",
    "# file_path = 'data36.mat'\n",
    "# scipy.io.savemat(file_path, {'data36': spike_times[36]})\n",
    "\n",
    "# file_path = 'data37.mat'\n",
    "# scipy.io.savemat(file_path, {'data37': spike_times[37]})\n",
    "\n",
    "# file_path = 'data38.mat'\n",
    "# scipy.io.savemat(file_path, {'data38': spike_times[38]})\n",
    "\n",
    "# file_path = 'data39.mat'\n",
    "# scipy.io.savemat(file_path, {'data39': spike_times[39]})\n",
    "\n",
    "# file_path = 'data40.mat'\n",
    "# scipy.io.savemat(file_path, {'data40': spike_times[40]})\n",
    "\n",
    "# file_path = 'data41.mat'\n",
    "# scipy.io.savemat(file_path, {'data41': spike_times[41]})\n",
    "\n",
    "# file_path = 'data42.mat'\n",
    "# scipy.io.savemat(file_path, {'data42': spike_times[42]})\n",
    "\n",
    "# file_path = 'data43.mat'\n",
    "# scipy.io.savemat(file_path, {'data43': spike_times[43]})\n",
    "\n",
    "# file_path = 'data44.mat'\n",
    "# scipy.io.savemat(file_path, {'data44': spike_times[44]})\n",
    "\n",
    "# file_path = 'data45.mat'\n",
    "# scipy.io.savemat(file_path, {'data45': spike_times[45]})\n",
    "\n",
    "# file_path = 'data46.mat'\n",
    "# scipy.io.savemat(file_path, {'data46': spike_times[46]})\n",
    "\n",
    "# file_path = 'data47.mat'\n",
    "# scipy.io.savemat(file_path, {'data47': spike_times[47]})\n",
    "\n",
    "# file_path = 'data48.mat'\n",
    "# scipy.io.savemat(file_path, {'data48': spike_times[48]})\n",
    "\n",
    "# file_path = 'data49.mat'\n",
    "# scipy.io.savemat(file_path, {'data49': spike_times[49]})\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "984ebae5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}