Skip to content
Snippets Groups Projects
Commit e5d98f18 authored by nugget's avatar nugget
Browse files

Rebuild packaging structure.

parent a1f62077
Branches
Tags
4 merge requests!12v.0.1 for alpha release,!11Draft: Merge version0.1 changes into dev,!10Version0.1,!9Packaging
Pipeline #734578 failed
"""Handling of hdf5 data files."""
import h5py
# Shows how to create an externalLink (symbolic) to a hdf5 File
# Documentation available at:
# https://docs.h5py.org/en/stable/high/group.html#external-links
myfile = h5py.File('./example.h5', 'w')
myfile['ext link'] = h5py.ExternalLink("testdata_2.h5", "/")
myfile.close()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Tag your plot with an ID.
For publishing the tagged plot along your research data have a look at the
module publish.
Functions:
TagPlot(figure object, string) -> list
"""
import warnings
from plotoptions import PlotOptions
from tagplot_matplotlib import tagplot_matplotlib
def tagplot(figs, engine, prefix='', id_method=1, location='east'):
"""
Tag your figure/plot with an ID.
After determining the plot engine, TagPlot calls the corresponding
function which tags the plot.
Parameters
----------
figs : list
Figures that should be tagged.
engine : string
Plot engine which should be used to tag the plot.
prefix : string
Will be added as prefix to the ID.
id_method : int, optional
id_method for creating the ID. Create an ID by Unix time is referenced
as 1, create a random ID with id_method=2. The default is 1.
location : string, optional
Location for ID to be displayed on the plot. Default is 'east'.
Raises
------
RuntimeWarning
DESCRIPTION.
Returns
-------
list
The resulting list contains two lists each with as many entries as
figures were given. The first list contains the tagged figures.
The second list contains the corresponding IDs as strings.
"""
if isinstance(location, str):
pass
else:
raise TypeError("Location is not a string.")
match location:
case 'north':
rotation = 0
position = (0.35, 0.975)
case 'east':
rotation = 90
position = (0.975, 0.35)
case 'south':
rotation = 0
position = (0.35, 0.015)
case 'west':
rotation = 90
position = (0.025, 0.35)
case 'southeast':
rotation = 0
position = (0.75, 0.015)
case 'custom':
# TODO: Get rotation and position from user input & check if valid
rotation = 0
position = (0.5, 0.5)
case _:
warnings.warn(f'Location "{location}" is not a defined '
'location, TagPlot uses location "east" '
'instead.')
rotation = 90
position = (0.975, 0.35)
option_container = PlotOptions(figs, prefix, id_method,
rotation, position)
option_container.validate_input()
match engine:
case 'matplotlib' | 'pyplot':
return tagplot_matplotlib(option_container)
case _:
raise ValueError(
f'The plot engine "{engine}" is not supported.')
# -*- coding: utf-8 -*-
# from fcn_help.FST_colors import Colors
import matplotlib
import matplotlib.pyplot as plt
import create_id
# plt.style.use('./fcn_help/FST.mplstyle')
def TagPlot_matplotlib(figs, prefix, method, rotation, position):
"""
Add IDs to figures with matplotlib.
The ID is placed visual on the figure window and
as Tag (Property of figure).
TagPlot can tag multiple figures at once
"""
# Check if figs is a valid figure or a list of valid figures
if isinstance(figs, matplotlib.figure.Figure):
pass
elif isinstance(figs, list):
for figure in figs:
if isinstance(figure, matplotlib.figure.Figure):
pass
else:
raise TypeError('Figure is not a valid matplotlib-figure.')
fontsize = 'small'
color = 'grey'
IDs = []
# Loop to create and position the IDs
for fig in figs:
ID = create_id.create_id(method)
ID = prefix + str(ID)
IDs.append(ID)
plt.figure(fig.number)
plt.figtext(x=position[0], y=position[1], s=ID, ha='left', wrap=True,
rotation=rotation, fontsize=fontsize, color=color)
fig.tight_layout()
return [figs, IDs]
File moved
File moved
File moved
File moved
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Unittests for TagPlot_matplotlib
'''
import unittest
from src.plotid.TagPlot_matplotlib import TagPlot_matplotlib
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
# %% Create data
x = np.linspace(0, 10, 100)
y = np.random.rand(100) + 2
y_2 = np.sin(x) + 2
# %% Create figure
color1 = 'black'
color2 = 'yellow'
# 1.Figure
fig1 = plt.figure()
plt.plot(x, y, color=color1)
plt.plot(x, y_2, color=color2)
plt.clf # Close figure
# 2.Figure
fig2 = plt.figure()
plt.plot(x, y, color=color2)
plt.plot(x, y_2, color=color1)
plt.clf # Close figure
fig = [fig1, fig2]
# Constants for tests
ProjectID = "MR01"
method = 1
rotation = 90
position = (0.975, 0.35)
class TestTagPlot_matplotlib(unittest.TestCase):
def test_mplfigures(self):
[figs, ID] = TagPlot_matplotlib(
fig, ProjectID, method, rotation, position)
self.assertIsInstance(figs[0], Figure)
self.assertIsInstance(figs[1], Figure)
with self.assertRaises(TypeError):
TagPlot_matplotlib(3, ProjectID, method, rotation, position)
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment