Skip to main content

video and data IO tools for Python

Project description

Python Version License: MIT tests PyPI - Version Conda Version GitHub last commit

daio

Video and data IO tools for Python.

Links: API documentation, GitHub repository

Installation

  • via conda or mamba: conda install danionella::daio
  • if you prefer pip: pip install daio
  • for development, clone this repository change to the directory containing pyproject.toml
    • conda env create -n env_name -f environment.yml
    • conda activate env_name
    • pip install -e .

Use

Video IO

Write video:

from daio.video import VideoReader, VideoWriter
writer = VideoWriter('/path/to/video.mp4', fps=25)
for i in range(20):
    frame = np.random.randint(0,255,size=(720,1280), dtype='uint8')
    writer.write(frame)
writer.close()

Read video using speed-optimized array-like indexing or iteration:

reader = VideoReader('/path/to/video.mp4')
frame_7 = reader[7]
first10_frames = reader[:10]
for frame in reader:
    process_frame(frame)
reader.close()

You can also use with statements to handle file closure:

with VideoWriter('/path/to/video.mp4', fps=25) as writer:
    for i in range(20):
        frame = np.random.randint(0,255,size=(720,1280), dtype='uint8')
        writer.write(frame)
#or
with VideoReader('/path/to/video.mp4') as reader:
    frame_7 = reader[7]

HDF5 file IO

Lazily load HDF5 with a dict-like interface (contents are only loaded when accessed):

from daio.h5 import lazyh5
h5 = lazyh5('/path/to/datafile.h5')
b_loaded = h5['b']
e_loaded = h5['c']['e']
h5.keys()

Create a new HDF5 file (or add items to existing file by setting argument readonly=False):

h5 = lazyh5('test.h5')
h5['a'] = 1
h5['b'] = 'hello'
h5['c'] = {} # create subgroup
h5['c']['e'] = [2,3,4]

Load entire HDF5-file to dict, or save dict to HDF5-file:

# save dict to HDF5 file:
some_dict = dict(a = 1, b = np.random.randn(3,4,5), c = dict(g='nested'), d = 'some_string')
lazyh5('/path/to/datafile.h5').from_dict(some_dict)
# load dict from HDF5 file:
loaded = lazyh5('/path/to/datafile.h5').to_dict()

In Jupyter, you can interactively explore the file structure:

image
Old interface (expand this)
from daio.h5 import save_to_h5, load_from_h5
# save dict to HDF5 file:
some_dict = dict(a = 1, b = np.random.randn(3,4,5), c = dict(g='nested'), d = 'some_string')
save_to_h5('/path/to/datafile.h5', some_dict)
# load dict from HDF5 file:
dict_loaded = load_from_h5('/path/to/datafile.h5')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

daio-0.0.5.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

daio-0.0.5-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file daio-0.0.5.tar.gz.

File metadata

  • Download URL: daio-0.0.5.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for daio-0.0.5.tar.gz
Algorithm Hash digest
SHA256 7c5340dbaafd2e357e1d9b30bc05e21fafbb3ab3e2c66b0484db4d30b5b5f895
MD5 8ec4d40913ea8063505efe5b66bebbaa
BLAKE2b-256 e27abde88d5c2a2de670fa2daa8f9ddd80566828c8ac3e814d8a67369cdb3ef0

See more details on using hashes here.

File details

Details for the file daio-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: daio-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for daio-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8f177bdb6d0d0297c5ae94e2346f79f635e02225738748e8ddb02c40cb23ca86
MD5 f7439e11c5afedd40bb68462c88f6e7e
BLAKE2b-256 e646372084141c1c68d14008b489be5753c335493832d8c2b4a988dea6eae9d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page