Skip to content
Open
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
42 changes: 42 additions & 0 deletions epoc-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# EPOC Redis Configuration

# Experiment metadata
affiliation: "YourInstitution"
PI_name: "DefaultPI"
project_id: "ProjectID"
experiment_class: "External"
measurement_tag: "sample1"

# Data directories
base_data_dir: "/data/jungfrau"
XDS_template: "/path/to/XDS.INP"
cal_dir: "/path/to/calibration"

# Detector settings (e.g. of 1 Megapixel JUNGFRAU)
nrows: 1064
ncols: 1030
threshold: 5

# Viewer settings
viewer_interval: 20.0
viewer_cmin: 0.0
viewer_cmax: 12000.0

# Network endpoints
jfjoch_host: "http://jungfrau-server:5232" # Replace by the HTTP address of the Jungfraujoch web GUI
receiver_endpoint: "tcp://jungfrau-server:5000" # look at the ZMQ stream endpoint in the Jungfraujoch Web GUI
temserver: "temserver" # IP address of the TEM control machine (define in /etc/hosts)

# Acquisition settings
rotation_speed_idx: 0
file_id: 0

# Display overlays (optional)
overlays:
- {'type': 'circle', 'xy': [526, 253], 'radius': 188, 'ec': 'r', 'fill': False, 'lw': 2}
- {'type': 'circle', 'xy': [526, 253], 'radius': 5, 'ec': 'g', 'fill': False, 'lw': 2}
- {'type': 'rectangle', 'xy': [574, 52], 'width': 60, 'height': 31, 'angle': 27.5, 'ec': 'y', 'fill': False}
- {'type': 'rectangle', 'xy': [0, 0], 'width': 1000, 'height': 1, 'angle': 19.8, 'ec': 'r', 'fill': False}

# Used affiliations list
usedAffiliations: ["YourInstitution", "External"]
11 changes: 11 additions & 0 deletions init_redis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pathlib import Path
from epoc import ConfigurationClient, auth_token, redis_host

# Connect to Redis
cfg = ConfigurationClient(redis_host(), token=auth_token())

# Load configuration from YAML (flush_db=True clears any existing data)
cfg.from_yaml(Path('epoc-config.yaml'), flush_db=True)

print("Redis database initialized successfully!")
print(cfg)
104 changes: 85 additions & 19 deletions jungfrau_gui/globals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ctypes
import numpy as np
import multiprocessing as mp
from epoc import ConfigurationClient, auth_token, redis_host
import subprocess

def get_git_info():
Expand Down Expand Up @@ -49,46 +48,113 @@ def get_git_info():
# Git not installed or command failed
return defaults

cfg = ConfigurationClient(redis_host(), token=auth_token())
# ----------------------------
# Runtime-configurable globals
# ----------------------------
stream = "tcp://localhost:4545"
tem_mode = True
# jfj = False
tem_host = "localhost"
tem_port = 3535

tem_host = cfg.temserver
dev = False
#Configuration
nrow = cfg.nrows
ncol = cfg.ncols

nrow = 0
ncol = 0

dtype = np.float32
cdtype = ctypes.c_float

# fitterWorkerReady = mp.Value(ctypes.c_bool)
# fitterWorkerReady.value = False

accframes = 0
acc_image = np.zeros((nrow,ncol), dtype = dtype)
acc_image = np.zeros((0, 0), dtype=dtype) # allocated properly in init()

exit_flag = mp.Value(ctypes.c_bool)
exit_flag.value = False

#Data type to write to file
# Data type to write to file
file_dt = np.int32

#Data type to receive from the stream
# Data type to receive from the stream
stream_dt = np.float32

# Flags for non-updated magnification values in MAG and DIFF modes
mag_value_img = [1, 'X', 'X1']
mag_value_diff = [1, 'mm', '1cm']
mag_value_img = [1, "X", "X1"]
mag_value_diff = [1, "mm", "1cm"]

tag, branch, commit = get_git_info()
# Version info (safe at import; no Redis!)
tag, branch, commit = get_git_info()

# constants, presets
UM_TO_NM = 1e3
MM_TO_UM = 1e3
KV_TO_V = 1e3
UM_TO_NM = MM_TO_UM = MS_TO_US = S_TO_MS = KV_TO_V = 1e3
PIXEL = 0.075 # mm

# TEM control variables
default_HT = 200000.00 # V
# Backlash correction (KT)
backlash = [100, 80, 0, 0]
# overshoot/preload used for two-step jog moves
preload = [2000, 2000, 0, 1] # X,Y,Z in nm (2 µm), TX in deg (1°)

min_mag_for_mag = 1500 # border between LowMag/Mag

## safety not to hit hardware-limit
click_on_move_thresholds = {'dxy_min': 0.3, 'dxy_max': 100,
'dz_min_mag': 1, 'dz_max_mag': 10,
'dz_min_lmag': 3, 'absz_min': -70, 'absz_max': 20}

## stage shift larger than these values will be hold in history
stage_relaxation_thresholds = [30, 30, 30, 0.2, 100] # nm, nm, nm, deg., deg.

## software limit for GATAN holder. Smaller value (~65) may be necessary for complete safety (e.g. remote-operation).
max_stage_tilt = 72
default_roation_end = 60

## variabls for autofocusing
IL1_0 = 21780 # 21819
ILS_0 = [32920, 32776] # [32820, 32976]
WAIT_TIME_S = 0.25 # TODO: optimize value


# Frame control variables
default_polling_frequency = 1000
min_polling_frequency = 100 # safety not to inquire TEM-values too frequently
max_polling_frequency = 10000

default_frame_summed = 100
default_image_time_us = 500
min_frame_summed = 10 # safety not to save unexpectedly large datasets
max_frame_summed = 1000
detector_freq = 2000
max_duration = 3600 # sec


# Communication variables
dataserver_host = "noether"
dataserver_port = 3463

max_retries_tagging = 3
inquiry_delay = 0.1 # sec


def init(*, stream_, dtype_, cdtype_, tem_mode_, tem_host_, dev_, nrow_, ncol_):
"""
Initialize globals that previously depended on Redis at import-time.

Call this exactly once in launch_gui.py *before* importing modules that use globals.
"""
global stream, dtype, cdtype, tem_mode, tem_host, dev, nrow, ncol, acc_image

stream = stream_
dtype = np.dtype(dtype_)
cdtype = cdtype_

tem_mode = bool(tem_mode_)
tem_host = str(tem_host_)
dev = bool(dev_)

nrow = int(nrow_)
ncol = int(ncol_)

if nrow <= 0 or ncol <= 0:
raise ValueError(f"Invalid detector geometry: nrow={nrow}, ncol={ncol}")

acc_image = np.zeros((nrow, ncol), dtype=dtype)
Loading