plotting module

plotting.py is a subroutine of EMUstack that contains numerous plotting routines.

Copyright (C) 2015 Bjorn Sturmberg, Kokou Dossou, Felix Lawrence

EMUstack is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

plotting.BM_amplitudes(stacks_list, xvalues=None, chosen_BMs=None, lay_interest=1, up_and_down=True, add_height=None, add_name='', save_pdf=False, save_npz=False, save_txt=False)[source]

Plot the amplitudes of Bloch modes in selected layer.

Parameters:

stacks_list (list) – Stack objects containing data to plot.

Keyword Arguments:
  • xvalues (list) – The values stacks_list is to be plotted as a function of.

  • chosen_BMs (list) – Bloch Modes to include, identified by their indices in the scattering matrices (order most propagating to most evanescent) eg. [0,2,4].

  • lay_interest (int) – The index in stacks_list of the layer in which amplitudes are calculated.

  • up_and_down (bool) – Average the amplitudes of up & downward propagating modes. Else include only downward in all layers except for the superstrate where include only upward.

  • add_height (float) – Print the heights of :Stack: layer in title.

  • add_name (str) – Add add_name to title.

  • save_pdf (bool) – If True, save plot as PDF. False by default.

  • save_npz (bool) – If True, saves lists of BM amplitudes to file.

  • save_txt (bool) – If True, saves lists of BM amps to txt file.

plotting.Bloch_fields_1d(stacks_list, lay_interest=None, save_pdf=False)[source]

Plot Bloch mode fields along the x axis.

Args:

stacks_list (list): Stack objects containing data to plot.

Keyword Args:

lay_interest (int): the index of the layer considered within the stack. Must be a 1D_array NanoStruct layer. By default routine finds all such layers.

save_pdf (bool): If True, save figures as PDF files. False by default.

plotting.EOT_plot(stacks_list, wavelengths=None, pol='TM', params_layer=1, add_name='', savetxt=False, save_pdf=False)[source]

Plot T_{00} as in Martin-Moreno PRL 86 2001.

Parameters:

pol (str) – Take the (0,0) component for TE->TE scattering or the (0,0) component for TM->TM scattering.

plotting.E_conc_plot(stacks_list, which_layer, which_modes, wavelengths, params_layer=1, stack_label=1, save_pdf=False)[source]

Plots the energy concentration (epsilon E_cyl / epsilon E_cell) of given layer.

Parameters:
  • stacks_list (list) – Stack objects containing data to plot.

  • which_layer (int) – The index in stacks_list of the layer for which the energy concentration is to be calculated.

  • which_modes (list) – Indices of Bloch modes for which to calculate the energy concentration.

  • wavelengths (list) – The wavelengths corresponding to stacks_list.

Keyword Arguments:
  • params_layer (int) – The index in stacks_list of the layer for which the geometric parameters are put in the title of the plots.

  • stack_label (int) – Label to differentiate plots of different :Stack:s.

  • save_pdf (bool) – If True, save plot to PDF file. False by default.

plotting.Fabry_Perot_res(stacks_list, freq_list, kx_list, f_0, k_0, lay_interest=1, save_pdf=False)[source]

Calculate the Fabry-Perot resonance condition for a resonances within a layer.

This is equivalent to finding the slab waveguide modes of the layer.

Parameters:
  • stacks_list (list) – Stack objects containing data to plot.

  • freq_list (list) – Frequencies included.

  • kx_list (list) – In-plane wavenumbers included.

  • f_0 (list) – Frequency w.r.t. which axis is normalised.

  • k_0 (list) – In-plane wavenumber w.r.t. which axis is normalised.

Keyword Arguments:
  • lay_interest (int) – The index in stacks_list of the layer of which F-P resonances are calculated.

  • save_pdf (bool) – If True, save plot as PDF. False by default.

class plotting.FieldBundle(ReEx, ImEx, ReEy, ImEy, ReEz, ImEz, AbsE, ReHx, ImHx, ReHy, ImHy, ReHz, ImHz, AbsH, k0=None, interface_z_nm=None, plane=None, slice_coord=None, u_grid=None, v_grid=None)[source]

Bases: object

Container for 2D electromagnetic field (E and H) interpolators.

Can be unpacked as a 14-tuple: (ReEx, ImEx, ReEy, ImEy, ReEz, ImEz, AbsE, ReHx, ImHx, ReHy, ImHy, ReHz, ImHz, AbsH) or accessed via named attributes.

Ex(x, y)[source]
Ey(x, y)[source]
Ez(x, y)[source]
Hx(x, y)[source]
Hy(x, y)[source]
Hz(x, y)[source]
Poynting(u, v)[source]

Evaluate 3D time-averaged Poynting vector (Sx, Sy, Sz) = 0.5 * Re(E x H*).

Sz(x, y)[source]

Evaluate z-component of time-averaged Poynting vector: Sz = 0.5 * Re(Ex * Hy^* - Ey * Hx^*).

chirality(u, v)[source]

Evaluate optical chirality density C = -0.5 * k0 * Im(E* . H).

chirality_enhancement(u, v)[source]

Evaluate local optical chirality enhancement normalized to CPL: C_hat = -Im(E* . H).

to_xarray(u_1d, v_1d, dims=('y', 'x'), period=1.0, fixed_coord=None, include_H=True, include_chirality=True)[source]
class plotting.GridInterpolatorWrapper(rgi)[source]

Bases: object

Wrapper around scipy.interpolate.RegularGridInterpolator so it can be called as f(u, v).

plotting.J_sc_eta_NO_plots(stacks_list, wavelengths, params_layer=1, active_layer_nu=1, stack_label=1, add_name='')[source]

Calculate J_sc & ultimate efficiency but do not save or plot spectra.

Parameters:
  • stacks_list (list) – Stack objects containing data to plot.

  • wavelengths (list) – The wavelengths corresponding to stacks_list.

Keyword Arguments:
  • params_layer (int) – The index in stacks_list of the layer for which the geometric parameters are put in the title of the plots.

  • active_layer_nu (int) – The index in stacks_list (from bottom) of the layer for which the ult_eta and/or J_sc are calculated.

  • stack_label (int) – Label to differentiate plots of different :Stack:s.

  • add_name (str) – Add add_name to title.

plotting.J_short_circuit(active_abs, wavelengths, params_2_print='', stack_label='', add_name='', save_txt=False)[source]

Calculate the short circuit current J_sc under ASTM 1.5 illumination. Assuming every absorbed photon produces a pair of charge carriers.

plotting.PW_amplitudes(stacks_list, xvalues=None, chosen_PWs=None, lay_interest=0, up_and_down=True, add_height=None, add_name='', save_pdf=False, save_npz=False, save_txt=False)[source]

Plot the amplitudes of plane wave orders in selected layer.

Assumes dealing with 1D grating and only have 1D diffraction orders. Takes the average of up & downward propagating modes.

Parameters:

stacks_list (list) – Stack objects containing data to plot.

Keyword Arguments:
  • xvalues (list) – The values stacks_list is to be plotted as a function of.

  • chosen_PWs (list) – PW diffraction orders to include. eg. [-1,0,2]. If ‘None’ are given all are plotted.

  • lay_interest (int) – The index in stacks_list of the layer in which amplitudes are calculated.

  • up_and_down (bool) – Average the amplitudes of up & downward propagating modes. Else include only downward in all layers except for the superstrate where include only upward.

  • add_height (float) – Print the heights of :Stack: layer in title.

  • add_name (str) – Add add_name to title.

  • save_pdf (bool) – If True, save plot to PDF. False by default.

  • save_npz (bool) – If True, saves lists of PW amplitudes to file.

  • save_txt (bool) – If True, saves lists of PW amps to txt file.

plotting.clear_previous()[source]

Delete all generated simulation files of specified type as well as field directories.

plotting.evanescent_merit(stacks_list, xvalues=None, chosen_PWs=None, lay_interest=0, add_height=None, add_name='', save_pdf=False, save_txt=False)[source]

Plot a figure of merit for the ‘evanescent-ness’ of excited fields.

Assumes dealing with 1D grating and only have 1D diffraction orders.

Parameters:

stacks_list (list) – Stack objects containing data to plot.

Keyword Arguments:
  • xvalues (list) – The values stacks_list is to be plotted as a function of.

  • chosen_PWs (list) – PW diffraction orders to include. eg. [-1,0,2].

  • lay_interest (int) – The index in stacks_list of the layer in which amplitudes are calculated.

  • add_height (float) – Print the heights of :Stack: layer in title.

  • add_name (str) – Add add_name to title.

  • save_pdf (bool) – If True, save plot to PDF. False by default.

  • save_txt (bool) – If True, saves average value of mean PW order to file.

plotting.extinction_plot(t_spec, wavelengths, params_2_print, stack_label, add_name, save_pdf=False)[source]

Plot extinction ratio in transmission extinct = log_10(1/t).

plotting.field_values(stacks_list, lay_interest=0, xyz_values=[(0.1, 0.1, 0.1)], save_files=False)[source]

Save electric field values at given x-y-z points. Points must be within a ThinFilm layer. In txt file fields are given as Re(Ex) Im(Ex) Re(Ey) Im(Ey) Re(Ez) Im(Ez) |E|

Args:

stacks_list (list): Stack objects containing data to plot.

Keyword Args:

lay_interest (int): the index of the layer considered within the stack. Must be a ThinFilm layer.

xyz_values (list): list of distances in normalised units of (d) from top surface of layer at which to calculate fields. For semi-inf substrate then z_value is distance from top of this layer (i.e. bottom interface of stack).

save_files (bool): If True, save npz and txt files to disk. False by default.

plotting.fields_3d(stacks_list, lay_interest=1)[source]

Plot fields in 3D using gmsh.

Args:

stacks_list (list): Stack objects containing data to plot.

Keyword Args:

lay_interest (int): the index of the layer considered within the stack.

plotting.fields_in_plane(stacks_list, lay_interest=1, z_values=[0.1, 3.6], nu_calc_pts=51, save_pdf=False, save_pos=False)[source]

Plot fields in the x-y plane at chosen values of z.

Args:

stacks_list (list): Stack objects containing data to plot.

Keyword Args:

lay_interest (int): the index of the layer considered within the stack.

z_values (float): distance in nm from bottom surface of layer at which to calculate fields. If layer is semi-inf substrate then z_value is distance from top of this layer (i.e. bottom interface of stack).

nu_calc_pts (int): fields are calculated over a mesh of nu_calc_pts * nu_calc_pts points.

save_pdf (bool): If True, save plots to PDF. False by default. save_pos (bool): If True, save Gmsh .pos files. False by default.

plotting.fields_interpolator_cross_section(pstack, plane='xz', slice_coord=0.5, lay_interest=None, n_horiz=151, n_vert_per_layer=61, semi_inf_height=0.5, return_H=True, return_h=False)[source]

Returns 2D cross-section interpolators (FieldBundle) along the xz or yz plane.

Inside any EMUstack layer, the electromagnetic field is separable: E(x, y, z) = sum_m [ P^+_m(z) e_{t,m}(x, y) + P^-_m(z) z_hat (-i k_{z,m} e_{z,m}(x, y)) ] allowing fast, vectorized cross-section evaluation via 1D line interpolation combined with matrix multiplication across z.

Parameters:

pstack – Evaluated Stack object.

Keyword Arguments:
  • plane (str) – ‘xz’ (default) or ‘yz’.

  • slice_coord (float) – Fixed coordinate value in [0, 1] (y for ‘xz’, x for ‘yz’).

  • lay_interest (int or None) – Specific layer index, or None to evaluate and stitch all layers in the stack.

  • n_horiz (int) – Number of horizontal grid points along the cut.

  • n_vert_per_layer (int) – Number of vertical grid points per layer.

  • semi_inf_height (float) – Normalized vertical extent for semi-infinite substrate/superstrate.

  • return_H (bool) – If True (default), returns FieldBundle (14 interpolators).

  • return_h (bool) – Alias for return_H.

Returns:

FieldBundle (if return_H=True) or 7-tuple (if return_H=False).

plotting.fields_interpolator_in_plane(pstack, lay_interest=1, z_value=0.1, return_H=False, return_h=False)[source]

Returns linear interpolators in the x-y plane at chosen value of z.

If return_H is False (default):

Returns 7-tuple: (ReEx, ImEx, ReEy, ImEy, ReEz, ImEz, AbsE).

If return_H is True (or return_h is True):

Returns FieldBundle containing 14 interpolators for E and H.

The interpolators take in-plane coordinates normalized to the period: x from 0 to 1 and y from 0 to period_y/period, whichever mesher (gmsh or netgen) built the layer. Points outside the unit cell return masked values.

Requires matplotlib v1.3.0 or later.

Args:

pstack: Stack object (not a list!!!) containing data to plot.

Keyword Args:

lay_interest (int): the index of the layer considered within the stack.

z_value (float): distance in nm from bottom surface of layer at which to calculate fields. If layer is semi-inf substrate then z_value is distance from top of this layer (i.e. bottom interface of stack).

return_H (bool): If True, compute both E and H fields, returning a FieldBundle instance (which can also be unpacked as a 14-tuple). return_h (bool): Alias for return_H.

plotting.fields_vertically(stacks_list, factor_pts_vert=31, nu_pts_hori=41, semi_inf_height=1.0, gradient=None, no_incoming=False, add_name='', force_eq_ratio=False, colour_res=30, plot_boundaries=True, save_pdf=False, save_png=False)[source]

Plot fields in the x-y plane at chosen values of z, where z is calculated from the bottom of chosen layer.

Args:

stacks_list (list): Stack objects containing data to plot.

Keyword Args:

factor_pts_vert (int): sampling factor for fields vertically. Calculated as factor_pts_vert * (epsilon*h/wl).

nu_pts_hori (int): in-plane fields are calculated over a mesh of nu_pts_hori * nu_pts_hori points.

semi_inf_height (float): distance to which fields are plotting in semi-infinite (sub)superstrates.

gradient (float): further slices calculated with given gradient and -gradient. It is entitled ‘specified_diagonal_slice’. These slices are only calculated for ThinFilm layers.

no_incoming (bool): if True, plots fields in superstrate in the absence of the incident driving field (i.e. only showing upward propagating scattered field).

add_name (str): concatenate add_name to title.

force_eq_ratio (bool): each layer plotted on equal space.

colour_res (int): number of colour intervals to use.

plot_boundaries (bool): plot boundaries of inclusions.

save_pdf (bool): If True, save plots as PDF. False by default.

save_png (bool): If True, save plots as PNG. False by default.

plotting.gen_params_string(stack, layer=1)[source]

Generate the string of simulation info that is to be printed at the top of plots.

plotting.layers_plot(spectra_name, spec_list, xvalues, xlabel, total_h, params_2_print, stack_label, add_name, save_pdf=False, save_txt=False, label_eV=False, set_y_lim=True)[source]

Plots one type of spectrum across all layers.

Is called from t_r_a_plots.

plotting.layers_print(spectra_name, spec_list, wavelengths, total_h, stack_label=1, add_name='')[source]

Save spectra to text files.

Is called from t_r_a_write_files.

plotting.max_n(stacks_list)[source]

Find maximum refractive index n in stacks_list.

plotting.omega_plot(stacks_list, wavelengths=None, params_layer=1, stack_label=1, save_pdf=False)[source]

Plots the dispersion diagram of each layer in one plot. k_z has units nm^-1.

Parameters:
  • stacks_list (list) – Stack objects containing data to plot.

  • wavelengths (list) – The wavelengths corresponding to stacks_list.

Keyword Arguments:
  • params_layer (int) – The index in stacks_list of the layer for which the geometric parameters are put in the title of the plots.

  • stack_label (int) – Label to differentiate plots of different :Stack:s.

  • save_pdf (bool) – If True, save plots to PDF files. False by default.

plotting.spectra_to_xarray(stacks_list, wavelengths=None)[source]

Extract T_total, R_total, A_total, and per-layer T, R, A into an xarray.Dataset.

Parameters:
  • stacks_list (list or Stack) – List of evaluated Stack objects (or single Stack).

  • wavelengths (array-like, optional) – Wavelength coordinates. Defaults to stack wavelengths.

Returns:

Labeled dataset with coordinates ‘wavelength’ (nm) and ‘layer_index’.

Return type:

xarray.Dataset

plotting.t_func_k_plot_1D(stacks_list, lay_interest=0, pol='TE', save_pdf=False)[source]

PW amplitudes in transmission as a function of their in-plane k-vector.

Parameters:

stacks_list (list) – Stack objects containing data to plot.

Keyword Arguments:
  • lay_interest (int) – The index in stacks_list of the layer in which amplitudes are calculated.

  • pol (str) – Include transmission in Which polarisation.

  • save_pdf (bool) – If True, save plot to PDF file. False by default.

plotting.t_r_a_plots(stacks_list, xvalues=None, xlabel='', params_layer=1, active_layer_nu=1, stack_label=1, ult_eta=False, J_sc=False, weight_spec=False, extinct=False, add_height=0, add_name='', save_pdf=False, save_txt=False, plot_layers=False, set_y_lim=True, label_eV=False)[source]

Plot t, r, a for each layer & in total.

Parameters:

stacks_list (list) – Stack objects containing data to plot.

Keyword Arguments:
  • xvalues (list) – The values stacks_list is to be plotted as a function of.

  • params_layer (int) – The index in stacks_list of the layer for which the geometric parameters are put in the title of the plots.

  • active_layer_nu (int) – The index in stacks_list (from bottom) of the layer for which the ult_eta and/or J_sc are calculated.

  • stack_label (int) – Label to differentiate plots of different :Stack:s.

  • ult_eta (bool) – If True; calculate the ‘ultimate efficiency’.

  • J_sc (bool) – If True; calculate the idealised short circuit current.

  • weight_spec (bool) – If True; plot t, r, a spectra weighted by the ASTM 1.5 solar spectrum.

  • extinct (bool) – If True; calculate the extinction ratio in transmission.

  • add_height (float) – Print the heights of :Stack: layer in title.

  • add_name (str) – Add add_name to title.

  • save_pdf (bool) – If True; save spectra as pdf files. False by default.

  • save_txt (bool) – If True; save spectra data to text files. False by default.

  • plot_layers (bool) – If True; plot per-layer spectra even if save_pdf is False.

  • set_y_lim (bool) – If True; set y limits to (0,1).

  • label_eV (bool) – If True; add energy label in eV.

plotting.t_r_a_plots_subs(stacks_list, wavelengths, period, sub_n, params_layer=1, active_layer_nu=1, stack_label=1, ult_eta=False, J_sc=False, weight_spec=False, extinct=False, add_name='', save_pdf=False, save_txt=False)[source]

Plot t, r, a indicating Wood anomalies in substrate for each layer & total.

Parameters:
  • stacks_list (list) – Stack objects containing data to plot.

  • wavelengths (list) – The wavelengths corresponding to stacks_list.

  • period (float) – Period of :Stack:s.

  • sub_n (float) – Refractive index of the substrate in which Wood anomalies are considered.

Keyword Arguments:
  • params_layer (int) – The index in stacks_list of the layer for which the geometric parameters are put in the title of the plots.

  • active_layer_nu (int) – The index in stacks_list (from bottom) of the layer for which the ult_eta and/or J_sc are calculated.

  • stack_label (int) – Label to differentiate plots of different :Stack:s.

  • ult_eta (bool) – If True, calculate the ‘ultimate efficiency’.

  • J_sc (bool) – If True, calculate the idealised short circuit current.

  • weight_spec (bool) – If True, plot t, r, a spectra weighted by the ASTM 1.5 solar spectrum.

  • extinct (bool) – If True, calculate the extinction ratio in transmission.

  • add_name (str) – Add add_name to title.

  • save_pdf (bool) – If True, save plot as PDF. False by default.

  • save_txt (bool) – If True, save spectra to txt. False by default.

plotting.t_r_a_write_files(stacks_list, wavelengths, stack_label=1, add_name='')[source]

Save t, r, a for each layer & total in text files.

Parameters:
  • stacks_list (list) – Stack objects containing data to plot.

  • wavelengths (list) – The wavelengths corresponding to stacks_list.

Keyword Arguments:
  • stack_label (int) – Label to differentiate plots of different :Stack:s.

  • add_name (str) – Add add_name to title.

plotting.tick_function(energies)[source]

Convert energy in eV into wavelengths in nm

plotting.total_tra_plot(plot_name, a_spec, t_spec, r_spec, xvalues, xlabel, params_2_print, stack_label, add_name, label_eV=False, set_y_lim=True, save_pdf=False)[source]

Plots total t, r, a spectra on one plot.

Is called from t_r_a_plots, t_r_a_plots_subs

plotting.total_tra_plot_subs(plot_name, a_spec, t_spec, r_spec, wavelengths, params_2_print, stack_label, add_name, period, sub_n, save_pdf=False)[source]

Plots total t, r, a spectra with lines at first 6 Wood anomalies.

Is called from t_r_a_plots_subs

plotting.ult_efficiency(active_abs, wavelengths, bandgap_wl=None, params_2_print='', stack_label='', add_name='', save_txt=False)[source]

Calculate the photovoltaic ultimate efficiency achieved in the specified active layer.

For definition see Sturmberg et al., Optics Express, Vol. 19, Issue S5, pp. A1067-A1081 (2011).

Parameters:

bandgap_wl (float) – allows you to set the wavelength equivalent to the bandgap. Else it is assumed to be the maximum wavelength simulated.

plotting.vis_matrix(scat_mat, add_name='', max_scale=None, only_real=False, save_pdf=False)[source]

Plot given matrix as a greyscale image.

Parameters:

scat_mat (np.matrix) – A matrix.

Keyword Arguments:
  • add_name (str) – Add add_name to title.

  • max_scale (float) – Limit maximum amplitude shown.

  • only_real (bool) – Only plot the real part of matrix.

  • save_pdf (bool) – If True, save plot to PDF file. False by default.

plotting.vis_scat_mats(scat_mat, nu_prop_PWs=0, wl=None, add_name='', max_scale=None, save_pdf=False)[source]

Plot given scattering matrix as greyscale images.

Parameters:

scat_mat (np.matrix) – A scattering matrix, which is organised as | TE -> TE | TM -> TE | | TE -> TM | TM -> TM |

Keyword Arguments:
  • nu_prop_PWs (int) – Number of propagating PWs.

  • wl (int) – Index in case of calling in a loop.

  • add_name (str) – Add add_name to title.

  • max_scale (float) – Limit maximum amplitude shown.

  • save_pdf (bool) – If True, save plot to PDF file. False by default.

plotting.zeros_int_str(zero_int)[source]

Convert integer into string with ‘0’ in place of ‘ ‘.