plotter

This module contains the following classes:

Note

This module requires Python module PIL (pip install Pillow).

Warning

This module is likely to be refactored in a future version

New in version 1.5.0.

class aeneas.plotter.PlotElement(label=None, rconf=None, logger=None)[source]

A generic element of a Plot.

Parameters:
FONT_PATH = '/home/alberto/projects/rb/aeneas/aeneas/res/LiberationMono-Regular.ttf'

Path of the font to be used for drawing

TEXT_MARGIN = 2

Margin between text and anchor point, in pixels

TICK_WIDTH = 2

A tick will be drawn with (1 + 2 times this value) pixels

height

The height of this element, in modules.

Return type:int
text_bounding_box(size_pt, text)[source]

Return the bounding box of the given text at the given font size.

Parameters:
  • size_pt (int) – the font size in points
  • text (string) – the text
Return type:

tuple (width, height)

width

The width of this element, in modules.

Return type:int
class aeneas.plotter.PlotLabelset(labelset, label=None, parameters=None, rconf=None, logger=None)[source]

A set of labels.

Parameters:
  • labelset (list) – a list of triples (begin, end, label) of type (float, float, string), times in seconds
  • label (string) – a label for this set
  • parameters (dict) – a dictionary holding drawing parameters
  • rconf (RuntimeConfiguration) – a runtime configuration
  • logger (Logger) – the logger object
draw_png(image, h_zoom, v_zoom, current_y)[source]

Draw this set of labels to PNG.

Parameters:
  • image (PIL.Image) – the image to draw onto
  • h_zoom (int) – the horizontal zoom
  • v_zoom (int) – the vertical zoom
  • current_y (int) – the current y offset, in modules
class aeneas.plotter.PlotTimeScale(max_time, time_step=1, rconf=None, logger=None)[source]

A time scale.

Parameters:
  • max_time (float) – the maximum length of the time scale
  • time_step (int) – the step of the time scale numbers
  • rconf (RuntimeConfiguration) – a runtime configuration
  • logger (Logger) – the logger object
draw_png(image, h_zoom, v_zoom, current_y)[source]

Draw this time scale to PNG.

Parameters:
  • image (PIL.Image) – the image to draw onto
  • h_zoom (int) – the horizontal zoom
  • v_zoom (int) – the vertical zoom
  • current_y (int) – the current y offset, in modules
class aeneas.plotter.PlotWaveform(audio_file, label=None, fast=False, rconf=None, logger=None)[source]

An audio file waveform.

Parameters:
  • audio_file (AudioFile) – the audio file from which the waveform must be drawn
  • label (string) – a label for this waveform
  • fast (bool) – if True, plot fast (only max, mirrored)
  • rconf (RuntimeConfiguration) – a runtime configuration
  • logger (Logger) – the logger object
draw_png(image, h_zoom, v_zoom, current_y)[source]

Draw this waveform to PNG.

Parameters:
  • image (PIL.Image) – the image to draw onto
  • h_zoom (int) – the horizontal zoom
  • v_zoom (int) – the vertical zoom
  • current_y (int) – the current y offset, in modules
class aeneas.plotter.Plotter(rconf=None, logger=None)[source]

Plot waveforms and labels to image files.

Parameters:
add_labelset(labelset)[source]

Add a set of labels to the plot.

Parameters:labelset (PlotLabelset) – the set of labels to be added
Raises:TypeError: if labelset is not an instance of PlotLabelset
add_timescale(timescale)[source]

Add a time scale to the plot.

Parameters:timescale (PlotTimeScale) – the timescale to be added
Raises:TypeError: if timescale is not an instance of PlotTimeScale
add_waveform(waveform)[source]

Add a waveform to the plot.

Parameters:waveform (PlotWaveform) – the waveform to be added
Raises:TypeError: if waveform is not an instance of PlotWaveform
draw_png(output_file_path, h_zoom=5, v_zoom=30)[source]

Draw the current plot to a PNG file.

Parameters:
  • output_path (string) – the path of the output file to be written
  • h_zoom (int) – the horizontal zoom
  • v_zoom (int) – the vertical zoom
Raises:

ImportError: if module PIL cannot be imported

Raises:

OSError: if output_file_path cannot be written

class aeneas.plotter.PlotterColors[source]

Enumeration of colors for Plotter.

AUDACITY_BACKGROUND_GREY = (192, 192, 192)

Audacity background grey

AUDACITY_DARK_BLUE = (50, 50, 200)

Audacity dark blue

AUDACITY_LIGHT_BLUE = (100, 100, 220)

Audacity light blue

BLACK = (0, 0, 0)

Black

BLUE = (0, 0, 255)

Blue

GREEN = (0, 255, 0)

Green

RED = (255, 0, 0)

Red

WHITE = (255, 255, 255)

White