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

Improve publish function. The 'individual' method should already work in principle.

parent 5ef76b32
No related branches found
No related tags found
2 merge requests!12v.0.1 for alpha release,!6Implement basic functionality of publish.
......@@ -6,7 +6,7 @@ import shutil
import sys
def Publish(src_datapath, dst_dirname):
def Publish(src_datapath, dst_path, data_storage):
"""
Save plot, data and measuring script.
......@@ -15,19 +15,65 @@ def Publish(src_datapath, dst_dirname):
src_datapath : string
Path to data that should be published.
dst_dirname : string
Name for the destination directory.
Path to the destination directory.
data_storage: string
Method how the data should be stored. Available options:
centralized: The raw data will copied only once. All other plots
will reference this data via sym link.
individual: The complete raw data will be copied to a folder for
every plot, respectively.
Returns
-------
None.
"""
#parent_dir = os.getcwd()
#print(parent_dir)
# os.mkdir('data')
# Check if source directory exists
if not os.path.exists(src_datapath):
raise ValueError('The specified source directory does not exist.')
dst_path_head, dst_dirname = os.path.split(dst_path)
if not os.path.exists(dst_path_head):
raise ValueError('The specified destination directory does not exist.')
# If directory already exists ask user if it should be overwritten or not.
if os.path.isdir(dst_path):
print(f'Folder {dst_dirname} already exists – plot has already been '
'published.')
overwrite_dir = input('Do you want to overwrite the existing folder?'
' (yes/no[default])\n')
if overwrite_dir == 'yes' or overwrite_dir == 'y':
shutil.rmtree(dst_dirname)
else:
raise RuntimeError('PlotID has finished without an export.\n'
'Rerun TagPlot if you need a new ID or '
'consider overwriting.')
# Create invisible folder
dst_path_invisible = os.path.join(dst_path_head, '.' + dst_dirname)
# If invisible Folder exists, delete it (publish was not successful before)
if os.path.isdir(dst_path_invisible):
shutil.rmtree(dst_path_invisible)
match data_storage:
case 'centralized':
# Do nothing, not implemented yet
pass
case 'individual':
# Copy data to invisible folder
print('Copying data has been started. Depending on the size of '
'your data this may take a while...')
shutil.copytree(src_datapath, dst_path_invisible)
# Copy data to folder
shutil.copytree(src_datapath, dst_dirname, dirs_exist_ok=True)
# Copy script that calls this function to folder
shutil.copy2(sys.argv[0], dst_dirname)
shutil.copy2(sys.argv[0], dst_path_invisible)
case _:
raise ValueError('The data storage method {data_storage} '
'is not available.')
print('Copying data finished. Starting to clean up.')
# If export was successful, make the directory visible
os.rename(dst_path_invisible, dst_path)
return
......@@ -7,9 +7,9 @@ import warnings
def TagPlot(figs, prefix, engine, method=1, location='east'):
"""
Determine which plot engine should be used to tag the plots.
Tag your figure/plot with an ID.
After determining the engine, TagPlot calls the corresponding
After determining the plot engine, TagPlot calls the corresponding
function which tags the plot.
Parameters
......
Image diff could not be displayed: it is too large. Options to address this: view the blob.
Image diff could not be displayed: it is too large. Options to address this: view the blob.
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 27 11:40:58 2021
@author: Richter
"""
from matplotlib import pyplot as plt
fig_size = (10, 5)
f = plt.figure(figsize=fig_size)
def plot_signal(time, signal, title='', xlab='', ylab='',
line_width=1, alpha=1, color='k',
subplots=False, show_grid=True, fig=f):
# Skipping a lot of other complexity here
axarr = f.add_subplot(1,1,1) # here is where you add the subplot to f
plt.plot(time, signal, linewidth=line_width,
alpha=alpha, color=color)
plt.set_xlim(min(time), max(time))
plt.set_xlabel(xlab)
plt.set_ylabel(ylab)
plt.grid(show_grid)
plt.title(title, size=16)
return(f)
time = [0:1:100]
signal= [200:300:100]
f = plot_signal(time, signal, fig=f)
\ No newline at end of file
This diff is collapsed.
import matplotlib.pyplot as plt
def set_FST_template(project_directory):
plt.style.use(f'{project_directory}\\Code\\''FST.mplstyle')
class Colors():
def __init__(self):
self.rgb_colors = {
'blue' : (0, 0.31, 0.45),
'red' : (0.91, 0.31, 0.24),
'green' : (0.69, 0.8, 0.31),
'black' : (0, 0, 0),
'orange' : (0.93, 0.48, 0.20),
'petrol' : (0.31, 0.71, 0.58),
'grey' : (0.54, 0.54, 0.54),
'yellow' : (0.99, 0.79, 0)
}
def get_rgb(self, color_name):
if color_name in self.rgb_colors.keys():
return self.rgb_colors[color_name]
else:
print(f"Error: Color '{color_name}' does not exist.\nAvailable colors are: {list(self.rgb_colors.keys())}")
def get_color_names(self):
return list(self.rgb_colors.keys())
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 20 12:22:33 2021
example workflow for integrating plotIDs
@author: Richter
"""
# %% Module einbinden
import sys
import numpy as np
from numpy import random
# import h5py as h5
# import matplotlib
import matplotlib.pyplot as plt
from TagPlot import TagPlot
from Publish import Publish
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 = "MR04"
# %% Plot engine
plot_engine = "matplotlib"
# %% Create sample data
x = np.linspace(0, 10, 100)
y = random.rand(100) + 2
y_2 = np.sin(x) + 2
# %% Create figure
# Colors
colors = Colors() # create instance from class
color_list = colors.get_color_names()
# Create plot
color1 = colors.get_rgb('black')
color2 = colors.get_rgb('yellow')
# 1.Figure
fig1 = plt.figure()
plt.plot(x, y, color=color1)
plt.plot(x, y_2, color=color2)
# 2.Figure
plt.clf # Close figure
fig2 = plt.figure()
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, plot_engine, method='2', location='west')
# %% Figure als tiff-Datei abspeichern
for i, figure in enumerate(figs):
name = "Test"+str(i)+".tiff"
figure.savefig(name)
# %% Publish
Publish('fcn_help', 'data')
......@@ -65,4 +65,4 @@ for i, figure in enumerate(figs):
figure.savefig(name)
# %% Publish
Publish('fcn_help', 'data')
Publish('fcn_help', '/home/chief/Dokumente/fst/plotid_python/data', 'individual')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment