Visualization, tools¶
visu¶
visu contains 2D visualization functions.
structure geometry¶
structure¶
-
pyGDM2.visu.
structure
(struct, projection='XY', color='auto', scale=1, borders=50, marker='s', EACHN=1, tit='', plot_legend=True, ax=None, absscale=False, show=True, **kwargs)¶ plot structure in 2d, projected to e.g. the XY plane
plot the structure struct as a scatter projection to a carthesian plane. Either from list of coordinates, or using a simulation definition as input.
kwargs are passed to matplotlib’s scatter
Parameters: - struct (list or
core.simulation
) – either list of 3d coordinate tuples or simulation description object - projection (str, default: "XY") – which 2D-projection to plot. One of “XY”, “YZ”, “XZ”
- color (str or matplotlib color, default: "auto") – Color of scatterplot. Either “auto”, or matplotlib-compatible color. “auto”: automatic color selection (multi-color for multiple materials).
- scale (float, default: 0.5) – symbol scaling in units of stepsize
- borders (float, default: 50) – additional space limits around plot in nm
- marker (str, default "s" (=squares)) – scatter symbols for plotting meshpoints. Convention of matplotlib’s scatter
- EACHN (int, default: 1 (=all)) – show each EACHN points only
- tit (str, default: "") – title for plot (optional)
- plot_legend (bool, default: True) – whether to add a legend if multi-material structure (requires auto-color enabled)
- ax (matplotlib axes, default: None (=create new)) – axes object (matplotlib) to plot into
- absscale (bool, default: False) – absolute or relative scaling. If True, override internal scaling calculation
- show (bool, default: True) – directly show plot
Returns: Return type: result returned by matplotlib’s scatter
- struct (list or
structure_contour¶
-
pyGDM2.visu.
structure_contour
(struct, projection='XY', color='b', N_points=4, borders=50, lw=1, s=5, style='lines', input_mesh='cube', tit='', add_first_point=True, show=True, **kwargs)¶ Contour around structure
further kwargs are passed to matplotlib’s scatter or plot
Parameters: - struct (list or
core.simulation
) – either list of 3d coordinate tuples or simulation description object - projection (str, default: "XY") – which 2D-projection to plot. One of “XY”, “YZ”, “XZ”
- color (str or matplotlib color, default: "b") – matplotlib-compatible color for scatter
- N_points (int, default: 4) – number of additional points to calculate at each meshpoint-side (basically meant for style “dots”, default: 4)
- borders (float, default: 50) – additional space limits around plot in nm
- lw (float, default: 1) – linewidth as used by pyplot.plot (style=’lines’ only)
- s (float, default: 5) – symbol scaling for scatterplot as used by pyplot.scatter (style=’dots’ only)
- stlye (str, default: 'lines') – Style of plot. One of [“dots”, “lines”]
- input_mesh (str, default: 'cube') – mesh type, default: “cube”. one of [“cube”, “hex”, “hex2”, “hex_onelayer”]
- tit (str, default: "") – title for plot (optional)
- add_first_point (bool, default: True) – If True, adds first point twice in order to close the contour. Might cause some strange lines if a single edge meshpoint is first in the geometry.
- show (bool, default: True) – directly show plot
Returns: contour plot object
Return type: matplotlib’s scatter or line return value
- struct (list or
vector fields¶
vectorfield¶
-
pyGDM2.visu.
vectorfield
(NF, struct=None, projection='XY', complex_part='real', tit='', slice_level=None, scale=10.0, vecwidth=1.0, cmap=<matplotlib.colors.LinearSegmentedColormap object>, cmin=0.3, ax=None, show=True, borders=50, EACHN=1, sortL=True, overrideMaxL=False, **kwargs)¶ plot 2D Vector field as quiver plot
plot nearfield list as 2D vector plot, using matplotlib’s quiver. kwargs are passed to pyplot.quiver
Parameters: - NF (list of 3- or 6-tuples) – Nearfield definition. np.array, containing 6-tuples:
(X,Y,Z, Ex,Ey,Ez), the field components being complex (use e.g.
tools.get_field_as_list()
). Optionally can also take a list of 3-tuples (Ex, Ey, Ez), in which case the structure must be provided via the struct kwarg. - struct (list or
core.simulation
, optional) – optional structure definition (necessary if field is supplied in 3-tuple form without coordinates). Either simulation description object, or list of (x,y,z) coordinate tuples - projection (str, default: 'XY') – Which projection to plot: “XY”, “YZ”, “XZ”
- complex_part (str, default: 'real') – Which part of complex field to plot. Either ‘real’ or ‘imag’.
- tit (str, default: "") – title for plot (optional)
- slice_level (float, default: None) –
optional value of depth where to slice. eg if projection==’XY’, slice_level=10 will take only values where Z==10.
- slice_level = None, plot all vectors one above another without slicing.
- slice_level = -9999 : take minimum value in field-list.
- slice_level = 9999 : take maximum value in field-list.
- scale (float, default: 10.0) – optional vector length scaling parameter
- vecwidth (float, default: 1.0) – optional vector width scaling parameter
- cmap (matplotlib colormap, default: cm.Blues) – matplotlib colormap to use for arrows (color scaling by vector length)
- cmin (float, default: 0.3) – minimal color to use from cmap to avoid pure white
- ax (matplotlib axes, default: None (=create new)) – optinal axes object (mpl) to plot into
- show (bool, default: True) – whether or not to call pyplot.show
- borders (float, default: 50) – additional space in nm to plotting borders
- EACHN (int, default: 1 [=all]) – show each N points only
- sortL (bool, default: True) – sort vectors by length to avoid clipping (True: Plot longest vectors on top)
Returns: Return type: return value of matplotlib’s quiver
- NF (list of 3- or 6-tuples) – Nearfield definition. np.array, containing 6-tuples:
(X,Y,Z, Ex,Ey,Ez), the field components being complex (use e.g.
vectorfield_by_fieldindex¶
-
pyGDM2.visu.
vectorfield_by_fieldindex
(sim, field_index, **kwargs)¶ Wrapper to
vectorfield()
, using simulation object and fieldindex as inputAll other keyword arguments are passed to
vectorfield()
.Parameters: - sim (simulation) – instance of
core.simulation
- field_index (int) – index of evaluated self-consistent field to use for calculation. Can be
obtained for specific parameter-set using
tools.get_closest_field_index()
- sim (simulation) – instance of
vectorfield_fieldlines¶
-
pyGDM2.visu.
vectorfield_fieldlines
(NF, projection='XY', tit='', complex_part='real', borders=0, NX=-1, NY=-1, show=True, **kwargs)¶ 2d plot of fieldlines of field ‘NF’
other optional arguments passed to matplotlib’s pyplot.streamplot
Parameters: - NF (list of 6-tuples) – Nearfield definition. np.array, containing 6-tuples:
(X,Y,Z, Ex,Ey,Ez), the field components being complex (use e.g.
tools.get_field_as_list()
). - projection (str, default: 'XY') – Which projection to plot: “XY”, “YZ”, “XZ”
- complex_part (str, default: 'real') – Which part of complex field to plot. Either ‘real’ or ‘imag’.
- tit (str, default: "") – title for plot (optional)
- borders (float, default: 50) – additional space in nm to plotting borders
- NY (NX,) – optional interpolation steps for nearfield. by default take number of independent positions in NF (if NX or NY == -1)
- show (bool, default: True) – whether or not to call pyplot.show
Returns: return matplotlib streamplot object
Return type: if show == False
- NF (list of 6-tuples) – Nearfield definition. np.array, containing 6-tuples:
(X,Y,Z, Ex,Ey,Ez), the field components being complex (use e.g.
scalar fields¶
vectorfield_color¶
-
pyGDM2.visu.
vectorfield_color
(NF, projection='XY', complex_part='real', tit='', slice_level=-9999, NX=None, NY=None, fieldComp='I', borders=0, cmap='seismic', clim=None, show=True, **kwargs)¶ plot of 2D field data as colorplot
other kwargs are passed to matplotlib’s imshow
Parameters: - NF (list of 6-tuples) – Nearfield definition. np.array, containing 6-tuples:
(X,Y,Z, Ex,Ey,Ez), the field components being complex (use e.g.
tools.get_field_as_list()
). - projection (str, default: 'XY') – Which projection to plot: “XY”, “YZ”, “XZ”
- complex_part (str, default: 'real') – Which part of complex field to plot. Either ‘real’ or ‘imag’.
- tit (str, default: "") – title for plot (optional)
- slice_level (float, default: None) –
optional value of depth where to slice. eg if projection==’XY’, slice_level=10 will take only values where Z==10.
- slice_level = None, plot all vectors one above another without slicing.
- slice_level = -9999 : take minimum value in field-list.
- slice_level = 9999 : take maximum value in field-list.
- NY (NX,) – optional interpolation steps for nearfield. by default take number of independent positions in NF (if NX or NY == -1)
- fieldComp (str, default: 'I') – Which component to use. One of [“I”, “Ex”, “Ey”, “Ez”]. If “I” is used, complex_part argument has no effect.
- borders (float, default: 50) – additional space in nm to plotting borders
- cmap (matplotlib colormap, default: "seismic") – matplotlib colormap to use for colorplot
- clim (float, default: None) – optional colormap limits to pass to plt.clim()
- show (bool, default: True) – whether or not to call pyplot.show
Returns: Return type: result of matplotlib’s imshow
- NF (list of 6-tuples) – Nearfield definition. np.array, containing 6-tuples:
(X,Y,Z, Ex,Ey,Ez), the field components being complex (use e.g.
vectorfield_color_by_fieldindex¶
-
pyGDM2.visu.
vectorfield_color_by_fieldindex
(sim, field_index, **kwargs)¶ Wrapper to
vectorfield_color()
, using simulation object and fieldindex as inputAll other keyword arguments are passed to
vectorfield_color()
.Parameters: - sim (simulation) – instance of
core.simulation
- field_index (int) – index of evaluated self-consistent field to use for calculation. Can be
obtained for specific parameter-set using
tools.get_closest_field_index()
- sim (simulation) – instance of
scalarfield¶
-
pyGDM2.visu.
scalarfield
(NF, **kwargs)¶ Wrapper to
vectorfield_color()
, using scalar data tuples (x,y,z,S) as inputAll other keyword arguments are passed to
vectorfield_color()
.Parameters: NF (list of 4-tuples) – list of tuples (x,y,z,S). Alternatively, the scalar-field can be passed as list of 2 lists containing the x/y positions and scalar values, respectively. ([xy-values, S], with xy-values: list of 2-tuples [x,y]; S: list of scalars). This format is returned e.g. by tools.calculate_rasterscan()
.
farfield_pattern_2D¶
-
pyGDM2.visu.
farfield_pattern_2D
(theta, phi, I, degrees=True, show=True, **kwargs)¶ Plot BFP-like 2D far-field radiation pattern
Plot a “back-focal plane”-like radiation pattern. All arrays are of shape (Nteta, Nphi)
kwargs are passed to matplotlib’s pyplot.pcolormesh.
Parameters: - tetalist (2D-numpy.ndarray, float) – teta angles
- philist (2D-numpy.ndarray, float) – phi angles
- Iff (2D-numpy.ndarray, float) – Intensities at (teta, phi) positions
- degrees (bool, default: True) – Transform polar angle to degrees for plotting (False: radians)
- show (bool, default: True) – whether to call pyplot.show()
Returns: Return type: result of matplotlib’s pyplot.pcolormesh
animation¶
animate_vectorfield¶
-
pyGDM2.visu.
animate_vectorfield
(NF, Nframes=50, projection='XY', doQuiver=True, doColor=False, alphaColor=1.0, scale=5.0, clim=None, kwargs={'cmin': 0.3}, kwargsColor={'fieldComp': 'Ex'}, ax=None, show=True)¶ Create animation of oszillating complex nearfield (2D-Projection)
Parameters: - NF (list of 6-tuples) – Nearfield definition. np.array, containing 6-tuples:
(X,Y,Z, Ex,Ey,Ez), the field components being complex (use e.g.
tools.get_field_as_list()
). - Nframes (int, default: 50) – number of frames per oscillation cycle
- projection (str, default: 'XY') – 2D projection plane
- doQuiver (bool, default: True) – plot field as quiverplot.
- doColor (bool, default: True) – plot field as colorplot (real part)
- alphaColor (float, default: 0.5) – alpha value of colormap
- kwargs (dict, default: {}) – are passed to
vectorfield()
(if doQuiver) - kwargsColor (dict, default: {}) – are passed to
vectorfield_color()
(if doColor) - ax (optional matplotlib axes, default: None) – optional axes object (mpl) to plot into
- show (bool, default: True) – directly show animation
Returns: im_ani
Return type: Animation as matplotlib “ArtistAnimation” object
Notes
You can save the animation as video-file using: im_ani.save(‘video.mp4’, writer=”ffmpeg”, codec=’h264’, bitrate=1500). See also matplotlib’s documentation of the animation module for more info.
- NF (list of 6-tuples) – Nearfield definition. np.array, containing 6-tuples:
(X,Y,Z, Ex,Ey,Ez), the field components being complex (use e.g.
visu3d¶
visu3d contains 3D visualization functions, the API is compatible to the visu module.
structure geometry¶
structure¶
-
pyGDM2.visu3d.
structure
(struct, scale=0.75, abs_scale=False, tit='', color=(0.3, 0.3, 0.3), mode='cube', draw_substrate=True, substrate_size=2.0, axis_labels=True, show=True, **kwargs)¶ plot structure in 3d
plot the structure “struct” using 3d points. Either from list of coordinates, or using a simulation definition dict as input.
Parameters: - struct (-) –
- scale (-) –
- abs_scale (-) –
- color (-) –
- mode (-) –
- draw_substrate (-) –
- substrate_size (-) –
- axis_labels (-) –
- show (-) –
- kwargs (-) –
vector fields¶
vectorfield¶
-
pyGDM2.visu3d.
vectorfield
(NF, struct=None, scale=1.5, abs_scale=False, tit='', complex_part='real', clim=[0.0, 1.0], axis_labels=True, show=True, **kwargs)¶ 3d quiverplot of nearfield
Parameters: - NF (-) – (X,Y,Z, Ex,Ey,Ez), the field components being complex.
- struct (-) – form without coordinates). Either simulation object, or list of coordinate (x,y,z) tuples
- scale (-) –
- abs_scale (-) –
- complex_part (-) – Either ‘real’ or ‘imag’. (default: ‘real’)
- axis_labels (-) –
- show (-) –
All other keyword arguments are passed to mlab’s quiver3d.
vectorfield_by_fieldindex¶
-
pyGDM2.visu3d.
vectorfield_by_fieldindex
(sim, field_index, **kwargs)¶ Wrapper to
vectorfield()
, using simulation object and fieldindex as inputParameters: - sim (simulation) – instance of
core.simulation
- field_index (int) – index of evaluated self-consistent field to use for calculation. Can be
obtained for specific parameter-set using
tools.get_closest_field_index()
:param All other keyword arguments are passed to
vectorfield()
.:- sim (simulation) – instance of
scalar fields¶
vectorfield_color¶
-
pyGDM2.visu3d.
vectorfield_color
(NF, complex_part='real', fieldComp='I', scale=0.5, abs_scale=False, mode='sphere', tit='', axis_labels=True, show=True, **kwargs)¶ plot of scalar electric field data as 3D colorplot
vectorfield_color is using mlab.quiver3d to plot colored data-points in order to be able to fix the size of the points while varying the color-code
Parameters: - NF (-) – (X,Y,Z, Ex,Ey,Ez), the field components being complex.
- complex_part (-) – (default ‘real’)
- fieldComp (-) – if “I” is used, complex_part argument has no effect.
- scale (-) –
- abs_scale (-) –
- mode (-) –
- tit (-) –
- axis_labels (-) –
- show (-) –
other kwargs are passed to mlabs’s quiver3d
vectorfield_color_by_fieldindex¶
-
pyGDM2.visu3d.
vectorfield_color_by_fieldindex
(sim, field_index, **kwargs)¶ Wrapper to
vectorfield_color()
, using simulation object and fieldindex as inputParameters: - sim (simulation) – instance of
core.simulation
- field_index (int) – index of evaluated self-consistent field to use for calculation. Can be
obtained for specific parameter-set using
tools.get_closest_field_index()
:param All other keyword arguments are passed to
vectorfield_color()
.:- sim (simulation) – instance of
scalarfield¶
-
pyGDM2.visu3d.
scalarfield
(NF, **kwargs)¶ Wrapper to
vectorfield_color()
, using scalar data tuples (x,y,z,S) as inputParameters: NF (list of 4-tuples) – list of tuples (x,y,z,S). Alternatively, the scalar-field can be passed as list of 2 lists containing the x/y positions and scalar values, respectively. ([xy-values, S], with xy-values: list of 2-tuples [x,y]; S: list of scalars). This format is returned e.g. by tools.calculate_rasterscan()
.:param All other keyword arguments are passed to
vectorfield_color()
.:
animation¶
animate_vectorfield¶
-
pyGDM2.visu3d.
animate_vectorfield
(NF, Nframes=50, show=True, scale=1.5, abs_scale=False, draw_struct=False, draw_substrate=True, substrate_size=2.0, clim=[0.0, 1.0], figsize=(600, 400), save_anim=False, fig=None, view=(45, 45), ffmpeg_args='', mov_file='pygdm_animated_field.mp4', **kwargs)¶
tools¶
tools contains data-processing tools and helper functions
Save / Load / Print info¶
-
pyGDM2.tools.
save_simulation
(sim, fname, mode='h5', tables_filter_kwargs={'complevel': 5, 'complib': 'blosc'})¶ Save simulation object to file using pickle and hdf5 via tables
The electric fields are stored using hdf5 (via tables), the rest via pickle. If not tables module available, everything will be stored via pickle. This behavior can be forced with the mode parameter.
Parameters: - sim (
simulation
) – simulation description - fname (str) – filename to save sim to
- mode (str, default: "hdf5") – which method to use to store data. Either “pickle” or “hd5f” (“h5”==”hd5f”)
- tables_filter_kwargs (dict, default: {'complib':'blosc', 'complevel':5}) – filter kwargs, passed to tables.Filters if using the “hdf5” mode
- sim (
-
pyGDM2.tools.
load_simulation
(fname)¶ Load simulation from file using pickle
Try loading hdf5 first, if no hdf5 file or no tables module available, fallback to pickle.
Parameters: fname (str) – filename to load sim from Returns: Return type: instance of core.simulation
-
pyGDM2.tools.
print_sim_info
(sim, prnt=True, verbose=False)¶ print simulation info from simdict
Parameters: - sim (
simulation
) – simulation description - prnt (bool, default: True) – If True, print to sdtout. If False, return string
- verbose (bool, default: False) – if True, print more details like exhaustive incident field parameter list
Notes
print_sim_info()
is implemented as its __repr__ attribute incore.simulation
. This means>>> print sim
and
>>> print_sim_info(sim)
will result in the identical output
- sim (
Field-index searching¶
-
pyGDM2.tools.
get_field_indices
(sim)¶ List all field-configurations including wavelength sorted by field-index
Parameters: sim ( simulation
) – simulation descriptionReturns: list of kwargs-dict containing field-config parameters. list in the order of the “field_index” convention. Return type: list of dict
-
pyGDM2.tools.
get_closest_field_index
(sim, search_kwargs)¶ Find closest calculated scattered field matching to search parameters
Parameters: - sim (
simulation
) – simulation description - search_kwargs (dict) – searched kwargs for incident field
Returns: index – index of field which matches closest search incident field parameters
Return type: - sim (
Structure geometry tools¶
-
pyGDM2.tools.
get_geometry
(struct, return_type='lists')¶ return coordinate lists X,Y,Z either from list of tuples or simulation object
Parameters: - struct (list of tuple or
core.simulation
) – list of coordinate tuples or instance ofcore.simulation
- projection (str, default: "XY") – 2D plane for projection. One of [‘XY’, ‘XZ’, ‘YZ’]
- return_type (str, default: 'lists') –
- either ‘lists’ or ‘tuples’
- ’tuples’ : return list of (X,Y,Z)-tuples
- ’lists’ : return 3 lists with X, Y and Z values
Returns: - if return_type == ‘lists’ – np.array containing 3 np.arrays with the X, Y and Z coordinates
- if return_type == ‘tuples’ – list of 3-tuples : (x,y,z) coordinates of geometry
- struct (list of tuple or
-
pyGDM2.tools.
get_step_from_geometry
(struct, max_meshpoints=1000)¶ Calculate step from coordinate list defining a nano-object
Will return closest distance occuring between two meshpoints. Uses scipy.spatial.distance.
Parameters: - struct (list of tuples or
core.simulation
) – - max_meshpoints (int, default: 1000) – maximum number of meshpoints to consider for step-calculation if using scipy.spatial.distance. (for computational speed at large structures)
Returns: step – stepsize between mesh-points
Return type: - struct (list of tuples or
-
pyGDM2.tools.
get_geometry_2d_projection
(struct, projection='XY')¶ return the geometry projection onto a 2D-plane
Parameters: - struct (list of tuples or
core.simulation
) – - projection (str, default: "XY") – 2D plane for projection. One of [‘XY’, ‘XZ’, ‘YZ’]
Returns: list of 3-tuples
Return type: (x,y,z) coordinates of 2D-projection (third coordinate set to zero)
- struct (list of tuples or
-
pyGDM2.tools.
get_geometric_cross_section
(struct, projection='XY', step=None)¶ return the geometrical cross-section (=’footprint’) of struct in nm
Parameters: - struct (list of tuples or
core.simulation
) – - projection (str, default: "XY") – 2D plane for projection. One of [‘XY’, ‘XZ’, ‘YZ’]
- step (float, default: None) – optional pass step-size. If None, calculate it from geometry (may be slower)
Returns: float
Return type: geometric cross section of structure projection in nm^2
- struct (list of tuples or
-
pyGDM2.tools.
get_surface_meshpoints
(struct, NN_bulk=6, max_bound=1.2, NN_surface=-1, max_bound_sf=5.0, return_sfvec_all_points=False)¶ get surface elements and normal surface vectors of structure
Calculate normal vectors using next-neighbor counting.
- To use outmost surface layer only, parameters are:
- 2D: NN_bulk=4, max_bound=1.1
- 3D: NN_bulk=6, max_bound=1.1
Parameters: - struct (-) – list of tuples or instance of
core.simulation
- NN_bulk (-) – Number of Next neighbors of a bulk lattice point
- max_bound (-) – Max. distance in step-units to search for next neighbors
- NN_surface (-) – different number of neighbours to consider for normal surfacevectors
- max_bound_sf (-) – different calculation range for normal surfacevectors. By default, use search radius of up to 5 steps. If a large number of neighbours should be considered for vector calculation, it might be necessary to increased this limit, which might however slow down the KD-tree queries.
- return_sfvec_all_points (-) – if True, return vector list for all meshpoints, with zero length if bulk
Returns: - - SF (list of surface meshpoint coordinates)
- - SF_vec (list of normal surface vectors)
-
pyGDM2.tools.
get_closest_field_index
(sim, search_kwargs) Find closest calculated scattered field matching to search parameters
Parameters: - sim (
simulation
) – simulation description - search_kwargs (dict) – searched kwargs for incident field
Returns: index – index of field which matches closest search incident field parameters
Return type: - sim (
Spectra tools¶
-
pyGDM2.tools.
get_possible_field_params_spectra
(sim)¶ Return all possible field-parameter permutations for spectra
Parameters: sim ( simulation
) – simulation descriptionReturns: params – list of all possible parameter-permutation at each wavelength Return type: list of dict
-
pyGDM2.tools.
calculate_spectrum
(sim, field_kwargs, func, verbose=False, **kwargs)¶ calculate spectra using function func
Parameters: - sim (
simulation
) – simulation description - field_kwargs (dict or int) – dict of field-configuration to use from simulation. If an int is given,
it is used as field-index (use e.g.
get_closest_field_index()
) - func (function) – evaluation function, which will be called as: func(sim, field_index, **kwargs)
- **kwargs – all other keyword args are passed to func
Returns: - np.array (wavelengths)
- np.array (results of func for each wavelength)
- sim (
Raster-scan tools¶
-
pyGDM2.tools.
get_possible_field_params_rasterscan
(sim, key_x_pos='xSpot', key_y_pos='ySpot')¶ Return all possible field-parameter permutations for raster-scan simulations
Parameters: - sim (
simulation
) – simulation description - key_x_pos (str, default: ‘xSpot’) – parameter-name defining the rasterscan beam/illumination x-position
- key_y_pos (str, default: ‘ySpot’) – parameter-name defining the rasterscan beam/illumination y-position
Returns: params – list of dict for all possible parameter-permutation, defining rasterscan map
Return type: list of dict
- sim (
-
pyGDM2.tools.
get_rasterscan_fields
(sim, search_kwargs, key_x_pos='xSpot', key_y_pos='ySpot')¶ Return list of all field-parameter sets for a raster-scan
Parameters: - sim (
simulation
) – simulation description - search_kwargs (dict) – searched kwargs for incident field
- key_x_pos (str, default: 'xSpot') – parameter-name defining the rasterscan beam/illumination x-position
- key_y_pos (str, default: 'ySpot') – parameter-name defining the rasterscan beam/illumination y-position
Returns: NF_rasterscan – Each element corresponds to the simulated E-field inside the particle at a scan position: [field_param_dict, NF] - field_param_dict is the dict with the field-generator parameters - NF is the nearfield, as list of complex 3-tuples (Ex_i, Ey_i, Ez_i)
Return type: list of lists
- sim (
-
pyGDM2.tools.
get_rasterscan_field_indices
(sim, search_kwargs, key_x_pos='xSpot', key_y_pos='ySpot')¶ Return list of all field-parameter-indices corresponding to a raster-scan
Parameters: - sim (
simulation
) – simulation description - search_kwargs (dict) – searched kwargs for incident field
- key_x_pos (str, default: 'xSpot') – parameter-name defining the rasterscan beam/illumination x-position
- key_y_pos (str, default: 'ySpot') – parameter-name defining the rasterscan beam/illumination y-position
Returns: NF_rasterscan_indices – index of field which matches closest search incident field parameters
Return type: list of int
- sim (
-
pyGDM2.tools.
calculate_rasterscan
(sim, field_kwargs, func, key_x_pos='xSpot', key_y_pos='ySpot', verbose=False, **kwargs)¶ calculate rasterscan using function func
Parameters: - sim (
simulation
) – simulation description - field_kwargs (dict or int) – dict of field-configuration to use from simulation. If an int is given,
it is used as index on results of
get_possible_field_params_rasterscan()
- func (function) – evaluation function, which will be called as: func(sim, field_index, **kwargs)
- key_x_pos (str, default: 'xSpot') – parameter-name defining the rasterscan beam/illumination x-position
- key_y_pos (str, default: 'ySpot') – parameter-name defining the rasterscan beam/illumination y-position
- **kwargs – all other keyword args are passed to func
Returns: - list of tuples (x,y) – positions of raster-scan evaluation
- list of float or tuple (S) – S is the scalar (or tuple) returned by func
- sim (
-
pyGDM2.tools.
get_possible_field_params_rasterscan
(sim, key_x_pos='xSpot', key_y_pos='ySpot') Return all possible field-parameter permutations for raster-scan simulations
Parameters: - sim (
simulation
) – simulation description - key_x_pos (str, default: ‘xSpot’) – parameter-name defining the rasterscan beam/illumination x-position
- key_y_pos (str, default: ‘ySpot’) – parameter-name defining the rasterscan beam/illumination y-position
Returns: params – list of dict for all possible parameter-permutation, defining rasterscan map
Return type: list of dict
- sim (
-
pyGDM2.tools.
get_rasterscan_fields
(sim, search_kwargs, key_x_pos='xSpot', key_y_pos='ySpot') Return list of all field-parameter sets for a raster-scan
Parameters: - sim (
simulation
) – simulation description - search_kwargs (dict) – searched kwargs for incident field
- key_x_pos (str, default: 'xSpot') – parameter-name defining the rasterscan beam/illumination x-position
- key_y_pos (str, default: 'ySpot') – parameter-name defining the rasterscan beam/illumination y-position
Returns: NF_rasterscan – Each element corresponds to the simulated E-field inside the particle at a scan position: [field_param_dict, NF] - field_param_dict is the dict with the field-generator parameters - NF is the nearfield, as list of complex 3-tuples (Ex_i, Ey_i, Ez_i)
Return type: list of lists
- sim (
Coordinate-list transformations¶
-
pyGDM2.tools.
unique_rows
(a)¶ delete all duplicates with same x/y coordinates
Parameters: a (list of tuples) – list of (x,y) or (x,y,z) coordinates with partially redunant (x,y) values. Returns: - list of tuples in which all multiple tuples with equal first and second value
- (x,y coordinates) are removed.
- If 3-D data (Z-coordinate (3rd column) is replaced by 0.)
-
pyGDM2.tools.
unique_rows_3D
(a)¶ delete all duplicates with same x/y/z coordinates
Parameters: a (list of tuples) – list of (x,y,z) coordinates with partially redunant (x,y) values. Returns: - list of tuples in which all multiple tuples with equal (x,y,z) coordinates
- are removed.
-
pyGDM2.tools.
adapt_map_to_structure_mesh
(mapping, structure, projection=None, min_dist=1.5, nthreads=-1, verbose=False)¶ changes the positions of mapping coordinates close to meshpoints
All coordinates closer than a minimum (e.g. the stepsize) to a meshpoint of the nanostructure are replaced by the position of the closest meshpoint
Parameters: - mapping (list of 3-lists/-tuples) – list containing the mapping coordinates
- structure (list of coordinate 3-tuples or
core.simulation
) – instance of object containing the mapping information. - projection (str, default: None) – consider some geometric projection. possible values: [‘XY’, ‘XZ’, ‘YZ’, None] if None: use closest meshpoint no matter which direction in space. If one of the strings, only consider meshpoints in the same plane as the mapping coordinates.
- min_dist (float, default: 1.5) – minimum distance to meshpoints in units of stepsize
- nthreads (int, default: all CPUs) – number of threads to work on in parallel
- verbose (bool, default: False) – print timing info
Returns: coords – mapping with positions close to / inside the structure replaced by the nearest mesh-point coordinates
Return type: list of 3-tuples
-
pyGDM2.tools.
map_to_grid_2D
(MAP, IVALUES, NX=-1, NY=-1)¶ Generate XY plottable map e.g. from 2D nearfield calculation
Parameters: - MAP (list of lists or list of tuples) –
2D MAP corresponding to data-array (e.g. from ‘generate_NF_map’).
- If list of lists :
- MAP[0] –> first coordinate; MAP[1] –> second coordinate.
- If list of tuples :
- list of (x,y) or (x,y,z) tuples. In the latter case, “z” will be ignored.
- IVALUES (list of floats) – Data-array: Intensity at each MAP position
- NY (NX,) – Nr of points to calculate for each dimension (do interpolation in nescessary)
Returns: - NF_MAP (2d-array) – nearfield map
- extent (tuple) – extent of map (x0,x1, y0,y1)
- MAP (list of lists or list of tuples) –
-
pyGDM2.tools.
grid_to_list
(arr2d, extent=None, add_z=False)¶ create list of X/Y/S tuples from 2D map data
Parameters: - arr2d (2D np.array) – 2D data array of shape (Nx, Ny)
- extent (4-tuple, default: None) – X / Y limits of array as tuple (x0, x1, y0, y1). If None, uses integer steps between 0 and Nx, Ny.
- add_z (bool, default: False) – if true, returns (x,y,z,S) tuples, with z=0
Returns: scalarfield – list of (x,y,S) values, where S are the values of the original 2D map arr2d
Return type: np.array
-
pyGDM2.tools.
get_field_as_list
(NF, struct)¶ convert field NF and geometry struct to a list of coordinate/field tuples
Note, that usually it is easier to use
get_field_as_list_by_fieldindex()
instead.Parameters: - NF (list of 3-tuples, complex) – field as returned e.g. from
core.scatter()
- struct (list of tuples, float) – geometry of nano-object, as returned by structure generated in module structures
Returns: fieldlist – geometry and field in one list: [(x,y,z, Ex,Ey,Ez), (…), …]
Return type: list of 6-tuples
- NF (list of 3-tuples, complex) – field as returned e.g. from
-
pyGDM2.tools.
get_field_as_list_by_fieldindex
(sim, field_index)¶ return internal fields in structure as list of (x,y,z,Ex,Ey,Ez) tuples
Parameters: - sim (
simulation
) – simulation description - field_index (int) – field-index corresponding to the incident field configuration
Returns: fieldlist – geometry and field in one list: [(x,y,z, Ex,Ey,Ez), (…), …]
Return type: list of 6-tuples
- sim (
-
pyGDM2.tools.
get_intensity_from_fieldlist
(NF_list)¶ calculate intensity values from complex fields in field-vector-list
Parameters: - NF (list of 3-tuples, complex) – field as returned e.g. from
core.scatter()
- struct (list of tuples, float) – geometry of nano-object, as returned by structure generated in module structures
Returns: fieldlist – list of tuples containing coordinates and field-intensity: [(x,y,z, I), (…), …]
Return type: list of 4-tuples
- NF (list of 3-tuples, complex) – field as returned e.g. from
2D-mapping coordinate generators¶
-
pyGDM2.tools.
generate_NF_map
(X0, X1, NX, Y0, Y1, NY, Z0=0, projection='XY', dtype='f')¶ Generate coordinate list with equidistant positions on a rectangular map
e.g. for nearfield calcuation on this map
Parameters: - X0,X1 (-) – X-Limits for Map
- NX (-) – Nr of discretization pts in first projection direction
- Y0,Y1 (-) – Y-Limits for Map
- NY (-) – Nr of discretization pts in second projection direction
- Z0 (-) – Z-Height of map
- projection (-) – projection of map. must be one of [‘XY’,’XZ’,’YZ’], default: ‘XY’
- dtype (-) – dtype of coordinates. passed to np.asfortranarray. e.g. “f” (single) or “d” (double). default: “f”
Returns: list of 3 lists of X, Y, Z coordinates, to use e.g. in
linear.nearfield()
Return type: list of lists
-
pyGDM2.tools.
generate_NF_map_XY
(X0, X1, NX, Y0, Y1, NY, Z0=0, dtype='f')¶ Generate coordinate list with equidistant positions on a rectangular map in XY plane
see
generate_NF_map()
for doc.
-
pyGDM2.tools.
generate_NF_map_XZ
(X0, X1, NX, Z0, Z1, NZ, Y0=0, dtype='f')¶ Generate coordinate list with equidistant positions on a rectangular map in XZ plane
see
generate_NF_map()
for doc.
-
pyGDM2.tools.
generate_NF_map_YZ
(Y0, Y1, NY, Z0, Z1, NZ, X0=0, dtype='f')¶ Generate coordinate list with equidistant positions on a rectangular map in YZ plane
see
generate_NF_map()
for doc.
Other¶
-
pyGDM2.tools.
evaluate_incident_field
(field_generator, wavelength, kwargs, r_probe, n1=1.0, n2=1.0, n3=None, spacing=5000.0)¶ Evaluate an incident field generator
Calculate the field defined by a field_generator function for a given set of coordinates.
Parameters: - field_generator (callable) –
- field generator function. Mandatory arguments are
- struct (instance of
structures.struct
) - wavelength (list of wavelengths)
- struct (instance of
- wavelength (float) – wavelength in nm
- kwargs (dict) – optional kwargs for the field_generator functions (see also
fields.efield
). - r_probe (tuple (x,y,z) or list of 3-lists/-tuples) – (list of) coordinate(s) to evaluate nearfield on.
Format: tuple (x,y,z) or list of 3 lists: [Xmap, Ymap, Zmap]
(the latter can be generated e.g. using
tools.generate_NF_map()
) - n1,n2,n3 (complex, default: 1.0, 1.0, None) – indices of 3 layered media. if n3==None: n3=n2.
- spacing (float, default: 5000) – distance between substrate and cladding (=thickness of layer “n2”)
Returns: field_list – field at coordinates as list of tuples (x,y,z, Ex,Ey,Ez)
Return type: list of tuples
- field_generator (callable) –
-
pyGDM2.tools.
get_intensity_from_fieldlist
(NF_list) calculate intensity values from complex fields in field-vector-list
Parameters: - NF (list of 3-tuples, complex) – field as returned e.g. from
core.scatter()
- struct (list of tuples, float) – geometry of nano-object, as returned by structure generated in module structures
Returns: fieldlist – list of tuples containing coordinates and field-intensity: [(x,y,z, I), (…), …]
Return type: list of 4-tuples
- NF (list of 3-tuples, complex) – field as returned e.g. from