Skip to content

Instantly share code, notes, and snippets.

@rossant
Last active September 24, 2019 09:10
Show Gist options
  • Save rossant/b56cf91eed704df33af815c2b2ee4be2 to your computer and use it in GitHub Desktop.
Save rossant/b56cf91eed704df33af815c2b2ee4be2 to your computer and use it in GitHub Desktop.
ONE light API proposal
from onelib import one
"""
Different ONE backends are available, HTTP, figshare, etc.
One has to implement the following functions to create a new ONE backend:
* list_all_files(): return a list of relative file paths for ALL available files.
* search(...): return a list of dset_ids (by default, a dset_id is a relative file path).
The default implementation calls list_all_files(), and performs the search directly on that list.
More sophisticated backends (like the alyx one) could use a REST API instead, which will be
more efficient when there is a huge number of files.
* download_file(dset_id): download a file and return a local file path
"""
# Set the configuration.
# The following is the default.
# one.set_download_dir('~/.one/data/{lab}/Subjects/{subject}/{date}/{session}/alf/{filename}')
# Use this to download all files directly in the current directory instead.
one.set_download_dir('.')
# Find all sessions that have both spikes.times and spikes.clusters
sessions = one.search(['spikes.times', 'spikes.clusters'])
# First argument is dataset_types. Other filters available as keyword arguments : subjects, lab, date_range, number.
# Get the first session, or do a loop.
session = sessions[0]
# OPTION 1: load object
# Load the spikes object of that first session. Files are first saved in the download directory, which acts as a cache.
spikes = one.load_object(session, 'spikes') # Load all default dataset types for that object, at least spikes.times and spikes.clusters. There is an optional dataset_types keyword arguments to override that default list.
# Raster plot
plt.plot(spikes.times, spikes.clusters, 'o')
# OPTION 2: load datasets
spike_times = one.load_dataset(session, 'spikes.times') # first dataset with that dataset type
spike_clusters = one.load_dataset(session, 'spikes.clusters')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment