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

Merge branch 'dev' into 'qrcode'

# Conflicts:
#   plotid/example.py
#   tests/test_save_plot.py
parents 5d5b68f3 ad6a6043
No related branches found
No related tags found
1 merge request!24QR Codes now work with mpl and image engine.
Pipeline #808084 waiting for manual action
...@@ -44,8 +44,8 @@ FIGS_AS_LIST = [FIG1, FIG2] ...@@ -44,8 +44,8 @@ FIGS_AS_LIST = [FIG1, FIG2]
IMGS_AS_LIST = [IMG1, IMG2] IMGS_AS_LIST = [IMG1, IMG2]
# Example for how to use tagplot with matplotlib figures # Example for how to use tagplot with matplotlib figures
# FIGS_AND_IDS = tagplot(FIGS_AS_LIST, 'matplotlib', prefix=PROJECT_ID, # FIGS_AND_IDS = tagplot(FIGS_AS_LIST, 'matplotlib', location='west',
# id_method='time', location='west') # id_method='random', prefix=PROJECT_ID)
# Example for how to use tagplot with image files # Example for how to use tagplot with image files
FIGS_AND_IDS = tagplot(IMGS_AS_LIST, 'image', prefix=PROJECT_ID, FIGS_AND_IDS = tagplot(IMGS_AS_LIST, 'image', prefix=PROJECT_ID,
...@@ -57,4 +57,4 @@ FIGS_AND_IDS = tagplot(IMGS_AS_LIST, 'image', prefix=PROJECT_ID, ...@@ -57,4 +57,4 @@ FIGS_AND_IDS = tagplot(IMGS_AS_LIST, 'image', prefix=PROJECT_ID,
# plots or images. # plots or images.
publish(FIGS_AND_IDS, ['../README.md', '../docs', '../LICENSE'], publish(FIGS_AND_IDS, ['../README.md', '../docs', '../LICENSE'],
'/home/chief/Dokumente/fst/plotid_python/data/', 'Bild') '/home/chief/Dokumente/fst/plotid_python/data/', 'image')
...@@ -146,7 +146,7 @@ class PublishOptions: ...@@ -146,7 +146,7 @@ class PublishOptions:
""" """
# Export plot figure to picture. # Export plot figure to picture.
plot_paths = save_plot(self.figure, self.plot_names) plot_paths = save_plot(self.figure, self.plot_names)
print(plot_paths)
match self.data_storage: match self.data_storage:
case 'centralized': case 'centralized':
self.centralized_data_storage() self.centralized_data_storage()
...@@ -194,9 +194,9 @@ class PublishOptions: ...@@ -194,9 +194,9 @@ class PublishOptions:
raise ValueError(f'The data storage method {self.data_storage}' raise ValueError(f'The data storage method {self.data_storage}'
' is not available.') ' is not available.')
print(f'Publish was successful.\nYour plot(s) {plot_paths},\nyour' print(f'Publish was successful.\nYour plot(s), your'
f' data {self.src_datapaths}\nand your script {sys.argv[0]}\n' f' data and your\nscript {sys.argv[0]}'
f'were copied to {self.dst_path}\nin {self.data_storage} mode.') f'\nwere copied to {self.dst_path}.')
def centralized_data_storage(self): def centralized_data_storage(self):
""" """
...@@ -240,10 +240,18 @@ class PublishOptions: ...@@ -240,10 +240,18 @@ class PublishOptions:
# Copy script that calls this function to folder # Copy script that calls this function to folder
shutil.copy2(sys.argv[0], destination) shutil.copy2(sys.argv[0], destination)
# Copy plot files to folder
if os.path.isfile(pic_path): if os.path.isfile(pic_path):
# Copy plot file to folder
shutil.copy2(pic_path, destination) shutil.copy2(pic_path, destination)
# Remove by plotID exported .tmp plot
os.remove(pic_path) os.remove(pic_path)
# Remove .tmp. from file name in destinaion
name_tmp, orig_ext = os.path.splitext(pic_path)
orig_name, _ = os.path.splitext(name_tmp)
final_file_path = orig_name + orig_ext
os.rename(os.path.join(destination, pic_path),
os.path.join(destination, final_file_path))
def publish(figs_and_ids, src_datapath, dst_path, plot_name, **kwargs): def publish(figs_and_ids, src_datapath, dst_path, plot_name, **kwargs):
......
...@@ -57,10 +57,10 @@ def save_plot(figures, plot_names, extension='png'): ...@@ -57,10 +57,10 @@ def save_plot(figures, plot_names, extension='png'):
for i, fig in enumerate(figures): for i, fig in enumerate(figures):
if isinstance(fig, matplotlib.figure.Figure): if isinstance(fig, matplotlib.figure.Figure):
plt.figure(fig) plt.figure(fig)
plot_path.append(plot_names[i] + '.' + extension) plot_path.append(plot_names[i] + '.tmp.' + extension)
plt.savefig(plot_path[i]) plt.savefig(plot_path[i])
elif all(x in str(type(fig)) for x in ['PIL', 'ImageFile']): elif all(x in str(type(fig)) for x in ['PIL', 'ImageFile']):
plot_path.append(plot_names[i] + '.' + extension) plot_path.append(plot_names[i] + '.tmp.' + extension)
fig.save(plot_path[i]) fig.save(plot_path[i])
else: else:
raise TypeError(f'Figure number {i} is not a valid figure object.') raise TypeError(f'Figure number {i} is not a valid figure object.')
......
...@@ -219,8 +219,8 @@ class TestPublish(unittest.TestCase): ...@@ -219,8 +219,8 @@ class TestPublish(unittest.TestCase):
with self.assertRaises(RuntimeError): with self.assertRaises(RuntimeError):
publish(FIGS_AND_IDS, SRC_DIR, DST_PATH, PIC_NAME) publish(FIGS_AND_IDS, SRC_DIR, DST_PATH, PIC_NAME)
assert not os.path.isdir(invisible_path1) assert not os.path.isdir(invisible_path1)
os.remove('test_picture1.png') os.remove('test_picture1.tmp.png')
os.remove('test_picture2.png') os.remove('test_picture2.tmp.png')
def test_plot_names(self): def test_plot_names(self):
""" Test if Error is raised if plot_name is not a string. """ """ Test if Error is raised if plot_name is not a string. """
......
...@@ -32,7 +32,7 @@ class TestSavePlot(unittest.TestCase): ...@@ -32,7 +32,7 @@ class TestSavePlot(unittest.TestCase):
""" """
plot_paths = save_plot(FIGURE, [PLOT_NAME], extension='jpg') plot_paths = save_plot(FIGURE, [PLOT_NAME], extension='jpg')
self.assertIsInstance(plot_paths, list) self.assertIsInstance(plot_paths, list)
os.remove(PLOT_NAME + '.jpg') os.remove(PLOT_NAME + '.tmp.jpg')
def test_save_plot_image_png(self): def test_save_plot_image_png(self):
""" """
...@@ -42,7 +42,7 @@ class TestSavePlot(unittest.TestCase): ...@@ -42,7 +42,7 @@ class TestSavePlot(unittest.TestCase):
img1 = Image.open(IMG1) img1 = Image.open(IMG1)
plot_paths = save_plot(img1, [PLOT_NAME]) plot_paths = save_plot(img1, [PLOT_NAME])
self.assertIsInstance(plot_paths, list) self.assertIsInstance(plot_paths, list)
os.remove(PLOT_NAME + '.png') os.remove(PLOT_NAME + '.tmp.png')
def test_save_plot_image_jpg(self): def test_save_plot_image_jpg(self):
""" """
...@@ -53,8 +53,8 @@ class TestSavePlot(unittest.TestCase): ...@@ -53,8 +53,8 @@ class TestSavePlot(unittest.TestCase):
imgs_as_list = [img2, img2] imgs_as_list = [img2, img2]
plot_paths = save_plot(imgs_as_list, [PLOT_NAME], extension='jpg') plot_paths = save_plot(imgs_as_list, [PLOT_NAME], extension='jpg')
self.assertIsInstance(plot_paths, list) self.assertIsInstance(plot_paths, list)
os.remove(PLOT_NAME + '1.jpg') os.remove(PLOT_NAME + '1.tmp.jpg')
os.remove(PLOT_NAME + '2.jpg') os.remove(PLOT_NAME + '2.tmp.jpg')
def test_more_figs_than_names(self): def test_more_figs_than_names(self):
""" """
...@@ -64,8 +64,8 @@ class TestSavePlot(unittest.TestCase): ...@@ -64,8 +64,8 @@ class TestSavePlot(unittest.TestCase):
with self.assertWarns(Warning): with self.assertWarns(Warning):
save_plot([FIGURE, FIGURE, FIGURE], [PLOT_NAME]) save_plot([FIGURE, FIGURE, FIGURE], [PLOT_NAME])
for i in (1, 2, 3): for i in (1, 2, 3):
assert os.path.isfile(PLOT_NAME + f'{i}.png') assert os.path.isfile(PLOT_NAME + f'{i}.tmp.png')
os.remove(PLOT_NAME + f'{i}.png') os.remove(PLOT_NAME + f'{i}.tmp.png')
def test_more_names_than_figs(self): def test_more_names_than_figs(self):
""" Test if Error is raised if more names than figures are given. """ """ Test if Error is raised if more names than figures are given. """
...@@ -84,7 +84,7 @@ class TestSavePlot(unittest.TestCase): ...@@ -84,7 +84,7 @@ class TestSavePlot(unittest.TestCase):
""" """
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
save_plot([FIGURE, 'figure', FIGURE], 'PLOT_NAME', extension='jpg') save_plot([FIGURE, 'figure', FIGURE], 'PLOT_NAME', extension='jpg')
os.remove(PLOT_NAME + '1.jpg') os.remove('PLOT_NAME1.tmp.jpg')
def tearDown(self): def tearDown(self):
os.remove(IMG1) os.remove(IMG1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment