arpest 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. arpest/__init__.py +0 -0
  2. arpest/app.py +79 -0
  3. arpest/core/__init__.py +0 -0
  4. arpest/core/loaders/__init__.py +11 -0
  5. arpest/core/loaders/base.py +84 -0
  6. arpest/core/loaders/bloch.py +518 -0
  7. arpest/core/loaders/i05.py +553 -0
  8. arpest/models/__init__.py +12 -0
  9. arpest/models/dataset.py +336 -0
  10. arpest/models/file_stack.py +173 -0
  11. arpest/operations/__init__.py +5 -0
  12. arpest/operations/basic.py +125 -0
  13. arpest/operations/fermi.py +188 -0
  14. arpest/operations/k_space.py +326 -0
  15. arpest/ui/__init__.py +0 -0
  16. arpest/ui/dialogs/__init__.py +0 -0
  17. arpest/ui/dialogs/settings.py +133 -0
  18. arpest/ui/main_window.py +1269 -0
  19. arpest/ui/widgets/__init__.py +0 -0
  20. arpest/ui/widgets/file_catalog.py +104 -0
  21. arpest/ui/widgets/operations/__init__.py +5 -0
  22. arpest/ui/widgets/operations/base.py +70 -0
  23. arpest/ui/widgets/operations/basic.py +253 -0
  24. arpest/ui/widgets/operations/fermi_level.py +162 -0
  25. arpest/ui/widgets/operations/k_space.py +209 -0
  26. arpest/ui/widgets/operations/registry.py +22 -0
  27. arpest/ui/widgets/operations_panel.py +73 -0
  28. arpest/ui/widgets/state_history.py +47 -0
  29. arpest/utils/__init__.py +0 -0
  30. arpest/utils/config.py +117 -0
  31. arpest/utils/constants.py +8 -0
  32. arpest/utils/cursor/cursor_helpers.py +185 -0
  33. arpest/utils/cursor/cursor_manager.py +187 -0
  34. arpest/utils/cursor/pg_line_cursor.py +108 -0
  35. arpest/utils/functions/fermi_dirac_ditribution.py +73 -0
  36. arpest/utils/session.py +121 -0
  37. arpest/visualization/__init__.py +6 -0
  38. arpest/visualization/figure_2d.py +401 -0
  39. arpest/visualization/figure_3d.py +664 -0
  40. arpest-1.0.0.dist-info/METADATA +152 -0
  41. arpest-1.0.0.dist-info/RECORD +44 -0
  42. arpest-1.0.0.dist-info/WHEEL +5 -0
  43. arpest-1.0.0.dist-info/entry_points.txt +2 -0
  44. arpest-1.0.0.dist-info/top_level.txt +1 -0
arpest/__init__.py ADDED
File without changes
arpest/app.py ADDED
@@ -0,0 +1,79 @@
1
+ """
2
+ ARpest application entry point.
3
+
4
+ This module initializes and runs the main PyQt5 application.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from PyQt5.QtWidgets import QApplication
13
+
14
+ from arpest.ui.main_window import MainWindow
15
+ from arpest.utils.config import Config
16
+
17
+ #TODO
18
+ #subtarct, add and divide by MDC, EDC, bg_Matt
19
+ #divide by gold
20
+
21
+ #smooth, 2nd derivative, curvature
22
+ #normalise slices (for kz thingy)
23
+ #set cursor position
24
+ #rotate the map for allignment
25
+ #fully integrated MDC, EDC
26
+ #overlap plots to compare
27
+ #export data for additional analysis
28
+ #phi rotation in k convert?
29
+
30
+ #stuff:
31
+ #bg subtract (there may be angle dependence: bg_matt, bg_fermi)
32
+ #normalisation:
33
+ #1) by number of sweeps (can chekc the BG above FL to check for number of sweeps),
34
+ #2) MDC/EDC cuts divided by max value (fake data, just to enhance)
35
+ #select area:
36
+ #normalise based on some selected area?
37
+ #fermi level for photon ebergy scan? -> Chun does it manually for each hv measuerment
38
+ #range plots
39
+ #fitting?
40
+
41
+ class ARpestApp:
42
+ """Main ARpest application class."""
43
+
44
+ def __init__(self):
45
+ """Initialize the application."""
46
+ self.app = QApplication(sys.argv)
47
+ self.app.setApplicationName("ARpest")
48
+ self.app.setOrganizationName("ARpest")
49
+
50
+ # Load configuration
51
+ self.config = Config()
52
+
53
+ # Create main window
54
+ self.window = MainWindow(self.config)
55
+
56
+ def run(self) -> int:
57
+ """
58
+ Run the application.
59
+
60
+ Returns:
61
+ Exit code (0 for success)
62
+ """
63
+ self.window.show()
64
+ return self.app.exec_()
65
+
66
+
67
+ def main() -> int:
68
+ """
69
+ Main entry point for ARpest application.
70
+
71
+ Returns:
72
+ Exit code (0 for success)
73
+ """
74
+ app = ARpestApp()
75
+ return app.run()
76
+
77
+
78
+ if __name__ == "__main__":
79
+ sys.exit(main())
File without changes
@@ -0,0 +1,11 @@
1
+ """Data loaders for different beamlines."""
2
+
3
+ from .base import BaseLoader
4
+ from .bloch import BlochLoader
5
+ from .i05 import I05Loader
6
+
7
+ __all__ = [
8
+ "BaseLoader",
9
+ "BlochLoader",
10
+ "I05Loader",
11
+ ]
@@ -0,0 +1,84 @@
1
+ """
2
+ Base loader interface for beamline-specific data loaders.
3
+
4
+ All beamline loaders must inherit from BaseLoader and implement
5
+ the load() method to convert beamline-specific formats into
6
+ the standard Dataset model.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from abc import ABC, abstractmethod
12
+ from pathlib import Path
13
+ from typing import Union
14
+
15
+ from ...models import Dataset
16
+
17
+
18
+ class BaseLoader(ABC):
19
+ """
20
+ Abstract base class for beamline data loaders.
21
+
22
+ Each beamline has its own data format. Loaders convert these
23
+ formats into the unified Dataset model.
24
+ """
25
+
26
+ @property
27
+ @abstractmethod
28
+ def name(self) -> str:
29
+ """Human-readable name of the beamline/instrument."""
30
+ pass
31
+
32
+ @property
33
+ @abstractmethod
34
+ def extensions(self) -> list[str]:
35
+ """Supported file extensions (e.g., ['.txt', '.dat'])."""
36
+ pass
37
+
38
+ @abstractmethod
39
+ def can_load(self, filepath: Union[str, Path]) -> bool:
40
+ """
41
+ Check if this loader can handle the given file.
42
+
43
+ This should be a quick check (e.g., file extension, magic bytes,
44
+ header inspection) without fully parsing the file.
45
+
46
+ Args:
47
+ filepath: Path to file to check
48
+
49
+ Returns:
50
+ True if this loader can handle the file
51
+ """
52
+ pass
53
+
54
+ @abstractmethod
55
+ def load(self, filepath: Union[str, Path]) -> Dataset:
56
+ """
57
+ Load data from file and convert to standard Dataset.
58
+
59
+ This is where the beamline-specific parsing happens.
60
+ The loader must:
61
+ 1. Read the file
62
+ 2. Extract axes, intensity data, and metadata
63
+ 3. Normalize naming conventions (e.g., tilt angles)
64
+ 4. Return a valid Dataset
65
+
66
+ Args:
67
+ filepath: Path to file to load
68
+
69
+ Returns:
70
+ Dataset object with standardized format
71
+
72
+ Raises:
73
+ ValueError: If file format is invalid
74
+ IOError: If file cannot be read
75
+ """
76
+ pass
77
+
78
+ def __str__(self) -> str:
79
+ """String representation."""
80
+ return f"{self.name} Loader"
81
+
82
+ def __repr__(self) -> str:
83
+ """Detailed representation."""
84
+ return f"<{self.__class__.__name__}: {self.name} ({', '.join(self.extensions)})>"
@@ -0,0 +1,518 @@
1
+ """
2
+ Bloch beamline data loader (MAX IV).
3
+
4
+ Loads ZIP files from the Bloch beamline at MAX IV and converts
5
+ them to the standard Dataset format.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import zipfile
11
+ from pathlib import Path
12
+ from typing import Union
13
+
14
+ import numpy as np
15
+ from numpy.typing import NDArray
16
+
17
+ from ...models import Axis, AxisType, Dataset, Measurement
18
+ from .base import BaseLoader
19
+
20
+ def start_step_n(start: float, step: float, n: int) -> NDArray[np.floating]:
21
+ """
22
+ Create array from start, step, and number of points.
23
+
24
+ Args:
25
+ start: Starting value
26
+ step: Step size
27
+ n: Number of points
28
+
29
+ Returns:
30
+ Array of n points
31
+ """
32
+ end = start + n * step
33
+ return np.linspace(start, end, n)
34
+
35
+
36
+ class BlochLoader(BaseLoader):
37
+ """
38
+ Loader for Bloch beamline (MAX IV) data.
39
+
40
+ Supports .zip files containing spectrum data.
41
+ """
42
+
43
+ @property
44
+ def name(self) -> str:
45
+ """Human-readable name."""
46
+ return "Bloch (MAX IV)"
47
+
48
+ @property
49
+ def extensions(self) -> list[str]:
50
+ """Supported file extensions."""
51
+ return [".zip", ".ibw"]
52
+
53
+ def can_load(self, filepath: Union[str, Path]) -> bool:
54
+ """
55
+ Check if file is a Bloch beamline file (ZIP or IBW).
56
+
57
+ Args:
58
+ filepath: Path to check
59
+
60
+ Returns:
61
+ True if this is a Bloch file
62
+ """
63
+ filepath = Path(filepath)
64
+
65
+ if filepath.suffix.lower() == ".zip":
66
+ # Check if it contains Bloch-specific files
67
+ try:
68
+ with zipfile.ZipFile(filepath, 'r') as z:
69
+ files = z.namelist()
70
+ # Bloch files have viewer.ini and Spectrum_*.ini
71
+ return 'viewer.ini' in files and any('Spectrum_' in f for f in files)
72
+ except (zipfile.BadZipFile, OSError):
73
+ return False
74
+ elif filepath.suffix.lower() == ".ibw":
75
+ # IBW files from Bloch can be loaded
76
+ return True
77
+
78
+ return False
79
+
80
+ def load(self, filepath: Union[str, Path]) -> Dataset:
81
+ """
82
+ Load Bloch beamline data from ZIP or IBW file.
83
+
84
+ Args:
85
+ filepath: Path to .zip or .ibw file
86
+
87
+ Returns:
88
+ Dataset with standardized format
89
+
90
+ Raises:
91
+ ValueError: If file format is invalid
92
+ """
93
+ filepath = Path(filepath)
94
+
95
+ if filepath.suffix.lower() == ".zip":
96
+ return self._load_zip(filepath)
97
+ elif filepath.suffix.lower() == ".ibw":
98
+ return self._load_ibw(filepath)
99
+ else:
100
+ raise ValueError(f"Unsupported file type: {filepath.suffix}")
101
+
102
+ def _load_ibw(self, filepath: Path) -> Dataset:
103
+ """Load IBW file from Bloch beamline."""
104
+ try:
105
+ from igor import binarywave
106
+ except ImportError:
107
+ raise ValueError(
108
+ "igor package required for IBW files. Install with: pip install igor"
109
+ )
110
+
111
+ print("\n" + "="*60)
112
+ print(f"BLOCH LOADER (IBW): Loading {filepath.name}")
113
+ print("="*60)
114
+
115
+ try:
116
+ wave = binarywave.load(str(filepath))['wave']
117
+ data = np.array([wave['wData']])
118
+
119
+ print(f"[1] Raw data from IBW:")
120
+ print(f" Shape: {data.shape}")
121
+
122
+ # Get header
123
+ header = wave['wave_header']
124
+ nDim = header['nDim']
125
+ steps = header['sfA']
126
+ starts = header['sfB']
127
+
128
+ print(f"[2] Header dimensions: {nDim}")
129
+ print(f" Steps: {steps[:3]}")
130
+ print(f" Starts: {starts[:3]}")
131
+
132
+ # Parse metadata from note
133
+ note = wave['note'].decode('ASCII').split('\r')
134
+ M2 = {}
135
+ for line in note:
136
+ try:
137
+ name, val = line.split('=')
138
+ M2[name] = val
139
+ except ValueError:
140
+ continue
141
+
142
+ # Extract metadata
143
+ metadata = {}
144
+ for key, name, dtype in self._meta_keys():
145
+ try:
146
+ if name == 'hv' or name == 'tilt':
147
+ metadata[name] = float(M2.get(key, 0))
148
+ else:
149
+ metadata[name] = M2.get(key, '')
150
+ except (KeyError, ValueError):
151
+ pass
152
+
153
+ # Create measurement
154
+ measurement = Measurement(
155
+ photon_energy=metadata.get('hv', 0.0),
156
+ temperature=300.0, # Not in IBW files
157
+ beamline="Bloch (MAX IV)",
158
+ tilt_theta=metadata.get('tilt', 0.0),
159
+ custom=metadata
160
+ )
161
+
162
+ # Determine if 2D or 3D based on data shape
163
+ print(f"[3] Processing data...")
164
+
165
+ if len(data.shape) == 4: # 3D scan (hv scan)
166
+ print(f" Detected 3D data (photon energy scan)")
167
+ # data shape is (1, n_angle, n_energy, n_hv)
168
+ # That's: (1, 972, 740, 11) for your example
169
+
170
+ # Remove first dimension
171
+ data = data[0] # Now: (n_angle, n_energy, n_hv)
172
+ data = np.transpose(data, (1, 0, 2)) # Energy on x, angle on y
173
+ data = np.flip(data)
174
+ print(f" After squeeze: {data.shape}")
175
+
176
+ # Dimensions from header
177
+ n_angle = nDim[0] # 972
178
+ n_energy = nDim[1] # 740
179
+ n_hv = nDim[2] # 11
180
+
181
+ print(f" Header says: n_angle={n_angle}, n_energy={n_energy}, n_hv={n_hv}")
182
+
183
+ # Construct axes
184
+ energy_axis = start_step_n(starts[0], steps[0], n_angle)
185
+ angle_axis = start_step_n(starts[1], steps[1], n_energy)
186
+
187
+ # Z-scale: photon energies from metadata
188
+ # Extract from M2['Point 1'], M2['Point 2'], etc.
189
+ zscale_list = []
190
+ for i in range(1, n_hv + 1): # Use actual n_hv from data
191
+ key = f'Point {i}'
192
+ if key in M2:
193
+ val_str = M2[key].replace(" eV", "").strip()
194
+ try:
195
+ zscale_list.append(float(val_str))
196
+ except ValueError:
197
+ pass
198
+
199
+ if len(zscale_list) == n_hv:
200
+ zscale = np.array(zscale_list)
201
+ else:
202
+ # Fallback
203
+ print(f" WARNING: Could not extract {n_hv} photon energies, found {len(zscale_list)}")
204
+ zscale = np.arange(n_hv, dtype=float)
205
+
206
+ print(f"[4] 3D axes:")
207
+ print(f" angle_axis: {len(angle_axis)} points")
208
+ print(f" energy_axis: {len(energy_axis)} points")
209
+ print(f" zscale (photon energy): {len(zscale)} points")
210
+
211
+ # Data is currently: (n_angle, n_energy, n_hv)
212
+ # We want: (n_angle, n_energy, n_hv) for Dataset
213
+ # That's already correct!
214
+ print(f" Data shape: {data.shape}")
215
+ print(f" Expected: ({n_angle}, {n_energy}, {n_hv})")
216
+
217
+ dataset = Dataset(
218
+ y_axis=Axis(angle_axis, AxisType.ANGLE, "Angle", "°"),
219
+ x_axis=Axis(energy_axis, AxisType.ENERGY_KINETIC, "Kinetic Energy", "eV"),
220
+ z_axis=Axis(zscale, AxisType.PHOTON_ENERGY, "Photon Energy", "eV"),
221
+ intensity=data,
222
+ measurement=measurement,
223
+ filename=filepath.name,
224
+ )
225
+
226
+ else: # 2D data
227
+ print(f" Detected 2D data")
228
+ data = np.swapaxes(data, 1, 2) # Energy on x, angle on y
229
+
230
+ # Construct axes
231
+ xscale = start_step_n(starts[0], steps[0], nDim[0])
232
+ yscale = start_step_n(starts[1], steps[1], nDim[1])
233
+
234
+ # Squeeze data
235
+ data = data.squeeze()
236
+
237
+ print(f"[4] 2D axes:")
238
+ print(f" yscale (angle): {len(yscale)} points")
239
+ print(f" xscale (energy): {len(xscale)} points")
240
+ print(f" Final shape: {data.shape}")
241
+
242
+ dataset = Dataset(
243
+ y_axis=Axis(yscale, AxisType.ANGLE, "Angle", "°"),
244
+ x_axis=Axis(xscale, AxisType.ENERGY_KINETIC, "Kinetic Energy", "eV"),
245
+ intensity=data,
246
+ measurement=measurement,
247
+ filename=filepath.name,
248
+ )
249
+
250
+ print("="*60)
251
+ print("BLOCH LOADER (IBW): Success!")
252
+ print("="*60 + "\n")
253
+
254
+ return dataset
255
+
256
+ except Exception as e:
257
+ import traceback
258
+ print("\n" + "="*60)
259
+ print("BLOCH LOADER (IBW): ERROR!")
260
+ print("="*60)
261
+ traceback.print_exc()
262
+ print("="*60 + "\n")
263
+ raise ValueError(f"Failed to load IBW file {filepath}: {e}")
264
+
265
+ def _load_zip(self, filepath: Path) -> Dataset:
266
+ """
267
+ Load Bloch beamline data from ZIP file.
268
+
269
+ Args:
270
+ filepath: Path to .zip file
271
+
272
+ Returns:
273
+ Dataset with standardized format
274
+
275
+ Raises:
276
+ ValueError: If file format is invalid
277
+ """
278
+ print("\n" + "="*60)
279
+ print(f"BLOCH LOADER (ZIP): Loading {filepath.name}")
280
+ print("="*60)
281
+
282
+ try:
283
+ with zipfile.ZipFile(filepath, 'r') as z:
284
+ # Get file ID from viewer.ini
285
+ with z.open('viewer.ini') as viewer:
286
+ file_id = self._read_viewer(viewer)
287
+ print(f"[1] File ID: {file_id}")
288
+
289
+ # Load metadata from spectrum ini
290
+ with z.open(f'Spectrum_{file_id}.ini') as metadata_file:
291
+ spectrum_meta = self._read_metadata(metadata_file, self._spectrum_keys())
292
+
293
+ print(f"[2] Spectrum metadata:")
294
+ print(f" Dimensions: ({spectrum_meta['n_y']}, {spectrum_meta['n_x']}, {spectrum_meta['n_energy']})")
295
+ print(f" Energy range: {spectrum_meta['first_energy']} to {spectrum_meta['last_energy']}")
296
+
297
+ # Load additional metadata
298
+ with z.open(f'{file_id}.ini') as metadata_file2:
299
+ extra_meta = self._read_metadata(metadata_file2, self._meta_keys())
300
+
301
+ # Load binary data
302
+ with z.open(f'Spectrum_{file_id}.bin') as f:
303
+ data_flat = np.frombuffer(f.read(), dtype='float32')
304
+
305
+ print(f"[3] Binary data loaded: {len(data_flat)} values")
306
+
307
+ # Reshape data
308
+ n_y = int(spectrum_meta['n_y'])
309
+ n_x = int(spectrum_meta['n_x'])
310
+ n_energy = int(spectrum_meta['n_energy'])
311
+
312
+ print(f"[4] Attempting reshape:")
313
+ print(f" n_y (dim 0): {n_y}")
314
+ print(f" n_x (dim 1): {n_x}")
315
+ print(f" n_energy (dim 2): {n_energy}")
316
+ print(f" Expected total: {n_y * n_x * n_energy}")
317
+ print(f" Actual values: {len(data_flat)}")
318
+
319
+ data = np.reshape(data_flat, (n_y, n_x, n_energy))
320
+ print(f" Reshaped to: {data.shape}")
321
+
322
+ # Cut off unswept region
323
+ first = int(spectrum_meta['first_energy'])
324
+ last = int(spectrum_meta['last_energy'])
325
+
326
+ print(f"[5] Energy range from metadata:")
327
+ print(f" first_energy: {first}")
328
+ print(f" last_energy: {last}")
329
+ print(f" Data dim 2 size: {data.shape[2]}")
330
+
331
+ # Make sure indices are valid for dimension 2 (energy)
332
+ max_index = data.shape[2] - 1
333
+ if last > max_index:
334
+ print(f" WARNING: last={last} > max_index={max_index}, adjusting to {max_index}")
335
+ last = max_index
336
+ if first < 0:
337
+ first = 0
338
+ if first > last:
339
+ print(f" WARNING: first > last, swapping")
340
+ first, last = last, first
341
+
342
+ print(f" Slicing [:, :, {first}:{last + 1}]")
343
+ data = data[:, :, first:last + 1]
344
+ print(f"[6] After cutting: {data.shape}")
345
+
346
+ # Transpose to (energy, x, y)
347
+ data = np.moveaxis(data, 2, 0)
348
+ print(f"[7] After moveaxis(2, 0): {data.shape}")
349
+
350
+ # Create axes
351
+ xscale = start_step_n(
352
+ spectrum_meta['start_x'],
353
+ spectrum_meta['step_x'],
354
+ n_x
355
+ )
356
+ yscale = start_step_n(
357
+ spectrum_meta['start_y'],
358
+ spectrum_meta['step_y'],
359
+ n_y
360
+ )
361
+
362
+ # Create FULL energy axis first
363
+ energies_full = start_step_n(
364
+ spectrum_meta['start_energy'],
365
+ spectrum_meta['step_energy'],
366
+ n_energy
367
+ )
368
+ print(f" Full energy axis: {len(energies_full)} points")
369
+
370
+ # Now cut energies to match the cut data
371
+ energies = energies_full[first:last + 1]
372
+
373
+ print(f"[8] Axes created:")
374
+ print(f" xscale: {len(xscale)} points")
375
+ print(f" yscale: {len(yscale)} points")
376
+ print(f" energies: {len(energies)} points (cut from {len(energies_full)})")
377
+ print(f" Data shape after cutting: {data.shape}")
378
+ print(f" Expected match: data.shape[0]={data.shape[0]} == len(energies)={len(energies)}")
379
+
380
+ # Create measurement metadata
381
+ measurement = Measurement(
382
+ photon_energy=extra_meta.get('hv', 0.0),
383
+ temperature=extra_meta.get('temperature', 300.0),
384
+ beamline="Bloch (MAX IV)",
385
+ tilt_theta=extra_meta.get('tilt', 0.0),
386
+ tilt_phi=extra_meta.get('azimuth', 0.0),
387
+ custom=extra_meta
388
+ )
389
+
390
+ # Determine if 2D or 3D
391
+ print(f"[9] Determining dimensionality...")
392
+ if len(yscale) == 1: # 2D data
393
+ print(f" 2D data detected (yscale length = 1)")
394
+ # Transpose to (x, energy)
395
+ data_2d = np.transpose(data, (1, 2, 0)).squeeze()
396
+ print(f" Final 2D shape: {data_2d.shape}")
397
+
398
+ dataset = Dataset(
399
+ x_axis=Axis(energies, AxisType.ENERGY_KINETIC, "Kinetic Energy", "eV"),
400
+ y_axis=Axis(xscale, AxisType.ANGLE, "Angle", "°"),
401
+ intensity=data_2d,
402
+ measurement=measurement,
403
+ filename=filepath.name,
404
+ )
405
+ else: # 3D data
406
+ print(f" 3D data detected")
407
+ # Data after moveaxis is: (energy, y, x) = (972, 49, 740)
408
+ # Transpose to: (y, x, energy) = (49, 740, 972)
409
+ # But Dataset expects: (y_axis, x_axis, z_axis)
410
+
411
+ # Current data shape: (energy, y, x) = (972, 49, 740)
412
+ # We want: (y, x, energy) = (49, 740, 972)
413
+ data_3d = np.transpose(data, (1, 2, 0))
414
+ print(f" Transposed from {data.shape} to {data_3d.shape}")
415
+
416
+ # Now data is (y, x, energy) = (49, 740, 972)
417
+ # So: y_axis=yscale (49), x_axis=xscale (740), z_axis=energies (972)
418
+
419
+ dataset = Dataset(
420
+ x_axis=Axis(xscale, AxisType.ANGLE, "Angle X", "°"),
421
+ y_axis=Axis(yscale, AxisType.ANGLE, "Angle Y", "°"),
422
+ z_axis=Axis(energies, AxisType.ENERGY_KINETIC, "Kinetic Energy", "eV"),
423
+ intensity=data_3d,
424
+ measurement=measurement,
425
+ filename=filepath.name,
426
+ )
427
+
428
+ print(f" Dataset shape check:")
429
+ print(f" intensity: {data_3d.shape}")
430
+ print(f" expected: ({len(yscale)}, {len(xscale)}, {len(energies)})")
431
+
432
+ print("="*60)
433
+ print("BLOCH LOADER (ZIP): Success!")
434
+ print("="*60 + "\n")
435
+
436
+ return dataset
437
+
438
+ except Exception as e:
439
+ import traceback
440
+ print("\n" + "="*60)
441
+ print("BLOCH LOADER (ZIP): ERROR!")
442
+ print("="*60)
443
+ traceback.print_exc()
444
+ print("="*60 + "\n")
445
+ raise ValueError(f"Failed to load Bloch ZIP file {filepath}: {e}")
446
+
447
+ @staticmethod
448
+ def _read_viewer(viewer) -> str:
449
+ """Extract file ID from viewer.ini."""
450
+ for line in viewer.readlines():
451
+ l = line.decode('UTF-8')
452
+ if l.startswith('name'):
453
+ return l.split('=')[1].split()[0]
454
+ raise ValueError("Could not find file ID in viewer.ini")
455
+
456
+ @staticmethod
457
+ def _read_metadata(metadata_file, keys):
458
+ """
459
+ Read metadata from INI file.
460
+
461
+ Args:
462
+ metadata_file: File object
463
+ keys: List of (key_name, output_name, dtype) tuples
464
+
465
+ Returns:
466
+ Dictionary of metadata
467
+ """
468
+ metadata = {}
469
+ for line in metadata_file.readlines():
470
+ tokens = line.decode('utf-8').split('=')
471
+ if len(tokens) < 2:
472
+ continue
473
+
474
+ for key, name, dtype in keys:
475
+ if tokens[0] == key:
476
+ value = tokens[1].split()[0]
477
+ metadata[name] = dtype(value)
478
+ return metadata
479
+
480
+ @staticmethod
481
+ def _spectrum_keys():
482
+ """Keys for Spectrum_*.ini file."""
483
+ return [
484
+ ('width', 'n_energy', int),
485
+ ('height', 'n_x', int),
486
+ ('depth', 'n_y', int),
487
+ ('first_full', 'first_energy', int),
488
+ ('last_full', 'last_energy', int),
489
+ ('widthoffset', 'start_energy', float),
490
+ ('widthdelta', 'step_energy', float),
491
+ ('heightoffset', 'start_x', float),
492
+ ('heightdelta', 'step_x', float),
493
+ ('depthoffset', 'start_y', float),
494
+ ('depthdelta', 'step_y', float),
495
+ ]
496
+
497
+ @staticmethod
498
+ def _meta_keys():
499
+ """Keys for main metadata file."""
500
+ return [
501
+ ('Date', 'Date', str),
502
+ ('Time', 'Time', str),
503
+ ('Excitation Energy', 'hv', float),
504
+ ('A', 'azimuth', float),
505
+ ('P', 'polar', float),
506
+ ('T', 'tilt', float),
507
+ ('X', 'X', float),
508
+ ('Y', 'Y', float),
509
+ ('Z', 'Z', float),
510
+ ('ThetaY', 'Deflector', float),
511
+ ('Pass Energy', 'Pass Energy', int),
512
+ ('Number of Sweeps', 'Number of Sweeps', int),
513
+ ('Acquisition Mode', 'Acquisition Mode', str),
514
+ ('Center Energy', 'Center Energy', float),
515
+ ('Low Energy', 'Low Energy', float),
516
+ ('High Energy', 'High Energy', float),
517
+ ('Energy Step', 'Energy Step', float),
518
+ ]