Skip to content
Snippets Groups Projects
Commit 654327a9 authored by Mayr, Hannes's avatar Mayr, Hannes
Browse files

Make the figure_ids an attribute of PlotOptions.

parent 779cd772
Branches
Tags
7 merge requests!41Include latest changes in main branch,!37Merge dev upstream changes into improve/metadata,!34Include architecture diagram in docs,!32SAST implementation,!27Update documentation and version number,!26Merge !23, !24, !25 into main,!22Restructure and introduce additional object to transfer figures and IDs from...
Pipeline #800449 waiting for manual action
......@@ -28,7 +28,7 @@ def create_id(id_method):
match id_method:
case 'time':
figure_id = time.time() # UNIX Time
figure_id = hex(int(figure_id)) # convert time to hexadecimal
figure_id = hex(int(figure_id)) # convert time to hexadecimal str
time.sleep(0.5) # break for avoiding duplicate IDs
case 'random':
figure_id = str(uuid.uuid4()) # creates a random UUID
......
......@@ -44,12 +44,12 @@ FIGS_AS_LIST = [FIG1, FIG2]
IMGS_AS_LIST = [IMG1, IMG2]
# Example for how to use tagplot with matplotlib figures
[TAGGED_FIGS, ID] = tagplot(FIGS_AS_LIST, 'matplotlib', location='west',
id_method='random', prefix=PROJECT_ID)
# [TAGGED_FIGS, ID] = tagplot(FIGS_AS_LIST, 'matplotlib', location='west',
# id_method='random', prefix=PROJECT_ID)
# Example for how to use tagplot with image files
# [TAGGED_FIGS, ID] = tagplot(IMGS_AS_LIST, 'image', prefix=PROJECT_ID,
# id_method='random', location='west')
[TAGGED_FIGS, ID] = tagplot(IMGS_AS_LIST, 'image', prefix=PROJECT_ID,
id_method='time', location='west')
# %% Publish
# Arguments: Source directory or files as list, destination directory, figures,
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Contains the PlotOptions and PublishOptions class."""
"""Contains the PlotOptions class."""
class PlotOptions:
......@@ -14,8 +14,10 @@ class PlotOptions:
Attributes
----------
figs : figure object
Figure that will be tagged.
figs : figure object or list of figures
Figures that will be tagged.
figure_ids: str or list of str
IDs that the figures are tagged with.
rotation : int
Rotation angle for the ID.
position : tuple
......@@ -36,11 +38,16 @@ class PlotOptions:
def __init__(self, figs, rotation, position, **kwargs):
self.figs = figs
self.figure_ids = kwargs.get('figure_ids', [])
self.rotation = rotation
self.position = position
self.prefix = kwargs.get('prefix', '')
self.id_method = kwargs.get('id_method', 'time')
def __str__(self):
"""Representation if an object of this class is printed."""
return str(self.__class__) + ": " + str(self.__dict__)
def validate_input(self):
"""
Validate if input for PlotOptions is correct type.
......
......@@ -39,13 +39,12 @@ def tagplot_image(plotid_object):
raise TypeError('File does not exist.')
# Check if figs is a valid file is done by pillow internally
ids_as_list = []
color = (128, 128, 128) # grey
font = ImageFont.load_default()
for i, img in enumerate(plotid_object.figs):
img_id = plotid_object.prefix + create_id(plotid_object.id_method)
ids_as_list.append(img_id)
plotid_object.figure_ids.append(img_id)
img = Image.open(img)
img_txt = Image.new('L', font.getsize(img_id))
......@@ -57,4 +56,4 @@ def tagplot_image(plotid_object):
int(img.height*(1-plotid_object.position[1]))), txt)
plotid_object.figs[i] = img
return [plotid_object.figs, ids_as_list]
return [plotid_object.figs, plotid_object.figure_ids]
......@@ -39,18 +39,17 @@ def tagplot_matplotlib(plotid_object):
fontsize = 'small'
color = 'grey'
ids_as_list = []
# Loop to create and position the IDs
for fig in plotid_object.figs:
figure_id = create_id(plotid_object.id_method)
figure_id = plotid_object.prefix + str(figure_id)
ids_as_list.append(figure_id)
fig_id = create_id(plotid_object.id_method)
fig_id = plotid_object.prefix + fig_id
plotid_object.figure_ids.append(fig_id)
plt.figure(fig)
plt.figtext(x=plotid_object.position[0], y=plotid_object.position[1],
s=figure_id, ha='left', wrap=True,
s=fig_id, ha='left', wrap=True,
rotation=plotid_object.rotation,
fontsize=fontsize, color=color)
fig.tight_layout()
return [plotid_object.figs, ids_as_list]
return [plotid_object.figs, plotid_object.figure_ids]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment