Visualization

CLI tool: tdgl.visualize

tdgl.visualize is a command line interface (CLI) for animating and interactively viewing the time- and space-dependent results of TDGL simulations.

Visualize TDGL simulation data.

usage: python -m tdgl.visualize [-h] [-i INPUT] [-o OUTPUT] [-v]
                                [--shading {flat,gouraud}] [--dimensionless]
                                [--xlim XLIM XLIM] [--ylim YLIM YLIM]
                                [--axis-labels] [--autoscale] [--axes-off]
                                [--title-off] [--figsize FIGSIZE FIGSIZE]
                                [-d DPI]
                                {interactive,animate,monitor,convert,snapshot}
                                ...

Named Arguments

-i, --input

H5 file to visualize.

-o, --output

Output file path.

-v, --verbose

Run in verbose mode.

Default: False

--shading

Possible choices: flat, gouraud

Shading method, see matplotlib.pyplot.tripcolor.

Default: “gouraud”

--dimensionless

Use dimensionless x-y units.

Default: False

--xlim

x-axis limits

--ylim

y-axis limits

--axis-labels

Add x-y axis labels.

Default: False

--autoscale

Autoscale colorbar limits at each frame.

Default: False

--axes-off

Turn the axes off.

Default: False

--title-off

Turn figure title off.

Default: False

--figsize

Figure size (width, height) in inches.

-d, --dpi

Resolution in dots per inch.

Default: 200

Sub-commands

interactive

Create an interactive plot of one or more quantities.

python -m tdgl.visualize interactive [-h]
                                     [-q [{ORDER_PARAMETER,PHASE,SUPERCURRENT,NORMAL_CURRENT,VORTICITY,SCALAR_POTENTIAL,APPLIED_VECTOR_POTENTIAL,INDUCED_VECTOR_POTENTIAL,EPSILON,ALL} ...]]
Named Arguments
-q, --quantities

Possible choices: ORDER_PARAMETER, PHASE, SUPERCURRENT, NORMAL_CURRENT, VORTICITY, SCALAR_POTENTIAL, APPLIED_VECTOR_POTENTIAL, INDUCED_VECTOR_POTENTIAL, EPSILON, ALL

Name(s) of the quantities to show.

animate

Create an animation of the TDGL data.

python -m tdgl.visualize animate [-h] [-f FPS] [--min-frame MIN_FRAME]
                                 [--max-frame MAX_FRAME]
                                 [-q [{ORDER_PARAMETER,PHASE,SUPERCURRENT,NORMAL_CURRENT,VORTICITY,SCALAR_POTENTIAL,APPLIED_VECTOR_POTENTIAL,INDUCED_VECTOR_POTENTIAL,EPSILON,ALL} ...]]
Named Arguments
-f, --fps

Frame rate of the animation.

Default: 30

--min-frame

The first frame to render.

Default: 0

--max-frame

The last frame to render (-1 indicates the last step in the simulation).

Default: -1

-q, --quantities

Possible choices: ORDER_PARAMETER, PHASE, SUPERCURRENT, NORMAL_CURRENT, VORTICITY, SCALAR_POTENTIAL, APPLIED_VECTOR_POTENTIAL, INDUCED_VECTOR_POTENTIAL, EPSILON, ALL

Name(s) of the quantities to show.

monitor

Visualize the results of a simulation as it is running.

python -m tdgl.visualize monitor [-h] [--interval INTERVAL]
                                 [-q [{ORDER_PARAMETER,PHASE,SUPERCURRENT,NORMAL_CURRENT,VORTICITY,SCALAR_POTENTIAL,APPLIED_VECTOR_POTENTIAL,INDUCED_VECTOR_POTENTIAL,EPSILON,ALL} ...]]
Named Arguments
--interval

Monitor update interval in seconds.

Default: 1

-q, --quantities

Possible choices: ORDER_PARAMETER, PHASE, SUPERCURRENT, NORMAL_CURRENT, VORTICITY, SCALAR_POTENTIAL, APPLIED_VECTOR_POTENTIAL, INDUCED_VECTOR_POTENTIAL, EPSILON, ALL

Name(s) of the quantities to show.

convert

Convert a Solution from HDF5 to another data format.

python -m tdgl.visualize convert [-h] [--format {xdmf}]
Named Arguments
--format

Possible choices: xdmf

Data format into which to convert the Solution.

snapshot

Generate snapshots of a Solution.

python -m tdgl.visualize snapshot [-h] [-t TIMES [TIMES ...]]
                                  [-q [{ORDER_PARAMETER,PHASE,SUPERCURRENT,NORMAL_CURRENT,VORTICITY,SCALAR_POTENTIAL,APPLIED_VECTOR_POTENTIAL,INDUCED_VECTOR_POTENTIAL,EPSILON,ALL} ...]]
Named Arguments
-t, --times

The time(s) at which to generate a snapshot.

-q, --quantities

Possible choices: ORDER_PARAMETER, PHASE, SUPERCURRENT, NORMAL_CURRENT, VORTICITY, SCALAR_POTENTIAL, APPLIED_VECTOR_POTENTIAL, INDUCED_VECTOR_POTENTIAL, EPSILON, ALL

Name(s) of the quantities to show.

Create animations

tdgl.visualization.create_animation(input_file, *, output_file=None, quantities=('order_parameter', 'phase', 'supercurrent', 'normal_current'), shading='gouraud', fps=30, dpi=100, max_cols=4, min_frame=0, max_frame=-1, autoscale=False, dimensionless=False, xlim=None, ylim=None, axis_labels=False, axes_off=False, title_off=False, full_title=True, logger=None, figure_kwargs=None, writer=None)[source]

Generates, and optionally saves, and animation of a TDGL simulation.

Parameters
  • input_file (Union[str, File]) – An open h5py file or a path to an H5 file containing the tdgl.Solution you would like to animate.

  • output_file (Optional[str]) – A path to which to save the animation, e.g., as a gif or mp4 video.

  • quantities (Union[str, Sequence[str]]) – The names of the quantities to animate.

  • shading (Literal['flat', 'gouraud']) – Shading method, “flat” or “gouraud”. See matplotlib.pyplot.tripcolor.

  • fps (int) – Frame rate in frames per second.

  • dpi (float) – Resolution in dots per inch.

  • max_cols (int) – The maxiumum number of columns in the subplot grid.

  • min_frame (int) – The first frame of the animation.

  • max_frame (int) – The last frame of the animation.

  • autoscale (bool) – Autoscale colorbar limits at each frame.

  • dimensionless (bool) – Use dimensionless units for axes

  • xlim (Optional[Tuple[float, float]]) – x-axis limits

  • ylim (Optional[Tuple[float, float]]) – y-axis limits

  • axes_off (bool) – Turn off the axes for each subplot.

  • title_off (bool) – Turn off the figure suptitle.

  • full_title (bool) – Include the full “state” for each frame in the figure suptitle.

  • figure_kwargs (Optional[Dict[str, Any]]) – Keyword arguments passed to plt.subplots() when creating the figure.

  • writer (Union[str, MovieWriter, None]) – A matplotlib.animation.MovieWriter instance to use when saving the animation.

  • logger (Optional[Logger]) – A logger instance to use.

  • axis_labels (bool) –

Return type

FuncAnimation

Returns

The animation as a matplotlib.animation.FuncAnimation.

Plot Solutions

tdgl.plot_currents(solution, ax=None, dataset=None, units=None, cmap='inferno', colorbar=True, auto_range_cutoff=None, symmetric_color_scale=False, vmin=None, vmax=None, streamplot=True, min_stream_amp=0.025, cross_section_coords=None, **kwargs)[source]

Plots the sheet current density for a given tdgl.Solution.

Additional keyword arguments are passed to plt.subplots().

Parameters
  • solution (Solution) – The Solution from which to extract sheet current.

  • dataset (Optional[str]) – The dataset to plot, either "supercurrent" or "normal_current". None indicates the total current density.

  • ax (Optional[Axes]) – Matplotlib axes on which to plot.

  • units (Optional[str]) – Units in which to plot the current density. Defaults to solution.current_units / solution.device.length_units.

  • cmap (str) – Name of the matplotlib colormap to use.

  • colorbar (bool) – Whether to add a colorbar to each subplot.

  • auto_range_cutoff (Union[float, Tuple[float, float], None]) – Cutoff percentile for tdgl.solution.plot_solution.auto_range_iqr().

  • symmetric_color_scale (bool) – Whether to use a symmetric color scale (vmin = -vmax).

  • vmin (Optional[float]) – Color scale minimum to use for all layers

  • vmax (Optional[float]) – Color scale maximum to use for all layers

  • streamplot (bool) – Whether to overlay current streamlines on the plot.

  • min_stream_amp (float) – Streamlines will not be drawn anywhere the current density is less than min_stream_amp * max(current_density). This avoids streamlines being drawn where there is no current flowing.

  • cross_section_coords (Union[ndarray, Sequence[ndarray], None]) – Shape (m, 2) array of (x, y) coordinates for a cross-section (or a list of such arrays).

Return type

Tuple[Figure, Sequence[Axes]]

Returns

matplotlib figure and axes

tdgl.plot_order_parameter(solution, squared=False, mag_cmap='viridis', phase_cmap='twilight_shifted', shading='gouraud', **kwargs)[source]

Plots the magnitude (or the magnitude squared) and phase of the complex order parameter, \(\psi=|\psi|e^{i\theta}\).

Parameters
  • solution (Solution) – The solution for which to plot the order parameter.

  • squared (bool) – Whether to plot the magnitude squared, \(|\psi|^2\).

  • mag_cmap (str) – Name of the colormap to use for the magnitude.

  • phase_cmap (str) – Name of the colormap to use for the phase.

  • shading (str) – May be "flat" or "gouraud". The latter does some interpolation.

Return type

Tuple[Figure, Sequence[Axes]]

Returns

matplotlib Figure and an array of two Axes objects.

tdgl.plot_field_at_positions(solution, positions, zs=None, vector=False, units=None, grid_shape=(200, 200), grid_method='cubic', cmap='cividis', colorbar=True, auto_range_cutoff=None, share_color_scale=False, symmetric_color_scale=False, vmin=None, vmax=None, cross_section_coords=None, **kwargs)[source]

Plots the Biot-Savart field (either all three components or just the z component) at a given set of positions (x, y, z) outside of the device.

Note

This function plots only the field due to currents flowing in the device. It does not include the applied field.

Additional keyword arguments are passed to plt.subplots(). This function first evaluates the field at positions, then interpolates the resulting fields to a rectangular grid for plotting.

Parameters
  • solution (Solution) – The Solution from which to extract fields.

  • positions (ndarray) – Shape (m, 2) array of (x, y) coordinates, or (m, 3) array of (x, y, z) coordinates at which to calculate the magnetic field.

  • zs (Union[float, ndarray, None]) – z coordinates at which to calculate the field. If positions has shape (m, 3), then this argument is not allowed. If zs is a scalar, then the fields are calculated in a plane parallel to the x-y plane. If zs is an array, then it must be same length as positions.

  • vector (bool) – Whether to plot the full vector magnetic field or just the z component.

  • units (Optional[str]) – Units in which to plot the fields. Defaults to solution.field_units.

  • grid_shape (Union[int, Tuple[int, int]]) – Shape of the desired rectangular grid. If a single integer n is given, then the grid will be square, shape (n, n).

  • grid_method (str) – Interpolation method to use (see scipy.interpolate.griddata()).

  • max_cols – Maximum number of columns in the grid of subplots.

  • cmap (str) – Name of the matplotlib colormap to use.

  • colorbar (bool) – Whether to add a colorbar to each subplot.

  • auto_range_cutoff (Union[float, Tuple[float, float], None]) – Cutoff percentile for tdgl.solution.plot_solution.auto_range_iqr().

  • share_color_scale (bool) – Whether to force all layers to use the same color scale.

  • symmetric_color_scale (bool) – Whether to use a symmetric color scale (vmin = -vmax).

  • vmin (Optional[float]) – Color scale minimum to use for all layers

  • vmax (Optional[float]) – Color scale maximum to use for all layers

  • cross_section_coords (Union[float, List[float], None]) – Shape (m, 2) array of (x, y) coordinates for a cross-section (or a list of such arrays).

Return type

Tuple[Figure, Sequence[Axes]]

Returns

matplotlib figure and axes

tdgl.plot_vorticity(solution, ax=None, cmap='coolwarm', units=None, auto_range_cutoff=None, symmetric_color_scale=True, vmin=None, vmax=None, shading='gouraud', **kwargs)[source]

Plots the vorticity in the film: \(\mathbf{\omega}=\mathbf{\nabla}\times\mathbf{K}\).

Parameters
  • solution (Solution) – The solution for which to plot the vorticity.

  • ax (Optional[Axes]) – Matplotlib axes on which to plot.

  • cmap (str) – Name of the matplotlib colormap to use.

  • units (Optional[str]) – The units in which to plot the vorticity. Must have dimensions of [current] / [length]^2.

  • auto_range_cutoff (Union[float, Tuple[float, float], None]) – Cutoff percentile for tdgl.solution.plot_solution.auto_range_iqr().

  • symmetric_color_scale (bool) – Whether to use a symmetric color scale (vmin = -vmax).

  • vmin (Optional[float]) – Color scale minimum.

  • vmax (Optional[float]) – Color scale maximum.

  • shading (str) – May be "flat" or "gouraud". The latter does some interpolation.

Returns

matplotlib Figure and and Axes.

tdgl.plot_scalar_potential(solution, ax=None, cmap='magma', auto_range_cutoff=None, vmin=None, vmax=None, shading='gouraud', **kwargs)[source]

Plots the scalar potential \(\mu(\mathbf{r})\) in the film.

Parameters
  • solution (Solution) – The solution for which to plot the scalar potential.

  • ax (Optional[Axes]) – Matplotlib axes on which to plot.

  • cmap (str) – Name of the matplotlib colormap to use.

  • auto_range_cutoff (Union[float, Tuple[float, float], None]) – Cutoff percentile for tdgl.solution.plot_solution.auto_range_iqr().

  • vmin (Optional[float]) – Color scale minimum.

  • vmax (Optional[float]) – Color scale maximum.

  • shading (str) – May be "flat" or "gouraud". The latter does some interpolation.

Returns

matplotlib Figure and and Axes.

tdgl.plot_current_through_paths(solution_path, paths, dataset=None, interp_method='linear', units=None, progress_bar=True, grid=True, labels=True, legend=True, **figure_kwargs)[source]

Plots the current through one or more paths for each saved time step.

Parameters
  • solution_path (str) – Path to the solution HDF5 file.

  • paths (Union[ndarray, List[ndarray]]) – A list of (n, 2) arrays of (x, y) coordinates defining the paths. A single (n, 2) array is also allowed.

  • dataset (Optional[str]) – None, "supercurrent", or "normal_current". None indicates the total current.

  • interp_method (Literal['linear', 'cubic']) – Interpolation method: either “linear” or “cubic”.

  • units (Optional[str]) – The current units to return.

  • with_units – Whether to return a pint.Quantity with units attached.

  • progress_bar (bool) – Whether to display a progress bar.

  • grid (bool) – Whether to add grid lines to the plot.

  • labels (bool) – Whether to include axis labels.

  • legend (bool) – Whether to include a legend.

Return type

Tuple[Tuple[Figure, Axes], Tuple[ndarray, Union[ndarray, List[ndarray]]]]

Returns

(fig, ax), (times, currents), where currents is a list of arrays of the time-dependent current through each path. If paths is given as a single array, currents will be returned as a single array.

Plotting utilities

tdgl.visualization.convert_to_xdmf(path_to_solution, xdmf_path=None, dimensionless=False)[source]

Convert a tdgl.Solution from HDF5 to XDMF.

XDMF files can be viewed using tools like ParaView. This function requires the meshio Python package.

Parameters
  • path_to_solution (str) – Path to the HDF5 file containing the tdgl.Solution

  • xdmf_path (Optional[str]) – Path to the output XDMF file. Defaults to path_to_solution.replace('.h5', '-converted.xdmf')

  • dimensionless (bool) – Save the mesh in dimensionless units (scaled to the coherence length).

Return type

None

tdgl.visualization.auto_range_iqr(data_array, cutoff_percentile=1)[source]

Get the min and max range of the provided array that excludes outliers following the IQR rule.

This function computes the inter-quartile-range (IQR), defined by Q3-Q1, i.e. the percentiles for 75 and 25 percent of the distribution. The region without outliers is defined by [Q1-1.5*IQR, Q3+1.5*IQR]. Taken from qcodes.

Parameters
  • data_array (ndarray) – Array of arbitrary dimension containing the statistical data.

  • cutoff_percentile (Union[float, Tuple[float, float]]) – Percentile of data that may maximally be clipped on both sides of the distribution. If given a tuple (a, b) the percentile limits will be a and 100-b.

Return type

Tuple[float, float]

Returns

vmin, vmax

tdgl.visualization.auto_grid(num_plots, max_cols=3, delaxes=True, **kwargs)[source]

Creates a grid of at least num_plots subplots with at most max_cols columns.

Additional keyword arguments are passed to plt.subplots().

Parameters
  • num_plots (int) – Total number of plots that will be populated.

  • max_cols (int) – Maximum number of columns in the grid.

  • delaxes (bool) – Whether to remove unused axes.

Return type

Tuple[Figure, Sequence[Axes]]

Returns

matplotlib figure and axes

tdgl.non_gui_backend()[source]

A contextmanager that temporarily uses a non-GUI backend for matplotlib.