Skip to content
Snippets Groups Projects
Commit 88d697b0 authored by Jakobsen, Mads Bregenholt's avatar Jakobsen, Mads Bregenholt
Browse files

trying static method

parent eab60053
No related branches found
No related tags found
No related merge requests found
Pipeline #167507 passed
......@@ -9,33 +9,11 @@ from matplotlib.backends.backend_agg import FigureCanvasAgg
import numpy as np
def plot_data(data):
plt.switch_backend("agg")
fig = plt.figure(figsize=(15,10))
plt.imshow(data, interpolation=None)
plt.title(f"this is my plot")
plt.xlabel('kbar')
plt.ylabel('Pk')
canvas = FigureCanvasAgg(fig)
canvas.draw()
image_buffer = np.frombuffer(canvas.buffer_rgba(), dtype=np.uint8).reshape(
canvas.get_width_height()[::-1] + (4,))
plt.close(fig)
return image_buffer
class AgipdModulePlotter():
def __init__(self):
self.onlineImagePlotter = OnlineImagePlotter(figsize=(15,10))
def plot(self, train_id, module_data):
print("type trainid", type(train_id))
......@@ -43,10 +21,31 @@ class AgipdModulePlotter():
print(f"Error, AgipdModulePlotter.plot received data must be of shape (512, 128), and not {module_data.shape}")
return
img = self.onlineImagePlotter.get_image_buffer_if_ready_and_make_new_image(train_id, plot_data, module_data)
img = self.onlineImagePlotter.get_image_buffer_if_ready_and_make_new_image(train_id, AgipdModulePlotter.make_plot, module_data)
return img
@staticmethod
def make_plot(data):
plt.switch_backend("agg")
fig = plt.figure(figsize=(15,10))
plt.imshow(data, interpolation=None)
plt.title(f"this is my plot")
plt.xlabel('kbar')
plt.ylabel('Pk')
canvas = FigureCanvasAgg(fig)
canvas.draw()
image_buffer = np.frombuffer(canvas.buffer_rgba(), dtype=np.uint8).reshape(
canvas.get_width_height()[::-1] + (4,))
plt.close(fig)
return image_buffer
\ No newline at end of file
......@@ -106,16 +106,13 @@ class DataToPlotToHash():
print(f"key {hash_key} does not exist, init plotter")
self.hash_keys_and_plotter[hash_key] = Plotter()
else:
print(f"self.hash_keys_and_plotter[{hash_key}] is of type", type(Plotter))
if not isinstance(self.hash_keys_and_plotter[hash_key], Plotter):
print("wrong type, initializing!")
self.hash_keys_and_plotter[hash_key] = Plotter()
print(f"self.hash_keys_and_plotter[{hash_key}] is of type", type(Plotter))
# plotter is initialized, give plotter data
current_img = self.hash_keys_and_plotter[hash_key].plot(*args)
from karabo.bound import Hash, Schema, ImageData
if current_img is not None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment