porescene.layout module

class porescene.layout.Annotation[source]

Bases: ABC

class porescene.layout.BackgroundAnnotation(pth, res=(4096, 4096), pad=(100, 100, 100, 100), bg=None)[source]

Bases: Annotation

Base class for the different annotation types.

You can use this class to create a plain unicolored image without anything else. It is also possible to add an bitmap image like PNG to the center.

Parameters:
  • res (tuple[int, int]) – Size of the image in pixels. The first entry specifies width, second height.

  • pad (tuple[int, int, int, int]) – The padding of the image. Does not apply to the background color.

Examples

This example creates the most simply overlay: just a simple colored image.

Create a simple colored image.
1from collib import Color
2
3res = (1600, 900)
4fpath = Path("unicolor_image.svg")
5ovl = BackgroundAnnotation(res)
6ovl.background = Color("#382655")
7ovl.save(fpath)
get_svg()[source]

Returns the SVG element without XML declaration.

Builds the <svg> element with all its child elements. The drawn content is centered on the canvas (see _center()).

Return type:

str

save()[source]

Saves the SVG image as file with specified filename.

Return type:

Self

property color_background: Color | None

Image background color as Color object or None for transparent background.

property padding: tuple[int, int, int, int]

Padding of the image contained in a 4-element tuple of int in following order: top, right, bottom, left.

The padding does not apply to the background color.

property resolution: tuple[int, int]

Resolution of the SVG file denoted as 2-element tuple containing width ad height.

class porescene.layout.DiscreteGradientAnnotation(pth, res=(4096, 4096), pad=(100, 100, 100, 100))[source]

Bases: SegmentedGradientAnnotation

class porescene.layout.Gradient(pth, res=(4096, 4096), pad=(100, 100, 100, 100))[source]

Bases: TitleAnnotation, ABC

Create an annotation image with heading, subheading, text and a gradient with scaclebars.

Parameters:
  • project – Directory of the current project. All other specified filepath are relative to this directory.

  • res (tuple[int, int]) – Size of the image in pixels. The first entry specifies width, second height.

Examples

>>> ovl = Gradient('myproject')
>>> ovl.heading = 'My beautiful work:'
>>> ovl.subheading = 'You can see a '
>>>
property align: CompassDirection

Location to place the text on the image.

There are 4 available options to choose: ‘NW’, ‘NE’, ‘SE’, ‘SW’ (like the direction of compass).

The default align is ‘NW’.

property color_nan: Color | None

Color of NaN values.

If None, the label won’t beshown on the image.

property color_ticks: Color

Color of the ticks.

property exponent: float | int | str | None

Exponent of the factor of the scale.

property font_size_ticks: float

Font size of the color gradient axis ticks.

property gradient_colors: list[Color]

Colors of the gradient bar.

property gradient_height: float

Height of the gradient bar (always referred to horizontal orientation).

property gradient_length: float

Length of the gradient bar (always referred to horizontal orientation).

property line_width: float

Line width of the scalebar.

property orientation: Orientation

Orientation of the text flow and gradient bar on the image.

There are 2 available options to choose: ‘H’, ‘V’. The default orientation is ‘V’.

property roundness: float

Roundness of the lines of the scalebar.

property seperator_decimal: str

The decimal seperator of numbers of the scalebar can be either ‘COMMA’ or ‘DOT’.

property seperator_exponent: MultiplicationSymbol

The multiplication sign of the scalebar exponent can be either ‘CROSS’ or ‘DOT’.

property spacing: float | int

Space between the individual components (heading, subheading, gradient bar…).

property text_nan: str

Description of the NaN label. Default is ‘NaN’.

property tick_length: float

Length of the ticks.

property ticks: list[str]

Ticks of the color scalebar.

class porescene.layout.LabelsAnnotation(pth, res=(4096, 4096), pad=(100, 100, 100, 100))[source]

Bases: TitleAnnotation

add_label(color, text)[source]

Add a label to the overlay.

property box_size: tuple[float, float]

Size of each colored box.

property color_labeltext
property font_size_labeltext
property roundness: float

Roundness of the lines of the scalebar.

class porescene.layout.SegmentedGradientAnnotation(pth, res=(4096, 4096), pad=(100, 100, 100, 100))[source]

Bases: Gradient

class porescene.layout.SmoothGradientAnnotation(pth, res=(4096, 4096), pad=(100, 100, 100, 100))[source]

Bases: Gradient

class porescene.layout.TitleAnnotation(pth, res=(4096, 4096), pad=(100, 100, 100, 100))[source]

Bases: BackgroundAnnotation

Create an annotation image with heading, subheading an some lines of text.

Parameters:

res (tuple[int, int]) – Size of the image in pixels. The first entry specifies width, second height.

Examples

>>> from fefacolors import gray, red, light3
>>> ovl = TitleAnnotation()
>>> ovl.heading = "My super topic!"
>>> ovl.subheading = "Maybe its only interesting for me, not for you?"
>>> ovl.text = [
        "I do not know what to write here.",
        "It's only a few lines",
        "of text nobody cares."]
>>> ovl.color_text = gray
>>> ovl.color_heading = red
>>> ovl.background = light3
>>> ovl.align = 'SE'
>>> ovl.save('mytitle')
*Look for the save file!*
property align: CompassDirection

Location to place the text on the image.

There are 4 available options to choose: ‘NW’, ‘NE’, ‘SE’, ‘SW’ (like the direction of compass). The default align is ‘NW’.

property color_heading: Color

Color of the heading as Color.

property color_subheading: Color

Color of the subheading as Color object.

property color_text: Color

Color of the text as Color object.

property font_family: str

Font family used for headings and text.

property font_size_heading: float

Font size of the heading.

property font_size_subheading: float

Font size of the subheading.

property font_size_text: float

Font size of the text.

property heading: str | None

Headline of the image.

The text is displayed in bold typeface in a single line. It should not be too long.

property line_height: float

Line height of texts

property spacing: float

Space between elements.

property subheading: str | None

Second headline of the image.

The text is displayed in bold typeface but smaller font-size a heading in a single line. It should not be too long. You can minimize the property font_size_subheading to fit more word in the line.

property text: list[str]

Multiline text on the image.

Since linebreaks are not inserted automatically by SVG, a list of strings each representing a line is required.