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=True, 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 spectra as pdf files. True 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)[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.
- plotting.EOT_plot(stacks_list, wavelengths, pol='TM', params_layer=1, add_name='', savetxt=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)[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.
- plotting.Fabry_Perot_res(stacks_list, freq_list, kx_list, f_0, k_0, lay_interest=1)[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.
- 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='')[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=True, 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 spectra as pdf files. True 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.evanescent_merit(stacks_list, xvalues=None, chosen_PWs=None, lay_interest=0, add_height=None, add_name='', save_pdf=True, 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 spectra as pdf files. True 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)[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)])[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).
- 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)[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.
- plotting.fields_interpolator_in_plane(pstack, lay_interest=1, z_value=0.1)[source]¶
Returns linear interpolators in the x-y plane at chosen value of z for Re[Ex],Re[Ey],Re[Ez],Im[Ex],Im[Ey],Im[Ez],|E|.
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).
- 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)[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.
- 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, save_txt, label_eV, set_y_lim)[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.omega_plot(stacks_list, wavelengths, params_layer=1, stack_label=1)[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.
- plotting.t_func_k_plot_1D(stacks_list, lay_interest=0, pol='TE')[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.
- 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=True, save_txt=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. True by default.
- save_txt (bool) – If True; save spectra data to text files.
- 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='')[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.
- 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.total_tra_plot(plot_name, a_spec, t_spec, r_spec, xvalues, xlabel, params_2_print, stack_label, add_name, label_eV, set_y_lim)[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)[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='')[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)[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.
- plotting.vis_scat_mats(scat_mat, nu_prop_PWs=0, wl=None, add_name='', max_scale=None)[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.