{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# LFP Analysis\n", "\n", "## Tutorial overview\n", "\n", "This Jupyter notebook will demonstrate how to access and analyze LFP data from the Neuropixels Visual Coding dataset. LFP, which stands for \"local field potential,\" contains information about low-frequency (0.1-500 Hz) voltage fluctations around each recording site. It's complementary to the spiking activity, and can be analyzed on its own or in conjunction with spikes.\n", "\n", "This tutorial will cover the following topics:\n", "\n", "* Selecting probes to analyze\n", "* Loading LFP data\n", "* Aligning data in time\n", "* Aligning data in space\n", "* Exploring pre-computed CSD plots\n", "\n", "This tutorial assumes you've already created a data cache, or are working with the files on AWS. If you haven't reached that step yet, we recommend going through the [data access tutorial](./ecephys_data_access.ipynb) first.\n", "\n", "Functions related to analyzing spike data will be covered in other tutorials. For a full list of available tutorials, see the [SDK documentation](https://allensdk.readthedocs.io/en/latest/visual_coding_neuropixels.html)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's start by creating an `EcephysProjectCache` object, and pointing it to a new or existing manifest file:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "import numpy as np\n", "import pandas as pd\n", "\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "from allensdk.brain_observatory.ecephys.ecephys_project_cache import EcephysProjectCache" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you're not sure what a manifest file is or where to put it, please check out [this tutorial](./ecephys_data_access.ipynb) before going further." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Example cache directory path, it determines where downloaded data will be stored\n", "data_directory = '/local1/ecephys_cache_dir/'\n", "\n", "manifest_path = os.path.join(data_directory, \"manifest.json\")\n", "\n", "cache = EcephysProjectCache.from_warehouse(manifest=manifest_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's load the `sessions` table and grab the data for the first experiment in the list:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING:root:downloading a 2.72e+03mb file from http://api.brain-map.org//api/v2/well_known_file_download/1026124469\n" ] } ], "source": [ "sessions = cache.get_session_table()\n", "\n", "session = cache.get_session_data(sessions.index.values[0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Learning about the available probes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `session` object contains all of the spike data for one recording session, as well as information about the stimulus, mouse behavior, and probes. To prevent the underlying NWB file from becoming too large, the LFP data is stored separately, on a probe-by-probe basis. Before loading the LFP, let's take a look at the probes that are available for this session." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | description | \n", "location | \n", "sampling_rate | \n", "lfp_sampling_rate | \n", "has_lfp_data | \n", "
---|---|---|---|---|---|
id | \n", "\n", " | \n", " | \n", " | \n", " | \n", " |
810755797 | \n", "probeA | \n", "See electrode locations | \n", "29999.954846 | \n", "1249.998119 | \n", "True | \n", "
810755799 | \n", "probeB | \n", "See electrode locations | \n", "29999.906318 | \n", "1249.996097 | \n", "True | \n", "
810755801 | \n", "probeC | \n", "See electrode locations | \n", "29999.985470 | \n", "1249.999395 | \n", "True | \n", "
810755803 | \n", "probeD | \n", "See electrode locations | \n", "29999.908100 | \n", "1249.996171 | \n", "True | \n", "
810755805 | \n", "probeE | \n", "See electrode locations | \n", "29999.985679 | \n", "1249.999403 | \n", "True | \n", "
810755807 | \n", "probeF | \n", "See electrode locations | \n", "30000.028033 | \n", "1250.001168 | \n", "True | \n", "
array([[-2.43750e-05, -3.08100e-05, -3.19800e-05, ..., -1.95000e-07,\n", " -1.34550e-05, -1.15050e-05],\n", " [-4.44600e-05, -3.31500e-05, -1.42350e-05, ..., 1.95000e-06,\n", " -2.49600e-05, -1.34550e-05],\n", " [-4.58250e-05, 1.17000e-06, -1.42350e-05, ..., 1.36500e-06,\n", " -1.03350e-05, -1.71600e-05],\n", " ...,\n", " [-9.59400e-05, -1.54245e-04, -1.06275e-04, ..., 4.89450e-05,\n", " 0.00000e+00, 4.09500e-06],\n", " [-1.93050e-05, -7.17600e-05, -4.25100e-05, ..., 6.10350e-05,\n", " -9.75000e-07, 1.15050e-05],\n", " [-2.73000e-05, -7.21500e-05, -6.24000e-05, ..., 3.04200e-05,\n", " -1.95000e-06, -1.95000e-07]], dtype=float32)
array([ 13.581063, 13.581863, 13.582663, ..., 9636.777657, 9636.778457,\n", " 9636.779257])
array([850258492, 850258500, 850258508, 850258516, 850258524, 850258532,\n", " 850258540, 850258548, 850258556, 850258564, 850258572, 850258580,\n", " 850258588, 850258596, 850258604, 850258612, 850258620, 850258628,\n", " 850258636, 850258644, 850258652, 850258660, 850258668, 850258676,\n", " 850258684, 850258692, 850258700, 850258708, 850258716, 850258724,\n", " 850258732, 850258740, 850258748, 850258756, 850258764, 850258772,\n", " 850258780, 850258788, 850258796, 850258804, 850258812, 850258820,\n", " 850258828, 850258836, 850258844, 850258852, 850258860, 850258868,\n", " 850258876, 850258884, 850258892, 850258900, 850258908, 850258916,\n", " 850258924, 850258932, 850258940, 850258948, 850258956, 850258964,\n", " 850258972, 850258980, 850258988, 850258996, 850259004, 850259012,\n", " 850259020, 850259028, 850259036, 850259044, 850259052, 850259060,\n", " 850259068, 850259076, 850259084, 850259092, 850259100, 850259108,\n", " 850259116, 850259124, 850259132, 850259140, 850259148, 850259156,\n", " 850259164, 850259172, 850259180, 850259188, 850259196, 850259204,\n", " 850259212, 850259220, 850259228, 850259236, 850259244])
array([[ 1.50149994e-04, 1.49954998e-04, 1.65749996e-04, ...,\n", " 4.68000007e-06, 2.30099995e-05, -1.13099995e-05],\n", " [ 1.64190002e-04, 1.41569995e-04, 1.50734995e-04, ...,\n", " 6.62999992e-06, 1.18950002e-05, -1.30649996e-05],\n", " [ 1.43519996e-04, 1.47030005e-04, 1.80959993e-04, ...,\n", " 4.48499986e-06, 1.96950004e-05, 8.18999979e-06],\n", " ...,\n", " [-2.35949992e-05, -1.63799996e-05, -3.45150002e-05, ...,\n", " 1.55999999e-06, -1.48199997e-05, -1.11150002e-05],\n", " [-1.87200003e-05, -5.75249978e-05, -4.93349980e-05, ...,\n", " 8.38500000e-06, -2.00849991e-05, -5.26499980e-06],\n", " [-3.17849990e-05, -5.53799982e-05, -4.17299998e-05, ...,\n", " 2.14500005e-06, -1.67700000e-05, -2.73000001e-06]], dtype=float32)
array([100.000304, 100.001104, 100.001904, ..., 100.997905, 100.998705,\n", " 100.999505])
array([850258492, 850258500, 850258508, 850258516, 850258524, 850258532,\n", " 850258540, 850258548, 850258556, 850258564, 850258572, 850258580,\n", " 850258588, 850258596, 850258604, 850258612, 850258620, 850258628,\n", " 850258636, 850258644, 850258652, 850258660, 850258668, 850258676,\n", " 850258684, 850258692, 850258700, 850258708, 850258716, 850258724,\n", " 850258732, 850258740, 850258748, 850258756, 850258764, 850258772,\n", " 850258780, 850258788, 850258796, 850258804, 850258812, 850258820,\n", " 850258828, 850258836, 850258844, 850258852, 850258860, 850258868,\n", " 850258876, 850258884, 850258892, 850258900, 850258908, 850258916,\n", " 850258924, 850258932, 850258940, 850258948, 850258956, 850258964,\n", " 850258972, 850258980, 850258988, 850258996, 850259004, 850259012,\n", " 850259020, 850259028, 850259036, 850259044, 850259052, 850259060,\n", " 850259068, 850259076, 850259084, 850259092, 850259100, 850259108,\n", " 850259116, 850259124, 850259132, 850259140, 850259148, 850259156,\n", " 850259164, 850259172, 850259180, 850259188, 850259196, 850259204,\n", " 850259212, 850259220, 850259228, 850259236, 850259244])
array([[ 58327.03371574, 20117.6298887 , -14617.79294315, ...,\n", " -179410.38257756, -140541.81597896, -99855.52022176],\n", " [ -65434.3204571 , -32932.62888488, -3367.24904473, ...,\n", " 161433.08930627, 136244.74051173, 109671.1407354 ],\n", " [ 28505.59773412, 31288.43801342, 33892.68350592, ...,\n", " 39946.37351702, 24588.34919833, 8571.48977541],\n", " ...,\n", " [ -3201.28149464, -1289.03683893, 502.04419085, ...,\n", " -943.9933153 , -2669.37931577, -4375.39738216],\n", " [ -32827.35201643, -16409.56190898, -1052.05581321, ...,\n", " -106129.85783238, -94380.54770586, -82251.01882374],\n", " [ 34153.87655675, 16950.77633742, 815.89811501, ...,\n", " 94579.10700446, 89217.81476538, 83741.3728981 ]])
array([ 0, 1, 2, ..., 381, 382, 383])
array([-0.1 , -0.0996, -0.0992, ..., 0.2488, 0.2492, 0.2496])
array([ 0., 10., 20., 30., 40., 50., 60., 70., 80.,\n", " 90., 100., 110., 120., 130., 140., 150., 160., 170.,\n", " 180., 190., 200., 210., 220., 230., 240., 250., 260.,\n", " 270., 280., 290., 300., 310., 320., 330., 340., 350.,\n", " 360., 370., 380., 390., 400., 410., 420., 430., 440.,\n", " 450., 460., 470., 480., 490., 500., 510., 520., 530.,\n", " 540., 550., 560., 570., 580., 590., 600., 610., 620.,\n", " 630., 640., 650., 660., 670., 680., 690., 700., 710.,\n", " 720., 730., 740., 750., 760., 770., 780., 790., 800.,\n", " 810., 820., 830., 840., 850., 860., 870., 880., 890.,\n", " 900., 910., 920., 930., 940., 950., 960., 970., 980.,\n", " 990., 1000., 1010., 1020., 1030., 1040., 1050., 1060., 1070.,\n", " 1080., 1090., 1100., 1110., 1120., 1130., 1140., 1150., 1160.,\n", " 1170., 1180., 1190., 1200., 1210., 1220., 1230., 1240., 1250.,\n", " 1260., 1270., 1280., 1290., 1300., 1310., 1320., 1330., 1340.,\n", " 1350., 1360., 1370., 1380., 1390., 1400., 1410., 1420., 1430.,\n", " 1440., 1450., 1460., 1470., 1480., 1490., 1500., 1510., 1520.,\n", " 1530., 1540., 1550., 1560., 1570., 1580., 1590., 1600., 1610.,\n", " 1620., 1630., 1640., 1650., 1660., 1670., 1680., 1690., 1700.,\n", " 1710., 1720., 1730., 1740., 1750., 1760., 1770., 1780., 1790.,\n", " 1800., 1810., 1820., 1830., 1840., 1850., 1860., 1870., 1880.,\n", " 1890., 1900., 1910., 1920., 1930., 1940., 1950., 1960., 1970.,\n", " 1980., 1990., 2000., 2010., 2020., 2030., 2040., 2050., 2060.,\n", " 2070., 2080., 2090., 2100., 2110., 2120., 2130., 2140., 2150.,\n", " 2160., 2170., 2180., 2190., 2200., 2210., 2220., 2230., 2240.,\n", " 2250., 2260., 2270., 2280., 2290., 2300., 2310., 2320., 2330.,\n", " 2340., 2350., 2360., 2370., 2380., 2390., 2400., 2410., 2420.,\n", " 2430., 2440., 2450., 2460., 2470., 2480., 2490., 2500., 2510.,\n", " 2520., 2530., 2540., 2550., 2560., 2570., 2580., 2590., 2600.,\n", " 2610., 2620., 2630., 2640., 2650., 2660., 2670., 2680., 2690.,\n", " 2700., 2710., 2720., 2730., 2740., 2750., 2760., 2770., 2780.,\n", " 2790., 2800., 2810., 2820., 2830., 2840., 2850., 2860., 2870.,\n", " 2880., 2890., 2900., 2910., 2920., 2930., 2940., 2950., 2960.,\n", " 2970., 2980., 2990., 3000., 3010., 3020., 3030., 3040., 3050.,\n", " 3060., 3070., 3080., 3090., 3100., 3110., 3120., 3130., 3140.,\n", " 3150., 3160., 3170., 3180., 3190., 3200., 3210., 3220., 3230.,\n", " 3240., 3250., 3260., 3270., 3280., 3290., 3300., 3310., 3320.,\n", " 3330., 3340., 3350., 3360., 3370., 3380., 3390., 3400., 3410.,\n", " 3420., 3430., 3440., 3450., 3460., 3470., 3480., 3490., 3500.,\n", " 3510., 3520., 3530., 3540., 3550., 3560., 3570., 3580., 3590.,\n", " 3600., 3610., 3620., 3630., 3640., 3650., 3660., 3670., 3680.,\n", " 3690., 3700., 3710., 3720., 3730., 3740., 3750., 3760., 3770.,\n", " 3780., 3790., 3800., 3810., 3820., 3830.])
array([24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24., 24.,\n", " 24., 24., 24., 24., 24., 24., 24.])