xpcsviewer package¶
Main Package¶
XPCS Viewer - X-ray Photon Correlation Spectroscopy data analysis tool.
This package provides both a graphical user interface (GUI) and command-line interface (CLI) for analyzing XPCS data stored in HDF5/NeXus format.
- Main Components:
XpcsFile: Core data container for XPCS datasets with lazy loading XpcsViewer: PySide6-based GUI for interactive analysis ViewerKernel: Backend for data processing and plot management FileLocator: File discovery and management utilities
- Entry Points:
xpcsviewer-gui: Launch the graphical interface xpcsviewer: CLI for batch processing (e.g., twotime analysis)
Example
>>> from xpcsviewer import XpcsFile
>>> xf = XpcsFile('data.h5')
>>> print(f"Analysis type: {xf.atype}")
- class xpcsviewer.FileLocator[source]¶
Bases:
objectPlaceholder FileLocator class for documentation builds.
- class xpcsviewer.ViewerKernel[source]¶
Bases:
objectPlaceholder ViewerKernel class for documentation builds.
Core Classes¶
XpcsFile¶
- class xpcsviewer.XpcsFile[source]¶
Bases:
objectPlaceholder XpcsFile class for documentation builds.
The main data container class for XPCS datasets. Provides lazy loading of large data arrays and built-in analysis capabilities.
Note
XpcsFile automatically detects the analysis type (Multitau, Twotime, etc.) and loads appropriate data fields.
XpcsFile Submodules¶
The xpcsviewer.xpcs_file package splits internal concerns into submodules:
Cache¶
LRU data cache with memory-pressure awareness.
Data caching utilities for XpcsFile.
This module provides LRU caching with memory management for XPCS data.
- class xpcsviewer.xpcs_file.cache.CacheItem(data, size_mb)[source]
Bases:
objectIndividual cache item with metadata.
- Parameters:
data (Any)
size_mb (float)
- touch()[source]
Mark item as accessed.
- class xpcsviewer.xpcs_file.cache.DataCache(max_memory_mb=500.0, memory_pressure_threshold=0.85)[source]
Bases:
objectLRU cache with memory limit and automatic cleanup for XPCS data.
Features: - LRU eviction policy - Memory limit enforcement (default 500MB) - Automatic cleanup on memory pressure - Memory usage tracking per item - Thread-safe operations
- __init__(max_memory_mb=500.0, memory_pressure_threshold=0.85)[source]
- put(file_path, data_type, data)[source]
Store data in cache.
- get(file_path, data_type)[source]
Retrieve data from cache.
- clear()[source]
Clear all cached data.
Fitting Helpers¶
File-level fitting convenience functions used internally by
fit_g2().
Fitting functions for XPCS analysis.
This module provides fitting functions for G2 correlation analysis.
These functions are JIT-traced by nlsq (a JAX-based curve fitting library), so they must use jax.numpy operations instead of numpy to avoid TracerArrayConversionError when nlsq traces them with JAX tracers.
- xpcsviewer.xpcs_file.fitting.single_exp_all(x, a, b, c, d)[source]
Single exponential fitting for XPCS-multitau analysis.
- xpcsviewer.xpcs_file.fitting.double_exp_all(x, a, b1, c1, d, b2, c2, f)[source]
Double exponential fitting for XPCS-multitau analysis.
- Parameters:
x (float or ndarray) – Delay in seconds.
a (float) – Contrast.
b1 (float) – Characteristic time (tau) of the first exponential component.
c1 (float) – Restriction factor for the first component.
d (float) – Baseline offset.
b2 (float) – Characteristic time (tau) of the second exponential component.
c2 (float) – Restriction factor for the second component.
f (float) – Fractional contribution of the first exponential component (0 ≤ f ≤ 1).
- Returns:
Computed value of the double exponential model.
- Return type:
float or ndarray
- xpcsviewer.xpcs_file.fitting.power_law(x, a, b)[source]
Power-law fitting for diffusion behavior.
- xpcsviewer.xpcs_file.fitting.create_id(fname, label_style=None, simplify_flag=True)[source]
Generate a simplified or customized ID string from a filename.
- Parameters:
fname (str) – Input file name, possibly with path and extension.
label_style (str or None, optional) – Optional custom regex pattern for extracting a label from the filename. If None, uses simplified default label extraction.
simplify_flag (bool, optional) – If True (default), applies default simplification logic.
- Returns:
A simplified or customized ID string derived from the input filename.
- Return type:
Memory Monitor¶
Virtual-memory monitoring for adaptive cache eviction.
Memory monitoring utilities for XpcsFile.
This module provides memory monitoring and status tracking for XPCS data operations.
- class xpcsviewer.xpcs_file.memory.MemoryStatus(percent_used)[source]
Bases:
objectContainer for memory status information.
- Parameters:
percent_used (float)
- class xpcsviewer.xpcs_file.memory.MemoryMonitor[source]
Bases:
objectSimple memory monitoring utilities using psutil.
- get_memory_info()[source]
Get current memory usage information.
- get_memory_status()[source]
Get memory status object.
- Returns:
Object containing percent_used attribute
- Return type:
MemoryStatus
- static get_memory_usage()[source]
Get current memory usage in MB (static method for backward compatibility).
- static get_memory_pressure()[source]
Calculate memory pressure as a percentage (0-1) (static method for backward compatibility).
- Return type:
- static is_memory_pressure_high(threshold=0.85)[source]
Check if memory pressure is above threshold (static method for backward compatibility).
- xpcsviewer.xpcs_file.memory.get_cached_memory_monitor()[source]
Get or create a cached memory monitor instance.
- Returns:
Singleton memory monitor instance
- Return type:
MemoryMonitor
Package Information¶
- xpcsviewer.__version__ = version string¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.
- xpcsviewer.__author__ = "Miaoqi Chu & Wei Chen"¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.
- xpcsviewer.__credits__ = "Argonne National Laboratory"¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.