mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat: added functionality to load mask
This commit is contained in:
@ -1,14 +1,22 @@
|
|||||||
|
import csv
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
import h5py
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import zmq
|
import zmq
|
||||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal
|
from PyQt5.QtCore import pyqtSignal, Qt
|
||||||
from PyQt5.QtWidgets import QWidget
|
from PyQt5.QtCore import pyqtSlot
|
||||||
from pyqtgraph.Qt import uic
|
from PyQt5.QtWidgets import (
|
||||||
|
QWidget,
|
||||||
|
QFileDialog,
|
||||||
|
)
|
||||||
|
from pyqtgraph.Qt import QtWidgets, uic
|
||||||
|
|
||||||
from scipy.stats import multivariate_normal
|
from scipy.stats import multivariate_normal
|
||||||
|
|
||||||
|
|
||||||
@ -23,6 +31,8 @@ class EigerPlot(QWidget):
|
|||||||
uic.loadUi(os.path.join(current_path, "eiger_plot.ui"), self)
|
uic.loadUi(os.path.join(current_path, "eiger_plot.ui"), self)
|
||||||
|
|
||||||
self.hist_lims = None
|
self.hist_lims = None
|
||||||
|
self.mask = None
|
||||||
|
self.image = None
|
||||||
|
|
||||||
# UI
|
# UI
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
@ -51,6 +61,8 @@ class EigerPlot(QWidget):
|
|||||||
def hook_signals(self):
|
def hook_signals(self):
|
||||||
# Buttons
|
# Buttons
|
||||||
self.pushButton_test.clicked.connect(self.start_sim_stream)
|
self.pushButton_test.clicked.connect(self.start_sim_stream)
|
||||||
|
self.pushButton_mask.clicked.connect(self.load_mask_dialog)
|
||||||
|
self.pushButton_delete_mask.clicked.connect(self.delete_mask)
|
||||||
|
|
||||||
# SpinBoxes
|
# SpinBoxes
|
||||||
self.doubleSpinBox_hist_min.valueChanged.connect(self.update_hist)
|
self.doubleSpinBox_hist_min.valueChanged.connect(self.update_hist)
|
||||||
@ -70,9 +82,28 @@ class EigerPlot(QWidget):
|
|||||||
self.hist_levels[1] + 0.1 * self.hist_levels[1],
|
self.hist_levels[1] + 0.1 * self.hist_levels[1],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def load_mask_dialog(self):
|
||||||
|
options = QFileDialog.Options()
|
||||||
|
options |= QFileDialog.ReadOnly
|
||||||
|
file_name, _ = QFileDialog.getOpenFileName(
|
||||||
|
self, "Select Mask File", "", "H5 Files (*.h5);;All Files (*)", options=options
|
||||||
|
)
|
||||||
|
if file_name:
|
||||||
|
self.load_mask(file_name)
|
||||||
|
|
||||||
|
def load_mask(self):
|
||||||
|
with h5py.File(self.mask_file, "r") as f:
|
||||||
|
self.mask = f["data"][...]
|
||||||
|
|
||||||
|
def delete_mask(self):
|
||||||
|
self.mask = None
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def on_image_update(self):
|
def on_image_update(self):
|
||||||
# TODO first rotate then transpose
|
# TODO first rotate then transpose
|
||||||
|
if self.mask is not None:
|
||||||
|
# self.image = np.ma.masked_array(self.image, mask=self.mask) #TODO test if np works
|
||||||
|
self.image = self.image * (1 - self.mask) + 1
|
||||||
|
|
||||||
if self.comboBox_rotation.currentIndex() > 0: # rotate
|
if self.comboBox_rotation.currentIndex() > 0: # rotate
|
||||||
self.image = np.rot90(self.image, k=self.comboBox_rotation.currentIndex(), axes=(0, 1))
|
self.image = np.rot90(self.image, k=self.comboBox_rotation.currentIndex(), axes=(0, 1))
|
||||||
|
@ -70,6 +70,9 @@
|
|||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox">
|
<widget class="QCheckBox" name="checkBox">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>FFT</string>
|
<string>FFT</string>
|
||||||
</property>
|
</property>
|
||||||
@ -83,12 +86,19 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton_mask">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Load Mask</string>
|
<string>Load Mask</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_delete_mask">
|
||||||
|
<property name="text">
|
||||||
|
<string>Delete Mask</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Reference in New Issue
Block a user