Visualization¶
fdtdx.core.plotting.device_permittivity_index_utils.index_matrix_to_str(indices)
¶
Converts a 2D matrix of indices to a formatted string representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indices
|
Array
|
A 2D JAX array containing numerical indices. |
required |
Returns:
Type | Description |
---|---|
str
|
A string representation of the matrix where each row is space-separated |
str
|
and rows are separated by newlines. |
Source code in src/fdtdx/core/plotting/device_permittivity_index_utils.py
fdtdx.core.plotting.device_permittivity_index_utils.device_matrix_index_figure(device_matrix_indices, permittivity_configs)
¶
Creates a visualization figure of device matrix indices with permittivity configurations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_matrix_indices
|
Array
|
A 3D JAX array containing the device matrix indices. Shape should be (height, width, channels) where channels is typically 1. |
required |
permittivity_configs
|
tuple[tuple[str, float], ...]
|
A tuple of (name, value) pairs defining the permittivity configurations, where name is a string identifier (e.g., "Air") and value is the corresponding permittivity value. |
required |
Returns:
Type | Description |
---|---|
Figure
|
A matplotlib Figure object containing the visualization with: |
Figure
|
|
Figure
|
|
Figure
|
|
Figure
|
|
Figure
|
|
Raises:
Type | Description |
---|---|
AssertionError
|
If device_matrix_indices is not 3-dimensional. |
Source code in src/fdtdx/core/plotting/device_permittivity_index_utils.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
fdtdx.core.plotting.utils.plot_filled_std_curves(x, mean, color, lighter_color, std=None, upper=None, lower=None, linestyle='-', marker=None, label=None, alpha=0.2, min_val=None, max_val=None)
¶
Plots a curve with filled standard deviation or confidence intervals.
Creates a plot showing a mean curve with a filled region representing either standard deviation bounds or custom upper/lower bounds. The filled region uses a lighter color with transparency.
The function supports two modes: 1. Standard deviation mode: Provide std parameter to create bounds at mean ± std 2. Custom bounds mode: Provide explicit upper and lower bound arrays
The plotted curves can be optionally clipped to minimum/maximum values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
Array of x-axis values. |
required |
mean
|
ndarray
|
Array of y-axis values for the mean curve. |
required |
color
|
Any
|
Color for the mean curve line. |
required |
lighter_color
|
Any
|
Color for the filled standard deviation region. |
required |
std
|
Optional[ndarray]
|
Optional standard deviation array. If provided, used to compute upper/lower bounds. |
None
|
upper
|
Optional[ndarray]
|
Optional array of upper bound values. Must be provided with lower. |
None
|
lower
|
Optional[ndarray]
|
Optional array of lower bound values. Must be provided with upper. |
None
|
linestyle
|
str
|
Style of the mean curve line. Defaults to solid line "-". |
'-'
|
marker
|
Optional[str]
|
Optional marker style for data points on the mean curve. |
None
|
label
|
Optional[str]
|
Optional label for the plot legend. |
None
|
alpha
|
float
|
Transparency value for the filled region. Defaults to 0.2. |
0.2
|
min_val
|
Optional[float]
|
Optional minimum value to clip the curves. |
None
|
max_val
|
Optional[float]
|
Optional maximum value to clip the curves. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If neither std nor both upper/lower bounds are provided, or if only one of upper/lower is provided. |
Example
x = np.linspace(0, 10, 100) mean = np.sin(x) std = 0.1 * np.ones_like(x) plot_filled_std_curves(x, mean, 'blue', 'lightblue', std=std)
Source code in src/fdtdx/core/plotting/utils.py
fdtdx.core.plotting.debug.generate_unique_filename(prefix='file', extension=None)
¶
Generate a unique filename using timestamp and UUID.
Parameters:¶
prefix : str, optional Prefix for the filename extension : str, optional File extension (without dot)
Returns:¶
str : Unique filename
Source code in src/fdtdx/core/plotting/debug.py
fdtdx.core.plotting.debug.debug_plot_2d(array, cmap='viridis', show_values=False, tmp_dir='outputs/tmp/debug', filename=None)
¶
Creates a debug visualization of a 2D array and saves it to disk.
This function is useful for debugging array values during development and testing. It creates a heatmap visualization with optional value annotations and automatically saves it to a specified directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array
|
ndarray | Array
|
The 2D array to visualize. Can be either a numpy array or JAX array. |
required |
cmap
|
str
|
The matplotlib colormap to use for the visualization. Defaults to "viridis". |
'viridis'
|
show_values
|
bool
|
If True, overlays the numerical values on each cell. Defaults to False. |
False
|
tmp_dir
|
str | Path
|
Directory where the plot will be saved. Will be created if it doesn't exist. Defaults to "outputs/tmp/debug". |
'outputs/tmp/debug'
|
filename
|
str | None
|
Name for the output file. If None, generates a unique name using timestamp. The .png extension will be added automatically. |
None
|
The resulting plot includes
- A heatmap visualization of the array values
- A colorbar showing the value scale
- Grid lines for better readability
- Axis labels indicating array dimensions
- Optional numerical value annotations in each cell
Source code in src/fdtdx/core/plotting/debug.py
fdtdx.core.plotting.colors
¶
Color constants for visualization and plotting.
This module provides a collection of predefined RGB color tuples normalized to the range [0,1]. Colors are organized into categories: primary/bright colors, grayscale, and earth tones. These colors are designed to provide a consistent and visually appealing palette for plotting and visualization tasks throughout the FDTDX framework.
Each color is defined as a tuple of (red, green, blue) values normalized to [0,1]. The normalization is done by dividing 8-bit RGB values (0-255) by 255.
Categories
- Bright and primary colors: Vibrant colors for emphasis and contrast
- Grayscale colors: Various shades of gray for backgrounds and subtle elements
- Earth tones: Natural, warm colors for material representations
Example
import matplotlib.pyplot as plt plt.plot([0, 1], [0, 1], color=GREEN) # Plot a line in vibrant green plt.fill_between([0, 1], [0, 1], color=LIGHT_BLUE, alpha=0.3) # Fill with pale blue