Ray-tracing
Ray-tracing¶
There are two distinct uses of the ray-tracing code: to create redistribution matrices for the matrix framework,
and to define and calculate structures which are treated in their entirety by ray-tracing (so the matrix framework is not used).
Both of these methods can be used in combination with TMM lookup tables to calculate realistic reflection, transmission
and absorption probabilities.
The function RT
is used to create redistribution matrices, while the class rt_structure
is used to define
structures for ray-tracing.
- rayflare.ray_tracing.rt.RT(group, incidence, transmission, surf_name, options, structpath, Fr_or_TMM=0, front_or_rear='front', n_absorbing_layers=0, calc_profile=None, only_incidence_angle=False, widths=None, save=True, overwrite=False)¶
Calculates the reflection/transmission and absorption redistribution matrices for an interface using either a previously calculated TMM lookup table or the Fresnel equations.
- Parameters:
group – an RTgroup object containing the surface textures
incidence – incidence medium
transmission – transmission medium
surf_name – name of the surface (to save matrices)
options – user options (State object)
structpath – file path where matrices will be stored or loaded from
Fr_or_TMM – whether to use the Fresnel equations (0) or a TMM lookup table (1)
front_or_rear – whether light is incident from the front or rear
n_absorbing_layers – for a structure with multiple interface layers, where a TMM lookuptable is used, the number of layers in the interface
calc_profile – whether to save the relevant information to calculate the depth-dependent absorption profile. List of layers where the profile should be calculated, or otherwise None
only_incidence_angle – if True, the ray-tracing will only be performed for the incidence theta and phi specified in the options.
widths – if using TMM, width of the surface layers (in nm)
save – whether to save redistribution matrices (True/False), default True
overwrite – whether to overwrite existing matrices (True/False), default False
- Returns:
Number of returns depends on whether absorption profiles are being calculated; the first two items are always returned, the final one only if a profile is being calcualted.
allArrays: the R/T redistribution matrix at each wavelength, indexed as (wavelength, angle_bin_out, angle_bin_in)
absArrays: the absorption redistribution matrix (total absorption per layer), indexed as (wavelength, layer_out, angle_bin_in)
allres: xarray dataset storing the absorption profile data
- class rayflare.ray_tracing.rt.RTSurface(Points, interface_layers=None, **kwargs)¶
Class which is used to store information about the surface which is used for ray-tracing.
- find_area()¶
- refresh()¶
- shift(z_shift)¶
- rayflare.ray_tracing.rt.RT_wl(i1, wl, n_angles, nx, ny, widths, thetas_in, phis_in, h, xs, ys, nks, surfaces, pol, phi_sym, theta_intv, phi_intv, angle_vector, Fr_or_TMM, n_abs_layers, lookuptable, calc_profile, depth_spacing, side)¶
- rayflare.ray_tracing.rt.calc_R(n1, n2, theta, pol)¶
- rayflare.ray_tracing.rt.calc_angle(x)¶
- rayflare.ray_tracing.rt.calculate_interface_profiles(data_prof_layers, A_in_prof_layers, prof_layer_list_i, local_thetas_i, directions_i, z_list, offsets, lookuptable, wl, pol, depth_spacing)¶
- rayflare.ray_tracing.rt.check_intersect(r_a, d, tri)¶
- rayflare.ray_tracing.rt.decide_RT_Fresnel(n0, n1, theta, d, N, side, pol, rnd, wl=None, lookuptable=None)¶
- rayflare.ray_tracing.rt.decide_RT_TMM(n0, n1, theta, d, N, side, pol, rnd, wl, lookuptable)¶
- rayflare.ray_tracing.rt.exit_side(r_a, d, Lx, Ly)¶
- rayflare.ray_tracing.rt.make_lookuptable_rt_structure(textures, materials, incidence, transmission, options, save_location='default', overwrite=False)¶
- rayflare.ray_tracing.rt.make_profiles_wl(unique_thetas, n_a_in, side, widths, angle_distmat, wl, lookuptable, pol, depth_spacing, prof_layers)¶
- rayflare.ray_tracing.rt.make_tmm_args(arg_list)¶
- rayflare.ray_tracing.rt.normalize(x)¶
- rayflare.ray_tracing.rt.parallel_inner(nks, alphas, r_a_0, surfaces, widths, z_pos, I_thresh, pol, nx, ny, n_reps, xs, ys, randomize, initial_mat, initial_dir, periodic, tmm_args=None)¶
- rayflare.ray_tracing.rt.random() x in the interval [0, 1). ¶
- class rayflare.ray_tracing.rt.rt_structure(textures, materials, widths, incidence, transmission, options=None, use_TMM=False, save_location='default', overwrite=False)¶
Set up structure for RT calculations.
- Parameters:
textures – list of surface textures. Each entry in the list is another list of two RTSurface objects, describing what the surface looks like for front and rear incidence, respectively
materials – list of Solcore materials for each layer (excluding the incidence and transmission medium)
widths – list widths of the layers in m
incidence – incidence medium (Solcore material)
transmission – transmission medium (Solcore material)
options – dictionary/object with options for the calculation; only used if pre-computing lookup tables using TMM
use_TMM – if True, use TMM to pre-compute lookup tables for the structure. Surface layers most be specified in the relevant textures.
save_location – location to save the lookup tables; only used if pre-computing lookup tables using TMM
overwrite – if True, overwrite any existing lookup tables; only used if pre-computing lookup tables using TMM
- calculate(options)¶
Calculates the reflected, absorbed and transmitted intensity of the structure for the wavelengths and angles defined.
- Parameters:
options –
options for the calculation. Relevant entries are:
wavelength: Wavelengths (in m) in which calculate the data. An array.
theta_in: Polar angle (in radians) of the incident light.
phi_in: azimuthal angle (in radians) of the incident light.
I_thresh: once the intensity reaches this fraction of the incident light, the light is considered to be absorbed.
pol: Polarisation of the light: ‘s’, ‘p’ or ‘u’.
depth_spacing_bulk: depth spacing for absorption profile calculations in the bulk (m)
depth_spacing: depth spacing for absorption profile calculations in interface layers (m)
nx and ny: number of points to scan across the surface in the x and y directions (integers)
random_ray_position: True/False. instead of scanning across the surface, choose nx*ny points randomly
randomize_surface: True/False. Randomize the ray position in the x/y direction before each surface interaction
parallel: True/False. Whether to execute calculations in parallel
n_jobs: n_jobs argument for Parallel function of joblib. Controls how many threads are used.
x_limits: x limits (in same units as the size of the RTSurface) between which incident rays will be generated
y_limits: y limits (in same units as the size of the RTSurface) between which incident rays will be generated
- Returns:
A dictionary with the R, A and T at the specified wavelengths and angle.
- calculate_profile(options)¶
- rayflare.ray_tracing.rt.single_cell_check(r_a, d, ni, nj, tri, Lx, Ly, side, z_cov, pol, n_interactions=0, wl=None, Fr_or_TMM=0, lookuptable=None)¶
- rayflare.ray_tracing.rt.single_interface_check(r_a, d, ni, nj, tri, Lx, Ly, side, z_cov, pol, n_interactions=0, wl=None, Fr_or_TMM=0, lookuptable=None)¶
- rayflare.ray_tracing.rt.single_ray_interface(x, y, nks, r_a_0, theta, phi, surfaces, pol, wl, Fr_or_TMM, lookuptable)¶
- rayflare.ray_tracing.rt.single_ray_stack(x, y, nks, alphas, r_a_0, surfaces, tmm_kwargs_list, widths, z_pos, I_thresh, pol='u', randomize=False, mat_i=0, direction_i=1, periodic=1)¶
- rayflare.ray_tracing.rt.traverse(width, theta, alpha, x, y, I_i, positions, I_thresh, direction)¶