Python client for the Blackfynn Platform
Project description
Python client and command line tool for Blackfynn.
Installation
Note: we currently only support Python v2.7.
pip install blackfynn
Credentials Setup
Connection credentials to Blackfynn can sourced from environment variables. In your ~/.bashrc or ~/.bash_profile, set the following variables. Before using the client library or command line tool, ensure these environment variables are set.
export BLACKFYNN_USER=you@company.com
export BLACKFYNN_PASS=<your-password>
Client Library
Basic Usage: examples
# imports
from blackfynn import Blackfynn
# client
bf = Blackfynn()
# If you belong to more than one organization, explicitly set your context, otherwise, ignore.
bf.set_context('my organization name')
# print your available datasets
datasets = bf.datasets()
print datasets
# grab some dataset (e.g. first one)
ds = datasets[0]
# list items inside dataset (first level)
print ds.items
Upload data
Upload files
You must upload files into a Dataset or Collection.
# upload a file into a dataset (ds)
ds.upload_files('/path/to/my_data.nii.gz')
Stream timeseries data
Note: Before streaming, ensure you have the proper AWS credentials (environment variables) set to stream data to Kinesis. Full example of creating an empty timeseries package and streaming a dataframe is shown below:
from blackfynn import Blackfynn, TimeSeries, TimeSeriesChannel
from blackfynn.utils import generate_dataframe
# generate data (4 channels)
df = generate_dataframe(minutes=2, freq=100)
# login
bf = Blackfynn()
bf.set_context('blackfynn')
# dataset (assumes exists)
ds = bf.get_dataset('streaming')
# create an empty timeseries
ts = TimeSeries('My Test TimeSeries')
ds.add(ts) # add to dataset
# create channels (match names to dataframe columns)
channels = [TimeSeriesChannel(col, rate) for col in df.columns]
# add channels to timeseries
ts.add_channels(*channels)
# stream the data up!
ts.stream_data(df)
Retrieve data
Retrieve timeseries data
ts = bf.get('N:package:your-timeseries-id')
# get first minute of data in 1-second chunks
for chunk in ts.get_data_iter(chunk_size='1s', length='1m'):
# do something with data (pandas Dataframe)
print "Mean values =", chunk.mean()
# you can do the same thing for a single channel
channel = ts.channels[0]
for chunk in channel.get_data_iter(chunk_size='5s', length='10m'):
# do something with data (pandas Series)
print "Max value =", chunk.max()
Command Line Tool
Usage
>> bf --help
Blackfynn Client
Usage:
bf upload [options] <destination> <file> [<file>...]
bf append [options] <destination> <file> [<file>...]
bf search [options] <term> [<term>...]
bf datasets [options]
bf dataset [options] <dataset> [<command>] [<action>] [<action-args>...]
bf create [options] collection <destination> <name>
bf create [options] dataset <name>
bf delete [options] <item>
bf show [options] <item>
bf orgs [options]
bf env [options]
bf version
Options
-h --help Show help.
--user=<user> Email/username
--pass=<pass> Password
--host=<host> Blackfynn host
--org=<org> Set organization context
Basic examples
Show your setup
bf env
Show your datasets
>> bf datasets --org blackfynn Datasets: - Studies (id: N:dataset:<id>) - Blackfynn (id: N:dataset:<id>) - Streaming (id: N:dataset:<id>) - Patients (id: N:dataset:<id>) - Subjects (id: N:dataset:<id>)
Search for things
>> bf search Jon * <TimeSeries name='Jon Doe' id='<id>'> * <TimeSeries name='Jon Snow' id='<id>'>
Show specific item
>> bf show 'N:package:<id>'
File uploads
Upload a file into a Dataset.
bf upload 'N:dataset:1234-1234-1234-1234' /path/to/my_data.nii.gz
If your environment variables are not set, you can also enter credentials
bf upload --user=<email> --pass=<pass> 'N:dataset:1234-1234-1234-1234' /path/to/data_i_want_to_upload.mef
Append data into an existing TimeSeries object (note: append process currently only supports timeseries data)
bf append 'N:package:1234-1234-1234-1234' /path/to/data_i_want_to_append.mef
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for blackfynn-1.6.2-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e568f0ea31a413103a6fae340940e643377294594f87af1916f3814c898e9dee |
|
MD5 | 138819415cd46a69bb99787912ef4f94 |
|
BLAKE2b-256 | 4dea2db77a19e4782784c1f28ca358d26b9635a8b1155a5d20a3bfe9dce3bcb6 |