diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1005ace..12321fd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,14 @@ - + - + - - + @@ -190,7 +189,7 @@ - + 1658494877565 @@ -220,7 +219,14 @@ - @@ -272,6 +278,11 @@ file://$PROJECT_DIR$/HelperClasses/Plotting1.py - + diff --git a/HelperClasses/AbsorptionImaging.py b/HelperClasses/AbsorptionImaging.py index 50a96e7..214626a 100644 --- a/HelperClasses/AbsorptionImaging.py +++ b/HelperClasses/AbsorptionImaging.py @@ -127,12 +127,12 @@ class absorption_imaging: # select the effective data in an rectangle area defined by coordinates of two conner # The select region will be presented as a red box in the plotting - def select_effective_data(self, left_up_conner, right_down_conner): + def select_effective_data(self, center, span): - self.x_start = left_up_conner[0] - self.x_end = right_down_conner[0] - self.y_end = left_up_conner[1] - self.y_start = right_down_conner[1] + self.x_start = int(center[0] - span[0] / 2) + self.x_end = int(center[0] + span[0] / 2) + self.y_end = int(center[1] + span[1] / 2) + self.y_start = int(center[1] - span[1] / 2) self.image_absorption_cut = self.image_absorption[self.y_start:self.y_end, self.x_start:self.x_end] diff --git a/HelperClasses/Plotting/DataExtractorLyse.py b/HelperClasses/Plotting/DataExtractorLyse.py index d3f0ff3..6fd3438 100644 --- a/HelperClasses/Plotting/DataExtractorLyse.py +++ b/HelperClasses/Plotting/DataExtractorLyse.py @@ -23,7 +23,7 @@ class DataExtractorManager: def __init__(self, data_path=None): self.data_extractors = {} - self.h5_file = None + # self.h5_file = None self.data_path = data_path self.local_data_changed = False diff --git a/HelperClasses/Plotting/MainPlotPanel.py b/HelperClasses/Plotting/MainPlotPanel.py index d47caf8..19fa940 100644 --- a/HelperClasses/Plotting/MainPlotPanel.py +++ b/HelperClasses/Plotting/MainPlotPanel.py @@ -45,7 +45,8 @@ class MainPlotPanel(QtGui.QMainWindow): self.danalyse_panel.addWidget(self.analyse_panel) self.area.addDock(self.danalyse_panel, 'bottom') - self.show() + self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) + self.showMaximized() self.plots = {} diff --git a/HelperClasses/Plotting/Widget1DLivingPlot.py b/HelperClasses/Plotting/Widget1DLivingPlot.py new file mode 100644 index 0000000..e11253f --- /dev/null +++ b/HelperClasses/Plotting/Widget1DLivingPlot.py @@ -0,0 +1,76 @@ +import numpy as np + +from .DataExtractorLyse import DataExtractorManager +from .WidgetPlot import WidgetPlot + +import pyqtgraph as pg +from pyqtgraph import OrderedDict +from PyQt5.QtWidgets import QLabel, QLineEdit +from pyqtgraph import Qt +from pyqtgraph.Qt import QtCore +from PyQt5.QtWidgets import * +from PyQt5.QtCore import * +from PyQt5.QtGui import QRegExpValidator +from PyQt5.QtCore import QRegExp + +from PIL import ImageColor + + +class Widget1DLivingPlot(WidgetPlot): + + def __init__(self, title, x_data_path=None, y_data_path=None, x_in_results=False, y_in_results=False, **kwargs): + + super().__init__(title, **kwargs) + + # set data extractor + if x_data_path is not None: + self.x_data_extractor_manager = DataExtractorManager(x_data_path) + self.x_data_extractor_manager.add_data_extractor('warning', 'single', (x_data_path[0], 'warning')) + if x_in_results: + self.x_data_extractor_manager.add_data_extractor('x', 'single', x_data_path) + else: + self.x_data_extractor_manager.add_data_extractor('x', 'global', x_data_path) + else: + self.x_data_extractor_manager = None + + self.y_data_extractor_manager = DataExtractorManager(y_data_path) + self.y_data_extractor_manager.add_data_extractor('warning', 'single', (y_data_path[0], 'warning')) + if y_in_results: + self.y_data_extractor_manager.add_data_extractor('y', 'single', y_data_path) + else: + self.y_data_extractor_manager.add_data_extractor('y', 'global', y_data_path) + + self.aximg = self.plots.addPlot(title="") + self.img = pg.PlotCurveItem() + self.aximg.setClipToView(True) + self.aximg.setDownsampling(mode='peak') + self.aximg.addItem(self.img) + + self.x = np.empty(100) + self.y = np.empty(100) + self.current_data_length = 0 + + def update(self, h5_path): + + if self.current_data_length >= self.x.shape[0]: + tmp = self.x + self.x = np.empty(self.x.shape[0] * 2) + self.x[:tmp.shape[0]] = tmp + tmp = self.y + self.y = np.empty(self.y.shape[0] * 2) + self.y[:tmp.shape[0]] = tmp + + if self.x_data_extractor_manager is not None: + x_data = self.x_data_extractor_manager.get_data(h5_path) + self.x[self.current_data_length] = x_data['x'] + else: + self.x[self.current_data_length] = self.current_data_length + y_data = self.y_data_extractor_manager.get_data(h5_path) + self.y[self.current_data_length] = y_data['y'] + + print(y_data['y']) + self.img.setData(x=self.x[:self.current_data_length], y=self.y[:self.current_data_length]) + self.current_data_length = self.current_data_length + 1 + + + diff --git a/HelperClasses/Plotting/WidgetAnalysePanel.py b/HelperClasses/Plotting/WidgetAnalysePanel.py index 8e0b84c..58d6113 100644 --- a/HelperClasses/Plotting/WidgetAnalysePanel.py +++ b/HelperClasses/Plotting/WidgetAnalysePanel.py @@ -37,12 +37,9 @@ class WidgetAnalysePanel(QSplitter): x_span = int(x_span) y_span = int(y_span) - left_up_conner = (x, y + y_span) - right_down_conner = (x + x_span, y) - self.absorption_image.image_absorption = self.absorption_image_plot.data_image - self.absorption_image.select_effective_data(left_up_conner, right_down_conner) + self.absorption_image.select_effective_data((x, y), (x_span, y_span)) self.absorption_image.get_atom_number(force_to_run=True) diff --git a/HelperClasses/Plotting/WidgetFakeColorPlot.py b/HelperClasses/Plotting/WidgetFakeColorPlot.py index bc6d67c..3edfa8c 100644 --- a/HelperClasses/Plotting/WidgetFakeColorPlot.py +++ b/HelperClasses/Plotting/WidgetFakeColorPlot.py @@ -1,6 +1,4 @@ import numpy as np -from PyQt5 import QtGui -from PyQt5.QtGui import QDoubleValidator from .DataExtractorLyse import DataExtractorManager from .WidgetPlot import WidgetPlot diff --git a/HelperClasses/Plotting/WidgetQuickWaterFlowPlot.py b/HelperClasses/Plotting/WidgetQuickWaterFallPlot.py similarity index 100% rename from HelperClasses/Plotting/WidgetQuickWaterFlowPlot.py rename to HelperClasses/Plotting/WidgetQuickWaterFallPlot.py diff --git a/test_absorption_imaging.py b/test_absorption_imaging.py index 437c231..4ed74ab 100644 --- a/test_absorption_imaging.py +++ b/test_absorption_imaging.py @@ -1,26 +1,16 @@ from lyse import * -from HelperClasses import DyTransition, Camera, AbsorptionImaging, Plotting1 -import matplotlib.pyplot as plt -import matplotlib.style as mplstyle - -import matplotlib -matplotlib.use("qt5agg") - -mplstyle.use('fast') +from HelperClasses import DyTransition, Camera, AbsorptionImaging absorption_imaging_transition = DyTransition.creat_Dy421() mot_3D_camera = Camera.c11440_36u(absorption_imaging_transition['wavelength']) with AbsorptionImaging.absorption_imaging(path, 'MOT_3D_Camera', 'in_situ_absorption', absorption_imaging_transition, mot_3D_camera, 0, 0) as absorption_image: - - absorption_image.select_effective_data((800, 500), (1000, 700)) + # Please selecte the effective area here + # The first tuple is the center position (x,y) + # The second tuple is the span in x and y direction (x_span, y_span) + absorption_image.select_effective_data((900, 600), (200, 200)) absorption_image.get_atom_number() - print(absorption_image.atom_number) - - -plotting = Plotting1.plotting_absorption_imaging(absorption_image) -plotting.four_plots() -# plotting.absorption_plots() + # print(absorption_image.atom_number) diff --git a/test_living_plot.py b/test_living_plot.py index 48c4b5b..e8d246a 100644 --- a/test_living_plot.py +++ b/test_living_plot.py @@ -7,7 +7,7 @@ Created on Thu Mar 11 14:58:18 2021 import lyse import numpy as np -from HelperClasses.Plotting import WidgetFakeColorPlot, MainPlotPanel +from HelperClasses.Plotting import WidgetFakeColorPlot, MainPlotPanel, Widget1DLivingPlot from HelperClasses import DyTransition, Camera, AbsorptionImaging import cProfile @@ -55,6 +55,7 @@ if not plot_name in figure_manager.MainPlotPanel.plots: Roi=False, colorbarText=False) figure_manager.MainPlotPanel.add_plot_dock(plot_name + '1', current_plotting) +# Add plotting for absorption imaging plot_name = '3D-MOT Absorption Imaging' if not plot_name in figure_manager.MainPlotPanel.plots: current_plotting = WidgetFakeColorPlot.WidgetFakeColorPlot(plot_name, ('absorption_imaging', 'absorption_imaging')) @@ -67,8 +68,15 @@ if not plot_name in figure_manager.MainPlotPanel.plots: absorption_imaging_transition, mot_3D_camera, 0, 0) figure_manager.MainPlotPanel.analyse_panel.add_absorption_imaging(absorption_image, current_plotting) -figure_manager.MainPlotPanel.update_h5_paths(h5_paths) -figure_manager.MainPlotPanel.refresh(h5_path) +# Add realtime plotting for atom number +# plot_name = '3D-MOT Atom Number' +# if not plot_name in figure_manager.MainPlotPanel.plots: +# current_plotting = Widget1DLivingPlot.Widget1DLivingPlot(plot_name, y_data_path=('absorption_imaging', 'atom_number'), y_in_results=True) +# +# figure_manager.MainPlotPanel.add_plot_dock(plot_name, current_plotting) +# +# figure_manager.MainPlotPanel.update_h5_paths(h5_paths) +# figure_manager.MainPlotPanel.refresh(h5_path) profile.disable() ps = pstats.Stats(profile)