diff --git a/.gitignore b/.gitignore
index 11614af2870733183efe883810764d8708bddf8f..e01aca0bfc95772299812615a69de3808b12ba9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -90,7 +90,7 @@ celerybeat-schedule
# Environments
.env
.venv
-env/
+env*/
venv/
ENV/
env.bak/
diff --git a/2.py b/2.py
deleted file mode 100644
index 465e2da2aa965ba44d13d05b35a171593fea171f..0000000000000000000000000000000000000000
--- a/2.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on Fri Jul 23 10:09:46 2021
-
-@author: Richter
-"""
-
-#%% Test
-a = 1
-b = 2
-
-print(a+b)
-print(a-b)
\ No newline at end of file
diff --git a/CreateID.py b/CreateID.py
new file mode 100644
index 0000000000000000000000000000000000000000..a65aebe249a5408a06afe3e217e73a72ec35d590
--- /dev/null
+++ b/CreateID.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+import time
+import uuid
+
+
+def CreateID(method):
+ """
+ Create an Identifier (str).
+
+ Creates an (sometimes unique) identifier based on the selected method
+ if no method is selected method 1 will be the default method
+
+ Returns
+ -------
+ ID
+ """
+ if method == 1:
+ ID = time.time() # UNIX Time
+ ID = hex(int(ID)) # convert time to hexadecimal
+ time.sleep(0.5) # break for avoiding duplicate IDs
+ elif method == 2:
+ ID = str(uuid.uuid4()) # creates a random UUID
+ ID = ID[0:8] # only use first 8 numbers
+ else:
+ raise ValueError(
+ f'Your chosen ID method "{method}" is not supported.\n'
+ 'At the moment these methods are available:\n'
+ '"1": Unix time converted to hexadecimal\n'
+ '"2": Random UUID')
+ return ID
diff --git a/README.md b/README.md
index 58de42ddc60a1be7d4c653ab83c188a1a4a3d723..e873d62fc0f29ae08ed91cf1131273e856e1c5fe 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
# plot_ID_python
-This is the python PlotID project
\ No newline at end of file
+This is the python PlotID project.
+
+To run the program python version 3.10 is required.
\ No newline at end of file
diff --git a/TagPlot.py b/TagPlot.py
new file mode 100644
index 0000000000000000000000000000000000000000..81c0f7a95b261ee8134a3be7f375eaad585ccb19
--- /dev/null
+++ b/TagPlot.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from TagPlot_matplotlib import TagPlot_matplotlib
+import warnings
+
+
+def TagPlot(figs, engine, prefix='', method=1, location='east'):
+ """
+ Determine which plot engine should be used to tag the plots.
+
+ After determining the engine, TagPlot calls the corresponding
+ function which tags the plot.
+
+ Parameters
+ ----------
+ figs : list
+ Figures that should be tagged.
+ prefix : string
+ Will be added as prefix to the ID.
+ engine : string
+ Plot engine which should be used to tag the plot.
+ method : int, optional
+ Method for creating the ID. Create an ID by Unix time is referenced
+ as 1, create a random ID with 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.
+ """
+ # %% Validate inputs
+ if isinstance(prefix, str):
+ pass
+ else:
+ raise TypeError("Prefix is not a string.")
+
+ if isinstance(figs, list):
+ pass
+ else:
+ raise TypeError("Figures are not a list.")
+
+ # TODO: Rename method to more specific name (maybe id_method?).
+ # TODO: Change method key from integer to (more meaningful) string.
+ try:
+ method = int(method)
+ except ValueError:
+ raise TypeError('The chosen ID method is not an integer.')
+
+ if isinstance(location, str):
+ pass
+ else:
+ raise TypeError("Location is not a string.")
+
+ # TODO: Implement backwards combatibility with if-clauses
+ 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)
+
+ if engine == 'matplotlib' or engine == 'pyplot':
+ return TagPlot_matplotlib(figs, prefix, method, rotation, position)
+ else:
+ raise ValueError(f'The plot engine "{engine}" is not supported.')
+
+
+# Following code only works for python >= 3.10
+ # match engine:
+ # case 'matplotlib' | 'pyplot':
+ # return TagPlot_matplotlib(figs, prefix, method)
+ # case _:
+ # raise ValueError(
+ # f'The plot engine "{engine}" is not supported.')
diff --git a/TagPlot_matplotlib.py b/TagPlot_matplotlib.py
new file mode 100644
index 0000000000000000000000000000000000000000..a4e62742005062bad55f6cacfc477c6f45d2f78d
--- /dev/null
+++ b/TagPlot_matplotlib.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+
+import CreateID
+# from fcn_help.FST_colors import Colors
+import matplotlib.pyplot as plt
+import matplotlib
+# 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 i in range(len(figs)):
+ if isinstance(figs[i], 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 = CreateID.CreateID(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]
diff --git a/Test0.tiff b/Test0.tiff
index ee04732d78e20d3406702d1f13a7ec788b1b7079..3fae33c545d0cbb59e34c87d3296b8a5bdd48c1f 100644
Binary files a/Test0.tiff and b/Test0.tiff differ
diff --git a/Test1.tiff b/Test1.tiff
index 3b0d4ac0d396dc252acf3d6455bde520211e2de3..ad34eedaa7492fa401b78d017c73e854effa6186 100644
Binary files a/Test1.tiff and b/Test1.tiff differ
diff --git a/example.py b/example.py
index 6557ef77952b33b6f089d06d307b3520791990f0..2e36ea9b12732a460b685a7d09aa63479b224309 100644
--- a/example.py
+++ b/example.py
@@ -4,68 +4,62 @@ Created on Tue Jul 20 12:22:33 2021
example workflow for integrating plotIDs
@author: Richter
"""
-#%% Code und Konsole aufräumen
-%reset
-%matplotlib
-%clear
-#%% Module einbinden
+
+# %% Module einbinden
import sys
import numpy as np
from numpy import random
-import h5py as h5
-import matplotlib
+# import h5py as h5
+# import matplotlib
import matplotlib.pyplot as plt
-plt.style.use('fcn_help/FST.mplstyle')
-%matplotlib qt
-#%matplotlib inline
-from FST_colors import Colors
from TagPlot import TagPlot
-#%% Pfade hinzufügen
+from fcn_help.FST_colors import Colors
+plt.style.use('fcn_help/FST.mplstyle')
+# %matplotlib qt
+# %matplotlib inline
+# %% Pfade hinzufügen
sys.path.append("fcn_core")
sys.path.append("fcn_help")
-
-#%% Project ID
-ProjectID= "MR01"
-#%% Daten erzeugen
-x = np.linspace(0,10,100)
-y= random.rand(100) + 2
-y_2 = np.sin(x) +2
+# %% Project ID
+ProjectID = "MR04_"
+
+# %% Plot engine
+plot_engine = "matplotlib"
-#%% Daten speichern
-dataset1 = "test_data.npy"
-np.save(dataset1, x,y, y_2)
+# %% Create sample data
+x = np.linspace(0, 10, 100)
+y = random.rand(100) + 2
+y_2 = np.sin(x) + 2
-#%% figure erstellen
-# Farben
-colors = Colors() # create instance from class
+# %% Create figure
+# Colors
+colors = Colors() # create instance from class
color_list = colors.get_color_names()
-# Plot erstellen
+# Create plot
color1 = colors.get_rgb('black')
color2 = colors.get_rgb('yellow')
-#1.Figure
+# 1.Figure
fig1 = plt.figure()
-plt.plot(x,y, color=color1)
-plt.plot(x,y_2, color= color2)
-#plt.draw()
+plt.plot(x, y, color=color1)
+plt.plot(x, y_2, color=color2)
+
# 2.Figure
-plt.clf #Figure schließen
+plt.clf # Close figure
fig2 = plt.figure()
-plt.plot(x,y, color=color2)
-plt.plot(x,y_2, color= color1)
-#plt.draw()
-plt.clf #Figure schließen
+plt.plot(x, y, color=color2)
+plt.plot(x, y_2, color=color1)
+plt.clf # Close figure
fig = [fig1, fig2]
-#%% TagPlot
-[figs, ID] = TagPlot(fig, ProjectID)
+# %% TagPlot
+[figs, ID] = TagPlot(fig, plot_engine, prefix=ProjectID,
+ method='2', location='west')
-#%% Figure als tiff-Datei abspeichern
-for i in range(len(figs)):
+# %% Figure als tiff-Datei abspeichern
+for i, figure in enumerate(figs):
name = "Test"+str(i)+".tiff"
- figs[i].savefig(name)
-
-
+ figure.savefig(name)
diff --git a/fcn_help/test.py b/fcn_help/?test.py
similarity index 100%
rename from fcn_help/test.py
rename to fcn_help/?test.py
diff --git a/fcn_help/CreateID.py b/fcn_help/CreateID.py
deleted file mode 100644
index 387ef9feefc59fca8ebd4301f34c7055f7cfad72..0000000000000000000000000000000000000000
--- a/fcn_help/CreateID.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on Tue Jul 27 17:02:27 2021
-CreateID
-@author: Richter
-"""
-#%% Module importieren
-import time
-import uuid
-
-#%% Funktion
-
-
-def CreateID(method):
- """
- % CreateID Creates an Identifier (str)
- % Creates an (sometimes unique) identifier based on the selected method
- % if no method is selected method 1 will be the default method
-
- Returns
- -------
- ID
-
- """
- if method == 1:
- ID = time.time() # UNIX Time
- ID = hex(int(ID)) # Hexadezimalzahl
- time.sleep(0.5) # Pause
- elif method == 2:
- ID = str(uuid.uuid4()) # creates a random UUID
- ID = ID[0:8] # Verwendung der ersten 8 Ziffern
- time.sleep(0.5) # Pause
-
- return ID
-
diff --git a/fcn_help/TagPlot.py b/fcn_help/TagPlot.py
deleted file mode 100644
index a65bb9d615f28de49374650824ae63aad964b074..0000000000000000000000000000000000000000
--- a/fcn_help/TagPlot.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on Tue Jul 27 10:50:20 2021
-
-@author: Richter
-"""
-import matplotlib
-import matplotlib.pyplot as plt
-plt.style.use('fcn_help/FST.mplstyle')
-#%matplotlib qt
-#%matplotlib inline
-import numpy as np
-from FST_colors import Colors
-import CreateID
-
-def TagPlot(figs,prefix, *method):
-
- """
- TagPlot adds IDs to figures
- The ID is placed visual on the figure window and as Tag (Property of figure)
- TagPlot can tag multiple figures at once
- """
-
- #%% Eingaben prüfen
- if prefix:
- pass
- else:
- raise RuntimeWarning("no prefix set")
-
- if figs:
- pass
- else:
- raise RuntimeWarning("no figures set")
-
- if method:
- method = method
- else:
- method = 1
- pass
-
-
- #isinstance(figs, t)
-
- #%% Schleife zur Erzeugung und Positionierung der IDs
-
- for i in range(len(figs)):
- #print(i)
- #CreateID aufrufen
- ID = CreateID.CreateID(method)
- #ID = prefix + '_' +'Test'+str(i)
- ID = prefix + '_' + str(ID)
- #print(ID)
- fig =figs[i]
- #print(type(fig))
- plt.figure(fig.number)
- x_lim = plt.xlim()
- y_lim = plt.ylim()
- y_mitte = 0.4*(y_lim[1]+y_lim[0])
- plt.text(x = x_lim[1], y = y_mitte, s = ID, ha='left',
- rotation='vertical', fontsize = "small", wrap=True, color = "grey")
- fig.tight_layout()
- #plt.draw()
-
- #%% Rückgabewerte
- return(figs, ID)
\ No newline at end of file
diff --git a/fcn_help/__init__.py b/fcn_help/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..8d1c8b69c3fce7bea45c73efd06983e3c419a92f
--- /dev/null
+++ b/fcn_help/__init__.py
@@ -0,0 +1 @@
+
diff --git a/test_filecompare.py b/filecompare.py
similarity index 100%
rename from test_filecompare.py
rename to filecompare.py
diff --git a/requirements.txt b/requirements.txt
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..79256b38402a8ad070164938860212570325f22f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -0,0 +1 @@
+matplotlib == 3.5.1
diff --git a/test_data.npy b/sample_data.npy
similarity index 100%
rename from test_data.npy
rename to sample_data.npy
diff --git a/test_data.py b/test_data.py
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/test_git.py b/test_git.py
deleted file mode 100644
index 465e2da2aa965ba44d13d05b35a171593fea171f..0000000000000000000000000000000000000000
--- a/test_git.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on Fri Jul 23 10:09:46 2021
-
-@author: Richter
-"""
-
-#%% Test
-a = 1
-b = 2
-
-print(a+b)
-print(a-b)
\ No newline at end of file
diff --git a/tests/sample_data.npy b/tests/sample_data.npy
new file mode 100644
index 0000000000000000000000000000000000000000..9e1a1df4be29620d23f4628e2616ecce6af3505a
Binary files /dev/null and b/tests/sample_data.npy differ
diff --git a/tests/test_CreateID.py b/tests/test_CreateID.py
new file mode 100644
index 0000000000000000000000000000000000000000..6ceb8b68230c431e28abce90b1353cb472755f37
--- /dev/null
+++ b/tests/test_CreateID.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+'''
+Unittests for CreateID
+'''
+import unittest
+import CreateID
+
+
+class TestCreateID(unittest.TestCase):
+
+ def test_existence(self):
+ self.assertIsInstance(CreateID.CreateID(1), str)
+ self.assertIsInstance(CreateID.CreateID(2), str)
+
+ def test_errors(self):
+ with self.assertRaises(ValueError):
+ CreateID.CreateID(3)
+ with self.assertRaises(ValueError):
+ CreateID.CreateID('h')
+
+ def test_length(self):
+ self.assertEqual(len(CreateID.CreateID(1)), 10)
+ self.assertEqual(len(CreateID.CreateID(2)), 8)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_TagPlot.py b/tests/test_TagPlot.py
new file mode 100644
index 0000000000000000000000000000000000000000..3da6fca68835f144a00c3de944cfaf4651719fa9
--- /dev/null
+++ b/tests/test_TagPlot.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+'''
+Unittests for TagPlot
+'''
+import unittest
+from TagPlot import TagPlot
+import numpy as np
+import matplotlib.pyplot as plt
+
+
+# %% 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"
+plot_engine = "matplotlib"
+method = 1
+
+
+class TestTagPlot(unittest.TestCase):
+
+ def test_figures(self):
+ with self.assertRaises(TypeError):
+ TagPlot('fig', ProjectID, plot_engine, method)
+ with self.assertRaises(TypeError):
+ TagPlot(figs=fig1, prefix=ProjectID, engine=plot_engine)
+
+ def test_prefix(self):
+ with self.assertRaises(TypeError):
+ TagPlot(fig, 3, plot_engine, method)
+
+ def test_plotengine(self):
+ with self.assertRaises(ValueError):
+ TagPlot(fig, ProjectID, 1, method)
+ with self.assertRaises(ValueError):
+ TagPlot(fig, ProjectID, 'xyz', method)
+
+ def test_idmethod(self):
+ with self.assertRaises(TypeError):
+ TagPlot(fig, ProjectID, plot_engine, method='(0,1)')
+ with self.assertRaises(TypeError):
+ TagPlot(fig, ProjectID, plot_engine, method='h')
+ with self.assertRaises(TypeError):
+ TagPlot(fig, ProjectID, plot_engine, method='[0,1]')
+
+ def test_location(self):
+ with self.assertRaises(TypeError):
+ TagPlot(fig, ProjectID, plot_engine, method, location=1)
+ with self.assertWarns(Warning):
+ TagPlot(fig, ProjectID, plot_engine, method, location='up')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_TagPlot_matplotlib.py b/tests/test_TagPlot_matplotlib.py
new file mode 100644
index 0000000000000000000000000000000000000000..d0c324d8f10bde8cb38eea05d0c436c68e6d74d6
--- /dev/null
+++ b/tests/test_TagPlot_matplotlib.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+'''
+Unittests for TagPlot_matplotlib
+'''
+import unittest
+from 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()