Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent state, complex images, DPC #27

Merged
merged 8 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "py4D_browser"
version = "1.1.3"
version = "1.2.0"
authors = [
{ name="Steven Zeltmann", email="[email protected]" },
]
Expand All @@ -21,6 +21,7 @@ dependencies = [
"h5py",
"numpy >= 1.19",
"matplotlib >= 3.2.2",
"platformdirs",
"PyQt5 >= 5.10",
"pyqtgraph >= 0.11",
"sigfig",
Expand Down
8 changes: 5 additions & 3 deletions src/py4D_browser/dialogs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from py4DSTEM import DataCube, data, tqdmnd
from py4DSTEM import DataCube, data
import pyqtgraph as pg
import numpy as np
from tqdm import tqdm
from PyQt5.QtWidgets import QFrame, QPushButton, QApplication, QLabel
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import Qt, QObject
Expand Down Expand Up @@ -428,8 +429,9 @@ def reconstruct(self):
qy_operator = qy_operator * -2.0j * np.pi

# loop over images and shift
for mx, my in tqdmnd(
*mask.shape,
img_indices = np.argwhere(mask)
for mx, my in tqdm(
img_indices,
desc="Shifting images",
file=StatusBarWriter(self.parent.statusBar()),
mininterval=1.0,
Expand Down
62 changes: 46 additions & 16 deletions src/py4D_browser/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
QLabel,
QToolTip,
QPushButton,
QShortcut,
)

from matplotlib.backend_bases import tools
Expand All @@ -21,6 +22,7 @@
from pathlib import Path
import importlib
import os
import platformdirs

from py4D_browser.utils import pg_point_roi, VLine, LatchingButton
from py4D_browser.scalebar import ScaleBar
Expand Down Expand Up @@ -97,6 +99,21 @@ def __init__(self, argv):

self.datacube = None

# Load settings from cofig file
config_path = os.path.join(
platformdirs.user_config_dir("py4DGUI", "py4DSTEM"), "GUI_config.ini"
)
print(f"Loading configuration from {config_path}")
QtCore.QCoreApplication.setOrganizationName("py4DSTEM")
QtCore.QCoreApplication.setOrganizationDomain("py4DSTEM.com")
QtCore.QCoreApplication.setApplicationName("py4DGUI")
self.settings = QtCore.QSettings(config_path, QtCore.QSettings.Format.IniFormat)

# Reset stored state if so asked:
if os.environ.get("PY4DGUI_RESET"):
self.settings.remove("last_state")
print("Cleared saved state, using defaults...")

self.setup_menus()
self.setup_views()

Expand All @@ -108,7 +125,9 @@ def __init__(self, argv):
font.setPointSize(10)
QToolTip.setFont(font)

self.resize(1000, 800)
self.resize(
self.settings.value("last_state/window_size", QtCore.QSize(1000, 800)),
)

self.show()

Expand All @@ -134,6 +153,7 @@ def setup_menus(self):
self.load_auto_action = QAction("&Load Data...", self)
self.load_auto_action.triggered.connect(self.load_data_auto)
self.file_menu.addAction(self.load_auto_action)
self.load_auto_action.setShortcut(QtGui.QKeySequence("Ctrl+O"))

self.load_mmap_action = QAction("Load &Memory Map...", self)
self.load_mmap_action.triggered.connect(self.load_data_mmap)
Expand Down Expand Up @@ -163,6 +183,8 @@ def setup_menus(self):
for method in ["Raw float32", "py4DSTEM HDF5", "Plain HDF5"]:
menu_item = datacube_export_menu.addAction(method)
menu_item.triggered.connect(partial(self.export_datacube, method))
if method == "py4DSTEM HDF5":
menu_item.setShortcut(QtGui.QKeySequence("Ctrl+S"))

# Submenu to export virtual image
vimg_export_menu = QMenu("Export Virtual Image", self)
Expand Down Expand Up @@ -293,6 +315,9 @@ def setup_menus(self):
diff_range_group = QActionGroup(self)
diff_range_group.setExclusive(True)

scale_range_default = self.settings.value(
"last_state/diffraction_autorange", [0.1, 99.9], type=float
)
for scale_range in [(0, 100), (0.1, 99.9), (1, 99), (2, 98), (5, 95)]:
action = QAction(f"{scale_range[0]}% – {scale_range[1]}%", self)
diff_range_group.addAction(action)
Expand All @@ -302,7 +327,10 @@ def setup_menus(self):
partial(self.set_diffraction_autoscale_range, scale_range)
)
# set default
if scale_range[0] == 2 and scale_range[1] == 98:
if (
scale_range[0] == scale_range_default[0]
and scale_range[1] == scale_range_default[1]
):
action.setChecked(True)
self.set_diffraction_autoscale_range(scale_range, redraw=False)

Expand All @@ -315,6 +343,9 @@ def setup_menus(self):
vimg_range_group = QActionGroup(self)
vimg_range_group.setExclusive(True)

scale_range_default = self.settings.value(
"last_state/realspace_autorange", [0.1, 99.9], type=float
)
for scale_range in [(0, 100), (0.1, 99.9), (1, 99), (2, 98), (5, 95)]:
action = QAction(f"{scale_range[0]}% – {scale_range[1]}%", self)
vimg_range_group.addAction(action)
Expand All @@ -324,7 +355,10 @@ def setup_menus(self):
partial(self.set_real_space_autoscale_range, scale_range)
)
# set default
if scale_range[0] == 2 and scale_range[1] == 98:
if (
scale_range[0] == scale_range_default[0]
and scale_range[1] == scale_range_default[1]
):
action.setChecked(True)
self.set_real_space_autoscale_range(scale_range, redraw=False)

Expand Down Expand Up @@ -357,19 +391,11 @@ def setup_menus(self):
detector_mode_group.addAction(detector_maximum_action)
self.detector_menu.addAction(detector_maximum_action)

detector_CoM_magnitude = QAction("CoM Ma&gnitude", self)
detector_CoM_magnitude.setCheckable(True)
detector_CoM_magnitude.triggered.connect(
partial(self.update_real_space_view, True)
)
detector_mode_group.addAction(detector_CoM_magnitude)
self.detector_menu.addAction(detector_CoM_magnitude)

detector_CoM_angle = QAction("CoM &Angle", self)
detector_CoM_angle.setCheckable(True)
detector_CoM_angle.triggered.connect(partial(self.update_real_space_view, True))
detector_mode_group.addAction(detector_CoM_angle)
self.detector_menu.addAction(detector_CoM_angle)
detector_CoM = QAction("C&oM", self)
detector_CoM.setCheckable(True)
detector_CoM.triggered.connect(partial(self.update_real_space_view, True))
detector_mode_group.addAction(detector_CoM)
self.detector_menu.addAction(detector_CoM)

detector_iCoM = QAction("i&CoM", self)
detector_iCoM.setCheckable(True)
Expand Down Expand Up @@ -659,6 +685,10 @@ def setup_views(self):
)
self.statusBar().addPermanentWidget(self.realspace_rescale_button)

def resizeEvent(self, event):
# Store window size for next run
self.settings.setValue("last_state/window_size", event.size())

# Handle dragging and dropping a file on the window
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
Expand Down
Loading
Loading