Skip to main content

pyanthem - an audiovisualization tool to make your data more interesting

Project description

Features:

  1. Converts three-dimensional datasets to visually pleasing, audible representations

  2. A variety of video and audio parameters

  3. In-place video and audio merge

  4. GUI and Command-line interface for maximum flexibility

  5. Example datasets to get you started

  6. Headache-free installation with an Anaconda environment

Usage

pyanthem was primarily developed to interpret matrix-decomposed functional imaging datasets - for example, a dataset V with shape [height,width,time], is decomposed into two matrixes: W with shape [height*width,n], and H with shape [n,time] such that H x W = V. Here, n represents the number of variables represented by the decomposition. There are various techniques used to decompose matrixes - two popular techniques include Non-negative Matrix Factorization (NMF), and Singular Value Decomposition (SVD).

Here’s a visual illustration of matrix decomposition - note that in this example, n=2:

https://upload.wikimedia.org/wikipedia/commons/f/f9/NMF.png

If you would prefer to keep things simple, you can skip matrix decomposition altogether and focus solely on converting raw data to audio - only working with the H matrix, where each row represents a variable and each column represents a time point.

If this is too much information to digest, don’t worry! Try the example below to get more familiar with what the data looks like, and how pyanthem transforms it.

Requirements

See installation guide below before proceeding!

Python 3.7:

Currently, pyanthem is tested to work on Python 3.7. This will be updated as more versions are tested.

FFmpeg:

ffmpeg enables video creation and merging.

FluidSynth:

FluidSynth enables conversion of MIDI files to crisp, high quality sound files.

If you do have the above requirements installed, you can install pyanthem using pip: pip install pyanthem

Conda (optional, but highly recommended):

Conda enables simple and reliable package installation. Use Miniconda for a minimal installation, or Anaconda otherwise.

Installation

Note: If you do not have working installations of the listed requirements (Python 3.7 + fluidsynth + ffmpeg), it is strongly recommended that you use Miniconda/Anaconda for a straightforward installation process. If you do not have either, Miniconda is preferred as it is a faster install and takes up much less space than Anaconda.

Using Miniconda/Anaconda:

Create an environment and install the required packages:

conda create -n pyanthem python=3.7 pip ffmpeg fluidsynth --channel conda-forge --channel nicthib

Next, activate the environment:

conda activate pyanthem

Finally, install the pyanthem Python package using pip:

pip install pyanthem

Example datasets and Scripts

If you want to get familiar with the datasets that pyanthem uses and try some applications of pyanthem, clone this repository or download here.

Using pyanthem in a Jupyter Notebook

To access the pyanthem environment in a Jupyter notebook, first install ipykernel in your environment:

conda install -c anaconda ipykernel

After this, create the kernel:

python -m ipykernel install --user --name=pyanthem

Once in a notebook, switch to the pyanthem kernel by selecting Kernel > Change kernel > pyanthem

Note: While the pyanthem kernel will now be available in any Jupyter notebook session, pyanthem will not function properly unless the Jupyter notebook is launched inside the pyanthem environment.

Example

Using pyanthem in GUI mode

First, import pyanthem and begin a pyanthem session:

import pyanthem
pyanthem.run()

Note: You may run into an error here where some packages are missing. Simply install them using pip, and try running pyanthem again.

The first time you run pyanthem, it will download a necessary soundfont file - this will take a minute or two.

♫ Initializing soundfont library...
♫ Downloading 17QuXRbApe0JTlYfBs7iSMCMu3xRWMHOV into...
♫ 238.3 MiB Done.

Once completed, the pyanthem GUI will initialize:

https://github.com/nicthib/pyanthem/blob/media/GUI1.png

Next, load a dataset by clicking File > Load from .mat. For this section, we will load the dataset demo1.mat. Currently, you can import any .mat or hdf5 file that contains the following variables:

  1. Temporal variable (H, required): A 2D matrix of shape [n,t], where each row is a component and each column is a time-point. This variable is referred to as “H” in the pyanthem environment.

  2. Spatial variable (W, optional): A 3D matrix of shape [h,w,n], where h and w represent the spatial height and width of your dataset. If this variable is not given, no video output is possible.

  3. Framerate (fr, optional): A single float value, representing the frame rate of your dataset in Hz. If a framerate is not given, pyanthem will provide a default.

Note: Make sure to only include these variables in your file to avoid any errors. You can name them however you like, but make sure there are only one of each variable.

Once loading is complete, the GUI should update with default options, and plots of H and W:

https://github.com/nicthib/pyanthem/blob/media/GUI2.png

The bottom left plots show two representations of the dataset: A preview of the output movie (left), and a visualization of what components are included and the colormap selection. The right two plots show raw representations of H (top), and a visualization of the audio output file (right). Lighter colors indicate loud notes, and darker colors indicate quiet notes, with black indicating silence.

From here, you can adjust parameters, preview the output, and finally save video and audio files. If you want to check how your parameter adjustments impact your audivisualization, click the Update button, and your changes will be reflected. Any issues with your selected parameters will be indicated in the white status box. Try adjusting a few parameters and observing how the plots change.

Finally, render output files with the Save --> Write A/V then merge menu command.

Congratulations - you’ve created your first audiovisualization!

Using pyanthem in CLI (command-line interface) mode

pyanthem’s CLI mode is useful for running batch conversions of large amounts of data once you are happy with your audiovisualization parameters, or creating more complex audiovisualizions that use multiple datasets and instruments. CLI mode is not recommended to use until you have used the GUI and are comfortable with the parameters and usage.

To run pyanthem in CLI mode, pass the argument display=False, and assign the .run() method to a variable:

import pyanthem
g=pyanthem.run(display=False)

Next, load a dataset and config file using the .load_data() and .load_config() methods. You can pass an explicit file name to the file_in argument, or pass none to recieve a file select prompt (note the use of the leading r when naming a file location):

g.load_data(file_in=r'path/to/your/file.mat')
g.load_config(file_in=r'path/to/your/config.p')

Finally, render the audio and video file, then merge the files using the .write_audio(), .write_video() and .merge() methods:

g.write_audio()
g.write_video()
g.merge()

Once you’re comfortable with this syntax, you can combine all of these steps into a single line, write a merged video with the .write_AV() method, and even remove the intermediate files using the .cleanup() method:

data_file = r'path/to/your/file.mat'
config_file = r'path/to/your/config.p'
g.load_data(file_in=data_file).load_config(file_in=config_file).write_AV().cleanup()

Congratulations - you’ve created your first audiovisualization in CLI mode!

Team

Nic Thibodeaux

niclogo

http://github.com/nicthib

FAQ

Under construction!

Support

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

pyanthem-1.2.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

pyanthem-1.2.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file pyanthem-1.2.0.tar.gz.

File metadata

  • Download URL: pyanthem-1.2.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pyanthem-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8669100f7b56d5d5f28f5d3b249255eb608d63cb89d4c43bc191839406b588e5
MD5 71891bba8e422b5f89cc1b857f26e8ba
BLAKE2b-256 0bb81e9f02f59613ceb07635125d3e6871b6fa86179d41c77ded4de611a15872

See more details on using hashes here.

Provenance

File details

Details for the file pyanthem-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyanthem-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pyanthem-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48e01b1d6d3bb6bd32ad5fa815054983297d615ef0b3dc93a49d65748d301fa3
MD5 0a69de0cb14d742dafa004b54031b60a
BLAKE2b-256 dd6435f7199e36246175c3df51828415ca969b840c2d4108a9b482b818959452

See more details on using hashes here.

Provenance

Supported by

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