<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Repository and Data Access
Fork my github repository
Clone the forked repository to a local directory
Install miniconda (or anaconda) if it isn't already installed. Type into bash
Step1:  N_DAYS corresponds to the number of days of recording and SAMPLING_FREQUENCY corresponds to the sampling rate of the tetrodes recording neural activity
Step2:  Data Processing Module
The src.data_processing module has convenient functions for importing the data files into Pandas dataframes. You can use these functions in conjunction with the constants from the src.parameters module. The most useful functions are
Step3:  Often we use the epoch as a key to access more information about that epoch (information about the tetrodes, neuron, etc). Epoch keys are tuples with the following format
Step4:  This is useful if we want to filter the epoch dataframe by a particular attribute (Say we only want sessions where the animal is asleep) and use the keys to access the data for that epoch.
Step5:  make_tetrode_dataframe
make_tetrode_dataframe is a dictionary of pandas dataframes, where the keys corresponds to an epoch and the values are pandas dataframes detailing information about the tetrodes in that epoch (brain area, number of cells recorded, etc.).
The dictionary keys for the epochs are tuples (Animal, Day, Epoch). For example, let's load the tetrode dataframe and display all the keys
Step6:  If we want to access a particular epoch we can just pass the corresponding epoch tuple. In this case, we want animal HPa, day 6, epoch 2. This returns a dataframe where each row corresponds to a tetrode for that epoch.
Step7:  Remember that the epoch dataframe index can be used as keys, which can be useful if we want to access a particular epoch.
Step8:  make_neuron_dataframe
The neuron dataframe is set up similarly to the tetrode dataframe. It is a dictionary of pandas dataframes, where the keys are the epoch tuples (Animal, Day, Epoch) and the values are the pandas dataframes. The dataframes give descriptive information about the number of spikes, the average spiking rate, which brain area, etc.
Step9:  We can access the neuron dataframe for a particular epoch in the same way as the tetrodes
Step10:  get_spike_indicator_dataframe
The spike indicator dataframe is a dataframe where each row corresponds to the recording timestamp and is_spike is an indicator function where 1 indicates a spike has occurred at that timestamp and 0 indicates no spike has occurred at that timestamp. We can access the spike indicator dataframe for a particular neuron by using the neuron key (Animal, Day, Epoch, Tetrode, Neuron).
Step11:  This information can be obtained from the neuron dataframe. The index of the neuron dataframe gives the key.
Step12:  Like the epoch and tetrode dataframe, this allows us to filter for certain attributes (like if we want neurons in a certain brain area) and select only those neurons. For example, if we want only CA1 neurons
Step13:  We can get the keys for CA1 neurons only
Step14:  And then get the spike indicator data for those neurons
Step15:  If we want the numpy array, use .values
Step16:  get_interpolated_position_dataframe
This dataframe gives information about the animal's position during an epoch. Like the tetrode and neuron dataframes, it is a dictionary of dataframes where the keys correspond to the epoch (Animal, Day, Epoch).
<ASSISTANT_TASK:>
Python Code:
from src.parameters import ANIMALS
ANIMALS
Explanation: Repository and Data Access
Fork my github repository
Clone the forked repository to a local directory
Install miniconda (or anaconda) if it isn't already installed. Type into bash:
bash
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
hash -r
Switch to the development branch. Type into bash:
bash
git checkout develop
Go to the local repository (.../Jadhav-2016-Data-Analysis) and install the anaconda environment for the repository. Type into bash:
bash
conda update -q conda
conda info -a
conda env create -f environment.yml
source activate Jadhav-2016-Data-Analysis
python setup.py develop
Make sure the environment is set up correctly by running the tests. Type into bash:
bash
pytest
Copy the data folders HPa_direct, HPb_direct, HPc_direct from the dropbox folder EastWestSideHippos Team Folder/HCPFCdata to Jadhav-2016-Data-Analysis/Raw-Data
Accessing the Data via Python
Parameters Module
The src.parameters module has some convenient constants for accessing the data. Most important are the ANIMALS dictionary, the N_DAYS, and the SAMPLING_FREQUENCY.
The ANIMALS dictionary maps the animal name to the data directory containing the animal's data.
End of explanation
from src.parameters import N_DAYS, SAMPLING_FREQUENCY
print('Days: {0}'.format(N_DAYS))
print('Sampling Frequency: {0}'.format(SAMPLING_FREQUENCY))
Explanation: N_DAYS corresponds to the number of days of recording and SAMPLING_FREQUENCY corresponds to the sampling rate of the tetrodes recording neural activity
End of explanation
from src.data_processing import make_epochs_dataframe
days = range(1, N_DAYS + 1)
epoch_info = make_epochs_dataframe(ANIMALS, days)
epoch_info
Explanation: Data Processing Module
The src.data_processing module has convenient functions for importing the data files into Pandas dataframes. You can use these functions in conjunction with the constants from the src.parameters module. The most useful functions are:
make_epochs_dataframe: returns descriptive information about each epoch
make_tetrode_dataframe: returns descriptive information about each tetrode
make_neuron_dataframe: returns descriptive information about each neuron 
get_spike_indicator_dataframe: returns the spiking data for each neuron for each time point
get_interpolated_position_dataframe: returns data about the position of animal for each time point
Let's take each of these functions in turn.
make_epochs_dataframe
An epoch is a single recording session. There are typically multiple recording sessions (epochs) a day. The epoch dataframe gives information about what task the animal is performing during the epoch (sleeping, running a linear track, running a w-track, resting, etc). Each row of the epoch dataframe corresponds to an epoch.
End of explanation
epoch_info.index.tolist()
Explanation: Often we use the epoch as a key to access more information about that epoch (information about the tetrodes, neuron, etc). Epoch keys are tuples with the following format: (Animal, Day, Epoch).
The index of the epoch dataframe can be used to produce these keys.
End of explanation
epoch_info.loc[epoch_info.type == 'run']
epoch_info.loc[epoch_info.type == 'run'].index.tolist()
Explanation: This is useful if we want to filter the epoch dataframe by a particular attribute (Say we only want sessions where the animal is asleep) and use the keys to access the data for that epoch.
End of explanation
from src.data_processing import make_tetrode_dataframe
tetrode_info = make_tetrode_dataframe(ANIMALS)
list(tetrode_info.keys())
Explanation: make_tetrode_dataframe
make_tetrode_dataframe is a dictionary of pandas dataframes, where the keys corresponds to an epoch and the values are pandas dataframes detailing information about the tetrodes in that epoch (brain area, number of cells recorded, etc.).
The dictionary keys for the epochs are tuples (Animal, Day, Epoch). For example, let's load the tetrode dataframe and display all the keys:
End of explanation
epoch_key = ('HPa', 6, 2)
tetrode_info[epoch_key]
Explanation: If we want to access a particular epoch we can just pass the corresponding epoch tuple. In this case, we want animal HPa, day 6, epoch 2. This returns a dataframe where each row corresponds to a tetrode for that epoch.
End of explanation
[tetrode_info[epoch_key]
 for epoch_key in epoch_info.loc[
     (epoch_info.type == 'sleep') & (epoch_info.day == 8)].index]
Explanation: Remember that the epoch dataframe index can be used as keys, which can be useful if we want to access a particular epoch.
End of explanation
from src.data_processing import make_neuron_dataframe
neuron_info = make_neuron_dataframe(ANIMALS)
list(neuron_info.keys())
Explanation: make_neuron_dataframe
The neuron dataframe is set up similarly to the tetrode dataframe. It is a dictionary of pandas dataframes, where the keys are the epoch tuples (Animal, Day, Epoch) and the values are the pandas dataframes. The dataframes give descriptive information about the number of spikes, the average spiking rate, which brain area, etc.
End of explanation
epoch_key = ('HPa', 6, 2)
neuron_info[epoch_key]
Explanation: We can access the neuron dataframe for a particular epoch in the same way as the tetrodes
End of explanation
from src.data_processing import get_spike_indicator_dataframe
neuron_key = ('HPa', 6, 2, 1, 4)
get_spike_indicator_dataframe(neuron_key, ANIMALS)
Explanation: get_spike_indicator_dataframe
The spike indicator dataframe is a dataframe where each row corresponds to the recording timestamp and is_spike is an indicator function where 1 indicates a spike has occurred at that timestamp and 0 indicates no spike has occurred at that timestamp. We can access the spike indicator dataframe for a particular neuron by using the neuron key (Animal, Day, Epoch, Tetrode, Neuron).
End of explanation
neuron_info[epoch_key].index.tolist()
Explanation: This information can be obtained from the neuron dataframe. The index of the neuron dataframe gives the key.
End of explanation
neuron_info[epoch_key].query('area == "CA1"')
Explanation: Like the epoch and tetrode dataframe, this allows us to filter for certain attributes (like if we want neurons in a certain brain area) and select only those neurons. For example, if we want only CA1 neurons:
End of explanation
neuron_info[epoch_key].query('area == "CA1"').index.tolist()
Explanation: We can get the keys for CA1 neurons only:
End of explanation
pd.concat(
    [get_spike_indicator_dataframe(neuron_key, ANIMALS)
     for neuron_key in neuron_info[epoch_key].query('area == "CA1"').index], axis=1)
Explanation: And then get the spike indicator data for those neurons:
End of explanation
pd.concat(
    [get_spike_indicator_dataframe(neuron_key, ANIMALS)
     for neuron_key in neuron_info[epoch_key].query('area == "CA1"').index], axis=1).values
Explanation: If we want the numpy array, use .values
End of explanation
from src.data_processing import get_interpolated_position_dataframe
epoch_key = ('HPa', 6, 2)
get_interpolated_position_dataframe(epoch_key, ANIMALS)
Explanation: get_interpolated_position_dataframe
This dataframe gives information about the animal's position during an epoch. Like the tetrode and neuron dataframes, it is a dictionary of dataframes where the keys correspond to the epoch (Animal, Day, Epoch).
End of explanation
<END_TASK>