pythiaplotter.printers package

Submodules

pythiaplotter.printers.dot_config module

pythiaplotter.printers.dot_display_classes module

Classes to describe and generate visual attributes for making the Graphviz description.

Also set particle label in here, see get_particle_label(). Or should this be a method for the particle?

class pythiaplotter.printers.dot_display_classes.DotAttrGenerator(particle_opts=None, label_opts=None)[source]

Bases: object

Base class for generating particle attr dicts

dict_to_gv_str(attr_dict)[source]

Convert a dict to a graphviz-legal string.

get_non_particle_attr(obj, fancy)[source]

Base method for getting an attribute dict for not a particle.

key:value pairs must be legal graphviz key/values.

The user should override this method.

Parameters:
  • obj (object) – The object in question.
  • fancy (bool) –
Returns:

Return type:

dict

get_particle_attr(particle, fancy)[source]

Base method for getting an attribute dict for a particle.

key:value pairs must be legal graphviz key/values.

The user should override this method.

Parameters:
  • particle (Particle) –
  • fancy (bool) –
Returns:

Return type:

dict

gv_str(obj, fancy)[source]

Create attribute string for obj.

If “particle” in obj.keys(), will style it as a Particle, otherwise will assume it’s a non-Particle.

Parameters:
  • obj (an object) – Object to create string for
  • fancy (bool) – Whether to style plain or fancy
static validate_particle_opt(opt)[source]

Validate particle options dict

class pythiaplotter.printers.dot_display_classes.DotEdgeAttrGenerator(particle_opts, label_opts)[source]

Bases: pythiaplotter.printers.dot_display_classes.DotAttrGenerator

AttrGenerator specifically for Edges.

get_particle_attr(particle, fancy)[source]
class pythiaplotter.printers.dot_display_classes.DotGraphAttrGenerator(attr)[source]

Bases: pythiaplotter.printers.dot_display_classes.DotAttrGenerator

Generate Graphviz string with overall graph options

gv_str()[source]

Print graph attributes in dot-friendly format

class pythiaplotter.printers.dot_display_classes.DotNodeAttrGenerator(particle_opts, label_opts)[source]

Bases: pythiaplotter.printers.dot_display_classes.DotAttrGenerator

AttrGenerator specifically for Nodes.

get_non_particle_attr(obj, fancy)[source]
get_particle_attr(particle, fancy)[source]
pythiaplotter.printers.dot_display_classes.get_particle_label(particle, representation, label_opts, fancy=True)[source]

Return string for particle label to be displayed on graph.

Parameters:
  • particle (Particle) – Particle under consideration
  • representation ({"NODE", "EDGE"}) – Particle representation
  • label_opts (dict) – Dict of labels for different representations and fancy/plain
  • fancy (bool) – If True, will use HTML/unicode in labels
Returns:

Particle label string

Return type:

str

Raises:

RuntimeError – If representation is not one of “NODE”, “EDGE”

pythiaplotter.printers.dot_printer module

Print graph using Graphviz.

Aim to be fairly generic, so can have particles as edges or nodes. All we do is attach display attributes to each node/edge, then print these to file.

Several stages: 1. Go through nodes & edges and attach display attributes [add_display_attr()] 2. Write to Graphviz format file [write_gv()] 3. Render to file [print_diagram()]

class pythiaplotter.printers.dot_printer.DotPrinter(opts)[source]

Bases: object

Class to print event to file using Graphviz

add_display_attr(event, fancy)[source]

Add display attribute to graph, nodes & edges

Parameters:
  • event (Event) – Event to process
  • fancy (bool) – If True, will use HTML/unicode in labels
print_event(event)[source]

Convert the event diagram to Graphivz language, then run the renderer.

Can also optionally save the Graphviz description to file.

Parameters:event (Event) – Event to print
pythiaplotter.printers.dot_printer.construct_gv_full(event)[source]

Turn event graph into Graphviz string in DOT language

Parameters:event (Event) –
Returns:
Return type:str
pythiaplotter.printers.dot_printer.print_diagram(gv_str, output_filename, renderer, output_format)[source]

Pass graph in DOT language to a Graphviz program to produce a diagram.

Parameters:
  • gv_str (str) – Graph contents in DOT language
  • output_filename (str) – Final diagram filename
  • renderer (str) – Graphviz program to use
  • output_format (str) –

    Each has its own advantages, see http://www.graphviz.org/doc/info/output.html

    • ps - uses ps:cairo. Obeys HTML tags & unicode, but not searchable
    • ps2 - PDF searchable, but won’t obey all HTML tags or unicode.
    • pdf - obeys HTML but not searchable
Returns:

List of commands run to produce diagram from graphviz file

Return type:

list[str]

pythiaplotter.printers.dot_printer.write_gv(gv_str, gv_filename)[source]

Write event graph to file in Graphviz format

pythiaplotter.printers.web_config module

pythiaplotter.printers.web_printer module

Print webpage with interactive graph.

This uses vis.js to do all the hard work: http://visjs.org/, but we still use graphviz to do the layout for (a) parity with the PDF version, (b) because it is faster, whereas web pages (so far) crash.

Of course if I could find a graphviz-as-as-JS service, that would be cooler...

class pythiaplotter.printers.web_printer.VisPrinter(opts)[source]

Bases: object

print_event(event)[source]

Calculate layout, add to graph nodes, and make website file for this event.

Parameters:event (Event) –
pythiaplotter.printers.web_printer.add_node_positions(graph, raw_json)[source]

Update graph nodes with their positions, using info in raw_json.

Parameters:
  • graph (NetworkX.MultiDiGraph) – Graph to be updated
  • raw_json (str) – JSON with nodes & their positions
pythiaplotter.printers.web_printer.construct_gv_only_edges(graph, graph_attr=None)[source]

Create a graph in DOT language with just edges specified.

This is a minimal graph, just used to determine the node positioning.

Parameters:
  • graph (NetworkX.MultiDiGraph) –
  • graph_attr (dict, optional) – Graph attributes such as rankdir, nodesep
Returns:

The graph in DOT language

Return type:

str

pythiaplotter.printers.web_printer.create_vis_dicts(graph)[source]

Create list of dicts for nodes & edges suitable for input to vis.js

This includes node position, label, hover info, etc

Parameters:graph (NetworkX.MultiDiGraph) –
Returns:Lists of dicts corresponding to (nodes, edges)
Return type:list[dict], list[dict]
pythiaplotter.printers.web_printer.get_dot_json(graphviz_str, renderer='dot')[source]

Get the JSON output (with co-ords) from running a layout renderer.

Parameters:
  • graphviz_str (str) – Graph in DOT language.
  • renderer (str, optional) – Renderer to use. Default is dot.
Returns:

JSON string

Return type:

str

pythiaplotter.printers.web_printer.write_webpage(field_data, output_filename)[source]

Write webpage using template file and filling with user data.

Parameters:
  • field_data (dict) – Dict of template {field name: value str} to be replaced
  • output_filename (str) – Output HTML filename

Module contents

Printers take in a NetworkX graph of Particles, then produce an output diagram.

pythiaplotter.printers.printer_opts_all

dict[str, PrinterOption]

Store a record of all printers and their requirements.

pythiaplotter.printers.printer_opts_checked

dict{str: PrinterOption}

Store a record of only those printers available on the user’s system.

class pythiaplotter.printers.PrinterOption(description, printer, requires, default_output_fmt)[source]

Bases: object

pythiaplotter.printers.print_printers_requirements(output=<built-in method write of file object>)[source]

Print program and python package requirements for all printers

Parameters:output (function, optional) – The outputmessage is passed as the parameter to this function. Default is sys.stdout.write()