{
 "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\" : 0*pA,\n",
    "        \"c\": 85 * pF,\n",
    "        \"tau_w\": 18 * 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": {},
   "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 3. s\n",
      "0.95134 s (31%) simulated in 10s, estimated 22s remaining.\n",
      "1.91078 s (63%) simulated in 20s, estimated 11s remaining.\n",
      "2.80958 s (93%) simulated in 30s, estimated 2s remaining.\n",
      "3. s (100%) simulated in 32s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[<matplotlib.collections.EventCollection at 0x2cb308296a0>]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAASmElEQVR4nO3db4xd913n8fdn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z5/G/A7gLOLeS8QN/Bfwsg9XIPgfs3yBz+U3gV0e03ehzuQW4q9u+Cfh6N+ZNd26WmMtmPTcB3tBtbwX+Erh7Lc5NC1f0LS1AfgD44277j4F/N1T+WFX936r6BoP/93/v2g/vn1XVU8DLC4qXNf4MFpD/l1X1pRr87f3UUJ81s8hcFrPR5/JSVX252/4O8ByDdZo33blZYi6L2bBzAaiB73a7W7tHsQbnpoWg770A+QZTwJNJziSZ6cpursHKXHTPb+nKN8sclzv+W7vtheUbxeEkz3S3dq79Or1p5pJkJ/BTDK4cN/W5WTAX2KTnJsmWJGeBK8AXqmpNzk0LQd97AfIN5p6qugvYDzyY5B1LtN2sc7xmxYvHr4NPAv8auBN4CfjPXfmmmEuSNwCPA79cVd9equmIsg01nxFz2bTnpqq+X1V3Mlg/e2+Sn1yi+cTm00LQ91m8fMOpqsvd8xXgBINbMX/b/VpG93yla75Z5rjc8V/qtheWr7uq+tvuh/L/A/+Ff75VtuHnkmQrg2D8k6r6TFe8Kc/NqLls5nNzTVX9H+C/A/tYg3PTQtBvugXIk9yY5KZr28D9wDkG4/6FrtkvAJ/ttk8CB5P8QJJdwG4Gb8ZsNMsaf/dr6neS3N19auADQ33W1bUfvM57GJwf2OBz6V77j4Dnqup3h6o23blZbC6b+NxMJXljt/1DwL8BvsZanJu1fud5NR4MFib/OoN3pX9jvcfTY7w/xuDd9K8A56+NGXgz8N+Av+6e3zTU5ze6+V1gHT4xMGIOjzL4tfn/MbjC+ND1jB+YZvCD+jfAJ+i+rb0B5vJfgWeBZ7ofuFs2yVzezuDX+GeAs93jgc14bpaYy2Y9N28D/lc37nPAQ135qp8b/wsESWpcC7duJElLMOglqXEGvSQ1zqCXpMYZ9JLUOINekhpn0EtS4/4RXlnSTEO4AGQAAAAASUVORK5CYII=\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.HIGH, n=1, # Model.OFF, Model.LOW, Model,HIGH\n",
    "                                )\n",
    "\n",
    "\n",
    "model.f = 100 * Hz\n",
    "model.set_stimulus_current(50 * pA) # current should be scaled by 100x for Active Offset so (500nS is actually 5nS)\n",
    "model._set_variable(\"i_injected\", 120 * pA)\n",
    "\n",
    "\n",
    "model.run(3*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": "7f22e21e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([  11.4 ,   52.2 ,  112.53,  163.32,  223.74,  282.83,  342.44,\n",
      "        393.5 ,  462.39,  513.32,  551.42,  623.55,  672.78,  721.33,\n",
      "        763.71,  813.73,  861.92,  903.15,  950.91, 1011.26, 1064.03,\n",
      "       1111.7 , 1152.35, 1192.45, 1253.93, 1302.89, 1351.97, 1405.34,\n",
      "       1443.49, 1503.12, 1553.12, 1590.39, 1628.59, 1673.29, 1743.4 ,\n",
      "       1783.73, 1941.85, 1995.04, 2042.32, 2090.48, 2142.43, 2204.9 ,\n",
      "       2263.11, 2351.07, 2403.68, 2444.84, 2487.09, 2533.25, 2611.62,\n",
      "       2672.94, 2735.16, 2773.64, 2842.8 , 2882.27, 2932.88, 2975.41])]\n"
     ]
    }
   ],
   "source": [
    "print(spike_times)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "20e3191c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy.io\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "file_path = 'data0.mat'\n",
    "scipy.io.savemat(file_path, {'data0': spike_times[0]})\n",
    "\n",
    "file_path = 'data1.mat'\n",
    "scipy.io.savemat(file_path, {'data1': spike_times[0]})\n",
    "\n",
    "file_path = 'data2.mat'\n",
    "scipy.io.savemat(file_path, {'data2': spike_times[0]})\n",
    "\n",
    "file_path = 'data3.mat'\n",
    "scipy.io.savemat(file_path, {'data3': spike_times[0]})\n",
    "\n",
    "file_path = 'data4.mat'\n",
    "scipy.io.savemat(file_path, {'data4': spike_times[0]})\n",
    "\n",
    "file_path = 'data5.mat'\n",
    "scipy.io.savemat(file_path, {'data5': spike_times[0]})\n",
    "\n",
    "file_path = 'data6.mat'\n",
    "scipy.io.savemat(file_path, {'data6': spike_times[0]})\n",
    "\n",
    "file_path = 'data7.mat'\n",
    "scipy.io.savemat(file_path, {'data7': spike_times[0]})\n",
    "\n",
    "file_path = 'data8.mat'\n",
    "scipy.io.savemat(file_path, {'data8': spike_times[0]})\n",
    "\n",
    "file_path = 'data9.mat'\n",
    "scipy.io.savemat(file_path, {'data9': spike_times[0]})\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": "d353eff4",
   "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
}