Graviti TensorBay python SDK
Project description
Graviti python SDK
Installation
pip3 install graviti
Usage
Get accessKey
AccessKey is required when upload data.
Use your username and password to login to Graviti website, and get accessKey on profile page.
Upload data
This sample is for uploading dataset which only contains data collected from a single sensor.
#!/usr/bin/env python3
from graviti import GAS
ACCESS_KEY = "Accesskey-****"
DATASET_NAME = "TestDataset"
SEGMENT_NAME = "segment1"
gas = GAS(ACCESS_KEY)
dataset = gas.get_or_create_dataset(DATASET_NAME) # create dataset
segment = dataset.get_or_create_segment(SEGMENT_NAME) # create segment
# single-thread upload
for filename in FILE_LIST:
segment.upload_data(filename, "remote_path")
# 'remote_path' should follow linux style. If it has wrong format, raise GASPathError.
# # multi-thread uploading
# # when use multi-thread uploading
# # uncomment the following code and comment single-thread uploading code
# from concurrent.futures import ThreadPoolExecutor
# THREAD_NUM = 8 # number of threads
# with ThreadPoolExecutor(THREAD_NUM) as executor:
# for filename in FILE_LIST:
# executor.submit(segment.upload_data, filename, "remote_path")
Upload fusion data
This sample is for uploading dataset which contains data collected from fusion.
#!/usr/bin/env python3
from graviti import GAS
from graviti.dataset import Frame, Data
from graviti.sensor import Camera
ACCESS_KEY = "Accesskey-****"
DATASET_NAME = "TestFusionDataset"
SEGMENT_NAME = "segment1"
gas = GAS(ACCESS_KEY)
dataset = gas.get_or_create_dataset(DATASET_NAME, is_fusion=True) # create fusion dataset
segment = dataset.get_or_create_segment(SEGMENT_NAME) # create segment
for sensor_name in SENSOR_LIST:
camera = Camera(sensor_name)
camera.description = "This is a camera"
camera.set_translation(x=1.1, y=2.2, z=3.3)
camera.set_rotation(w=1.1, x=2.2, y=3.3, z=4.4)
camera.set_camera_matrix(fx=1.1, fy=2.2, cx=3.3, cy=4.4)
camera.set_distortion_coefficient(p1=1.1, p2=2.2, k1=3.3, k2=4.4, k3=5.5)
segment.upload_sensor_object(camera)
# single-thread uploading
for index, frame_info in enumerate(FRAME_LIST):
frame = Frame()
for sensor_name in SENSOR_LIST:
frame[sensor_name] = Data(
frame_info.filename, remote_path="remote_path", timestamp=frame_info.timestamp,
)
# 'remote_path' should follow linux style. If it has wrong format, raise GASPathError.
segment.upload_frame_object(frame, index)
# # multi-thread uploading
# # when use multi-thread uploading
# # uncomment the following code and comment single-thread uploading code
# from concurrent.futures import ThreadPoolExecutor
# THREAD_NUM = 8 # number of threads
# with ThreadPoolExecutor(THREAD_NUM) as executor:
# for index, frame_info in enumerate(FRAME_LIST):
# frame = Frame()
# for sensor_name in SENSOR_LIST:
# frame[sensor_name] = Data(
# frame_info.filename, remote_path="remote_path", timestamp=frame_info.timestamp,
# )
# executor.submit(segment.upload_frame_object, frame, index)
Command line
We also provide gas
command to call SDK APIs.
Use gas
in terminal to see the available commands as follows.
gas config
gas create
gas delete
gas publish
gas ls
gas cp
gas rm
config environment
gas config [accessKey] # config accesskey to default environment
gas -c [config_name] config [accessKey] # create an environment named [config_name]
# and config accesskey to it
show config
gas config # show config information of all environments
choose environment
gas [command] [args] # choose default environment
gas -c [config_name] [command] [args] # choose the environment named [config_name]
gas -k [accessKey] [command] [args] # appoint accessKey in current command line
# '-k' has higher priority than '-c'
create dataset
gas create tb:[dataset_name]
delete dataset
gas delete tb:[dataset_name]
publish dataset
gas publish tb:[dataset_name]
list data
gas ls [Options] [tbrn]
Options:
-a, --all List all files under all segments. Only works when [tbrn] is tb:[dataset_name].
tbrn:
None # list all dataset names
tb:[dataset_name] # list all segment names under the dataset
tb:[dataset_name]:[segment_name] # list all files under the segment
tb:[dataset_name]:[segment_name]://[remote_path] # list files under the remote path
upload data
gas cp [Options] [local_path1] [local_path2]... [tbrn]
Options:
-r, --recursive Copy directories recursively.
-j, --jobs INTEGER The number of threads.
tbrn:
tb:[dataset_name]:[segment_name] # copy files to the segment
tb:[dataset_name]:[segment_name]://[remote_path] # copy files to the remote path
# [segment_name] is must required.
# If only upload one file and [remote_path] doesn't end with '/',
# then the file will be uploaded and renamed as [remote_path]
delete data
gas rm [Options] [tbrn]
Options:
-r, --recursive Remove directories recursively.
-f, --force Delete segments forcibly regardless of the nature of the dataset.
By default, only segments with no sensor can be deleted.
Once '-f' is used, sensors along with their objects will also be deleted.
tbrn:
tb:[dataset_name] # remove all segments under the dataset
tb:[dataset_name]:[segment_name] # remove a segment
tb:[dataset_name]:[segment_name]://[remote_path] # remove files under the remote path
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
graviti-0.2.0.tar.gz
(38.2 kB
view details)
Built Distribution
graviti-0.2.0-py3-none-any.whl
(52.6 kB
view details)
File details
Details for the file graviti-0.2.0.tar.gz
.
File metadata
- Download URL: graviti-0.2.0.tar.gz
- Upload date:
- Size: 38.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9066c3ba41b1db544141cabde18ad63c3a36cde72211873d89195693732906e |
|
MD5 | 8696c32b212a9efc09bd60727e312364 |
|
BLAKE2b-256 | e0cac7eca39a74a2fc1526d96a0c19b46ea6674cfa923e47c4348613c6bb4f38 |
File details
Details for the file graviti-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: graviti-0.2.0-py3-none-any.whl
- Upload date:
- Size: 52.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 845be81274b22e70dbb6ca076b544ed713d20b5c980b1531dd4b0fa76c80e942 |
|
MD5 | 6c3e479c03fe11465a7b9e8c51c07b7c |
|
BLAKE2b-256 | 202409c789fca6a9c74081f4399b4eb92ab6ac429067042e6f906d747777fd62 |