User Tools

Site Tools


analysis:course:week2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
analysis:course:week2 [2013/09/15 21:33]
mvdm [Introductory remarks]
analysis:course:week2 [2018/07/07 10:19] (current)
Line 1: Line 1:
-NOTE: **This page is under construction! Please do not use until after the next class meeting! 8-)**+~~DISCUSSION~~
  
 ===== Visualizing neural data in MATLAB ===== ===== Visualizing neural data in MATLAB =====
Line 17: Line 17:
 Resources: Resources:
  
 +  * (required) read Chapter 1 of the Leis book, a gentle introduction to signal processing, in preparation for next week.
 +  * (required) review Chapter 2 of the Leis book. If you are uncertain about any of the material I recommend you work through the exercises to make sure you are up to speed.
   * (you will likely need this) MATLAB documentation for ''​plot'',​ [[ http://​www.mathworks.com/​help/​matlab/​ref/​figure_props.html | Figure properties ]], [[ http://​www.mathworks.com/​help/​matlab/​ref/​axes_props.html | Axis properties ]] and [[ http://​www.mathworks.com/​help/​matlab/​ref/​line_props.html | Line Properties ]]   * (you will likely need this) MATLAB documentation for ''​plot'',​ [[ http://​www.mathworks.com/​help/​matlab/​ref/​figure_props.html | Figure properties ]], [[ http://​www.mathworks.com/​help/​matlab/​ref/​axes_props.html | Axis properties ]] and [[ http://​www.mathworks.com/​help/​matlab/​ref/​line_props.html | Line Properties ]]
   * (optional) [[http://​www.mathworks.com/​help/​matlab/​creating_plots/​figures-plots-and-graphs.html | MATLAB plotting gallery ]]   * (optional) [[http://​www.mathworks.com/​help/​matlab/​creating_plots/​figures-plots-and-graphs.html | MATLAB plotting gallery ]]
Line 42: Line 44:
 Use the shortcut button created in the previous module to restore MATLAB'​s default path, add the vandermeerlab codebase to it, and move to your ''​BIOL680''​ folder. Use the shortcut button created in the previous module to restore MATLAB'​s default path, add the vandermeerlab codebase to it, and move to your ''​BIOL680''​ folder.
  
-Create a folder with today'​s date and ''​cd''​ to it. This will be your "​scratch"​ working directory with stuff that you don't intend to push to GitHub. At the end of this module you will have something to push, but this will go in the ''​shared''​ folder under ''​BIOL680''​ once you are satisfied with your work.+Create a folder with today'​s date and ''​cd''​ to it. This will be your "​scratch"​ working directory with stuff that you don'​t ​necessarily ​intend to push to GitHub ​(although you are welcome to if it's easier or you would like me to be able to see what you did). At the end of this module you will have something to push, but this will go in the ''​shared''​ folder under ''​BIOL680''​ once you are satisfied with your work.
  
-Grab the folder ''​R042-2013-08-18''​ from the lab database, making sure you login with ''​BIOL680''​ credentials so we all have the same version. As before, place the data in a sensible local location. This data set was collected from the dorsal CA1 region of the hippocampus of a rat performing a T-maze task, using a drive with 16 independently movable tetrodes.+Grab the folder ''​R042-2013-08-18''​ from the lab database, making sure you login with ''​BIOL680''​ credentials so we all have the same version. As before, place the data in a sensible local location. This data set was collected from the dorsal CA1 region of the hippocampus of a rat performing a T-maze task, using a drive with 16 independently movable tetrodes. ​Spike and LFP data was recorded from each tetrode; possible spike events were detected online and stored for offline spike-sorting,​ and LFPs were sampled at 2kHz and bandpass filtered between 1-475Hz. (A quirk of this particular data set is that certain time intervals are cut out of the spike data, but not the LFP. So you may notice some odd looking gaps in the rasterplot.)
  
 Create a ''​sandbox.m''​ file in your daily folder. In this file, use cell mode to load some spike trains, a LFP, and position data as follows (recall you can use Ctrl+Enter to execute the code in a cell): Create a ''​sandbox.m''​ file in your daily folder. In this file, use cell mode to load some spike trains, a LFP, and position data as follows (recall you can use Ctrl+Enter to execute the code in a cell):
  
 <code matlab> <code matlab>
-%% load the data+%% load the data (note, may need to unzip position data first)
 fc = FindFiles('​*.t'​);​ fc = FindFiles('​*.t'​);​
 S = LoadSpikes(fc);​ S = LoadSpikes(fc);​
  
-[csc,​csc_info] = LoadCSC('​R042-2013-08-18-CSC03a.Ncs');+[csc,​csc_info] = LoadCSC('​R042-2013-08-18-CSC03a.ncs');
  
 [Timestamps,​ X, Y, Angles, Targets, Points, Header] = Nlx2MatVT('​VT1.nvt',​ [1 1 1 1 1 1], 1, 1, [] ); [Timestamps,​ X, Y, Angles, Targets, Points, Header] = Nlx2MatVT('​VT1.nvt',​ [1 1 1 1 1 1], 1, 1, [] );
Line 90: Line 92:
 ==== Plotting with handles ==== ==== Plotting with handles ====
  
-☛ Plot the LFP (time against voltage) for the segment between 5950 and 6950 s. Remember to do this using a cell in your ''​sandbox.m''​ file so that it's easy to make changes later and you keep a record of what you did.+☛ Plot the LFP (time against voltage) for the segment between 5950 and 6050 s. Remember to do this using a cell in your ''​sandbox.m''​ file so that it's easy to make changes later and you keep a record of what you did.
  
 Any MATLAB figure is actually a collection of objects, all with their own properties which you can access and edit. For instance, to change the figure background to black, do Any MATLAB figure is actually a collection of objects, all with their own properties which you can access and edit. For instance, to change the figure background to black, do
Line 98: Line 100:
 </​code>​ </​code>​
  
-''​gcf''​ is MATLAB'​s name for "the current figure"​. The above command set its '''​Color'''​ property to ''​[0 0 0]''​ which is black (zero red, zero green, zero blue in the RGB world).+''​gcf''​ is MATLAB'​s name for "get current figure"​. The above command set its '''​Color'''​ property to ''​[0 0 0]''​ which is black (zero red, zero green, zero blue in the RGB world).
  
 ☛ Set the background of the current /axes/ to black (''​gca''​ is MATLAB'​s name for the current axes object; notice that the axes background is currently white, which looks ugly). ☛ Set the background of the current /axes/ to black (''​gca''​ is MATLAB'​s name for the current axes object; notice that the axes background is currently white, which looks ugly).
Line 162: Line 164:
 ☛ Create a keypress function that moves the x-limits of the current figure'​s axes to the left or right by 50% (i.e. if the current axes are from 1 to 2s, then pressing the right arrow key takes it to 1.5-2.5 s. It will be easier to do this with a ''​.m''​ file given the length of what you need to do. ☛ Create a keypress function that moves the x-limits of the current figure'​s axes to the left or right by 50% (i.e. if the current axes are from 1 to 2s, then pressing the right arrow key takes it to 1.5-2.5 s. It will be easier to do this with a ''​.m''​ file given the length of what you need to do.
  
-Hint: model your ''​.m''​ file on the template in the example given in the KeyPressFcn section of the [[http://​www.mathworks.com/​help/​matlab/​ref/​figure_props.html|Figure properties ]] page, and define it thus: ''​f_hdl = figure('​KeyPressFcn',​@your_function);''​ if your function is called ''​your_function.m''​.+Hint: model your ''​.m''​ file on the template in the example given in the KeyPressFcn section of the [[http://​www.mathworks.com/​help/​matlab/​ref/​figure_props.html|Figure properties ]] page, and define it thus: ''​f_hdl = figure('​KeyPressFcn',​@your_function);''​ if your function is called ''​your_function.m''​. Please keep in mind of the difference between ”==” and “strcmp” operators. The former treats two strings as vectors and does letter-wise comparison. Thus the two strings ought to be of the same dimension. The latter operator does lexical comparison and returns “1” if the two strings are identical, “0” otherwise
  
 ==== Varargins ==== ==== Varargins ====
  
 A standard function definition specifies the exact number of input and output arguments the function expects: ''​function y = sqrt(x)''​ has one input and one output argument. However, it is often useful to have a variable number of input arguments, so that you can override defaults or specify additional options as needed without complicating simple function calls. For instance, you want to be able to make quick plots with ''​plot(x)''​ but specify extra stuff when needed (''​plot(x,'​LineWidth',​2)''​). This is accomplished with the special argument ''​varargin''​. A standard function definition specifies the exact number of input and output arguments the function expects: ''​function y = sqrt(x)''​ has one input and one output argument. However, it is often useful to have a variable number of input arguments, so that you can override defaults or specify additional options as needed without complicating simple function calls. For instance, you want to be able to make quick plots with ''​plot(x)''​ but specify extra stuff when needed (''​plot(x,'​LineWidth',​2)''​). This is accomplished with the special argument ''​varargin''​.
 +
 +Here is the idea:
 +
 +<code matlab>
 +function test_fun(a,​varargin)
 +
 +b = 2; % set defaults for b and c
 +c = 3;
 +
 +extract_varargin;​ % override b and c if specified
 +
 +fprintf('​a is %d, b is %d, c is %d\n',​a,​b,​c);​
 +</​code>​
 +
 +Test it:
 +
 +<code matlab>
 +>> test_fun(1)
 +a is 1, b is 2, c is 3
 +>> test_fun(1,'​b',​1)
 +a is 1, b is 1, c is 3
 +>> ​
 +</​code>​
 +
 +Note how specifying a "​key-value"​ pair ('''​b',​1''​) overwrote the default for ''​b''​. ''​extract_varargin''​ basically goes through the varargins and assigns each value to the corresponding key.
 +
 +☛ Verify your understanding by calling ''​test_fun''​ such that ''​b''​ and ''​c''​ are both set to ''​0''​. Also note what happens when you do ''​test_fun(1,'​B',​1)''​!
  
 ==== Assignment ==== ==== Assignment ====
Line 178: Line 207:
 % inputs: % inputs:
 % %
-% spikes: ​[nCells x 1cell array of ts objects (spike train) +% spikes: ​{nCells x 1cell array of ts objects (spike train) 
-% csc: [nCSCs x 1cell array of tsd objects (LFPs)+% csc: {nCSCs x 1cell array of tsd objects (LFPs)
 % %
 % varargins: % varargins:
Line 192: Line 221:
 </​code>​ </​code>​
  
-This function should produce a rasterplot of spikes -- one neuron per row -- with one or multiple LFPs plotted above it, similar to panel Aa of the Dragoi and Tonegawa figure above. The values on the y-axis are not important for now, so you can feel free to hide this axis and rescale everything to look good. (However, if you want to include a scalebar for the LFPs, go ahead!)+This function should produce a rasterplot of spikes -- one neuron per row -- with one or multiple LFPs plotted above it, similar to panel Aa of the Dragoi and Tonegawa figure above. The values on the y-axis are not important for now, so you can feel free to hide this axis and rescale everything to look good. (However, if you want to include a scalebar for the LFPs, go ahead!) ​Set the default x range to 2 seconds.
  
 You can pick a default color to plot everything, but there should be optional arguments to have the user specify a color for each neuron and LFP. You can pick a default color to plot everything, but there should be optional arguments to have the user specify a color for each neuron and LFP.
  
-Also, we want to be able to overlay events of interest on this plot; these can be simple vertical lines that extend all the way through the plot.+Also, we want to be able to overlay events of interest on this plot; these can be simple vertical lines that extend all the way through the plot. You can make up a few event times yourself for testing.
  
 Finally, for data exploration it is helpful to be able to skip through the data with the arrow keys; set it up so that the left and right arrows can be used to scroll left and right. For extra awesomeness,​ add zoom functionality that scales the LFPs when pressing the up and down arrows. Finally, for data exploration it is helpful to be able to skip through the data with the arrow keys; set it up so that the left and right arrows can be used to scroll left and right. For extra awesomeness,​ add zoom functionality that scales the LFPs when pressing the up and down arrows.
  
-☛ When you are satisfied with your work, save a copy in your ''​shared''​ folder and push it to GitHub.+☛ When you are satisfied with your work, save a copy in your ''​shared''​ folder and push it to GitHub. Verify that your version is visible from the web.
 === Hints === === Hints ===
  
-Everything you need to know to make this work has been introduced in this module: beyond this (and basic MATLAB) no special functions or tricks are needed.+Everything you need to know to make this work has been introduced in this module: beyond this (and basic MATLAB) no special functions or tricks are needed. A few suggestions:​ 
 + 
 +  * Start simple. Instead of trying to implement everything at once, take it one step at a time. First, plot a single line (corresponding to one spike). Then, plot a spike train for one neuron, and keep building. 
 +  * Don't test on the full data set. Things will be faster if you use restricted data for testing. 
 +  * Plot everything in a single set of axes, i.e. without using ''​subplot()''​ or ''​axes()'';​ this means you have to rescale and add a baseline offset (a.k.a. DC component) to the LFP signals so that they don't overlap.  
 +  * Develop in the ''​sandbox''​ file so that you can use cell mode and have easy access to the workspace. Only when everything is basically working, move to putting everything inside a function.
analysis/course/week2.1379295197.txt.gz · Last modified: 2018/07/07 10:19 (external edit)