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]

__call__(value, clip=None)[source]

Apply normalization to values.

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:

bool

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

param use_paper_style:

type use_paper_style:

bool

param use_custom_fonts:

type use_custom_fonts:

bool

mmpp.fft.modes.check_ffmpeg_available()[source]

Check if ffmpeg is available for MP4 animations.

Return type:

bool

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:
  • figsize (tuple[float, float])

  • 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)

figsize: tuple[float, float] = (16, 10)
dpi: int = 100
spectrum_log_scale: bool = False
spectrum_normalize: bool = True
peak_threshold: float = 0.1
peak_min_distance: int = 5
show_magnitude: bool = True
show_phase: bool = True
show_combined: bool = True
colormap_magnitude: str = 'cmc.berlin'
colormap_phase: str = 'cmc.romaO'
colormap_animation: str = 'balance'
interpolation: str = 'nearest'
use_midpoint_norm: bool = False
animation_time_steps: int = 60
f_min: float = 0.0
f_max: float = 40.0
spectrum_width_ratio: float = 0.4
modes_width_ratio: float = 0.6
__post_init__()[source]

Validate configuration parameters.

__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:
  • figsize (tuple[float, float])

  • 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.Peak(idx, freq, amplitude)[source]

Bases: object

Peak data structure.

Parameters:
idx: int
freq: float
amplitude: float
__init__(idx, freq, amplitude)
Parameters:
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

param frequency:

type frequency:

float

param mode_array:

type mode_array:

ndarray

param extent:

type extent:

Optional[tuple[float, float, float, float]]

param metadata:

type metadata:

Optional[dict[str, Any]]

property magnitude: ndarray

Get magnitude of mode for each component.

property phase: ndarray

Get phase of mode for each component.

property total_magnitude: ndarray

Get total magnitude across all components.

get_component(component)[source]

Get specific magnetization component.

Return type:

ndarray

Parameters:

componentint or str

Component index (0, 1, 2) or name (‘x’, ‘y’, ‘z’, ‘mx’, ‘my’, ‘mz’)

Returns:

: np.ndarray

Complex mode array for specified component

param component:

type component:

Union[int, str]

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

param zarr_path:

type zarr_path:

str

param dataset_name:

type dataset_name:

Optional[str]

param config:

type config:

Optional[ModeVisualizationConfig]

param debug:

type debug:

bool

property modes_available: bool

Check if mode data is available.

get_mode(frequency, z_layer=0)[source]

Get mode data at specified frequency.

Return type:

FMRModeData

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

param frequency:

type frequency:

float

param z_layer:

type z_layer:

int

find_peaks(threshold=None, min_distance=None, component=0)[source]

Find peaks in the spectrum.

Return type:

list[Peak]

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

param threshold:

type threshold:

Optional[float]

param min_distance:

type min_distance:

Optional[int]

param component:

type component:

int

plot_modes(frequency, z_layer=0, components=None, save_path=None)[source]

Plot mode visualization for a specific frequency.

Return type:

tuple[Figure, ndarray]

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

param frequency:

type frequency:

float

param z_layer:

type z_layer:

int

param components:

type components:

Optional[list[Union[int, str]]]

param save_path:

type save_path:

Optional[str]

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:

Figure

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

param components:

type components:

Optional[list[Union[int, str]]]

param z_layer:

type z_layer:

int

param method:

type method:

int

param show:

type show:

bool

compute_modes(z_slice=slice(None, None, None), window=True, save=True, force=False)[source]

Compute FMR modes from magnetization data.

Return type:

None

Parameters:

z_sliceslice

Z-layer slice to process

windowbool

Apply Hanning window

savebool

Save results to zarr

forcebool

Force recomputation even if data exists

param z_slice:

type z_slice:

slice

param window:

type window:

bool

param save:

type save:

bool

param force:

type force:

bool

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:

None

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:

Optional[tuple[float, float]]

param frequency:

type frequency:

Optional[float]

param save_path:

type save_path:

str

param fps:

type fps:

int

param z_layer:

type z_layer:

int

param component:

type component:

Union[str, int]

param animation_type:

type animation_type:

str

param colormap:

type colormap:

Optional[str]

param use_midpoint_norm:

type use_midpoint_norm:

Optional[bool]

param figsize:

type figsize:

Optional[tuple[float, float]]

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:

FrequencyModeInterface

__repr__()[source]

Rich representation of the FFT mode interface.

Return type:

str

property mode_analyzer: FMRModeAnalyzer

Get or create mode analyzer (lazy initialization).

interactive_spectrum(dset=None, **kwargs)[source]

Create interactive spectrum plot.

Parameters:

dset (Optional[str])

Return type:

Figure

compute_modes(dset=None, **kwargs)[source]

Compute modes for specified dataset.

Parameters:

dset (Optional[str])

Return type:

None

plot_modes(frequency, dset=None, **kwargs)[source]

Plot modes at specified frequency.

Parameters:
Return type:

tuple[Figure, ndarray]

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:

None

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:

Optional[tuple[float, float]]

param frequency:

type frequency:

Optional[float]

param save_path:

type save_path:

str

param dset:

type dset:

Optional[str]

param fps:

type fps:

int

param z_layer:

type z_layer:

int

param component:

type component:

Union[str, int]

param animation_type:

type animation_type:

str

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)

property frequency: float

Get frequency value for this index.

plot_modes(**kwargs)[source]

Plot modes at this frequency.

Return type:

tuple[Figure, ndarray]

get_mode(**kwargs)[source]

Get mode data at this frequency.

Return type:

FMRModeData

__repr__()[source]

Rich string representation of FrequencyModeInterface.

Return type:

str