FFT Modes
FMR Mode Visualization Module
Professional implementation for visualizing FMR modes with interactive spectrum. Provides both programmatic and interactive interfaces for mode analysis.
- class mmpp.fft.modes.MidpointNormalize(vmin=None, vmax=None, midpoint=0, clip=False)[source]
Bases:
Normalize
Matplotlib normalization class with symmetric colormap around midpoint.
Useful for data that has meaningful zero point (like magnetic field components) where you want symmetric color scaling around zero.
- __init__(vmin=None, vmax=None, midpoint=0, clip=False)[source]
Initialize normalization.
Parameters:
- vminfloat, optional
Minimum value for normalization
- vmaxfloat, optional
Maximum value for normalization
- midpointfloat, optional
Value that should map to center of colormap (default: 0)
- clipbool, optional
Whether to clip values outside [vmin, vmax]
- mmpp.fft.modes.setup_animation_styling(use_paper_style=True, use_custom_fonts=True)[source]
Setup styling for FMR mode animations using MMPP paper style.
- Return type:
Parameters:
- use_paper_stylebool, optional
Whether to apply paper.mplstyle styling (default: True)
- use_custom_fontsbool, optional
Whether to setup custom fonts (default: True)
Returns:
: bool
True if styling was successfully applied
- mmpp.fft.modes.check_ffmpeg_available()[source]
Check if ffmpeg is available for MP4 animations.
- Return type:
Returns:
: bool
True if ffmpeg is available
- class mmpp.fft.modes.ModeVisualizationConfig(figsize=(16, 10), dpi=100, spectrum_log_scale=False, spectrum_normalize=True, peak_threshold=0.1, peak_min_distance=5, show_magnitude=True, show_phase=True, show_combined=True, colormap_magnitude='cmc.berlin', colormap_phase='cmc.romaO', colormap_animation='balance', interpolation='nearest', use_midpoint_norm=False, animation_time_steps=60, f_min=0.0, f_max=40.0, spectrum_width_ratio=0.4, modes_width_ratio=0.6)[source]
Bases:
object
Configuration for mode visualization.
- Parameters:
dpi (
int
)spectrum_log_scale (
bool
)spectrum_normalize (
bool
)peak_threshold (
float
)peak_min_distance (
int
)show_magnitude (
bool
)show_phase (
bool
)show_combined (
bool
)colormap_magnitude (
str
)colormap_phase (
str
)colormap_animation (
str
)interpolation (
str
)use_midpoint_norm (
bool
)animation_time_steps (
int
)f_min (
float
)f_max (
float
)spectrum_width_ratio (
float
)modes_width_ratio (
float
)
- __init__(figsize=(16, 10), dpi=100, spectrum_log_scale=False, spectrum_normalize=True, peak_threshold=0.1, peak_min_distance=5, show_magnitude=True, show_phase=True, show_combined=True, colormap_magnitude='cmc.berlin', colormap_phase='cmc.romaO', colormap_animation='balance', interpolation='nearest', use_midpoint_norm=False, animation_time_steps=60, f_min=0.0, f_max=40.0, spectrum_width_ratio=0.4, modes_width_ratio=0.6)
- Parameters:
dpi (
int
)spectrum_log_scale (
bool
)spectrum_normalize (
bool
)peak_threshold (
float
)peak_min_distance (
int
)show_magnitude (
bool
)show_phase (
bool
)show_combined (
bool
)colormap_magnitude (
str
)colormap_phase (
str
)colormap_animation (
str
)interpolation (
str
)use_midpoint_norm (
bool
)animation_time_steps (
int
)f_min (
float
)f_max (
float
)spectrum_width_ratio (
float
)modes_width_ratio (
float
)
- class mmpp.fft.modes.FMRModeData(frequency, mode_array, extent=None, metadata=None)[source]
Bases:
object
Container for FMR mode data at a specific frequency.
- Parameters:
- __init__(frequency, mode_array, extent=None, metadata=None)[source]
Initialize FMR mode data.
Parameters:
- frequencyfloat
Frequency in GHz
- mode_arraynp.ndarray
Complex mode array with shape (ny, nx, 3) for spatial x-y and magnetization components
- extenttuple, optional
Spatial extent [x_min, x_max, y_min, y_max] in nm
- metadatadict, optional
Additional metadata
- class mmpp.fft.modes.FMRModeAnalyzer(zarr_path, dataset_name=None, config=None, debug=False)[source]
Bases:
object
Professional FMR mode analyzer with interactive visualization.
Provides both programmatic access to mode data and interactive spectrum visualization for frequency selection.
- Parameters:
- __init__(zarr_path, dataset_name=None, config=None, debug=False)[source]
Initialize FMR mode analyzer.
Parameters:
- zarr_pathstr
Path to zarr file containing mode data
- dataset_namestr, optional
Base dataset name (default: auto-select largest m dataset)
- configModeVisualizationConfig, optional
Visualization configuration
- debugbool, optional
Enable debug logging
- get_mode(frequency, z_layer=0)[source]
Get mode data at specified frequency.
- Return type:
Parameters:
- frequencyfloat
Frequency in GHz
- z_layerint, optional
Z-layer index (default: 0)
Returns:
: FMRModeData
Mode data at specified frequency
Raises:
- ValueError
If frequency or z_layer is out of range
- RuntimeError
If mode data is not available
- find_peaks(threshold=None, min_distance=None, component=0)[source]
Find peaks in the spectrum.
Parameters:
- thresholdfloat, optional
Peak detection threshold (default: from config)
- min_distanceint, optional
Minimum distance between peaks (default: from config)
- componentint, optional
Spectrum component to analyze (default: 0)
Returns:
: List[Peak]
List of detected peaks
- plot_modes(frequency, z_layer=0, components=None, save_path=None)[source]
Plot mode visualization for a specific frequency.
Parameters:
- frequencyfloat
Frequency in GHz
- z_layerint, optional
Z-layer index (default: 0)
- componentslist, optional
List of components to plot (default: [‘x’, ‘y’, ‘z’])
- save_pathstr, optional
Path to save the figure
Returns:
: Tuple[Figure, np.ndarray]
Matplotlib figure and axes array
- interactive_spectrum(components=None, z_layer=0, method=1, show=True, **kwargs)[source]
Create interactive spectrum plot with mode visualization.
Click on spectrum to select frequency and visualize corresponding mode. Right-click to snap to nearest peak.
- Return type:
Parameters:
- componentslist, optional
List of components to plot (default: [‘x’, ‘y’, ‘z’])
- z_layerint, optional
Z-layer index (default: 0)
- methodint, optional
Visualization method (default: 1) 1 = Standard interactive plot 2 = Alternative layout (if implemented)
- showbool, optional
Whether to automatically display the figure (default: True)
- **kwargsdict
Additional keyword arguments: - figsize : tuple, optional
Figure size (width, height) in inches (default: from config)
- dpiint, optional
Figure resolution in dots per inch (default: from config)
- cmapstr, optional
Colormap for all mode visualizations (overrides config colormaps) Examples: ‘viridis’, ‘inferno’, ‘plasma’, ‘cividis’, ‘balance’
- acmapstr, optional
Colormap specifically for amplitude/magnitude plots (overrides cmap for magnitude) Examples: ‘viridis’, ‘inferno’, ‘plasma’, ‘hot’
- pcmapstr, optional
Colormap specifically for phase plots (overrides cmap for phase) Examples: ‘hsv’, ‘twilight’, ‘twilight_shifted’, ‘phase’
Returns:
: Figure
Interactive matplotlib figure
- compute_modes(z_slice=slice(None, None, None), window=True, save=True, force=False)[source]
Compute FMR modes from magnetization data.
- Return type:
Parameters:
- z_sliceslice
Z-layer slice to process
- windowbool
Apply Hanning window
- savebool
Save results to zarr
- forcebool
Force recomputation even if data exists
- save_modes_animation(frequency_range=None, frequency=None, save_path='mode_animation.gif', fps=15, z_layer=0, component='z', animation_type='temporal', colormap=None, use_midpoint_norm=None, figsize=None)[source]
Save animation of FMR modes.
- Return type:
Parameters:
- frequency_rangetuple, optional
(f_min, f_max) in GHz for frequency sweep animation
- frequencyfloat, optional
Single frequency for temporal animation (in GHz)
- save_pathstr
Output file path (.gif or .mp4)
- fpsint
Frames per second (default: 15)
- z_layerint
Z-layer to animate (default: 0)
- componentstr or int
Component to animate (default: ‘z’)
- animation_typestr
Type of animation: - ‘temporal’: Real part of mode oscillating in time at fixed frequency - ‘frequency’: Mode amplitude across frequency range - ‘phase’: Phase evolution at fixed frequency
- colormapstr, optional
Colormap name. If None, uses config defaults
- use_midpoint_normbool, optional
Use symmetric normalization around zero (default: from config)
- figsizetuple, optional
Figure size (width, height)
- param frequency_range:
- type frequency_range:
- param frequency:
- type frequency:
- param save_path:
- type save_path:
- param fps:
- type fps:
- param z_layer:
- type z_layer:
- param component:
- type component:
- param animation_type:
- type animation_type:
- param colormap:
- type colormap:
- param use_midpoint_norm:
- type use_midpoint_norm:
- param figsize:
- type figsize:
- class mmpp.fft.modes.FFTModeInterface(fft_result_index, parent_fft)[source]
Bases:
object
Enhanced FFT interface with mode visualization capabilities.
Provides elegant syntax like: op[0].fft[0][200].plot_modes()
- Parameters:
fft_result_index (
int
)
- __init__(fft_result_index, parent_fft)[source]
Initialize mode interface for specific FFT result.
- Parameters:
fft_result_index (
int
)
- __getitem__(frequency_index)[source]
Get mode interface for specific frequency index.
- Parameters:
frequency_index (
int
)- Return type:
- property mode_analyzer: FMRModeAnalyzer
Get or create mode analyzer (lazy initialization).
- save_modes_animation(frequency_range=None, frequency=None, save_path='mode_animation.gif', dset=None, fps=15, z_layer=0, component='z', animation_type='temporal', **kwargs)[source]
Save animation of FMR modes.
- Return type:
Parameters:
- frequency_rangetuple, optional
(f_min, f_max) in GHz for frequency sweep animation
- frequencyfloat, optional
Single frequency for temporal animation (in GHz)
- save_pathstr
Output file path (.gif or .mp4)
- dsetstr, optional
Dataset name. If None, uses default analyzer
- fpsint
Frames per second (default: 15)
- z_layerint
Z-layer to animate (default: 0)
- componentstr or int
Component to animate (default: ‘z’)
- animation_typestr
Type of animation (‘temporal’, ‘frequency’, ‘phase’)
- **kwargs
Additional arguments passed to FMRModeAnalyzer.save_modes_animation
- param frequency_range:
- type frequency_range:
- param frequency:
- type frequency:
- param save_path:
- type save_path:
- param dset:
- type dset:
- param fps:
- type fps:
- param z_layer:
- type z_layer:
- param component:
- type component:
- param animation_type:
- type animation_type:
- class mmpp.fft.modes.FrequencyModeInterface(frequency_index, parent_mode_interface)[source]
Bases:
object
Interface for mode operations at a specific frequency.
- Parameters:
frequency_index (
int
)
- __init__(frequency_index, parent_mode_interface)[source]
Initialize frequency-specific mode interface.
- Parameters:
frequency_index (
int
)