# Brain Observatory¶

This notebook documents some classes and functions in the AllenSDK that help manipulate files and data structures in the Allen Brain Observatory. The main entry point in the BrainObservatoryCache class. This class is responsible for downloading any requested data or metadata on request and storing it in well known locations.

## Experiment Containers¶

The experiment container describes a set of experiments performed with the same targeted area, imaging depth, and Cre line. The BrainObservatoryCache has a number of functions for figuring out what experiment containers are available at the moment.

An experiment container is a group of experiments. Each experiment has a different stimulus protocol. For example, one experiment protocol contains the static gratings stimulus and another has the natural scenes stimulus. The BrainObservatoryCache helps you find out which experiment associated with a container has the stimuli you are interested in. First, let's see what experiments are available for a single container.

The session_type field indicates which experimental protocol was used. If you just want to find which experiment contains the static gratings stimulus, you can do the following:

## Find Cells of Interest¶

Another way to look for data is to search for cells with interesting tuning properties. We have pre-computed a set of cell metrics. Take a look at this page to see the full list.

You can use these properties to filter the full set of cells down to the set your are interested in.

## Find Experiments for Cells¶

Once you have found a set of cells you would like to investigate, you can use the BrainObservatoryCache to find the experiments for those cells that contain the relevant stimulus.

Once you have some experiments, you can download the NWB files that contain the fluorescence traces for segmented cells in those experiments.

## Fluorescence Traces¶

Now that we have a data set, we can plot the traces for the cell we care about.

If you want to take a look at the cell visually, you can open the NWB file and extract a pixel mask. You can also pull out the maximum intensity projection of the movie for context.

## ROI Analysis¶

The code to compute all of the cell metrics available for download (along with several others we haven't put in our database yet) is in the AllenSDK. All you need is an NWB file. For example, this is how you compute metrics for the drifting gratings stimulus and plot some results.

## Neuropil Correction¶

All of the raw fluorescence traces are available in NWB files, but some of these signals are contaminated by nearby neuropil signal. Neuropil correction is performed after the signal from overlapping traces has been demixed. The code to perform neuropil correction is available in the AllenSDK and can be used as follows:

The NWB files contain the neuropil traces and r values needed to perform this correction, so you don't need to recompute them. The corrected trace can be computed on the fly when you use the get_corrected_fluorescence_traces method:

## Compute dF/F¶

You can compute dF/F for yourself using the allensdk.brain_observatory.dff module.

## Running Speed¶

We recorded the animal's running speed during the course of the experiment and made it available in the NWB file.

## Motion Correction¶

X and Y translation values in pixels required to correct for motion artifacts during the experiment are available as well.

## Eye Tracking¶

Many experiments contain pupil position and pupil size from eye tracking. Extreme outliers from the tracking have been removed and replaced with NaN, which will appear as gaps in the plotted data. If an experiment does not have eye tracking data, a NoEyeTrackingException will be raised.