|
48 | 48 | } |
49 | 49 | ], |
50 | 50 | "source": [ |
| 51 | + "from tklfp import read_data, clean_data\n", |
51 | 52 | "\n", |
52 | | - "def read_data(fname):\n", |
53 | | - " with open(fname) as csvfile:\n", |
54 | | - " r = csv.reader(csvfile)\n", |
55 | | - " rows = []\n", |
56 | | - " for row in r:\n", |
57 | | - " rows.append(row)\n", |
58 | | - " return np.array(rows, dtype=float)\n", |
59 | | - "\n", |
60 | | - "def clean_data(depth_amp, table_amp_values):\n", |
61 | | - " depth_amp = np.vstack((depth_amp, [800, 0]))\n", |
62 | | - " depth_amp[:, 0] = np.around(depth_amp[:, 0], -1)\n", |
63 | | - " depth_amp[[0, 4, 8, 12], 1] = table_amp_values\n", |
64 | | - " return depth_amp\n", |
65 | | - "\n", |
66 | | - "exc_depth_amp = read_data('../web-plot-digitizer/fig5a-points.csv')\n", |
| 53 | + "exc_depth_amp = read_data(\"../tklfp/fig5a-points.csv\")\n", |
67 | 54 | "exc_depth_amp = clean_data(exc_depth_amp, [-1.6, 4.8, 2.4, -0.8])\n", |
68 | 55 | "\n", |
69 | | - "inh_depth_amp = read_data('../web-plot-digitizer/fig5b-points.csv')\n", |
| 56 | + "inh_depth_amp = read_data(\"../tklfp/fig5b-points.csv\")\n", |
70 | 57 | "inh_depth_amp = clean_data(inh_depth_amp, [-2, 30, -12, 3])\n", |
71 | 58 | "\n", |
72 | 59 | "fig, axs = plt.subplots(1, 2, sharey=True, figsize=(6, 2.5))\n", |
73 | 60 | "axs[0].scatter(exc_depth_amp[:, 0], exc_depth_amp[:, 1])\n", |
74 | | - "axs[0].set(title='Excitatory uLFP', ylabel='uLFP amplitude (μV)', xlabel='Depth (μm)')\n", |
| 61 | + "axs[0].set(title=\"Excitatory uLFP\", ylabel=\"uLFP amplitude (μV)\", xlabel=\"Depth (μm)\")\n", |
75 | 62 | "axs[1].scatter(inh_depth_amp[:, 0], inh_depth_amp[:, 1])\n", |
76 | | - "axs[1].set(title='Inhibitory uLFP', xlabel='Depth (μm)')\n", |
| 63 | + "axs[1].set(title=\"Inhibitory uLFP\", xlabel=\"Depth (μm)\")\n", |
77 | 64 | "plt.show()" |
78 | 65 | ] |
79 | 66 | }, |
|
83 | 70 | "metadata": {}, |
84 | 71 | "source": [ |
85 | 72 | "## Some modifications\n", |
86 | | - "The amplitude values in the figure are 10 times what is recommended in table 1, so we will scale them down.\n", |
87 | | - "\n", |
88 | | - "To make the profile more flexible, we'll also interpolate and extrapolate, assuming that by 200 μm outside the reported range the uLFP drops to 0.\n", |
89 | | - "\n", |
90 | | - "Finally, we'll change from μm to mm for consistency with horizontal coordinates." |
| 73 | + "The package preprocesses the data a little more and interpolates.\n", |
| 74 | + "Preprocessing steps:\n", |
| 75 | + "- The amplitude values in the figure are 10 times what is recommended in table 1, so we scale them down.\n", |
| 76 | + "- To make the profile more flexible, we'll also interpolate and extrapolate, assuming that by 200 μm outside the reported range the uLFP drops to 0.\n", |
| 77 | + "- Finally, we change from μm to mm for consistency with horizontal coordinates." |
91 | 78 | ] |
92 | 79 | }, |
93 | 80 | { |
|
108 | 95 | } |
109 | 96 | ], |
110 | 97 | "source": [ |
111 | | - "from scipy.interpolate import interp1d\n", |
112 | | - "def modify_and_interpolate_data(data):\n", |
113 | | - " data_mod = data.copy()\n", |
114 | | - " data_mod[:, 1] /= 10\n", |
115 | | - " npad = 10 # adding multiple zeros will prevent spline interp overshoot\n", |
116 | | - " deep_padding = np.zeros((npad, 2))\n", |
117 | | - " deep_padding[:, 0] = np.linspace(-700, -600, npad)\n", |
118 | | - " sup_padding = np.zeros((npad, 2))\n", |
119 | | - " sup_padding[:, 0] = np.linspace(1000, 1100, npad)\n", |
120 | | - " data_mod = np.vstack([deep_padding, data_mod, sup_padding])\n", |
121 | | - " data_mod[:, 0] /= 1000\n", |
122 | | - " return interp1d(data_mod[:, 0], data_mod[:, 1], kind='cubic', \n", |
123 | | - " fill_value=0, bounds_error=False)\n", |
124 | | - "\n", |
125 | | - "f_exc = modify_and_interpolate_data(exc_depth_amp)\n", |
126 | | - "f_inh = modify_and_interpolate_data(inh_depth_amp)\n", |
| 98 | + "from tklfp import f_exc, f_inh\n", |
127 | 99 | "\n", |
128 | 100 | "fig, axs = plt.subplots(1, 2, sharey=True, figsize=(6, 2.5))\n", |
129 | 101 | "depths = np.linspace(-1, 1.4)\n", |
130 | | - "axs[0].scatter(exc_depth_amp[:, 0]/1000, exc_depth_amp[:, 1]/10)\n", |
131 | | - "axs[0].set(title='Excitatory uLFP', ylabel='uLFP amplitude (μV)', xlabel='Depth (mm)')\n", |
| 102 | + "axs[0].scatter(exc_depth_amp[:, 0] / 1000, exc_depth_amp[:, 1] / 10)\n", |
| 103 | + "axs[0].set(title=\"Excitatory uLFP\", ylabel=\"uLFP amplitude (μV)\", xlabel=\"Depth (mm)\")\n", |
132 | 104 | "axs[0].plot(depths, f_exc(depths), lw=1)\n", |
133 | | - "axs[1].scatter(inh_depth_amp[:, 0]/1000, inh_depth_amp[:, 1]/10, label='data')\n", |
134 | | - "axs[1].set(title='Inhibitory uLFP', xlabel='Depth (mm)')\n", |
135 | | - "axs[1].plot(depths, f_inh(depths), lw=1, label='interp')\n", |
| 105 | + "axs[1].scatter(inh_depth_amp[:, 0] / 1000, inh_depth_amp[:, 1] / 10, label=\"data\")\n", |
| 106 | + "axs[1].set(title=\"Inhibitory uLFP\", xlabel=\"Depth (mm)\")\n", |
| 107 | + "axs[1].plot(depths, f_inh(depths), lw=1, label=\"interp\")\n", |
136 | 108 | "axs[1].legend()\n", |
137 | 109 | "plt.show()" |
138 | 110 | ] |
|
142 | 114 | "id": "414972a3", |
143 | 115 | "metadata": {}, |
144 | 116 | "source": [ |
145 | | - "This looks reasonable. Now let's save the interpolation objects:" |
146 | | - ] |
147 | | - }, |
148 | | - { |
149 | | - "cell_type": "code", |
150 | | - "execution_count": null, |
151 | | - "id": "5e918b8d", |
152 | | - "metadata": {}, |
153 | | - "outputs": [], |
154 | | - "source": [ |
155 | | - "import pickle\n", |
156 | | - "with open('../tklfp/exc_A0_by_depth.pkl', 'wb') as exc_file, open('../tklfp/inh_A0_by_depth.pkl', 'wb') as inh_file:\n", |
157 | | - " pickle.dump(f_exc, exc_file)\n", |
158 | | - " pickle.dump(f_inh, inh_file)" |
| 117 | + "This looks reasonable." |
159 | 118 | ] |
160 | 119 | } |
161 | 120 | ], |
|
0 commit comments