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)
62 changes: 42 additions & 20 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,69 @@ 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 = cfg.temserver
tem_host = "localhost"
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
PIXEL = 0.075 # mm
KV_TO_V = 1e3
PIXEL = 0.075 # mm

default_HT = 200000.00 # V
default_HT = 200000.00 # V
backlash = [100, 80, 0, 0]


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