persunraveltorch.draw
Utilities for drawing unravelled persistence diagrams as SVGs.
- class persunraveltorch.draw.Draw(*, range_intervals: Tuple[float, float] = (0.0, pi / 2.0), seizing: Seizing = SeizingByHeight(length=Length(650.0, Unit.PX)), viewbox_creator: ViewboxCreator = ViewboxWithPadding(padding=0.06), strip_orientation: StripOrientation = StripOrientation.ORDINARY, background_creator: BackgroundCreator = svg.StripWithAxesPattern(), unravel: Callable | None = None, fmt: str = '%.5f', device=None, dtype=None)[source]
Bases:
object
Callable drawing unravelled persistence diagrams as
SVG
.- Parameters:
range_intervals (
Tuple[float, float]
, optional) – Seerange_intervals
for details, defaults to(0.0, pi/2.0)
.seizing (
Seizing
, optional) – Seeseizing
for details. The default is an instance ofSeizingByHeight
, specificallySeizingByHeight( length = Length(650.0, Unit.PX) )
.viewbox_creator (
ViewboxCreator
, optional) – Seeviewbox_creator
for details, defaults toViewboxWithPadding( padding=0.06 )
.strip_orientation (
StripOrientation
, optional) – The orientation of the strip to be drawn, see alsostrip_orientation
. The default isStripOrientation.ORDINARY
,StripOrientation.CROSS
can be a sensible choice for functional or extended persistence.background_creator (
svg.BackgroundCreator
, optional) – Draws the background based on the input, see alsobackground_creator
. The default is a default instance ofsvg.StripWithAxesPattern
.unravel (
Optional[ Callable ]
, optional) – If this is notNone
, then it is used to compute unravelled persistence diagrams instead of a newly created instance ofUnravel
, see alsounravel
. The default isNone
.fmt (
str
, optional) – Seefmt
for details, defaults to ‘%.5f’.
- __call__(intervals: Sequence[Tensor | Iterable[Tensor]], *, seizing: Seizing | None = None, viewbox_creator: ViewboxCreator | None = None, standalone: bool | None = None, complete_dimensions: bool | None = None) SVG [source]
Draws unravelled persistence diagram as
SVG
.- Parameters:
intervals (
Sequence[ torch.Tensor | Iterable[torch.Tensor] ]
) – Persistence intervals. If aSequence[torch.Tensor]
is passed, the indices of the outer sequence correspond to degrees, whereas if aSequence[Iterable[torch.Tensor]]
is passed, then the innerIterable
is assumend to correspond to the degrees and the outerSequence
corresponds to different persistence diagrams.seizing (
Optional[Seizing]
, optional) – If this is notNone
, then it is used in place ofseizing
, defaults toNone
.viewbox_creator (
Optional[ViewboxCreator]
, optional) – If this is notNone
, then it is used in place ofviewbox_creator
, defaults toNone
.standalone (
Optional[bool]
, optional) – If this is notNone
, then it is used in place ofstandalone
, defaults toNone
.complete_dimensions (
Optional[bool]
) – If this is notNone
, then it is used in place ofcomplete_dimensions
, defaults toNone
.
- Returns:
The SVG picturing unravelled persistence diagrams.
- Return type:
- background_creator
svg.BackgroundCreator
: Draws the background based on the input.
- classmethod complement_notebook()[source]
Complements the notebook with CSS and SVG containing ‘defs’.
This classmethod is supposed to be called from Jupyter Notebook. It adds a <style> element wrapping
stylesheet
and an invisible <svg> containing a <defs> element wrappingdefs
to the notebook. Moreover, it has the side effect of settingstandalone
toFalse
.
- defs: ClassVar[str] = '<marker id="marker-disc"\n markerUnits="userSpaceOnUse"\n viewBox="-0.02 -0.02 0.04 0.04"\n markerWidth="0.04"\n markerHeight="0.04">\n <circle r="0.015"\n fill="currentColor"\n class="tint-red" />\n</marker>\n<marker id="marker-x"\n markerUnits="userSpaceOnUse"\n viewBox="-0.03 -0.03 0.06 0.06"\n markerWidth="0.06"\n markerHeight="0.06">\n <g fill="currentColor"\n class="tint-green">\n <rect width="0.01" height="0.04"\n transform="rotate(-45) translate(-0.005 -0.02)" />\n <rect width="0.01" height="0.04"\n transform="rotate(45) translate(-0.005 -0.02)" />\n </g>\n</marker>\n'
str
: SVG code to be wrapped by a <defs> element.The initial value is
svg.MARKERS
.
- fmt
str
: The format string used to render floats into strings.
- range_intervals
Tuple[float, float]
: The finite range containing all persistence intervals.
- seizing
Seizing
: Computes ‘width’ and ‘height’ attributes based on the input.
- standalone: ClassVar[bool] = True
If drawn SVGs should be standalone (by default).
- Type:
bool
- strip_orientation
StripOrientation
: The orientation of the strip to be drawn.
- stylesheet: ClassVar[str] = '.unravelled-diagrams polyline {\n fill: none;\n}\n\n.unravelled-diagrams polyline:nth-of-type(odd) {\n marker: url(#marker-disc);\n}\n\n.unravelled-diagrams polyline:nth-of-type(even) {\n marker: url(#marker-x);\n}\n.tint-blue {\n color: #007AFF;\n}\n.tint-green {\n color: #34C759;\n}\n.tint-indigo {\n color: #5856D6;\n}\n.tint-orange {\n color: #FF9500;\n}\n.tint-pink {\n color: #FF2D55;\n}\n.tint-purple {\n color: #AF52DE;\n}\n.tint-red {\n color: #FF3B30;\n}\n.tint-teal {\n color: #5AC8FA;\n}\n.tint-yellow {\n color: #DEAE00;\n}\n\n.shade-000 {\n color: #000000;\n}\n.shade-005 {\n color: #0D0D0D;\n}\n.shade-010 {\n color: #1A1A1A;\n}\n.shade-015 {\n color: #262626;\n}\n.shade-020 {\n color: #333333;\n}\n.shade-025 {\n color: #404040;\n}\n.shade-030 {\n color: #4C4C4C;\n}\n.shade-035 {\n color: #595959;\n}\n.shade-040 {\n color: #666666;\n}\n.shade-045 {\n color: #737373;\n}\n.shade-050 {\n color: #808080;\n}\n.shade-055 {\n color: #8C8C8C;\n}\n.shade-060 {\n color: #999999;\n}\n.shade-065 {\n color: #A6A6A6;\n}\n.shade-070 {\n color: #B2B2B2;\n}\n.shade-075 {\n color: #BFBFBF;\n}\n.shade-080 {\n color: #CCCCCC;\n}\n.shade-085 {\n color: #D9D9D9;\n}\n.shade-090 {\n color: #E6E6E6;\n}\n.shade-095 {\n color: #F2F2F2;\n}\n.shade-100 {\n color: #FFFFFF;\n}\n'
str
: The stylesheet to be used by the SVG.The initial value is the concatenation of
css.POLYLINE
andcss.LIGHT_SCHEME
.
- unravel
Optional[ Callable ]
: Used to compute unravelled persistence diagrams.
- viewbox_creator
Creates a viewbox based on the input.
- Type:
- class persunraveltorch.draw.SVG[source]
Bases:
str
SVG as a string that is automatically displayed as such in Jupyter.
- class persunraveltorch.draw.StripOrientation(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
StrEnum
- CROSS = 'cross'
- ORDINARY = 'ordinary'
- class persunraveltorch.draw.VerticalOrientation(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
StrEnum
- DOWN = 'down'
- UP = 'up'
- class persunraveltorch.draw.Viewbox(*, vertical_orientation: VerticalOrientation, top: float, right: float, bottom: float, left: float)[source]
Bases:
object
Dataclass for attributes specifying a viewbox.
- bottom: float
- left: float
- right: float
- top: float
- vertical_orientation: VerticalOrientation
Orientation of the y axis.
- Type:
- class persunraveltorch.draw.ViewboxCreator(*args, **kwargs)[source]
Bases:
Protocol
Callable for creating a
Viewbox
from parameters.- __call__(*, range_intervals: Tuple[float, float], strip_orientation: StripOrientation, unravelled_intervals: Sequence, **kwargs: Any) Viewbox [source]
Creates a
Viewbox
from parameters.- Parameters:
range_intervals (
Tuple[float, float]
) – The finite range containing all persistence intervals.strip_orientation (
StripOrientation
) – The orientation of the strip to be drawn.unravelled_intervals (
Sequence
) – The unravelled persistence intervals as a sequence by degree.**kwargs (
Any
) – Any descendent ofViewboxCreator
needs this so the protocol can be extended in the future.
- Return type:
- class persunraveltorch.draw.ViewboxWithPadding(*, padding: float)[source]
Bases:
ViewboxCreator
Creates a
Viewbox
based on highest degree with padding.- __call__(*, range_intervals: Tuple[float, float], strip_orientation: StripOrientation, unravelled_intervals: Sequence, **kwargs: Any) Viewbox [source]
Creates a
Viewbox
from parameters.- Parameters:
range_intervals (
Tuple[float, float]
) – The finite range containing all persistence intervals.strip_orientation (
StripOrientation
) – The orientation of the strip to be drawn.unravelled_intervals (
Sequence
) – The unravelled persistence intervals as a sequence by degree.**kwargs (
Any
) – Any descendent ofViewboxCreator
needs this so the protocol can be extended in the future.
- Return type:
- padding: float
float
: The amount of padding to be added in local coordinates.