Skip to main content

pd_code_to_diagram

given a pd_code for a topological link or knot, output a possible 2d-diagram.

Install

pip install pd-code-to-diagram

Usage

import pd_code_to_diagram

# pd_code is a list of list of int
pd_code = [[6, 1, 7, 2], [14, 7, 15, 8], [4, 15, 1, 16], [10, 6, 11, 5], [8, 4, 9, 3], [18, 11, 19, 12], [20, 17, 5, 18], [12, 19, 13, 20], [16, 10, 17, 9], [2, 14, 3, 13]]

# last_socket should be int or None
#   the program will ensure in the components contains last_socket
#   there will be at least one arc on the border of 
last_socket = 1

# diagram_2d will be a matrix of int
#   its type will be list of list of int
#   get_diagram_from_pd_code will raise an RuntimeError if such diagram not exists
diagram_2d = pd_code_to_diagram.get_diagram_from_pd_code(pd_code, last_socket)
for line in diagram_2d:
    print(line)

# get string_form diagram and save to file
link = [[2, 9, 3, 10], [4, 11, 5, 12], [6, 7, 1, 8], [8, 5, 7, 6], [10, 1, 11, 2], [12, 3, 9, 4]]
with open("test.txt", "w") as fp:
    fp.write(pd_code_to_diagram.get_diagram_str_from_pd_code(link, last_socket))

diagram_now = pd_code_to_diagram.get_diagram_from_pd_code(link, last_socket)
print(pd_code_to_diagram.diagram_to_pd_code(diagram_now))

# Check pd_code -> diagram -> pd_code consistency (bool, new_pdcode)
# new_pdcode = None, if error
print(pd_code_to_diagram.pd_code_diagram_sanity(link))

# save diagram_2d as a png image
pd_code_to_diagram.diagram_to_png(diagram_now, "diagram.png")

# get a PIL.Image.Image object instead of writing a file
image = pd_code_to_diagram.diagram_to_image(diagram_now)

# optionally resize every grid tile, default tile size is 30 pixels
pd_code_to_diagram.diagram_to_png(diagram_now, "diagram_20px.png", tile_size=20)

# optionally draw small red labels for the four socket ids around each crossing
pd_code_to_diagram.diagram_to_png(diagram_now, "diagram_labeled.png", show_socket_labels=True)

In the diagram matrix, 0 means empty space, positive integers mean arc ids, -1 means the vertical strand is under the horizontal strand, and -2 means the horizontal strand is under the vertical strand.

Download files

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

Source Distribution

pd_code_to_diagram-0.1.7.tar.gz (48.5 kB view details)

Uploaded Source

Built Distribution

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

pd_code_to_diagram-0.1.7-py3-none-any.whl (77.1 kB view details)

Uploaded Python 3

File details

Details for the file pd_code_to_diagram-0.1.7.tar.gz.

File metadata

  • Download URL: pd_code_to_diagram-0.1.7.tar.gz
  • Upload date:
  • Size: 48.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for pd_code_to_diagram-0.1.7.tar.gz
Algorithm Hash digest
SHA256 f763e2eb75cf1d874b8215ae3d1e013707900bfd95ae72b78a0351ff44166cc8
MD5 96d8bec70238197b6acdb256d296c2e8
BLAKE2b-256 2eeb4178fde50a0b30c2dc62831e01fccdd89ae41d8dd9ed3a4f796ad59d6d6f

See more details on using hashes here.

File details

Details for the file pd_code_to_diagram-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for pd_code_to_diagram-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a7fa9c5f5494953f893f98ebac96b5e37278281846eefcb7e9feecdb1617a088
MD5 2f263440ed7b7927432b27311fa3a089
BLAKE2b-256 87b1ededfab6b9018bf7f85c3bd9101ef06d8813254a16e8742adf225662702f

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 Sentry Error logging StatusPage Status page