4.1. diffractio package

4.1.2. Submodules

4.1.3. diffractio.scalar_fields_X module

This module generates Scalar_field_X class and several functions for multiprocessing. It is required also for generating masks and fields.

The main atributes are:
  • self.x (numpy.array): linear array with equidistant positions. The number of data is preferibly \(2^n\) .
  • self.wavelength (float): wavelength of the incident field.
  • self.u (numpy.array): equal size than x. complex field
There are also some secondary atributes:
  • self.quality (float): quality of RS algorithm
  • self.info (str): description of data
  • self.type (str): Class of the field
  • self.date (str): date

Class for unidimensional scalar fields

Definition of a scalar field
  • instantiation, clear_field, print
  • add, substract sources
  • multiply masks and sources
  • save and load data
Functions for generation of masks
  • insert masks, insert_array_masks - insert other masks inside the mask
  • filter -
Propagation
  • fft, ifft - fourier transform
  • RS - Rayleigh Sommerfeld. It allows amplification of the field
  • BPM - Beam propagation method
Drawing functions
  • draw
Parameters:
  • intensity, average intensity
  • get_edges_transitions (mainly for pylithography)
Functions
  • kernelRS, kernelRSinverse
Multiprocessing
  • polychromatic_multiprocessing
  • extended_source_multiprocessing
  • extended_polychromatic_source
diffractio.scalar_fields_X.PWD_kernel(u, n, k0, k_perp2, dz)[source]

Step for scalar (TE) Plane wave decomposition (PWD) algorithm.

Parameters:
  • u (np.array) – fields
  • n (np.array) – refraction index
  • k0 (float) – wavenumber
  • k_perp2 (np.array) – transversal k**2
  • dz (float) – increment in distances
Returns:

Field at at distance dz from the incident field

Return type:

numpy.array()

References

  1. Schmidt, S. et al. “Wave-optical modeling beyond the thin-element-approximation”. ‘Opt. Express’ 24, 30188 (2016).
class diffractio.scalar_fields_X.Scalar_field_X(x=None, wavelength=None, n_background=1, info='')[source]

Bases: object

Class for unidimensional scalar fields.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly \(2^n\) .
  • wavelength (float) – wavelength of the incident field
  • n_background (float) – refraction index of background
  • info (str) – String with info about the simulation
self.x

Linear array with equidistant positions. The number of data is preferibly \(2^n\).

Type:numpy.array
self.wavelength

Wavelength of the incident field.

Type:float
self.u

Complex field. The size is equal to self.x.

Type:numpy.array
self.quality

Quality of RS algorithm.

Type:float
self.info

Description of data.

Type:str
self.type

Class of the field.

Type:str
self.date

Date when performed.

Type:str
MTF(kind='mm', has_draw=True)[source]

Computes the MTF of a field,.

Parameters:
  • kind (str) – ‘mm’, ‘degrees’
  • has_draw (bool) – If True draws the MTF
Returns:

frequencies in lines/mm (numpy.array) mtf_norm: normalizd MTF

Return type:

(numpy.array) fx

RS(z=10000.0, n=1, matrix=False, new_field=True, fast=False, amplification=1, kind='z', verbose=True)[source]

Fast-Fourier-Transform method for numerical integration of diffraction Rayleigh-Sommerfeld formula. Is we have a field of size N*M, the result of propagation is also a field N*M. Nevertheless, there is a parameter amplification which allows us to determine the field in greater observation planes (jN)x(jM).

Parameters:
  • z (float) – Distance to observation plane. if z<0 inverse propagation is executed
  • n (float) – Refraction index
  • matrix (bool) – If True, the result of the function is a numpy.array
  • new_field (bool) – if False the computation goes to self.u, if True a new instance is produced
  • fast (bool) – Instead of using Hankle function for RS kernel uses expotential
  • amplification (int) – number of frames in x direction
  • kind (str) – ‘z’. In some circunstamces the function is used for other integrals
  • verbose (bool) – if True it writes to shell
Returns:

Scalar_field_X, If matrix is True: numpy.array() Else: None

Return type:

If New_field is True

Info:
This approach a quality parameter: If self.quality>1, propagation is right.
average_intensity(verbose=False)[source]

Returns the average intensity as: (np.abs(self.u)**2).sum() / num_data

Parameters:verbose (bool) – If True it prints the value of the average intensity.
Returns:average intensity.
Return type:(float)
clear_field()[source]

Removes the field so that self.u = 0.

cut_resample(x_limits='', num_points=[], new_field=False, interp_kind='quadratic')[source]

Cuts the field to the range (x0,x1). If one of this x0,x1 positions is out of the self.x range it does nothing. It is also valid for resampling the field, just write x0,x1 as the limits of self.x

Parameters:
  • x_limits (numpy.array) – (x0,x1) - starting and final points to cut, if ‘’ - takes the current limit x[0] and x[-1]
  • num_points (int) – it resamples x, and u [],’’,0,None -> it leave the points as it is
  • new_field (bool) – if True it returns a new Scalar_field_X
  • interp_kind (str) – ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’
Returns:

if new_field is True

Return type:

(Scalar_field_X)

draw(kind='intensity', logarithm=False, normalize=False, cut_value=None, filename='', scale='')[source]

Draws X field. There are several data from the field that are extracted, depending of ‘kind’ parameter.

Parameters:
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘field’, ‘phase’, ‘fill’, ‘fft’
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
  • cut_value (float) – If not None, cuts the maximum intensity to this value
  • filename (str) – if not ‘’ stores drawing in file,
  • scale (str) – ‘’, ‘scaled’, ‘equal’, scales the XY drawing
fft(z=None, shift=True, remove0=False, matrix=False, new_field=False, verbose=False)[source]

Far field diffraction pattern using Fast Fourier Transform (FFT).

Parameters:
  • z (float) – distance to the observation plane or focal of lens. If None the exit is in radians
  • shift (bool) – if True, fftshift is performed
  • remove0 (bool) – if True, central point is removed
  • matrix (bool) – if True only matrix is returned. If False, returns Scalar_field_X
  • new_field (bool) – if True returns Scalar_field_X, else it puts in self
  • verbose (bool) – if True, prints info
Returns:

FFT of the input field

Return type:

(array or Scalar_field_X or None)

filter(size=0)[source]
get_edges(kind_transition='amplitude', min_step=0, verbose=False, filename='')[source]

Determine locations of edges for a binary mask.

Parameters:
  • kind_transition – ‘amplitude’ ‘phase’ if we see the amplitude or phase of the field
  • min_step – minimum step for consider a transition
Returns:

array with +1, -1 with rasing or falling edges pos_transition: positions x of transitions raising: positions of raising falling: positions of falling

Return type:

type_transition

ifft(z=None, shift=True, remove0=True, matrix=False, new_field=False, verbose=False)[source]

Inverse Fast Fourier Transform (ifft) of the field.

Parameters:
  • z (float) – distance to the observation plane or focal of lens
  • shift (bool) – if True, fftshift is performed
  • remove0 (bool) – if True, central point is removed
  • matrix (bool) – if True only matrix is returned. If False, returns Scalar_field_X
  • new_field (bool) – if True returns Scalar_field_X, else it puts in self
  • verbose (bool) – if True, prints info
Returns:

FFT of the input field

Return type:

(array or Scalar_field_X or None)

incident_field(u0)[source]

Incident field for the experiment. It takes a Scalar_source_X field.

Parameters:u0 (Scalar_source_X) – field produced by Scalar_source_X (or a X field)
insert_array_masks(t1, x_pos, clean=True, kind_position='left')[source]

Insert several identical masks t1 in self.u according to positions x_pos

Parameters:
  • t1 (Scalar_field_X) – mask to insert.
  • x_pos (numpy.array) – array with locations.
  • clean (bool) – elliminate preview fields in self.
  • kind_position (str) – ‘left’, ‘center’: positions are at left or center.
insert_mask(t1, x0_mask1, clean=True, kind_position='left')[source]

Insert mask t1 in mask self. It is performed using interpolation.

Parameters:
  • t1 (Scalar_field_X) – field X (shorter)
  • x0_mask1 (float) – location of starting point at t0 of init point of t1.
  • clean (bool) – if True remove previous fields, else substitute
  • kind_position (str) – ‘left’ ‘center’
intensity()[source]

Intensity.

Returns:Intensity
Return type:(numpy.array)
load_data(filename, verbose=False)[source]
Load data from a file to a Scalar_field_X.
The methods included are: npz, matlab
Parameters:
  • filename (str) – filename
  • verbose (bool) – shows data process by screen
normalize(kind='intensity', new_field=False)[source]

Normalizes the field so that intensity.max()=1.

Parameters:
  • kind (str) – ‘intensity, ‘amplitude’, ‘logarithm’… other.. Normalization technique
  • new_field (bool) – If False the computation goes to self.u. If True a new instance is produced
Returns
u (numpy.array): normalized optical field
save_data(filename, add_name='', description='', verbose=False)[source]

Common save data function to be used in all the modules. The methods included are: npz, matlab

Parameters:
  • filename (str) – filename
  • add_name= (str) – sufix to the name, if ‘date’ includes a date
  • description (str) – text to be stored in the dictionary to save.
  • verbose (bool) – If verbose prints filename.
Returns:

filename. If False, file could not be saved.

Return type:

(str)

diffractio.scalar_fields_X.WPM_schmidt_kernel(u, n, k0, k_perp2, dz)[source]

Kernel for fast propagation of WPM method

Parameters:
  • u (np.array) – fields
  • n (np.array) – refraction index
  • k0 (float) – wavenumber
  • k_perp2 (np.array) – transversal k**2
  • dz (float) – increment in distances

References

      1. Fertig and K.-H. Brenner, “Vector wave propagation method,” J. Opt. Soc. Am. A, vol. 27, no. 4, p. 709, 2010.
    1. Schmidt et al., “Wave-optical modeling beyond the thin-element-approximation,” Opt. Express, vol. 24, no. 26, p. 30188, 2016.
diffractio.scalar_fields_X.extended_polychromatic_source(function_process, x0s, wavelengths, spectrum, num_processors=2, verbose=False)[source]

It performs an analysis of extendes source light. It needs a function with only an input parameter, that is x0s positions of sources. It determines the intensity for each wavelength and it is added.

Parameters:
  • function_process (function) – function with accepts params as input Parameters:
  • x0s (array) – positions of sources
  • wavelengths (array) – wavelengths in the spectrum
  • spectrum (array) – weights for the spectrum. If None: uniform spectrum, else array with the same dimension as wavelengths
  • num_processors (int) – number of processors for the computation
  • verbose (bool) – if True send information to shell
Returns:

intensity = intensity + spectrum[i] * np.abs(u_s[i].u)**2 - u_s (Scalar_field_X): fields for each wavelength - time_proc (float): time interval in the processing

Return type:

  • intensity (array, complex)

diffractio.scalar_fields_X.extended_source_multiprocessing(function_process, x0s, num_processors=2, verbose=False)[source]

It performs an analysis of extendes source light. It needs a function with only an input parameter, that is x0s positions of sources. It determines the intensity for each wavelength and it is added.

Parameters:
  • function_process (function) – function with accepts params as input Parameters:
  • x0s (array) – positions of sources
  • num_processors (int) – number of processors for the computation
  • verbose (bool) – if True send information to shell
Returns:

intensity = intensity + spectrum[i] * np.abs(u_s[i].u)**2 - u_s (Scalar_field_X): fields for each wavelength - time_proc (float): time interval in the processing

Return type:

  • intensity (array, complex)

diffractio.scalar_fields_X.kernelRS(x, wavelength, z, n=1, kind='z', fast=False)[source]

Kernel for RS propagation. It uses the hankel tansform.

There is a ‘fast’ version based on \(hk_1 = \sqrt{2/(\pi \, k \, R)} e^{i (k \, R - 3 \pi / 4)}\) which approximates the result.

Parameters:
  • x (numpy.array) – positions x
  • wavelength (float) – wavelength of incident fields
  • z (float) – distance for propagation
  • n (float) – refraction index of background
  • kind (str) – ‘z’, ‘x’, ‘0’: for simplifying vector propagation
  • fast (bool) – If True The approximation is much faster. According to https://dlmf.nist.gov/10.2#E5
Returns:

kernel

Return type:

(complex array)

References

  • https://dlmf.nist.gov/10.2#E5
    1. Shen and A. Wang, “Fast-Fourier-transform based numerical integration method for the Rayleigh-Sommerfeld diffraction formula,” Appl. Opt., vol. 45, no. 6, pp. 1102–1110, 2006.
diffractio.scalar_fields_X.kernelRSinverse(x, wavelength, z, n=1, kind='z', fast=False)[source]

Kernel for inverse RS propagation. See also kernelRS

Parameters:
  • x (numpy.array) – positions x
  • wavelength (float) – wavelength of incident fields
  • z (float) – distance for propagation
  • n (float) – refraction index of background
  • kind (str) – ‘z’, ‘x’, ‘0’: for simplifying vector propagation
  • fast (bool) – If True The approximation is much faster. According to https://dlmf.nist.gov/10.2#E5
Returns:

kernel

Return type:

complex array

diffractio.scalar_fields_X.polychromatic_multiprocessing(function_process, wavelengths, spectrum, num_processors=2, verbose=False)[source]

It performs an analysis of polychromatic light. It needs a function with only one input parameter: wavelength. It determines the intensity for each wavelength and the final results is the summation of the intensities.

Parameters:
  • function_process (function) – function with accepts params as input parameters:
  • wavelengths (array) – wavelengths in the spectrum
  • spectrum (array) – weights for the spectrum. if None: uniform spectrum, else array with the same dimension as wavelengths
  • num_processors (int) – number of processors for the computation
  • verbose (bool) – if True send information to shell
Returns:

intensity = intensity + spectrum[i] * np.abs(u_s[i].u)**2 u_s (Scalar_field_X): fields for each wavelength time_proc (float): time interval in the processing

Return type:

intensity (array, complex)

4.1.4. diffractio.scalar_fields_XY module

This module generates Scalar_field_XY class.

It can be considered an extension of Scalar_field_X for visualizing XY fields

For the case of Rayleigh sommefeld it is not necessary to compute all z positions but the final.

Nevertheless, for BPM method, intermediate computations are required. In this class, intermediate results are stored.

X,Y fields are defined using ndgrid (not with meshgrid, it is different).

It is required also for generating masks and fields.

The main atributes are:
  • self.x - x positions of the field
  • self.y - y positions of the field
  • self.wavelength - wavdelength of the incident field. The field is monochromatic
  • self.u (numpy.array): equal size to x * y. complex field
  • self.X (numpy.array): equal size to x * y. complex field
  • self.Y (numpy.array): equal size to x * y. complex field
  • self.quality (float): quality of RS algorithm
  • self.info (str): description of data
  • self.type (str): Class of the field
  • self.date (str): date of execution

The magnitude is related to microns: micron = 1.

Class for XY scalar fields

Definition of a scalar field
  • instatiation,
  • save, load data
  • cut_resample, binarize, discretize
  • get_phase, get_amplitude, remove_amplitude, remove_phase, amplitude2phase, phase2amplitude
Propagation
  • fft, ifft, RS, RS_simple, RS_amplificacion
Drawing functions
  • draw, draw_profile,
  • video, progresion
Parameters
  • profile
Functions outside the class
  • draw_several_fields
  • draw2D
  • several_propagations
  • kernelRS, kernelRSinverse, kernelFresnel
diffractio.scalar_fields_XY.PWD_kernel(u, n, k0, k_perp2, dz)[source]

Step for scalar(TE) Plane wave decomposition(PWD) algorithm.

Parameters:
  • u (np.array) – field
  • n (np.array) – refraction index
  • k0 (float) – wavenumber
  • k_perp (np.array) – transversal k
  • dz (float) – increment in distances
Returns:

Field at at distance dz from the incident field

Return type:

(numpy.array)

References

  1. Schmidt, S. et al. Wave - optical modeling beyond the thin - element - approximation. Opt. Express 24, 30188 (2016).
class diffractio.scalar_fields_XY.Scalar_field_XY(x=None, y=None, wavelength=None, info='')[source]

Bases: object

Class for working with XY scalar fields.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly \(2^n\) .
  • y (numpy.array) – linear array wit equidistant positions for y values
  • wavelength (float) – wavelength of the incident field
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.y

linear array wit equidistant positions for y values

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.u

(x,z) complex field

Type:numpy.array
self.info

String with info about the simulation

Type:str
MTF(kind='mm', has_draw=True, is_matrix=True)[source]

Computes the MTF of a field, If this field is near to focal point, the MTF will be wide

Parameters:
  • kind (str) – ‘mm’, ‘degrees’
  • has_draw (bool) – If True draws the MTF
Returns:

frequencies in lines/mm (numpy.array) mtf_norm: normalizd MTF

Return type:

(numpy.array) fx

RS(z, amplification=(1, 1), n=1, new_field=True, matrix=False, kind='z', verbose=False)[source]

Fast-Fourier-Transform method for numerical integration of diffraction Rayleigh-Sommerfeld formula. Is we have a field of size N*M, the result of propagation is also a field N*M. Nevertheless, there is a parameter amplification which allows us to determine the field in greater observation planes (jN)x(jM).

Parameters:
  • amplification (int, int) – number of frames in x and y direction
  • z (float) – distance to observation plane. if z<0 inverse propagation is executed
  • n (float) – refraction index
  • new_field (bool) – if False the computation goes to self.u, if True a new instance is produced
  • kind (str) –
  • verbose (bool) – if True it writes to shell
Returns:

Scalar_field_X, else None.

Return type:

if New_field is True

Note

One advantage of this approach is that it returns a quality parameter: if self.quality>1, propagation is right.

References

Applied Optics vol 45 num 6 pp. 1102-1110 (2006).

WPM(fn, z_ini, z_end, dz, has_edges=True, matrix=False, verbose=False)[source]

WPM Methods. ‘schmidt method is very fast, only needs discrete number of refraction indexes’

Parameters:
  • - índice de refracción función (fn) –
  • kind (str) – ‘schmidt, scalar, TE, TM
  • filter (1, or np.array) – filter for edges
  • matrix (bool) – if True returns a matrix else
  • verbose (bool) – If True prints information

References

      1. Fertig and K.-H. Brenner, “Vector wave propagation method,” J. Opt. Soc. Am. A, vol. 27, no. 4, p. 709, 2010.
    1. Schmidt et al., “Wave-optical modeling beyond the thin-element-approximation,” Opt. Express, vol. 24, no. 26, p. 30188, 2016.
add(other, kind='standard')[source]

adds two Scalar_field_x. For example two light sources or two masks

Parameters:
  • other (Scalar_field_X) – 2 field to add
  • kind (str) – instruction how to add the fields: - ‘maximum1’: mainly for masks. If t3=t1+t2>1 then t3= 1. - ‘standard’: add fields u3=u1+u2 and does nothing.
Returns:

u3 = u1 + u2

Return type:

Scalar_field_X

average_intensity(verbose=False)[source]

Returns average intensity as: (np.abs(self.u)**2).sum() / num_data.

Parameters:verbose (bool) – If True prints data.
beam_width_4s(has_draw=True)[source]

Returns the beam width parameters according to ISO11146.

Parameters:has_draw (bool) – If True, it draws
Returns:dx width x (float): dy width y (float): principal_axis, angle (str): (x_mean, y_mean, x2_mean, y2_mean, xy_mean), Moments
Return type:(float)

References

binarize(kind='amplitude', corte=None, level0=None, level1=None, new_field=False, matrix=False)[source]

Changes the number of points in field, mantaining the area.

Parameters:
  • kind (str) – ‘amplitude’ or ‘phase’
  • corte (float) – value of cut. If None, the cut is in the mean value
  • level0 (float) – minimum value. If None, minimum value of field
  • level1 (float) – maximum value. If None, maximum value of field
  • new_field (bool) – if True returns new field
  • matrix (bool) – if True it returs a matrix
Returns:

if new_field is True returns Scalar_field_XY

Return type:

Scalar_field_XY

clear_field()[source]

Removes the field: self.u=0.

cut_resample(x_limits='', y_limits='', num_points=[], new_field=False, interp_kind=(3, 1))[source]

it cut the field to the range (x0,x1). If one of this x0,x1 positions is out of the self.x range it do nothing. It is also valid for resampling the field, just write x0,x1 as the limits of self.x

Parameters:
  • x_limits (float,float) – (x0,x1) starting and final points to cut. if ‘’ - takes the current limit x[0] and x[-1]
  • y_limits (float,float) – (y0,y1) - starting and final points to cut. if ‘’ - takes the current limit y[0] and y[-1]
  • num_points (int) – it resamples x, y and u. [],’’,,None -> it leave the points as it is
  • new_field (bool) – it returns a new Scalar_field_XY
  • interp_kind – numbers between 1 and 5
discretize(kind='amplitude', num_levels=2, factor=1, phaseInicial=0, new_field=True, matrix=False)[source]

Discretize in a number of levels equal to num_levels.

Parameters:
  • kind (str) – “amplitude” o “phase”
  • num_levels (int) – number of levels for the discretization
  • factor (float) – from the level, how area is binarized. if 1 everything is binarized,
  • phaseInicial (float) –
  • new_field (bool) – if True returns new field
  • matrix (bool) – if True it returs a matrix
Returns:

if new_field is True returns Scalar_field_XY

Return type:

Scalar_field_XY

draw(kind='intensity', logarithm=False, normalize=False, title='', filename='', cut_value=None, has_colorbar='', colormap_kind='', reduce_matrix='standard', **kwargs)[source]

Draws XY field.

Parameters:
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’, ‘ ‘field’, ‘real_field’, ‘contour’
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (str) – False, ‘maximum’, ‘area’, ‘intensity’
  • title (str) – title for the drawing
  • filename (str) – if not ‘’ stores drawing in file,
  • cut_value (float) – if provided, maximum value to show
  • has_colorbar (bool) – if True draws the colorbar
  • reduce_matrix (str) – ‘standard’
draw_profile(point1='', point2='', npixels=None, kind='intensity', order=2)[source]

Draws profile in image. If points are not given, then image is shown and points are obtained clicking.

Parameters:
  • point1 (float) – initial point. if ‘’ get from click
  • point2 (float) – final point. if ‘’ get from click
  • npixels (int) – number of pixels for interpolation
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’
  • order (int) – order for interpolation
Returns:

profile numpy.array: z values for profile (float, float): point1 (float, float): point2

Return type:

numpy.array

fft(z=10000.0, shift=True, remove0=True, matrix=False, new_field=False)[source]

Fast Fourier Transform (FFT) of the field. TODO: change to the frequency domain.

Parameters:
  • z (float) – distance to the observation plane or focal of lens
  • shift (bool) – if True, fftshift is performed
  • remove0 (bool) – if True, central point is removed
  • matrix (bool) – if True only matrix is returned. if False, returns Scalar_field_X
  • new_field (bool) – if True returns Scalar_field_X, else it puts in self
Returns:

FFT of the input field

Return type:

(np.array or Scalar_field_X or None)

get_amplitude(matrix=False, new_field=False)[source]

Gets the amplitude of the field.

Parameters:
  • matrix (bool) – if True numpy.matrix is returned
  • new_field (bool) – if True it returns a new Scalar_field_XY
Returns:

Scalar_field_X if Matrix is True: numpy.array

Return type:

if New_field is True

get_edges(kind_transition='amplitude', min_step=0, verbose=False, filename='')[source]

Determine locations of edges for a binary mask. Valid for litography engraving of gratings.

Parameters:
  • kind_transition – ‘amplitude’ ‘phase’.
  • min_step – minimum step for consider a transition
Returns:

array with +1, -1 with rasing or falling edges pos_transition: positions x of transitions raising: positions of raising falling: positions of falling

Return type:

type_transition

get_phase(matrix=False, new_field=False)[source]

Gets the phase of the field.

Parameters:
  • matrix (bool) – if True numpy.matrix is returned
  • new_field (bool) – if True it returns a new Scalar_field_XY
Returns:

Scalar_field_X. if Matrix is True: numpy.array.

Return type:

if New_field is True

ifft(z=10000.0, shift=True, remove0=True, matrix=False)[source]

Fast Fourier Transform (fft) of the field.

Parameters:
  • z (float) – distance to the observation plane or focal of lens
  • shift (bool) – if True, fftshift is performed
  • remove0 (bool) – if True, central point is removed
  • matrix (bool) – if True only matrix is returned. If False, returns Scalar_field_X
  • new_field (bool) – if True returns Scalar_field_X, else puts in self
Returns:

FFT of the input field

Return type:

(np.array or Scalar_field_X or None)

incident_field(u0)[source]

Incident field for the experiment. It takes a Scalar_source_X field.

Parameters:u0 (Scalar_source_X) – field produced by Scalar_source_X (or a X field)
intensity()[source]

Returns intensity.

load_data(filename, verbose=False)[source]
Load data from a file to a Scalar_field_X.
The methods included are: npz, matlab
Parameters:
  • filename (str) – filename
  • verbose (bool) – shows data process by screen
normalize(kind='intensity')[source]

Normalize the field.

Parameters:kind (str) – ‘intensity’ ‘area’
profile(point1='', point2='', npixels=None, kind='intensity', order=2)[source]

Determine profile in image. If points are not given, then image is shown and points are obtained clicking.

Parameters:
  • point1 (float) – initial point. if ‘’ get from click
  • point2 (float) – final point. if ‘’ get from click
  • npixels (int) – number of pixels for interpolation
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’
  • order (int) – order for interpolation
Returns:

profile numpy.array: z values for profile (float, float): point1 (float, float): point2

Return type:

numpy.array

remove_phase(sign=False, matrix=False, new_field=False)[source]

Removes the phase of the field. Amplitude is kept.

Parameters:
  • sign (bool) – If True, sign is kept, else, it is removed
  • matrix (bool) – if True numpy.matrix is returned
  • new_field (bool) – if True it returns a new Scalar_field_XY
Returns:

Scalar_field_X. if Matrix is True: numpy.array.

Return type:

if New_field is True

rotate(angle, position=None)[source]

Rotation of X,Y with respect to position. If position is not given, rotation is with respect to the center of the image

Parameters:
  • angle (float) – angle to rotate, in radians
  • position (float, float) – position of center of rotation
save_data(filename, add_name='', description='', verbose=False)[source]

Common save data function to be used in all the modules. The methods included are: npz, matlab

Parameters:
  • filename (str) – filename
  • add_name= (str) – sufix to the name, if ‘date’ includes a date
  • description (str) – text to be stored in the dictionary to save.
  • verbose (bool) – If verbose prints filename.
Returns:

filename. If False, file could not be saved.

Return type:

(str)

save_mask(filename='', kind='amplitude', binarize=False, info='')[source]

Create a mask in a file, for example, ablation or litography engraver

Parameters:
  • filename (str) – file name
  • kind (str) – save amplitude or phase
  • binarize (bool) – If True convert the mask in (0,1) levels
  • info (str) – info of the mask
Returns:

area (in um**2)

Return type:

float

search_focus(kind='moments', verbose=True)[source]

Search for location of .

Parameters:
  • kind (str) – ‘moments’ or ‘maximum’
  • verbose (bool) – If True prints information.
Returns:

positions of focus

Return type:

(x,y)

send_image_screen(id_screen, kind='amplitude')[source]

Takes the images and sends the images to a screen in full size.

Parameters:
  • id_screen (hdl) – handle to screen
  • kind ('str') – ‘amplitude’, ‘intensity’, ‘phase’
video(kind, zs, logarithm=False, normalize=False, time_video=10.0, frames_reduction=1, filename='video.avi', dpi=300)[source]

Makes a video

Parameters:kind (str) – ‘intensity’, ‘phase’, ‘amplitude’
diffractio.scalar_fields_XY.WPM_schmidt_kernel(u, n, k0, k_perp2, dz)[source]

Kernel for fast propagation of WPM method

Parameters:
  • u (np.array) – fields
  • n (np.array) – refraction index
  • k0 (float) – wavenumber
  • k_perp2 (np.array) – transversal k**2
  • dz (float) – increment in distances

References

      1. Fertig and K.-H. Brenner, “Vector wave propagation method,” J. Opt. Soc. Am. A, vol. 27, no. 4, p. 709, 2010.
    1. Schmidt et al., “Wave-optical modeling beyond the thin-element-approximation,” Opt. Express, vol. 24, no. 26, p. 30188, 2016.
diffractio.scalar_fields_XY.kernelFresnel(X, Y, wavelength=0.6328, z=10000.0, n=1)[source]

Kernel for Fesnel propagation

Parameters:
  • X (numpy.array) – positions x
  • Y (numpy.array) – positions y
  • wavelength (float) – wavelength of incident fields
  • z (float) – distance for propagation
  • n (float) – refraction index of background
Returns:

kernel

Return type:

complex np.array

diffractio.scalar_fields_XY.kernelRS(X, Y, wavelength, z, n=1, kind='z')[source]

Kernel for RS propagation.

Había una errata según: Juan Valencia <valen167@umn.edu> 210131

Parameters:
  • X (numpy.array) – positions x
  • Y (numpy.array) – positions y
  • wavelength (float) – wavelength of incident fields
  • z (float) – distance for propagation
  • n (float) – refraction index of background
  • kind (str) – ‘z’, ‘x’, ‘0’: for simplifying vector propagation
Returns:

kernel

Return type:

complex np.array

diffractio.scalar_fields_XY.kernelRSinverse(X, Y, wavelength=0.6328, z=-10000.0, n=1, kind='z')[source]

Kernel for inverse RS propagation

Parameters:
  • X (numpy.array) – positions x
  • Y (numpy.array) – positions y
  • wavelength (float) – wavelength of incident fields
  • z (float) – distance for propagation
  • n (float) – refraction index of background
  • kind (str) – ‘z’, ‘x’, ‘0’: for simplifying vector propagation
Returns:

kernel

Return type:

complex np.array

4.1.5. diffractio.scalar_fields_XYZ module

This module generates Scalar_field_XYZ class and several functions for multiprocessing. It is required also for generating masks and fields. The main atributes are:

  • self.u - field XYZ
  • self.x - x positions of the field
  • self.y - y positions of the fieldalgorithm
  • self.z - z positions of the field
  • self.wavelength - wavelength of the incident field. The field is monochromatic
  • self.u0 - initial field at z=z0
  • self.n_background - background refraction index
  • self.n - refraction index

The magnitude is related to microns: micron = 1.

Class for unidimensional scalar fields

Definition of a scalar field
  • load and save data
  • to_Scalar_field_XY
  • xy_2_xyz
  • cut_function
  • __rotate__
  • __rotate_axis__
Propagation
  • RS - Rayleigh Sommerfeld
  • RS_amplification
  • BPM - Beam Propagation method
Drawing functions
  • draw_XYZ
  • draw_XY
  • draw_XZ
  • draw_volume
  • draw_refraction_index
  • video
class diffractio.scalar_fields_XYZ.Scalar_field_XYZ(x=None, y=None, z=None, wavelength=None, n_background=1.0, info='')[source]

Bases: object

Class for 3D scalar fields.

Parameters:
  • u0 (Scalar_field_XY) – Initial scalar field. wavelength, and x, y arrays are obtained from this field.
  • z (numpy.array) – linear array with equidistant positions.
  • n_background (float) – refraction index of background
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.y

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.z

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.u

equal size than X. complex field

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.u0

Initial XY field

Type:Scalar_field_XY
self.n_background

background refraction index.

Type:float
self.n

refraction index. Same dimensions than self.u.

Type:numpy.array
BPM(has_edges=True, pow_edge=80, verbose=False)[source]

3D Beam propagation method (BPM).

Parameters:
  • has_edges (bool) – If True absorbing edges are used.
  • pow_edge (float) – If has_edges, power of the supergaussian
  • verbose (bool) – shows data process by screen

References

Algorithm in “Engineering optics with matlab” pag 119

PWD(n=None, matrix=False, verbose=False)[source]

Plane wave decompostion algorithm.

Parameters:
  • n (np. array) – refraction index, If None, it is n_background
  • verbose (bool) – If True prints state of algorithm
Returns:

Field at at distance dz from the incident field

Return type:

numpy.array()

References

  1. Schmidt, S. et al. Wave-optical modeling beyond the thin-element-approximation. Opt. Express 24, 30188 (2016).
RS(verbose=False, num_processors=0)[source]

Rayleigh Sommerfeld propagation algorithm

Parameters:
  • verbose (bool) – shows the quality of algorithm (>1 good)
  • num_processors (int) – number of processors for multiprocessing
Returns:

time in the processing

RS_amplification(amplification=(1, 1))[source]

Rayleigh Sommerfeld propagation algorithm. it performs amplification

Parameters:amplification (int,int) – number of fields
Returns:
Return type:Scalar_field_XY
WPM(has_edges=True, pow_edge=80, verbose=False)[source]

WPM Methods. ‘schmidt method is very fast, only needs discrete number of refraction indexes’

Parameters:
  • has_edges (bool) – If True absorbing edges are used.
  • pow_edge (float) – If has_edges, power of the supergaussian
  • verbose (bool) – If True prints information

References

      1. Fertig and K.-H. Brenner, “Vector wave propagation method,” J. Opt. Soc. Am. A, vol. 27, no. 4, p. 709, 2010.
    1. Schmidt et al., “Wave-optical modeling beyond the thin-element-approximation,” Opt. Express, vol. 24, no. 26, p. 30188, 2016.
beam_widths(kind='FWHM2D', has_draw=[True, False], percentaje=0.5, verbose=False)[source]

Determines the widths of the beam

Parameters:
  • kind (str) – kind of algorithm: ‘sigma4’, ‘FWHM2D’
  • has_draw (bool, bool) – First for complete analysis, second for all FWHM2D computations
  • verbose (bool) – prints info
Returns:

beam_width_x (np.array) beam_width_y (np.array) principal_axis_z (np.array)

clear_field()[source]

clear field.

clear_refraction_index()[source]

clear refraction index n(x,z)=n_background.

cut_resample(x_limits='', y_limits='', z_limits='', num_points=[], new_field=False, interp_kind=(3, 1))[source]

it cut the field to the range (x0,x1). If one of this x0,x1 positions is out of the self.x range it do nothing. It is also valid for resampling the field, just write x0,x1 as the limits of self.x

Parameters:
  • x_limits (float,float) – (x0,x1) starting and final points to cut, if ‘’ - takes the current limit x[0] and x[-1]
  • y_limits (float,float) – (y0,y1) - starting and final points to cut, if ‘’ - takes the current limit y[0] and z[-1]
  • num_points (int) – it resamples x, y and u, where [],’’,0,None -> it leave the points as it is new_field (bool): it returns a new Scalar_field_XY
  • interp_kind – numbers between 1 and 5
draw_XY(z0=5000.0, kind='intensity', logarithm=0, normalize='maximum', title='', filename='', cut_value='', has_colorbar='False', reduce_matrix='')[source]

longitudinal profile XY at a given z value

Parameters:
  • z0 (float) – value of z for interpolation
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’, ‘ ‘field’, ‘real_field’, ‘contour’
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (str) – False, ‘maximum’, ‘area’, ‘intensity’
  • title (str) – title for the drawing
  • filename (str) – if not ‘’ stores drawing in file,
  • cut_value (float) – if provided, maximum value to show
  • has_colorbar (bool) – if True draws the colorbar
  • () (reduce_matrix) –
draw_XYZ(kind='intensity', logarithm=False, normalize='', pixel_size=(128, 128, 128))[source]

Draws XZ field.

Parameters:
  • kind (str) – type of drawing: ‘intensity’, ‘phase’, ‘real_field’
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
  • pixel_size (float, float, float) – pixels for drawing
draw_XZ(y0=0.0, logarithm=0, normalize='', draw_borders=False, filename='')[source]

Longitudinal profile XZ at a given x0 value.

Parameters:
  • y0 (float) – value of y for interpolation
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (str) – False, ‘maximum’, ‘intensity’, ‘area’
  • draw_borders (bool) – check
  • filename (str) – filename to save
draw_YZ(x0=0.0, logarithm=0, normalize='', draw_borders=False, filename='')[source]

Longitudinal profile YZ at a given x0 value.

Parameters:
  • x0 (float) – value of x for interpolation
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (str) – False, ‘maximum’, ‘intensity’, ‘area’
  • draw_borders (bool) – check
  • filename (str) – filename to save
draw_proposal(kind='intensity', logarithm=0, normalize='maximum', draw_borders=False, filename='', scale='', min_incr=0.0005, reduce_matrix='standard', colorbar_kind=False, colormap_kind='gist_heat')[source]

Draws XYZ field.

Parameters:
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’, ‘real’
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
  • draw_borders (bool) – If True draw edges of objects
  • filename (str) – if not ‘’ stores drawing in file,
  • scale (str) – ‘’, ‘scaled’, ‘equal’, scales the XY drawing
  • min_incr – incrimum increment in refraction index for detecting edges
  • reduce_matrix (int, int) – when matrix is enormous, we can reduce it only for drawing purposes. If True, reduction factor
draw_refraction_index(kind='real')[source]

Draws XYZ refraction index with slicer

Parameters:kind (str) – ‘real’, ‘imag’, ‘abs’
draw_volume(logarithm=0, normalize='', maxintensity=None)[source]

Draws XYZ field with mlab

Parameters:
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
  • maxintensity (float) – maximum value of intensity
final_field()[source]

Returns the final field as a Scalar_field_XYZ.

incident_field(u0, z0=None)[source]

Incident field for the experiment. It takes a Scalar_source_XYZ field.

Parameters:
  • u0 (Scalar_source_X) – field produced by Scalar_source_XYZ (or a XYZ field)
  • z0 (float) – position of the incident field. if None, ‘’, [], is at the beginning
load_data(filename, verbose=False)[source]
Load data from a file to a Scalar_field_XZ.
The methods included are: npz, matlab
Parameters:
  • filename (str) – filename
  • verbose (bool) – shows data process by screen
save_data(filename, add_name='', description='', verbose=False)[source]

Common save data function to be used in all the modules. The methods included are: npz, matlab

Parameters:
  • filename (str) – filename
  • add_name= (str) – sufix to the name, if ‘date’ includes a date
  • description (str) – text to be stored in the dictionary to save.
  • verbose (bool) – If verbose prints filename.
Returns:

filename. If False, file could not be saved.

Return type:

(str)

surface_detection(mode=1, min_incr=0.01, has_draw=False)[source]

detect edges of variation in refraction index

Parameters:
  • min_incr (float) – minimum incremental variation to detect.
  • has_draw (bool) – if True, it draws the surface.
to_Scalar_field_XY(iz0=None, z0=None, is_class=True, matrix=False)[source]

pass results to Scalar_field_XY. Only one of the first two variables (iz0,z0) should be used

Parameters:
  • iz0 (int) – position i of z data in array
  • z0 (float) – position z to extract
  • class (bool) – If True it returns a class
  • matrix (bool) – If True it returns a matrix
to_Scalar_field_XZ(iy0=None, y0=None, is_class=True, matrix=False)[source]

pass results to Scalar_field_XZ. Only one of the first two variables (iy0,y0) should be used

Parameters:
  • iy0 (int) – position i of y data in array
  • y0 (float) – position y to extract
  • class (bool) – If True it returns a class
  • matrix (bool) – If True it returns a matrix
to_Scalar_field_YZ(ix0=None, x0=None, is_class=True, matrix=False)[source]

pass results to Scalar_field_XZ. Only one of the first two variables (iy0,y0) should be used

Parameters:
  • ix0 (int) – position i of x data in array
  • x0 (float) – position x to extract
  • class (bool) – If True it returns a class
  • matrix (bool) – If True it returns a matrix
to_Z(kind='amplitude', x0=None, y0=None, has_draw=True, z_scale='mm')[source]

pass results to u(z). Only one of the first two variables (iy0,y0) and (ix0,x0) should be used.

Parameters:
  • kind (str) – ‘amplitude’, ‘intensity’, ‘phase’
  • x0 (float) – position x to extract
  • y0 (float) – position y to extract
  • has_draw (bool) – draw the field
  • z_scale (str) – ‘mm’, ‘um’
Returns:

array with z field (numpy.array): amplitude, intensity or phase of the field

Return type:

z (numpy.array)

video(filename='', kind='intensity', fps=15, frame=True, axis='auto', verbose=False, directory_name='new_video')[source]

Makes a video in the range given by self.z.

Parameters:
  • filename (str) – filename (.avi, .mp4)
  • kind (str) – type of drawing: ‘intensity’, ‘phase’.
  • fps (int) – frames per second
  • frame (bool) – figure with or without axis.
  • verbose (bool) – If True prints
xy_2_xyz(u0_XY, z)[source]

Similar to Init. send a Scalarfield_XY and passes to XYZ.

Parameters:
  • u0_XY (Scalar_field_XY) – init field
  • z (numpy.array) – array with z positions

4.1.6. diffractio.scalar_fields_XZ module

This module generates Scalar_field_XZ class.

It includes multiprocessing for RS and BPM polychromatic

It can be considered an extension of Scalar_field_X for visualizing XZ fields

For the case of Rayleigh sommefeld it is not necessary to compute all z positions but the final.

Nevertheless, for BPM method, intermediate computations are required. In this class, intermediate results are stored.

X,Z fields are defined using ndgrid (not with meshgrid, it is different).

It is required also for generating masks and fields. The main atributes are:

  • self.x - x positions of the field
  • self.z - z positions of the field
  • self.u - field XZ
  • self.n - refraction index XZ
  • self.wavelength - wavelength of the incident field. The field is monochromatic

The magnitude is related to microns: micron = 1.

Class for XZ scalar fields

Definition of a scalar field
  • instatiation, clean_refraction_index
  • save, load data
  • rotate_field, cut_resample,
Illumination
  • incident_field
Operations
  • surface_detection
  • search focus
Propagation
  • RS, RS_polychormatic,
  • BPM, BPM_poychromatic, BPM_inverse, BPM_back_propagation
Drawing functions
  • draw
  • draw_refraction_index
  • draw_incident_field
  • video_profiles
  • draw_profiles_interactive
Parameters
  • final_field
  • profile_longitudinal
  • profile_transversal
class diffractio.scalar_fields_XZ.Scalar_field_XZ(x=None, z=None, wavelength=None, n_background=1, info='')[source]

Bases: object

Class for working with XZ scalar fields.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly \(2^n\) .
  • z (numpy.array) – linear array wit equidistant positions for z values
  • wavelength (float) – wavelength of the incident field
  • n_background (float) – refraction index of background
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.z

linear array wit equidistant positions for z values

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.u0
  1. size x - field at the last z position
Type:numpy.array
self.u

(x,z) complex field

Type:numpy.array
self.n_background

(x,z) refraction index

Type:numpy.array
self.fast

if True fast algoritm (approx. Hankle function)

Type:bool
self.info

String with info about the simulation

Type:str
BPM(division=False, matrix=False, verbose=False)[source]

Beam propagation method (BPM).

Parameters:
  • division (False, int) – If False nothing, else divides the BPM algorithm in several different executions. To avoid RAM problems
  • matrix (bool) – if True returns a matrix else
  • verbose (bool) – shows data process by screen

References

Algorithm in “Engineering optics with matlab” pag 119.

BPM_back_propagation(verbose=False)[source]

Beam propagation method (BPM). The field that generates the final field is obtained.

Parameters:verbose (bool) – shows data process by screen

References

Algorithm in “Engineering optics with matlab” pag 119

BPM_inverse(verbose=False)[source]

Beam propagation method (BPM) in inverse mode.

Parameters:verbose (bool) – shows data process by screen

References

Algorithm in “Engineering optics with matlab” pag 119

BPM_polychromatic(initial_field, wavelengths, spectrum, verbose=False, num_processors=4)[source]

Rayleigh Sommerfeld propagation algorithm for polychromatic light

Parameters:
  • initial_field (Scalar_field_X) – function with only input variable wavelength
  • wavelengths (numpy.array) – array with wavelengths
  • spectrum (numpy.array) – array with spectrum. if ‘’ then uniform_spectrum
  • verbose (bool) – shows the quality of algorithm (>1 good)
  • num_processors (int) – number of processors for multiprocessing
Returns:

self.u=sqrt(Intensities) - no phase is stored, only intensity

Return type:

Scalar_field_XZ

M_xz(j, kx)[source]

Refraction matrix given in eq. 18 from M. W. Fertig and K.-H. Brenner, “Vector wave propagation method,” J. Opt. Soc. Am. A, vol. 27, no. 4, p. 709, 2010.

PWD(n=None, matrix=False, verbose=False)[source]

Plane wave decomposition algorithm (PWD).

Parameters:
  • n (np. array) – refraction index, If None, it is n_background
  • matrix (bool) – if True returns a matrix else
  • verbose (bool) – If True prints state of algorithm
Returns:

Field at at distance dz from the incident field

Return type:

numpy.array()

References

  1. Schmidt, S. et al. Wave-optical modeling beyond the thin-element-approximation. Opt. Express 24, 30188 (2016).
RS(xout=None, yout=None, verbose=False, num_processors=2)[source]

Rayleigh Sommerfeld propagation algorithm

Parameters:
  • verbose (bool) – shows the quality of algorithm (>1 good)
  • num_processors (int) – number of processors for multiprocessing
Returns:

time in the processing

RS_polychromatic(initial_field, wavelengths, spectrum='', verbose=False, num_processors=2)[source]

Rayleigh Sommerfeld propagation algorithm for polychromatic light.

Parameters:
  • initial_field (Scalar_field_X) – function with only input variable wavelength
  • wavelengths (numpy.array) – array with wavelengths
  • spectrum (numpy.array) – array with spectrum. if ‘’ then uniform_spectrum
  • verbose (bool) – shows the quality of algorithm (>1 good)
  • num_processors (int) – number of processors for multiprocessing
Returns:

self.u=sqrt(Intensities) - no phase is stored, only intensity

Return type:

Scalar_field_XZ

WPM(kind='schmidt', has_edges=True, pow_edge=80, matrix=False, verbose=False)[source]

WPM Methods. ‘schmidt method is very fast, only needs discrete number of refraction indexes’

Parameters:
  • kind (str) – ‘schmidt, scalar, TE, TM
  • has_edges (bool) – If True absorbing edges are used.
  • pow_edge (float) – If has_edges, power of the supergaussian
  • matrix (bool) – if True returns a matrix else
  • verbose (bool) – If True prints information

References

      1. Fertig and K.-H. Brenner, “Vector wave propagation method,” J. Opt. Soc. Am. A, vol. 27, no. 4, p. 709, 2010.
    1. Schmidt et al., “Wave-optical modeling beyond the thin-element-approximation,” Opt. Express, vol. 24, no. 26, p. 30188, 2016.
beam_widths(kind='FWHM1D', has_draw=[True, False], percentaje=0.5, remove_background=None, verbose=False)[source]

Computes the beam width for all the distances z. :param kind: kind of algorithm: ‘sigma4’, ‘FWHM1D’ :type kind: str :param has_draw: First for complete analysis, second for all FWHM2D computations :type has_draw: bool, bool :param verbose: prints info :type verbose: bool

Returns:for each distance z (numpy.array) positions_center: positions of centers for each z
Return type:(numpy.array) widths
check_intensity(draw=True, normalized=True)[source]

Checks that intensity distribution is not lost by edges. It can be executed after a RS or BPM propagation.

Parameters:
  • draw (bool) – Draws the intensity
  • normalized (bool) – Draws it normalized
Returns:

array with intensity I(z)

Return type:

(np.array)

clear_field()[source]

clear field

clear_refraction_index()[source]

clear refraction index n(x,z)=n_background

cut_resample(x_limits='', z_limits='', num_points=[], new_field=False, interp_kind=(3, 1))[source]

it cut the field to the range (x0,x1). if one of this x0,x1 positions is out of the self.x range it do nothing. It is also valid for resampling the field, just write x0,x1 as the limits of self.x

Parameters:
  • x_limits (float,float) – (x0,x1) starting and final points to cut. if ‘’ - takes the current limit x[0] and x[-1]
  • z_limits (float,float) – (z0,z1) - starting and final points to cut. if ‘’ - takes the current limit z[0] and z[-1]
  • num_points (int) – it resamples x, z and u. ([],’’,0,None) -> it leave the points as it is
  • new_field (bool) – it returns a new Scalar_field_XZ
  • interp_kind – numbers between 1 and 5
detect_index_variations(n_edge, incr_n=0.1)[source]

In a XZ masks, detects refraction index variations.

Parameteres:
n_edge (float): incr_n (float): refraction index variation to detect
Returns:x for left edge. h_lens_l (np.array): h for left edge. x_lens_r (np.array): x for right edge. h_lens_r (np.array): h for right edge.
Return type:x_lens_l (np.array)
discretize_refraction_index(n_layers)[source]

Takes a refraction index an discretize it according refraction indexes.

Parameters:n_layers (np.array) – array with refraction indexes to discretize
draw(kind='intensity', logarithm=0, normalize='', draw_borders=False, filename='', scale='', min_incr=0.0005, reduce_matrix='standard', colorbar_kind=False, colormap_kind='', z_scale='um', edge_matrix=None, interpolation='spline36', **kwargs)[source]

Draws XZ field.

Parameters:
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’, ‘real’
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
  • draw_borders (bool) – If True draw edges of objects
  • filename (str) – if not ‘’ stores drawing in file,
  • scale (str) – ‘’, ‘scaled’, ‘equal’, scales the XY drawing
  • min_incr – incrimum increment in refraction index for detecting edges
  • reduce_matrix (int, int) – when matrix is enormous, we can reduce it only for drawing purposes. If True, reduction factor
  • z_scale (str) – ‘mm’, ‘um’
  • edge_matrix (numpy.array) – positions of borders
  • interpolation (str) – methods = [None, ‘none’, ‘nearest’, ‘bilinear’, ‘bicubic’, ‘spline16’, ‘spline36’, ‘hanning’, ‘hamming’, ‘hermite’, ‘kaiser’, ‘quadric’, ‘catrom’, ‘gaussian’, ‘bessel’, ‘mitchell’, ‘sinc’, ‘lanczos’]
draw_incident_field(kind='intensity', logarithm=False, normalize=False, filename='')[source]

Draws incident field self.u0

Parameters:
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘field’, ‘phase’, ‘fill’, ‘fft’
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
  • filename (str) – if not ‘’ stores drawing in file,
draw_profiles_interactive(kind='intensity', logarithm=False, normalize=False)[source]

Draws profiles interactivey. Only transversal

Parameters:
  • kind (str) – ‘intensity’, ‘amplitude’, ‘phase’
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
draw_refraction_index(kind='all', draw_borders=True, title='', filename='', scale='', min_incr=0.01, reduce_matrix='standard', colorbar_kind=None, colormap_kind=<matplotlib.colors.LinearSegmentedColormap object>, edge_matrix=None)[source]

Draws refraction index.

Parameters:
  • kind (str) – ‘all’, ‘real’, ‘imag’
  • draw_borders (bool) – If True draw edges of objects
  • filename (str) – if not ‘’ stores drawing in file,
  • title (str) – title of drawing
  • scale (str) – ‘’, ‘scaled’, ‘equal’, scales the XY drawing
  • min_incr – minimum increment in refraction index for detecting edges
  • reduce_matrix (int, int) – when matrix is enormous, we can reduce it only for drawing purposes. If True, reduction factor
  • edge_matrix (numpy.array) – positions of borders
fast_propagation(mask_xz, num_pixels_slice=1024, verbose=False)[source]

combines RS and BPM”” to generate the final field

Parameters:
  • mask_xz (Scalar_mask_XZ) – function that returns Scalar_mask_XZ
  • num_pixels_slice (int) – num of slices for each BPM propagation
  • verbose (bool) – If True prints info.

Returns:

filter_refraction_index(type_filter=2, pixels_filtering=10, max_diff_filter=0.1, draw_check=False)[source]

Technique to remove artifacts in BPM propagation.

Parameters:
  • type_filter (int) – 1 - 2D, 2 - 1D z (selective), 3 - 1D x (selective)
  • pixels_filtering (int) – num_pixels used for filtering
  • max_diff_filter (float) – maximum difference of n in profile between two adjancted pixels to use selective filtering
  • draw_check (bool) – draw the differences.
Returns:

percentaje_filtered (np.array): lineas_filtradas

Return type:

(float)

References

Robert McLeod “Numerical Methods in Photonics Lecture Notes” University of Colorado at Boulder, pag 204 (15/54)

final_field()[source]

Returns the final field as a Scalar_field_X.

incident_field(u0, z0=None)[source]

Incident field for the experiment. It takes a Scalar_source_X field

Parameters:
  • u0 (Scalar_source_X) – field produced by Scalar_source_X (or a X field)
  • z0 (float) – position of the incident field. if None, ‘’, [], is at the beginning
intensity()[source]

Returns the intensity of the field

Returns:intensity of the field.
Return type:(np.array)
load_data(filename, verbose=False)[source]
Load data from a file to a Scalar_field_XZ.
The methods included are: npz, matlab
Parameters:
  • filename (str) – filename
  • verbose (bool) – shows data process by screen
mask_field(size_edge=0)[source]

mask the incident field at the edges, each edge is masked size_edge

Parameters:size_edge (float) – size of edges
profile_longitudinal(kind='intensity', x0=0.0, logarithm=False, normalize=False, draw=True, filename='')[source]

Determine and draws longitudinal profile

Parameters:
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’, ‘refraction_index’
  • x0 (float) – profile that passes through x=x0
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (str) – False, ‘maximum’, ‘intensity’, ‘area’
  • draw (bool) – If True, draws, False only returns profile
  • filename (str) – if not ‘’ stores drawing in file
Returns:

profile

Return type:

numpy.array

profile_transversal(kind='intensity', z0=0.0, logarithm=False, normalize=False, draw=True, filename='')[source]

Determine and draws transversal profile.

Parameters:
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’, ‘refraction_index’
  • z0 (float) – profile that passes through z=z0
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (str) – False, ‘maximum’, ‘intensity’, ‘area’
  • draw (bool) – If True, draws, False only returns profile
  • filename (str) – if not ‘’ stores drawing in file,
Returns:

profile

Return type:

numpy.array

rotate_field(angle, center_rotation, kind='all', n_background=1)[source]

Rotate all the image a certain angle

Parameters:
  • angle (float) – angle to rotate, in radians
  • n_background (float) – refraction index of zone incoming
  • kind (str) – ‘all’, ‘n’, ‘field’
  • center_rotation (float, float) – (z,x) position for rotation
save_data(filename, add_name='', description='', verbose=False)[source]

Common save data function to be used in all the modules. The methods included are: npz, matlab

Parameters:
  • filename (str) – filename
  • add_name= (str) – sufix to the name, if ‘date’ includes a date
  • description (str) – text to be stored in the dictionary to save.
  • verbose (bool) – If verbose prints filename.
Returns:

filename. If False, file could not be saved.

Return type:

(str)

search_focus(verbose=True)[source]

Search for location of maximum.

Parameters:
  • kind (str) – type of drawing: ‘amplitude’, ‘intensity’, ‘phase’, ‘refraction_index’
  • x0 (float) – profile that passes through x=x0
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (str) – False, ‘maximum’, ‘intensity’, ‘area’
  • draw (bool) – If True, draws, False only returns profile
  • filename (str) – if not ‘’ stores drawing in file,
Returns:

positions of focus

Return type:

(x,z)

surface_detection(mode=1, min_incr=0.1, reduce_matrix='standard', has_draw=False)[source]

detect edges of variation in refraction index.

Parameters:
  • mode (int) – 1 or 2, algorithms for surface detection: 1-gradient, 2-diff
  • min_incr (float) – minimum incremental variation to detect
  • reduce_matrix (int, int) – when matrix is enormous, we can reduce it only for drawing purposes. If True, reduction factor
  • has_draw (bool) – If True draw.
video(kind='intensity', z_min=None, z_max=None, logarithm=False, normalize=False, time_video=10.0, frames_reduction=5, filename='video.avi', dpi=300)[source]

Generates a video in the z dimension.

Parameters:
  • kind (str) –
  • z_min (float) –
  • z_max (float) –
  • logarithm (bool) –
  • normalize (bool) –
  • time_video (float) –
  • frames_reduction (int) –
  • filename (str) –
  • dpi (int) –
video_profiles(kind='intensity', kind_profile='transversal', step=1, wait=0.001, logarithm=False, normalize=False, filename='', verbose=False)[source]

Draws profiles in a video fashion

Parameters:
  • kind (str) – ‘intensity’, ‘amplitude’, ‘phase’
  • kind_profile (str) – ‘transversal’, ‘longitudinal’
  • step (list) – number of frames shown (if 1 shows all, if 2 1/2, ..) for accelerating pruposes in video.
  • wait (float) – (in seconds) time for slow down the video
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
  • filename – (str)) filename of video
  • verbose (bool) – If True shows info

4.1.7. diffractio.scalar_masks_X module

This module generates Scalar_mask_X class for definingn masks. Its parent is Scalar_field_X.

The main atributes are:
  • self.u - field
  • self.x - x positions of the field
  • self.wavelength - wavelength of the incident field. The field is monocromatic

Class for unidimensional scalar masks

Functions
  • mask_from_function, mask_from_array
  • slit, double slit
  • two_levels, gray_scale
  • prism, biprism_fresnel, biprism_fresnel_nh
  • lens, aspheric, fresnel_lens
  • roughness, dust, dust_different_sizes
  • sine_grating, ronchi_grating, binary_grating, blazed_grating
  • chriped_grating, chirped_grating_p, chirped_grating_q
  • I0s
class diffractio.scalar_masks_X.Scalar_mask_X(x=None, wavelength=None, n_background=1, info='')[source]

Bases: diffractio.scalar_fields_X.Scalar_field_X

Class for unidimensional scalar masks.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly \(2^n\) .
  • wavelength (float) – wavelength of the incident field
  • n_background (float) – refraction index of background
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.u

equal size than x. complex field

Type:numpy.array
self.quality

quality of RS algorithm

Type:float
self.info

description of data

Type:str
self.type

Class of the field

Type:str
self.date

date when performed

Type:str
aspheric(x0, c, k, a, n0, n1, radius=None)[source]

asferic surface.

Parameters:
  • x0 (float) – position of center
  • c (float) –
  • k (float) –
  • a (list) –
  • n0 (float) – refraction index of first medium
  • n1 (float) – refraction index of second medium
  • radius (float) – radius of aspheric surface
binary_code(x0=0.0, kind='standard', code=[1, 1, 0, 0, 1, 0, 1], bit_width=20.0)[source]

Binary code in form of 1’s and 0’s.

Parameters:
  • kind (str) – there are serveral types of codes ‘standard’ - normal ‘abs_fag’ - used in some abs encoders
  • code (numpy.array) – array with values of code
  • bit_width (float) – size of each data of code
  • x0 (float) – Initial position
binary_code_positions(x_transitions, start='down', has_draw=True)[source]

Genenerates a binary code, using the positions given in x_transitions

Parameters:
  • x_transitions (numpy.array) – positions where transitions are placed
  • start (str) – How the binary code starts:’down’ (starts in 0) or ‘up’ (starts in 1)
  • has_draw (bool) – If True, draws the code
binary_grating(x0, period, fill_factor, amin, amax, phase)[source]

binary grating amplitude and/or phase

Parameters:
  • x0 (float) – shift of the grating
  • period (float) – period of the grating
  • fill_factor (float) – (0,1) - fill factor of grating
  • amin (float) – minimum amplitude
  • amax (float) – maximum amplitude
  • phase (float) – phase shift (radians)
biprism_fresnel(angle, x0, radius, mask)[source]

Fresnel biprism.

Parameters:
  • angle (float) – angle of the fresnel biprism
  • x0 (float) – central position of fresnel biprism
  • radius (float) – radius of the fresnel biprism, if mask is True
  • mask (bool) – if True radius is applied
biprism_fresnel_nh(x0, width, height, n)[source]

Fresnel biprism, uses height and refraction index.

Parameters:
  • x0 (float) – vertex of biprism
  • width (float) – size of biprism
  • height (float) – height of biprism
  • n (float) – refraction_index
blazed_grating(x0, period, height, n)[source]

Phase, blazed grating. The phase shift is determined by heigth and refraction index.

Parameters:
  • x0 (float) – shift of the grating
  • period (float) – period of the grating
  • height (float) – height of grating
  • n (float) – refraction index of grating
chirped_grating(kind, p_x, x0, amp_min, amp_max, phase_max, delta_x, length=0)[source]

General chirped grating with variation given by function p(x).

Parameters:
  • kind (str) – ‘amplitude’, ‘phase’, ‘amplitude_binary’, ‘phase_binary’
  • p_x (str) – function with variation of periods
  • amp_min (float) – minimum transmittance
  • amp_max (float) – maximum transmittance
  • phase_max (float) – maximum modulation for phase gratings
  • delta_x (float) – x shifting for movement of grating
  • length (float) – length of the grating. 0: length is equal to size of x l=(x[-1]-x[0]). <l: it can be shorter than l
Returns:

p(x)

Return type:

numpy.array

chirped_grating_p(kind, p0, p1, amp_min, amp_max, phase_max, delta_x=0, x0=None, length=0, x_center=0)[source]

Chirped grating with linear p(x) variation.

Parameters:
  • kind (str) – ‘amplitude’, ‘phase’, ‘amplitude_binary’, ‘phase_binary’
  • p0 (float) – initial period of the grating
  • p1 (float) – final period of the grating
  • amp_min (float) – minimum transmittance
  • amp_max (float) – maximum transmittance
  • phase_max (float) – maximum modulation for phase gratings
  • delta_x (float) – x shifting for movement of grating
  • x0 (float) –
  • length (float) – length of the grating. 0: length is equal to size of x l=(x[-1]-x[0]), <l: it can be shorter than l
  • x_center (float) – x-position of center of grating
Returns:

px

Return type:

numpy.array

chirped_grating_q(kind, p0, p1, amp_min, amp_max, phase_max, delta_x=0, length=0, x_center=0)[source]

Chirped grating with linear q(x) variation. The transmitance is: t = np.cos(np.pi*q*(x-x0) + np.pi*q0*(x-x0))

Parameters:
  • kind (str) – ‘amplitude’, ‘phase’, ‘amplitude_binary’, ‘phase_binary’
  • p0 (float) – initial period of the grating
  • p1 (float) – final period of the grating
  • amp_min (float) – minimum transmittance
  • amp_max (float) – maximum transmittance
  • phase_max (float) – maximum modulation for phase gratings
  • delta_x (float) – x shifting for movement of grating
  • length (float) – length of the grating, 0: length is equal to size of x l=(x[-1]-x[0]). <l: it can be shorter than l
  • x_center (float) – x-position of center of grating
Returns:

qx

Return type:

numpy.array

dots(x0)[source]

Generates 1 or several point masks at positions x0

Parameters:float or np.array (x0) – x point or points where mask is 1.
double_slit(x0, size, separation)[source]

double slit: 1 inside, 0 outside

Parameters:
  • x0 (float) – center of slit
  • size (float) – size of slit
  • separation (float) – separation between slit centers
dust(percentaje, size=0)[source]

Mask with dust particles of equal sizes.

Parameters:
  • percentaje (float) – percentaje of area afected by noise
  • size (float) – size of dust
  • value (float) – value included when there is noise
Returns:

positions - positions of dust numpy.array: sizes - size of dust float: percentaje_real - real percentaje of dust

Return type:

numpy.array

dust_different_sizes(percentaje, size, std=0)[source]

Mask with dust particles of different sizes.

Parameters:
  • percentaje (float) – percentaje of area afected by noise
  • size (float) – mean size of dust
  • std (float) – std for size of dust
Returns:

positions - positions of dust numpy.array: sizes - size of dust float: percentaje_real - real percentaje of dust

Return type:

numpy.array

filter(mask, new_field=True, binarize=False, normalize=False)[source]

Widens a field using a mask.

Parameters:
  • mask (diffractio.Scalar_mask_X) – filter
  • new_field (bool) – If True, develope new Field
  • binarize (bool, float) – If False nothing, else binarize in level
  • normalize (bool) – If True divides the mask by sum:
fresnel_lens(x0, focal, kind='amplitude', binary=True, phase=3.141592653589793, mask=True, radius=100.0)[source]

Fresnel lens. Amplitude phase, continuous or binary.

Parameters:
  • x0 (float) – center of lens
  • focal (float) – focal length of lens
  • kind (str) – ‘amplitude’ or phase
  • binary (bool) – binary or profile
  • phase (float) – if kind==’phase’ -> maximum phase
  • mask (bool) – if True, mask with size radius
  • radius (float) – radius of lens mask
Returns:

normalized heights [0,1] of lens

Return type:

h (np.array)

gray_scale(num_levels, levelMin=0, levelMax=1)[source]

Divides the mask in n, vertical levels.

Parameters:
  • num_levels (int) – number of levels
  • levelMin (float) – minimum value of levels
  • levelMax (float) – maximum value of levels
lens(x0, focal, radius, mask=True)[source]

Transparent lens.

Parameters:
  • x0 (float) – center of lens
  • focal (float) – focal length of lens
  • mask (bool) – if True, mask with size radius
  • radius (float) – radius of lens mask
mask_from_array(index=1.5, array1=None, array2=None, interp_kind='quadratic', mask=True, radius=100.0, x0=0.0)[source]

Phase mask defined between two surfaces defined by arrays: array1 and array2, \(t(x)=mask(x)e^{i\,k\,(n-1)(array2(x,z)-array1(x,z))}\)

Parameters:
  • index (float) – refraction index of the mask
  • array1 (numpy.array) – array of data (x,z) for the first surface
  • array2 (numpy.array) – array of data (x,z) for the second surface
  • interp_kind (str) – ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’
  • mask (bool) – True if a mask is defined to block areas
  • x0 (float) – center of mask
  • radius (float) – radius of the mask
mask_from_function(index=1.5, f1=0, f2=0, v_globals={}, mask=True, x0=0.0, radius=100.0)[source]

Phase mask defined between two surfaces \(f_1\) and \(f_2\): \(h(x,y)=f_2(x,y)-f_1(x,y)\), \(t(x)=mask(x)e^{i\,k\,(n-1)(f_{2}-f_{1})}\)

Parameters:
  • index (float) – refraction index of the mask
  • f1 (str) – first surface
  • f2 (str) – second surface
  • v_globals (dict) – variable definitions
  • mask (bool) – True if a mask is defined to block areas
  • x0 (float) – center of mask
  • radius (float) – radius of the mask
prism(x0, n, anglex)[source]

Prism.

Parameters:
  • x0 (float) – vertex of prism
  • n (float) – refraction_index
  • anglex (float) – angle of prism
ronchi_grating(x0, period, fill_factor=0.5)[source]

Amplitude binary grating, fill-factor can be defined. It is obtained as a sine_grating that after is binarized. Fill factor is determined as y0=cos(pi*fill_factor)

Parameters:
  • x0 (float) – shift of the grating
  • period (float) – period of the grating
  • fill_factor (float) – (0,1) - fill factor of grating
roughness(t=50.0, s=1.0)[source]

Rough surface, phase

According to movile average (Ogilvy p.224). very good in time for long arrays

Parameters:
  • t (float) – correlation lens
  • s (float) – std of roughness
Returns:

topography maps in microns

Return type:

numpy.array

sine_grating(x0, period, amp_min=0, amp_max=1)[source]

Sinusoidal grating

Parameters:
  • x0 (float) – shift of grating
  • period (float) – period of the grating
  • amp_min (float) – minimum amplitude
  • amp_max (float) – maximum amplitude
slit(x0=0, size=100.0)[source]

Slit: 1 inside, 0 outside

Parameters:
  • x0 (float) – center of slit
  • size (float) – size of slit
two_levels(level1=0, level2=1, x_edge=0)[source]

Divides the image in two levels.

Parameters:
  • level1 (float) – value of level1
  • level2 (float) – value of level2
  • x_edge (float) – position of separation of levels

4.1.8. diffractio.scalar_masks_XY module

This module generates Scalar_mask_XY class for definingn masks. Its parent is Scalar_field_X.

The main atributes are:
  • self.x - x positions of the field
  • self.z - z positions of the field
  • self.u - field XZ
  • self.n - refraction index XZ
  • self.wavelength - wavelength of the incident field. The field is monochromatic

The magnitude is related to microns: micron = 1.

Class for unidimensional scalar masks

Functions
  • set_amplitude, set_phase
  • binarize, two_levels, gray_scale
  • a_dataMatrix
  • area
  • save_mask
  • inverse_amplitude, inverse_phase
  • widen
  • image
  • point_maks, slit, double_slit, square, circle, super_gauss, square_circle, ring, cross
  • mask_from_function
  • prism, lens, fresnel_lens
  • sine_grating, sine_edge_grating ronchi_grating, binary_grating, blazed_grating, forked_grating, grating2D, grating_2D_chess
  • axicon, biprism_fresnel,
  • radial_grating, angular_grating, hyperbolic_grating, archimedes_spiral, laguerre_gauss_spiral
  • hammer
  • roughness, circle_rough, ring_rough, fresnel_lens_rough,
class diffractio.scalar_masks_XY.Scalar_mask_XY(x=None, y=None, wavelength=None, info='')[source]

Bases: diffractio.scalar_fields_XY.Scalar_field_XY

Class for working with XY scalar masks.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly \(2^n\)
  • x – linear array with equidistant positions for y values
  • wavelength (float) – wavelength of the incident field
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.y

linear array wit equidistant positions for y values

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.u

(x,z) complex field

Type:numpy.array
self.info

String with info about the simulation

Type:str
angular_aperture(a_coef, b_coef=None, angle=0.0)[source]

Creates a radial function using the Fourier coefficients.

Parameters:
  • a_coef (np.array, 2 rows and x columns) – coefficients that multiply the cosine function.
  • b_coef (np.array, 2 rows and x columns) – coefficients that multiply the sine function.
  • angle (float) – angle of rotation in radians
  • a_coef and b_coef, the first row are the coefficient orders and the second row are coefficient values. (For) –

Example

angular_aperture(t, a_coef=np.array(
[[0,1],[20,10]]), angle= 0 * degrees)
angular_grating(r0, period, phase, radius, is_binary=True)[source]

Angular grating.

Parameters:
  • r0 (float, float) – (x0,y0) - center of lens
  • period (float) – period of the grating
  • phase (float) – initial phase
  • radius (float) – radius of the grating (masked)
  • is_binary (bool) – if True binary else, scaled

Example

angular_grating(r0=(0 * um, 0 * um), period=20 * um, phase=0 * um, radius=400 * um, is_binary=True)

archimedes_spiral(r0, period, phase, p, radius, is_binary)[source]

Archimedes spiral

Parameters:
  • r0 (float, float) – (x0,y0) - center of archimedes_spiral
  • period (float) – period of spiral
  • phase (float) – initial phase of spiral
  • p (int) – power of spiral
  • radius (float) – radius of the mask
  • is_binary (bool) – if True binary mask

Example

archimedes_spiral(r0=(0 * um, 0 * um), period=20 * degrees, phase=0 * degrees, p=1, radius=200 * um, is_binary=True)

area(percentaje)[source]

Computes area where mask is not 0

Parameters:percentaje_maximum (float) – percentaje from maximum intensity to compute
Returns:area (in um**2)
Return type:float

Example

area(percentaje=0.001)

axicon(r0, radius, angle, refraction_index, off_axis_angle=0.0, reflective=False)[source]

Axicon,

Parameters:
  • r0 (float, float) – (x0,y0) - center of lens
  • radius (float) – radius of lens mask
  • height (float) – height of axicon
  • n (float) – refraction index

Example

axicon(r0=(0 * um, 0 * um), radius=200 * um, height=5 * um, n=1.5)

binary_grating(x0, period, fill_factor=0.5, amin=0, amax=1, phase=0.0, angle=0.0)[source]

Binary grating (amplitude and/or phase). The minimum and maximum value of amplitude and phase can be controlled.

Parameters:
period (float): period of the grating amin (float): minimum amplitude amax (float): maximum amplitude phase (float): max phase shift in phase gratings x0 (float): phase shift fill_factor (float): fill_factor angle (float): angle of the grating in radians

Example

binary_grating( x0=0, period=40 * um, fill_factor=0.5, amin=0, amax=1, phase=0 * degrees, angle=0 * degrees)

biprism_fresnel(r0, width, height, n)[source]

Fresnel biprism.

Parameters:
  • r0 (float, float) – (x0,y0) - center of lens
  • width (float) – width
  • height (float) – height of axicon
  • n (float) – refraction index

Example

biprism_fresnel(r0=(0 * um, 0 * um), width=100 * um, height=5 * um, n=1.5)

blazed_grating(period, height, index, x0, angle=0.0)[source]

Binary grating (amplitude and/or phase). The minimum and maximum value of amplitude and phase can be controlled.

Parameters:
period (float): period of the grating height (float): height of the blazed grating index (float): refraction index x0 (float): initial displacement of the grating angle (float): angle of the grating in radians

Example

blazed_grating(period=40 * um, height=2 * um, index=1.5, x0, angle=0 * degrees)

circle(r0, radius, angle=0.0)[source]

Creates a circle or an ellipse.

Parameters:
  • r0 (float, float) – center of circle/ellipse
  • radius (float, float) or (float) – radius of circle/ellipse
  • angle (float) – angle of rotation in radians

Example

circle(r0=(0 * um, 0 * um), radius=(250 * um, 125 * um), angle=0 * degrees)

circle_rough(r0, radius, angle, sigma, correlation_length)[source]

Circle with a rough edge.

Parameters:
  • r0 (float,float) – location of center
  • radius (float) – radius of circle
  • angle (float) – when radius are not equal, axis of ellipse
  • sigma (float) – std of roughness
  • correlation_length (float) – correlation length of roughness
cross(r0, size, angle=0.0)[source]

Cross

Parameters:
  • r0 (float, float) – center of cross
  • size (float, float) or (float) – length, width of cross
  • angle (float) – angle of rotation in radians
crossed_slits(r0, slope, angle=0.0)[source]

This function will create a crossed slit mask.

Parameters:
  • r0 (float, float) – center of the crossed slit
  • slope (float, float) – slope of the slit
  • angle (float) – Angle of rotation of the slit

Example

crossed_slits(r0 = (-10 * um, 20 * um), slope = 2.5, angle = 30 * degrees)

dots(r0)[source]

Generates 1 or several point masks at positions r0

Parameters:r0 (float, float) or (np.array, np.array) – (x,y) point or points where mask is 1
dots_regular(xlim, ylim, num_data, verbose=False)[source]

Generates n x m or several point masks.

Parameters:
  • xlim (float, float) – (xmin, xmax) positions
  • ylim (float, float) – (ymin, ymax) positions
  • num_data (int, int) – (x, y) number of points
double_slit(x0, size, separation, angle=0.0)[source]

double slit: 1 inside, 0 outside

Parameters:
  • x0 (float) – center of double slit
  • size (float) – size of slit
  • separation (float) – separation between slit centers
  • angle (float) – angle of rotation in radians
edge_series(r0, period, a_coef, b_coef=None, angle=0.0, invert=True)[source]

Creates a linear aperture using the Fourier coefficients.

Parameters:
  • x0 (float) – x-axis displacement (for ‘fslit’ function)
  • period (float) – Function period
  • a_coef (np.array, 2 rows and x columns) – coefficients that multiply the cosine function.
  • b_coef (np.array, 2 rows and x columns) – coefficients that multiply the sine function.
  • angle (float) – angle of rotation in radians
  • invert (bool) – inverts transmittance values (for ‘fslit’ function)
  • both arrays (For) –
  • row (Second) – coefficient orders
  • row – coefficient values

Example

t1.edge_series(x0=0, period=50, a_coef=np.array(
[[0,1],[100,50]]), angle = 0 * degrees, invert=False)
elliptical_phase(f1, f2, angle)[source]

Elliptical phase

Parameters:
  • f1 (float) – focal f1
  • f2 (float) – focal f2
  • angle (float) – angle
extrude_mask_x(mask_X, y0=None, y1=None, kind='unique', normalize=None)[source]

Converts a Scalar_mask_X in volumetric between z0 and z1 by growing between these two planes :param mask_X: an amplitude mask of type Scalar_mask_X. :type mask_X: Scalar_mask_X :param y0: initial position of mask :type y0: float :param y1: final position of mask :type y1: float :param kind: ‘superpose’, ‘unique’ :type kind: str :param normalize: if ‘cut’ (>1 -> 1), ‘normalize’, None :type normalize: str

filter(mask, new_field=True, binarize=False, normalize=False)[source]

Widens a field using a mask

Parameters:
  • mask (diffractio.Scalar_mask_X) – filter
  • new_field (bool) – If True, develope new Field
  • binarize (bool, float) – If False nothing, else binarize in level
  • normalize (bool) – If True divides the mask by sum.
forked_grating(r0, period, l, alpha, kind, angle=0.0)[source]

Forked grating: exp(1.j * alpha * cos(l * THETA - 2 * pi / period * (Xrot - r0[0])))

Parameters:
  • r0 (float, float) – (x0,y0) - center of forked grating
  • period (float) – basic period of teh grating
  • l (int) –
  • alpha (int) –
  • kind (str) – ‘amplitude’ or ‘phase’
  • angle (float) – angle of the grating in radians

Example

forked_grating(r0=(0 * um, 0 * um), period=20 * um, l=2, alpha=1, angle=0 * degrees)

fresnel_lens(r0, radius, focal, levels=(1, 0), kind='amplitude', phase=3.141592653589793, angle=0.0, mask=True)[source]

Fresnel lens, amplitude (0,1) or phase (0-phase)

Parameters:
  • r0 (float, float) – (x0,y0) - center of lens
  • radius (float, float) or (float) – radius of lens mask
  • focal (float, float) or (float) – focal length of lens
  • levels (float, float) – levels (1,0) or other of the lens
  • kind (str) – ‘amplitude’ or ‘phase’
  • phase (float) – phase shift for phase lens
  • angle (float) – angle of axis in radians
  • mask (bool) – if True, mask with size radius

Example

fresnel_lens( r0=(0 * um, 0 * um), radius=(100 * um, 200 * um), focal=(5 * mm, 10 * mm), angle=0 * degrees, mask=True, kind=’amplitude’,phase=pi)

fresnel_lens_rough(r0, radius, focal, angle, mask, kind, phase, sigma, correlation_length)[source]

Ring with a rough edge

Parameters:
  • r0 (float,float) – location of center
  • radius (float) – maximum radius of mask
  • focal (float) – outer radius
  • angle (float) – when radius are not equal, axis of ellipse
  • mask (bool) –
  • kind (str) – ‘amplitude’ o ‘phase’
  • phase (float) – maximum phase shift, only if kind=’phase’
  • sigma (float) – std of roughness
  • correlation_length (float) – correlation length of roughness
grating_2D(r0, period, fill_factor, amin=0, amax=1.0, phase=0, angle=0.0)[source]

2D binary grating

Parameters:
r0 (float, r0): initial position period (float, float): period of the grating fill_factor (float): fill_factor amin (float): minimum amplitude amax (float): maximum amplitude phase (float): max phase shift in phase gratings angle (float): angle of the grating in radians

Example

grating_2D(period=40. * um, amin=0, amax=1., phase=0. * pi / 2, x0=0, fill_factor=0.75, angle=0.0 * degrees)

grating_2D_chess(r0, period, fill_factor, amin=0, amax=1, phase=0.0, angle=0.0)[source]

2D binary grating as chess

Parameters:
r0 (float, r0): initial position period (float): period of the grating fill_factor (float): fill_factor amin (float): minimum amplitude amax (float): maximum amplitude phase (float): max phase shift in phase gratings angle (float): angle of the grating in radians

Example

grating_2D_chess(period=40. * um, amin=0, amax=1., phase=0. * pi / 2, x0=0, fill_factor=0.75, angle=0.0 * degrees)

gray_scale(num_levels=4, levelMin=0, levelMax=1)[source]

Generates a number of strips with different amplitude

Parameters:
  • num_levels (int) – number of levels
  • levelMin (float) – value of minimum level
  • levelMax (float) – value of maximum level
hammer(r0, size, hammer_width, angle=0.0)[source]

Square with hammer (like in lithography). Not very useful, an example

Parameters:
  • r0 (float, float) – (x0,y0) - center of square
  • size (float, float) – size of the square
  • hammer_width (float) – width of hammer
  • angle (float) – angle of the grating in radians

Example

hammer(r0=(0 * um, 0 * um), size=(250 * um, 120 * um), hammer_width=5 * um, angle=0 * degrees)

hermite_gauss_binary(r0, w0, n, m)[source]

Binary phase mask to generate an Hermite Gauss beam.

Parameters:
  • r0 (float, float) – (x,y) position of source.
  • w0 (float, float) – width of the beam.
  • n (int) – order in x.
  • m (int) – order in y.

Example

hermite_gauss_binary(r0=(0,0), w0=(100*um, 50*um), n=2, m=3)

hyperbolic_grating(r0, period, phase, radius, is_binary, angle=0.0)[source]

Hyperbolic grating.

Parameters:
  • r0 (float, float) – (x0,y0) - center of lens
  • period (float) – period of the grating
  • phase (float) – initial phase
  • radius (float) – radius of the grating (masked)
  • is_binary (bool) – if True binary else, scaled
  • angle (float) – angle of the grating in radians

Example

hyperbolic_grating(r0=(0 * um, 0 * um), period=20 * um, phase=0 * um, sfradius=400 * um, is_binary=True)

image(filename='', canal=0, normalize=True, lengthImage=False, invert=False, angle=0)[source]

Converts an image file XY mask. If the image is color, we get the first Red frame

Parameters:
  • filename (str) – filename of the image
  • canal (int) – number of channel RGB to get the image
  • normalize (bool) – if True normalizes the image
  • lengthImage (bool, int) – If False does nothing, if number resize image
  • invert (bool) – if True the image is inverted
  • angle (float) – rotates image a certain angle
Returns
str: filename
image2(filename, negativo=True)[source]
insert_array_masks(t1, space, margin=0, angle=0.0)[source]

Generates a matrix of shapes given in t1.

Parameters:
  • t1 (Scalar_mask_XY) – Mask of the desired figure to be drawn
  • space (float, float) or (float) – spaces between figures.
  • margin (float, float) or (float) – extra space outside the mask
  • angle (float) – Angle to rotate the matrix of circles
Returns:

number of points in the mask

Return type:

(int)

Example

A = Scalar_mask_XY(x, y, wavelength)

A.ring(r0, radius1, radius2, angle)

insert_array_masks(t1 = A, space = 50 * um, angle = 0 * degrees)

inverse_amplitude()[source]

Inverts the amplitude of the mask, phase is equal as initial

inverse_phase()[source]

Inverts the phase of the mask, amplitude is equal as initial

laguerre_gauss_binary(r0, w0, n, l)[source]

Binary phase mask to generate an Hermite Gauss beam.

Parameters:
  • r0 (float, float) – (x,y) position of source.
  • w0 (float, float) – width of the beam.
  • n (int) – radial order.
  • l (int) – angular order.

Example

laguerre_gauss_binary(r0=(0,0), w0=1*um, n=0, l=0)

laguerre_gauss_spiral(r0, kind, n, l, w0, z)[source]

laguerre_gauss spiral

Parameters:
  • r0 (float, float) – (x0,y0) - center of laguerre_gauss_spiral
  • kind (str) – ‘amplitude’ or ‘phase’
  • n (int) – of spiral
  • l (int) – power of spiral
  • w0 (float) – width of spiral
  • z (float) – propagation distance

Example

laguerre_gauss_spiral(r0=(0 * um, 0 * um), kind=’amplitude’, l=1, w0=625 * um, z=0.01 * um)

lens(r0, radius, focal, angle=0.0, mask=True)[source]

Transparent lens

Parameters:
  • r0 (float, float) – (x0,y0) - center of lens
  • radius (float, float) or (float) – radius of lens mask
  • focal (float, float) or (float) – focal length of lens
  • angle (float) – angle of axis in radians
  • mask (bool) – if True, mask with size radius

Example

lens(r0=(0 * um, 0 * um), radius=(100 * um, 200 * um), focal=(5 * mm, 10 * mm), angle=0 * degrees, mask=True)

mask_from_function(r0, index, f1, f2, radius, v_globals={}, mask=True)[source]

phase mask defined between 2 surfaces $f_1$ and $f_2$: $h(x,y)=f_2(x,y)-f_1(x,y)$

Parameters:
  • r0 (float, float) – center of cross
  • index (float) – refraction index
  • f1 (str) – function for first surface
  • f2 (str) – function for second surface
  • radius (float, float) or (float) – size of mask
  • v_globals (dict) – dictionary with globals
  • mask (bool) – If True applies mask
one_level(level=0)[source]

Sets one level for all the image.

Parameters:level (float) – value
photon_sieve(t1, r0)[source]

Generates a matrix of shapes given in t1.

Parameters:
  • t1 (Scalar_mask_XY) – Mask of the desired figure to be drawn
  • r0 (float, float) or (np.array, np.array) – (x,y) point or points where mask is 1
Returns:

number of points in the mask

Return type:

(int)

prism(r0, angle_wedge, angle=0.0)[source]

prism which produces a certain angle

Parameters:
  • r0 (float, float) – center wedge
  • angle_wedge (float) – angle of wedge in x direction
  • angle (float) – angle of rotation in radians
radial_grating(r0, period, phase, radius, is_binary=True)[source]

Radial grating.

Parameters:
  • r0 (float, float) – (x0,y0) - center of lens
  • period (float) – period of the grating
  • phase (float) – initial phase
  • radius (float) – radius of the grating (masked)
  • is_binary (bool) – if True binary else, scaled

Example

radial_grating(r0=(0 * um, 0 * um), period=20 * um, phase=0 * um, radius=400 * um, is_binary=True)

ring(r0, radius1, radius2, angle=0.0)[source]

Ring.

Parameters:
  • r0 (float, float) – center of ring
  • radius1 (float, float) or (float) – inner radius
  • radius2 (float, float) or (float) – outer radius
  • angle (float) – angle of rotation in radians
ring_rough(r0, radius1, radius2, angle, sigma, correlation_length)[source]

Ring with a rough edge

Parameters:
  • r0 (float,float) – location of center
  • radius1 (float) – inner radius
  • radius2 (float) – outer radius
  • angle (float) – when radius are not equal, axis of ellipse
  • sigma (float) – std of roughness
  • correlation_length (float) – correlation length of roughness
rings(r0, inner_radius, outer_radius, mask=True)[source]

Structure based on several rings, with radius given by inner_radius and outer_radius.

Parameters:
  • r0 (float, float) – (x0,y0) - center of lens
  • inner_radius (np.array) – inner radius
  • outer_radius (np.array) – inner radius
  • mask (bool) – if True, mask with size radius of maximum outer radius
ronchi_grating(x0, period, fill_factor=0.5, angle=0)[source]

Amplitude binary grating with fill factor: self.u = amp_min + (amp_max - amp_min) * (1 + cos(2 * pi * (Xrot - phase) / period)) / 2

Parameters:
  • x0 (float) – phase shift
  • period (float) – period of the grating
  • fill_factor (float) – fill_factor
  • angle (float) – angle of the grating in radians

Notes

Ronchi grating when fill_factor = 0.5.

It is obtained from a sinusoidal, instead as a sum of slits, for speed.

The equation to determine the position y0 is: y0=cos(pi*fill_factor)

Example

ronchi_grating(x0=0 * um, period=40*um, fill_factor=0.5, angle=0)

roughness(t, s)[source]

Generation of a rough surface. According to Ogilvy p.224

Parameters:
  • t (float, float) – (tx, ty), correlation length of roughness
  • s (float) – std of heights

Example

roughness(t=(50 * um, 25 * um), s=1 * um)

set_amplitude(q=1, positive=0, amp_min=0, amp_max=1)[source]

makes that the mask has only amplitude.

Parameters:
  • q (int) – 0 - amplitude as it is and phase is removed. 1 - take phase and convert to amplitude
  • positive (int) – 0 - value may be positive or negative. 1 - value is only positive
set_phase(q=1, phase_min=0, phase_max=3.141592653589793)[source]

Obliga a la mask a ser de phase, q=0: toma la phase que hay y hace la amplitude=1 q=1: la amplitude la pasa a phase

sine_edge_grating(r0, period, lp, ap, phase, radius, is_binary)[source]

TODO: function info

sine_grating(x0, period, amp_min=0, amp_max=1, angle=0.0)[source]

Sinusoidal grating: self.u = amp_min + (amp_max - amp_min) * (1 + cos(2 * pi * (Xrot - phase) / period)) / 2

Parameters:
  • x0 (float) – phase shift
  • period (float) – period of the grating
  • amp_min (float) – minimum amplitude
  • amp_max (float) – maximum amplitud
  • angle (float) – angle of the grating in radians

Example

sine_grating(period=40 * um, amp_min=0, amp_max=1, x0=0 * um, angle=0 * degrees)

sinusoidal_slit(size, x0, amplitude, phase, period, angle=0.0)[source]

This function will create a sinusoidal wave-like slit.

Parameters:
  • x0 (float) – center of slit
  • size (float) – size of slit
  • amplitude (float, float) – Phase between the wave-like borders of the slit.
  • phase (float) – Phase between the wave-like borders of the slit
  • period (float) – wavelength of the wave-like border of the slit
  • angle (float) – Angle to be rotated the sinusoidal slit

Example

sinusoidal_slit(y0=(10 * um, -10 * um), amplitude=(10 * um, 20 * um), phase=0 * degrees, angle=0 * degrees, period=(50 * um, 35 * um))

slit(x0, size, angle=0.0)[source]

Slit: 1 inside, 0 outside

Parameters:
  • x0 (float) – center of slit
  • size (float) – size of slit
  • angle (float) – angle of rotation in radians
slit_series(x0, width, period1, period2, Dy, a_coef1, a_coef2, b_coef1=None, b_coef2=None, angle=None, simmetrycal=False)[source]

Creates a lineal function using the Fourier coefficients.

Parameters:
  • x0 (float) – position of the center of the slit
  • width (float) – slit width
  • period1 (float) – Period of the first function
  • period2 (float) – Period of the second function
  • Dy (float, float) – Shifts of the edges
  • a_coef1 (np.array, 2 rows and x columns) – coefficients that multiply the cosine in the first function.
  • a_coef2 (np.array, 2 rows and x columns) – coefficients that multiply the cosine in the second function.
  • b_coef1 (np.array, 2 rows and x columns) – coefficients that multiply the sine in the first function.
  • b_coef2 (np.array, 2 rows and x columns) – coefficients that multiply the sine in the second function.
  • the arrays (For) – First row - coefficient orders, Second row - coefficient values
  • angle (float) – angle of rotation in radians
  • simmetrical (bool) – TODO - take edge 1 and repeat simmetrical y 2

Example

t1.slit_series(x0=0, width=10, period1=50,
period2=20, a_coef1=np.array([[0,1],[100,50]]) )
square(r0, size, angle)[source]

Square: 1 inside, 0 outside

Parameters:
  • r0 (float, float) – center of square
  • size (float, float) or (float) – size of slit
  • angle (float) – angle of rotation in radians

Example

m.square(r0=(0 * um, 0 * um), size=(250 * um, 120 * um), angle=0 * degrees)

square_circle(r0, R1, R2, s, angle=0.0)[source]

Between circle and square, depending on fill factor s

s=0 circle, s=1 square

Parameters:
  • r0 (float, float) – center of square_circle
  • R1 (float) – radius of first axis
  • R2 (float) – radius of first axis
  • s (float) – [0-1] shape parameter: s=0 circle, s=1 square
  • angle (float) – angle of rotation in radians
Reference:
  1. Fernandez Guasti, M. De la Cruz Heredia “diffraction pattern of a circle/square aperture” J.Mod.Opt. 40(6) 1073-1080 (1993)
super_ellipse(r0, radius, n=(2, 2), angle=0.0)[source]

Super_ellipse. Abs((Xrot - x0) / radiusx)^n1 + Abs()(Yrot - y0) / radiusy)=n2

Parameters:
  • r0 (float, float) – center of super_ellipse
  • radius (float, float) – radius of the super_ellipse
  • n (float, float) = degrees of freedom of the next equation, n = (n1, n2) –
  • angle (float) – angle of rotation in radians

Note

n1 = n2 = 1: for a square n1 = n2 = 2: for a circle n1 = n2 = 0.5: for a superellipse

References

https://en.wikipedia.org/wiki/Superellipse

Example

super_ellipse(r0=(0 * um, 0 * um), radius=(250 * um, 125 * um), angle=0 * degrees)

super_gauss(r0, radius, potencia=2, angle=0.0)[source]

Supergauss mask.

Parameters:
  • r0 (float, float) – center of circle
  • radius (float, float) or (float) – radius of circle
  • potencia (float) – value of exponential
  • angle (float) – angle of rotation in radians

Example

super_gauss(r0=(0 * um, 0 * um), radius=(250 * um,
125 * um), angle=0 * degrees, potencia=2)
triangle(r0=None, slope=2.0, height=50.0, angle=0.0)[source]

Create a triangle mask. It uses the equation of a straight line: y = -slope * (x - x0) + y0

Parameters:
  • r0 (float, float) – Coordinates of the top corner of the triangle
  • slope (float) – Slope if the equation above
  • height (float) – Distance between the top corner of the triangle and the basis of the triangle
  • angle (float) – Angle of rotation of the triangle
two_levels(level1=0, level2=1, x_edge=0, angle=0)[source]

Divides the field in two levels

Parameters:
  • level1 (float) – value of first level
  • level2 (float) – value of second level
  • x_edge (float) – position of division
  • angle (float) – angle of rotation in radians
widen(radius, new_field=True, binarize=True)[source]

Widens a mask using a convolution of a certain radius

Parameters:
  • radius (float) – radius of convolution
  • new_field (bool) – returns a new XY field
  • binarize (bool) – binarizes result.

4.1.9. diffractio.scalar_masks_XYZ module

This module generates Scalar_mask_XYZ class for definingn masks. Its parent is scalar_fields_XYZ.

The main atributes are:
  • self.x - x positions of the field
  • self.y - y positions of the field
  • self.z - z positions of the field
  • self.u - field XYZ
  • self.n - refraction index XYZ
  • self.wavelength - wavelength of the incident field. The field is monochromatic

The magnitude is related to microns: micron = 1.

Class for unidimensional scalar masks

Functions
  • object_by_surfaces
  • sphere
  • square
  • cylinder
class diffractio.scalar_masks_XYZ.Scalar_mask_XYZ(x, y, z, wavelength, n_background=1.0, info='')[source]

Bases: diffractio.scalar_fields_XYZ.Scalar_field_XYZ

cylinder(r0, radius, length, refraction_index, axis, angle)[source]

Insert a cylinder in background. If something previous, is removed.

Parameters:
  • r0 (float, float, float) – (x0, y0,z0) Location of the rectangle, for example (0*um, 0*um, 0*um)
  • radius (float,float) – x,y, size of the circular part of cylinder
  • length (float) – length of cylidner
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • axis (float float, float) – axis direction
  • angle (float) – angle of rotation of the semi-plane, in radians
object_by_surfaces(r0, refraction_index, Fs, angles, v_globals={})[source]

Mask defined by n surfaces given in array Fs={f1, f2, h(x,y,z)=f1(x,y,z)*f2(x,y,z)*….*fn(x,y,z)

Parameters:
  • rotation_point (float, float, float) – location of the mask
  • refraction_index (float, str) – can be a number or a function n(x, y,z)
  • Fs (list) – condtions as str that will be computed using eval
  • array1 (numpy.array) – array (x,y,z) that delimits the second surface
  • angle (float) – angle of rotation (radians)
  • v_globals (dict) – dict with global variables
  • verbose (bool) – shows data if true
sphere(r0, radius, refraction_index, angles)[source]

Insert a sphere in background. If it is something else previous, it is removed.

Parameters:
  • r0 – (x0, y0, z0) Location of sphere, for example (0 * um, 0*um, 0 * um)
  • radius – (rx, ry, rz) Radius of sphere. It can be a ellipsoid. If radius is a number, then it is a sphere refraction_index (float, str): refraction index , for example: 1.5 + 1.0j
square(r0, length, refraction_index, angles=None, rotation_point=None)[source]

Insert a rectangle in background. If something previous, is removed.

Parameters:
  • r0 (float, float, float) – (x0, y0,z0) Location of the rectangle, for example (0*um, 0*um, 0*um)
  • size (float, float, float) – x,y,z size of the rectangle
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float, float) –

4.1.10. diffractio.scalar_masks_XZ module

This module generates Scalar_mask_XZ class for definingn masks. Its parent is Scalar_field_XZ.

The main atributes are:
  • self.x - x positions of the field
  • self.z - z positions of the field
  • self.u - field XZ
  • self.n - refraction index XZ
  • self.wavelength - wavelength of the incident field. The field is monochromatic

The magnitude is related to microns: micron = 1.

Class for unidimensional scalar masks

Functions
  • extrude_mask, mask_from_function, mask_from_array, object_by_surfaces
  • image
  • semi_plane, layer, rectangle, slit, sphere, semi_sphere
  • wedge, prism, biprism
  • ronchi_grating, sine_grating
  • probe
  • lens_plane_convergent, lens_convergent, lens_plane_divergent, lens_divergent
  • roughness
class diffractio.scalar_masks_XZ.Scalar_mask_XZ(x=None, z=None, wavelength=None, n_background=1, info='')[source]

Bases: diffractio.scalar_fields_XZ.Scalar_field_XZ

Class for working with XZ scalar masks.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly \(2^n\) .
  • z (numpy.array) – linear array wit equidistant positions for z values
  • wavelength (float) – wavelength of the incident field
  • n_background (float) – refraction index of background
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly \(2^n\).

Type:numpy.array
self.z

linear array wit equidistant positions for z values

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.u0
  1. size x - field at the last z position
Type:numpy.array
self.u

(x,z) complex field

Type:numpy.array
self.n_background

(x,z) refraction index

Type:numpy.array
self.info

String with info about the simulation

Type:str
add_surfaces(fx, x_sides, refraction_index, min_incr=0.1, angle=0.0)[source]

A topography fx is added to one of the faces of object u (self.n).

Parameters:
  • u (Scalar_mask_XZ) – topography
  • fx (numpy.array, numpy.array) – [x1, fx1], [x2, fx2] array with topography to add
  • x_sides (float, float) – positions of edges
  • refraction_index (float, str) – refraction index: number of string
  • min_incr (float) – minimum variation of refraction index to detect edge.
  • angle (float (float, float)) – angle and optative rotation angle.
aspheric_lens(r0, angle, refraction_index, cx, Qx, depth, size, a2=(0, 0), a3=(0, 0), a4=(0, 0))[source]

Define an aspheric surface as defined in Gomez-Pedrero.

Parameters:
  • r0 (float, float) – position x,z of lens
  • angle (float) – rotation angle of lens + r0_rot
  • cx (float, float) – curvature
  • Qx (float, float) – Conic constant
  • depth (float, float) – distance of the apex
  • size (float) – diameter of lens
Returns:

Bool array with positions inside the surface

Return type:

numpy.array

aspheric_surface_z(r0, refraction_index, cx, Qx, a2, a3, a4, side, angle)[source]

Define an aspheric surface

Parameters:
  • r0 (float, float) – (x0,z0) position of apex
  • refraction_index (float, str) – refraction index
  • cx (float) – curvature
  • Qx (float) – Conic constant
  • side (str) – ‘left’, ‘right’
Returns:

Bool array with positions inside the surface

Return type:

numpy.array

biprism(r0, length, height, refraction_index, angle=0)[source]

Fresnel biprism.

Parameters:
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • length (float) – length of the long part (z direction)
  • height (float) – height of biprism
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
discretize_refraction_index(n_layers)[source]

Takes a refraction index an discretize it according refraction indexes.

Parameters:n_layers (np.array) – array with refraction indexes to discretize
dots(positions, refraction_index=1)[source]

Generates 1 or several point masks at positions r0

Parameters:
  • positions (float, float) or (np.array, np.array) – (x,z) point or points where mask is 1
  • refraction_index (float) – refraction index
extrude_mask(t, z0, z1, refraction_index, v_globals={}, angle=0)[source]

Converts a Scalar_mask_X in volumetric between z0 and z1 by growing between these two planes :param t: an amplitude mask of type Scalar_mask_X. :type t: Scalar_mask_X :param z0: initial position of mask :type z0: float :param z1: final position of mask :type z1: float :param refraction_index: can be a number or a function n(x,z) :type refraction_index: float, str

image(filename, n_max, n_min, angle=0, invert=False)[source]

Converts an image file in an xz-refraction index matrix. If the image is gray-scale the refraction index is gradual betwee n_min and n_max. If the image is color, we get the first Red frame

Parameters:
  • filename (str) – filename of the image
  • n_max (float) – maximum refraction index
  • n_min (float) – minimum refraction index
  • angle (float) – angle to rotate the image in radians
  • invert (bool) – if True the image is inverted
layer(r0, depth, refraction_index, angle, rotation_point=None)[source]

Insert a layer. If it is something else previous, it is removed.

Parameters: r0 (float, float): (x0,z0) Location of the same plane, for example (0 * um, 20 * um) depth (float): depth of the layer refraction_index (float, str): refraction index , for example: 1.5 + 1.0j angle (float): angle of rotation of the semi-plane, in radians rotation_point (float, float). Rotation point

lens_convergent(r0, aperture, radius, thickness, refraction_index, angle=0, rotation_point=None, mask=0)[source]

Inserts a convergent lens in background.

Parameters:
  • r0 (float, float) – (x0,z0) position of the center of lens, for example (0 * um, 20 * um) for plane-convergent z0 is the location of the plane for convergent-plane (angle =180*degrees) the thickness has to be added to z0
  • aperture (float) – aperture of the lens. If it is 0, then it is not applied
  • radius (float, float) – (radius1,radius2) radius of curvature (with sign)
  • thickness (float) – thickness at the center of the lens
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) – rotation point.
  • mask (array, str) – (mask_depth, refraction_index) or False. It masks the field outer the lens using a slit with depth = mask_depth
Returns:

geometrical focal distance (numpy.array): ipasa, indexes [iz,ix] of lens

Return type:

(float)

lens_divergent(r0, aperture, radius, thickness, refraction_index, angle=0, rotation_point=None, mask=0)[source]

Insert a divergent lens in background.

Parameters:
  • r0 (float, float) – (x0,z0) position of the center of lens, for example (0 * um, 20 * um) for plane-convergent z0 is the location of the plane for convergent-plane (angle =180*degrees) the thickness has to be added to z0
  • aperture (float) – aperture of the lens. If it is 0, then it is not applied
  • radius (float, float) – (radius1, radius2) radius of curvature (with sign)
  • thickness (float) – thickness at the center of the lens
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) – rotation point
  • mask (array, str) – (mask_depth, refraction_index) or False. It masks the field outer the lens using a slit with depth = mask_depth
Returns:

geometrical focal distance (numpy.array): ipasa, indexes [iz,ix] of lens

Return type:

(float)

lens_plane_convergent(r0, aperture, radius, thickness, refraction_index, angle=0, rotation_point=None, mask=0)[source]

Insert a plane-convergent lens in background-

Parameters:
  • r0 (float, float) –

    (x0,z0) position of the center of lens, for example (0 * um, 20 * um) for plane-convergent z0 is the location of the plane for convergent-plane (angle =180*degrees) the thickness has to be

    added to z0
  • aperture (float) – aperture of the lens. If it is 0, then it is not applied
  • radius (float) – radius of the curved surface
  • thickness (float) – thickness at the center of the lens
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
  • mask (array, str) – (mask_depth, refraction_index) or False. It masks the field outer the lens using a slit with depth = mask_depth
  • rotation_point (float, float) –
Returns:

geometrical focal distance (numpy.array): ipasa, indexes [iz,ix] of lens

Return type:

(float)

lens_plane_divergent(r0, aperture, radius, thickness, refraction_index, angle=0, rotation_point=None, mask=False)[source]

Insert a plane-divergent lens in background.

Parameters:
  • r0 (float, float) – (x0,z0) position of the center of lens, for example (0 * um, 20 * um) for plane-convergent z0 is the location of the plane for convergent-plane (angle =180*degrees) the thickness has to be added to z0
  • aperture (float) – aperture of the lens. If it is 0, then it is not applied
  • radius (float) – radius of curvature (with sign)
  • thickness (float) – thickness at the center of the lens
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
  • mask (array, str) – (mask_depth, refraction_index) or False. It masks the field outer the lens using a slit with depth = mask_depth
Returns:

geometrical focal distance (numpy.array): ipasa, indexes [iz,ix] of lens

Return type:

(float)

mask_from_array(r0=(0.0, 0.0), refraction_index=1.5, array1=None, array2=None, x_sides=None, angle=0.0, v_globals={}, interp_kind='quadratic', has_draw=False)[source]

Mask defined between two surfaces given by arrays (x,z): h(x,z)=f2(x,z)-f1(x,z). For the definion of f1 and f2 from arrays is performed an interpolation

Parameters:
  • r0 (float, float) – location of the mask
  • refractdion_index (float, str) – can be a number or a function n(x,z)
  • array1 (numpy.array) – array (x,z) that delimits the first surface
  • array2 (numpy.array) – array (x,z) that delimits the second surface
  • x_sides (float, float) – limiting upper and lower values in x,
  • angle (float) – angle of rotation (radians): TODO -> not working
  • v_globals (dict) – dict with global variables -> TODO perphaps it is not necessary
  • interp_kind – ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’
mask_from_array_proposal(r0=(0.0, 0.0), refraction_index_substrate=1.5, refraction_index_mask=None, array1=None, array2=None, x_sides=None, angle=0.0, v_globals={}, interp_kind='quadratic', has_draw=False)[source]

Mask defined between two surfaces given by arrays (x,z): h(x,z)=f2(x,z)-f1(x,z). For the definion of f1 and f2 from arrays is performed an interpolation

Parameters:
  • r0 (float, float) – location of the mask
  • refraction_index_mask (float, str) – can be a number or a function n(x,z)
  • refraction_index_substrate (float, str) – can be a number or a function n(x,z)
  • array1 (numpy.array) – array (x,z) that delimits the first surface
  • array2 (numpy.array) – array (x,z) that delimits the second surface
  • x_sides (float, float) – limiting upper and lower values in x,
  • angle (float) – angle of rotation (radians): TODO -> not working
  • v_globals (dict) – dict with global variables -> TODO perphaps it is not necessary
  • interp_kind – ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’
mask_from_function(r0, refraction_index, f1, f2, z_sides, angle, v_globals={})[source]

Phase mask defined between two surfaces f1 and f1: h(x,z)=f2(x,z)-f1(x,z)

Parameters:
  • r0 (float, float) – location of the mask
  • refraction_index (float, str) – can be a number or a function n(x,z)
  • f1 (str) – function that delimits the first surface
  • f2 (str) – function that delimits the second surface
  • z_sides (float, float) – limiting upper and lower values in z,
  • angle (float) – angle of rotation (radians)
  • v_globals (dict) – dict with global variables
object_by_surfaces(rotation_point, refraction_index, Fs, angle, v_globals={}, verbose=False)[source]

Mask defined by n surfaces given in array Fs={f1, f2, ….}. h(x,z)=f1(x,z)*f2(x,z)*….*fn(x,z)

Parameters:
  • rotation_point (float, float) – location of the mask
  • refraction_index (float, str) – can be a number or a function n(x,z)
  • Fs (list) – condtions as str that will be computed using eval
  • array1 (numpy.array) – array (x,z) that delimits the second surface
  • angle (float) – angle of rotation (radians)
  • v_globals (dict) – dict with global variables -> TODO perphaps it is not necessary
  • verbose (bool) – shows data if true
prism(r0, length, refraction_index, angle_prism, angle=0, rotation_point=None)[source]

Similar to wedge but the use is different. Also the angle is usually different. One of the sides is paralel to x=x0

Parameters:
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • length (float) – length of the long part (z direction)
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle_prism (float) –
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) –
probe(r0, base, length, refraction_index, angle)[source]

Probe with a sinusoidal shape.

Parameters:
  • r0 (float, float) – (x0,z0) position of the center of base, for example (0 * um, 20 * um)
  • base (float) – base of the probe
  • length (float) – length of the graprobeing
  • Dx (float) – displacement of grating with respect x=0
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
rectangle(r0, size, refraction_index, angle=0.0, rotation_point=None)[source]

Insert a rectangle in background. Something previous, is removed.

Parameters:
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • size (float, float) – x,z size of the rectangle
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) –
ronchi_grating(r0, period, fill_factor, length, height, Dx, refraction_index, heigth_substrate, refraction_index_substrate, angle)[source]

Insert a ronchi grating in background.

Parameters:
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • period (float) – period of the grating
  • fill_factor (float) – [0,1], fill factor of the grating
  • length (float) – length of the grating
  • height (float) – height of the grating
  • Dx (float) – displacement of grating with respect x=0
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • heigth_substrate (float) – height of the substrate
  • refraction_index_substrate (float, str) – refraction index of substrate , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
rough_sheet(r0, size, t, s, refraction_index, angle, rotation_point=None)[source]

Sheet with one of the surface rough.

Parameters:
  • r0 (float, float) – (x0,z0) Location of sphere, for example (0 * um, 20 * um)
  • size (float, float) – (sizex, sizez) size of the sheet
  • s (float) – std roughness
  • t (float) – correlation length of roughness
  • refraction_index (float, str) – refraction index
  • angle (float) – angle
  • rotation_point (float, float) – rotation point
Returns:

ipasa, indexes [iz,ix] of lens

Return type:

(numpy.array)

References

According to Ogilvy p.224

semi_plane(r0, refraction_index, angle=0, rotation_point=None)[source]

Inserts a semi-sphere in background (x>x0). If it is something else previous, it is removed.

Parameters:
  • r0= (x0,z0) (float,float) – Location of the same plane.
  • refraction_index (float, str) – refraction index.
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) –
semi_sphere(r0, radius, refraction_index, angle=0, rotation_point=None)[source]

Insert a semi_sphere in background.

Parameters:
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • radius (float, float) – radius x,y of the sphere (ellipsoid)
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) –
sine_grating(period, heigth_sine, heigth_substrate, r0, length, Dx, refraction_index, angle=0)[source]

Insert a sine grating in background.

Parameters:
  • period (float) – period of the grating
  • fill_factor (float) – [0,1], fill factor of the grating
  • heigth_sine (float) – height of the grating
  • heigth_substrate (float) – height of the substrate
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • length (float) – length of the grating
  • Dx (float) – displacement of grating with respect x=0
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
slit(r0, aperture, depth, refraction_index, refraction_index_center='', angle=0, rotation_point=None)[source]

Insert a slit in background.

Parameters:
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • aperture (float) – length of the opened part of the slit
  • depth (float) – depth of the slit
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • refraction_index_center (float, str?) – refraction index of center if refraction_index_center=’’, [], 0 then we copy what it was previously at aperture
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) –
sphere(r0, radius, refraction_index, angle=0, rotation_point=None)[source]

Insert a sphere in background.

Parameters:
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • radius (float, float) – radius x,y of the sphere (ellipsoid)
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) –
wedge(r0, length, refraction_index, angle_wedge, angle=0, rotation_point=None)[source]

Insert a wedge pointing towards the light beam

Parameters:
  • r0 (float, float) – (x0,z0) Location of the rectangle, for example (0 * um, 20 * um)
  • length (float) – length of the long part (z direction)
  • refraction_index (float, str) – refraction index , for example: 1.5 + 1.0j
  • angle_wedge (float) –
  • angle (float) – angle of rotation of the semi-plane, in radians
  • rotation_point (float, float) –

4.1.11. diffractio.scalar_sources_X module

This module generates Scalar_field_X class for defining sources. Its parent is Scalar_field_X.

The main atributes are:
  • self.u - field
  • self.x - x positions of the field
  • self.wavelength - wavelength of the incident field. The field is monocromatic

The magnitude is related to microns: mifcron = 1.

Class for unidimensional scalar masks

Functions
  • plane_wave
  • gauss_beam
  • spherical_wave
  • plane_waves_dict
  • plane_waves_several_inclined
  • gauss_beams_several_parallel
  • gauss_beams_several_inclined
Also
  • Polychromatic and extendes sources are defined in scalar_fields_X.py for multiprocessing purposes.
class diffractio.scalar_sources_X.Scalar_source_X(x, wavelength, n_background=1, info='')[source]

Bases: diffractio.scalar_fields_X.Scalar_field_X

Class for unidimensional scalar sources.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly \(2^n\) .
  • wavelength (float) – wavelength of the incident field
  • n_background (float) – refraction index of background
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.u

equal size than x. complex field

Type:numpy.array
self.quality

quality of RS algorithm

Type:float
self.info

description of data

Type:str
self.type

Class of the field

Type:str
self.date

date when performed

Type:str
gauss_beam(x0, w0, z0, A=1, theta=0.0)[source]

Gauss Beam.

Parameters:
  • x0 (float) – x position of center
  • w0 (float) – minimum beam width
  • z0 (float) – position of beam width
  • A (float) – maximum amplitude
  • theta (float) – angle in radians
gauss_beams_several_inclined(A, num_beams, w0, x0, z0, max_angle)[source]

Several inclined gauss beams

Parameters:
  • A (float) – maximum amplitude
  • num_beams (int) – number of gaussian beams (equidistintan)
  • w0 (float) – beam width of the bemas
  • x0 (fl(float) – maximum amplitude
  • num_beams – number of ints
  • maoat) – initial position of gauss beam at x
  • z0 (float) – constant value for phase shift
  • max_angle (float) – maximum angle for beams
gauss_beams_several_parallel(A, num_beams, w0, z0, x_central, x_range, theta=0.0)[source]

Several parallel gauss beams

Parameters:
  • A (float) – maximum amplitude
  • num_beams (int) – number of gaussian beams (equidistintan)
  • w0 (float) – beam width of the bemas
  • z0 (float) – constant value for phase shift
  • x_central (float) – central position of rays
  • x_range (float) – range of rays
  • theta (float) – angle of the parallel beams
plane_wave(A=1, theta=0.0, z0=0.0)[source]

Plane wave. self.u = A * exp(1.j * k * (self.x * sin(theta) + z0 * cos(theta)))

Parameters:
  • A (float) – maximum amplitude
  • theta (float) – angle in radians
  • z0 (float) – constant value for phase shift
plane_waves_dict(params)[source]

Several plane waves with parameters defined in dictionary

Parameters:params – list with a dictionary: A (float): maximum amplitude theta (float): angle in radians z0 (float): constant value for phase shift
plane_waves_several_inclined(A, num_beams, max_angle)[source]

Several paralel plane waves.

Parameters:
  • A (float) – maximum amplitude
  • num_beams (int) – number of ints
  • max_angle (float) – maximum angle for beams
spherical_wave(A=1, x0=0.0, z0=-1000.0, mask=True, radius=100.0, normalize=False)[source]

Spherical wave. self.u = amplitude * A * exp(-1.j * sign(z0) * k * Rz) / Rz

Parameters:
  • A (float) – maximum amplitude
  • x0 (float) – x position of source
  • z0 (float) – z position of source
  • mask (bool) – If true, masks the spherical wave with radius
  • radius (float) – size of slit for mask
  • normalize (bool) – If True, maximum of field is 1

4.1.12. diffractio.scalar_sources_XY module

This module generates Scalar_source_XY class for defining sources. Its parent is Scalar_field_XY.

The main atributes are:
  • self.x - x positions of the field
  • self.y - y positions of the field
  • self.u - field XY
  • self.wavelength - wavelength of the incident field. The field is monocromatic

The magnitude is related to microns: micron = 1.

Class for unidimensional scalar masks

Functions
  • plane_wave
  • gauss_beam
  • spherical_wave
  • vortex_beam
  • laguerre_beam
  • hermite_gauss_beam
  • zernike_beam
  • bessel_beam
  • plane_waves_dict
  • plane_waves_several_inclined
  • gauss_beams_several_parallel
  • gauss_beams_several_inclined
Also
  • laguerre_polynomial_nk
  • fZernike
  • delta_kronecker
class diffractio.scalar_sources_XY.Scalar_source_XY(x=None, y=None, wavelength=None, info='')[source]

Bases: diffractio.scalar_fields_XY.Scalar_field_XY

Class for XY scalar sources.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly \(2^n\) .
  • y (numpy.array) – linear array wit equidistant positions for y values
  • wavelength (float) – wavelength of the incident field
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly \(2^n\) .

Type:numpy.array
self.y

linear array wit equidistant positions for y values

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.u

(x,z) complex field

Type:numpy.array
self.info

String with info about the simulation

Type:str
bessel_beam(A, r0, alpha, n, theta=0.0, phi=0.0, z0=0)[source]

Bessel beam produced by an axicon. Bessel-beams are generated using 2D axicons.

Parameters:
  • A (float) – amplitude of the Hermite Gauss beam
  • r0 (float, float) – (x,y) position of source
  • alpha (float) – angle of the beam generator
  • n (int) – order of the beam
  • theta (float) – angle in radians
  • phi (float) – angle in radians
  • z0 (float) – constant value for phase shift

References

  1. Courvoisier, et al. “Surface nanoprocessing with nondiffracting femtosecond Bessel beams” Optics Letters Vol. 34, No. 20 3163 (2009)
gauss_beam(r0, w0, z0=0.0, A=1, theta=0.0, phi=0.0)[source]

Gauss Beam.

Parameters:
  • r0 (float, float) – (x,y) position of center
  • w0 (float, float) – (wx,wy) minimum beam width
  • z0 (float) – position of beam width
  • A (float) – maximum amplitude
  • theta (float) – angle in radians (direction of propagation)
  • phi (float) – angle in radians (direction of propagation)
gauss_beams_several_inclined(A, num_beams, w0, r0, z0, max_angle)[source]

Several inclined gauss beams

Parameters:
  • A (float) – maximum amplitude
  • num_beams (int, int) – number of gaussian beams (equidistintan) in x and y direction.
  • w0 (float) – beam width
  • r0 (float, float) – central position of rays (x_c, y_c)
  • z0 (float) – constant value for phase shift
  • max_angle (float, float) – maximum angles
gauss_beams_several_parallel(r0, A, num_beams, w0, z0, r_range, theta=0.0, phi=0.0)[source]

Several parallel gauss beams

Parameters:
  • A (float) – maximum amplitude
  • num_beams (int, int) – number of gaussian beams (equidistintan) in x and y direction.
  • w0 (float) – beam width of the bemas
  • z0 (float) – constant value for phase shift
  • r0 (float, float) – central position of rays (x_c, y_c)
  • r_range (float, float) – range of rays x, y
  • theta (float) – angle
  • phi (float) – angle
hermite_gauss_beam(r0, A, w0, n, m, z, z0)[source]

Hermite Gauss beam.

Parameters:
  • A (float) – amplitude of the Hermite Gauss beam.
  • r0 (float, float) – (x,y) position of the beam center.
  • w0 (float, float) – Gaussian waist.
  • n (int) – order in x.
  • m (int) – order in y.
  • z (float) – Propagation distance.
  • z0 (float, float) – Beam waist position at each dimension

Example

hermite_gauss_beam(A=1, r0=(0,0), w0=(100*um, 50*um), n=2, m=3, z=0)

laguerre_beam(r0, A, w0, n, l, z, z0)[source]

Laguerre beam.

Parameters:
  • A (float) – amplitude of the Hermite Gauss beam.
  • r0 (float, float) – (x,y) position of the beam center.
  • w0 (float) – Gaussian waist.
  • n (int) – radial order.
  • l (int) – angular order.
  • z (float) – Propagation distance.
  • z0 (float) – Beam waist position.

Example

laguerre_beam(A=1, r0=(0 * um, 0 * um), w0=1 * um, p=0, l=0, z=0)

plane_wave(A=1, theta=0.0, phi=0.0, z0=0.0)[source]

Plane wave. self.u = A * exp(1.j * k * (self.x * sin(theta) + z0 * cos(theta)))

Parameters:
  • A (float) – maximum amplitude
  • theta (float) – angle in radians
  • phi (float) – angle in radians
  • z0 (float) – constant value for phase shift
plane_waves_dict(params)[source]

Several plane waves with parameters defined in dictionary

Parameters:params – list with a dictionary: A (float): maximum amplitude theta (float): angle in radians phi (float): angle in radians z0 (float): constant value for phase shift
plane_waves_several_inclined(A, num_beams, max_angle, z0=0)[source]

Several paralel plane waves

Parameters:
  • A (float) – maximum amplitude
  • num_beams (int, int) – number of beams in the x and y directions
  • max_angle (float, float) – maximum angle of the beams
  • z0 (float) – position of the beams
spherical_wave(A=1, r0=(0.0, 0.0), z0=-1000.0, mask=True, radius=100.0, normalize=False)[source]

Spherical wave.

Parameters:
  • A (float) – maximum amplitude
  • r0 (float, float) – (x,y) position of source
  • z0 (float) – z position of source
  • mask (bool) – If true, masks the spherical wave with radius
  • radius (float) – size of slit for mask
  • normalize (bool) – If True, maximum of field is 1
vortex_beam(A, r0, w0, m)[source]

Vortex beam.

Parameters:
  • A (float) – Amplitude
  • r0 (float, float) – (x,y) position of source
  • w0 (float) – width of the vortex beam
  • m (int) – order of the vortex beam

Example

vortex_beam(r0=(0 * um, 0 * um), w0=100 * um, m=1)

zernike_beam(A, r0, radius, n, m, c_nm, mask=True)[source]

Zernike beam.

Parameters:
  • A (float) – amplitude of the Hermite Gauss beam
  • r0 (float, float) – (x,y) position of source
  • radius (float) – width of the beam
  • n (list) – list of integers with orders
  • m (list) – list of integers with orders
  • c_nm (list) – list of integers with coefficients
  • mask (bool) – if True a mask of radius is provided

Example

zernike_beam(A=1, r0=(0,0), radius=5 * mm, n=[1, 3, 3, 5, 5, 5], m=[1, 1, 3, 1, 3, 5], c_nm=[.25, 1, 1, 1, 1, 1], mask=True)

4.1.13. diffractio.utils_common module

Common functions to classes

diffractio.utils_common.clear_all()[source]

clear all variables

diffractio.utils_common.date_in_name(filename)[source]

introduces a date in the filename.

Parameters:filename (str) – filename
Returns:filename with current date
Return type:(str)
diffractio.utils_common.get_date()[source]

gets current date and hour.

Returns:date in text
Return type:(str)
diffractio.utils_common.load_data_common(cls, filename, verbose=False)[source]
Common load data function to be used in all the modules.
The methods included are: npz, matlab
Parameters:
  • cls (class) – class X, XY, XZ, XYZ, etc..
  • filename (str) – filename
  • verbose (bool) – If True prints data
diffractio.utils_common.print_axis_info(cls, axis)[source]

Prints info about axis

Parameters:
  • cls (class) – class of the modulus.
  • () (axis) – axis x, y, z… etc.
diffractio.utils_common.save_data_common(cls, filename, add_name='', description='', verbose=False)[source]

Common save data function to be used in all the modules. The methods included are: npz, matlab

Parameters:
  • filename (str) – filename
  • add_name= (str) – sufix to the name, if ‘date’ includes a date
  • description (str) – text to be stored in the dictionary to save.
  • verbose (bool) – If verbose prints filename.
Returns:

filename. If False, file could not be saved.

Return type:

(str)

diffractio.utils_common.several_propagations(iluminacion, masks, distances)[source]

performs RS propagation through several masks

Parameters:
  • iluminacion (Scalar_source_XY) – illumination
  • masks (list) – list with several (Scalar_masks_XY)
  • distances (list) – list with seera distances
Returns:

u0 field at the last plane given by distances Scalar_field_XY: u1 field just at the plane of the last mask

Return type:

Scalar_field_XY

4.1.14. diffractio.utils_drawing module

Functions for drawing

diffractio.utils_drawing.change_image_size(image_name, length='800x600', final_filename='prueba.png', dpi=300)[source]

change the size with imageMagick

Parameters:
  • image_name (str) – name of file
  • length (str) – size of image
  • final_filename (str) – final filename
  • dpi (int) – dpi

Examples:

convert image_name -resize ‘1000’ -units 300 final_filename.png
  • anchura 1000 - mantiene forma
convert image_name -resize ‘x200’ final_filename.png
  • height 200 - mantiene forma
convert image_name -resize ‘100x200>’ final_filename.png
  • mantiene forma, lo que sea mayor
convert image_name -resize ‘100x200<’ final_filename.png
  • mantiene forma, lo que sea menor
convert image_name -resize @1000000’ final_filename.png
  • mantiene la forma, con 1Mpixel
convert image_name -resize ‘100x200!’ final_filename.png
  • obliga a tener el tamaño, no mantiene escala
diffractio.utils_drawing.concatenate_drawings(kind1='png', kind2='png', nx=5, ny=3, geometria_x=256, geometria_y=256, raiz='fig4_nsensors_1', nombreFigura='figura2.png', directorio='')[source]
diffractio.utils_drawing.draw2D(image, x, y, xlabel='$x (\\mu m)$', ylabel='$y (\\mu m)$', title='', color='YlGnBu', interpolation='nearest', scale='scaled', reduce_matrix='standard', range_scale='um', verbose=False)[source]

makes a drawing of XY

Parameters:
  • image (numpy.array) – image to draw
  • x (numpy.array) – positions x
  • y (numpy.array) – positions y
  • xlabel (str) – label for x
  • ytlabel (str) – label for y
  • title (str) – title
  • color (str) – color
  • interpolation (str) – ‘bilinear’, ‘nearest’
  • scale (str) – kind of axis (None, ‘equal’, ‘scaled’, etc.)
  • range_scale (str) – ‘um’ o ‘mm’
  • verbose (bool) – if True prints information
Returns:

handle of figure IDax: handle of axis IDimage: handle of image

Return type:

id_fig

diffractio.utils_drawing.draw_several_fields(fields, titles='', title='', figsize='', kinds='', logarithm=False, normalize=False)[source]

Draws several fields in subplots

Parameters:
  • fields (list) – list with several scalar_fields_XY
  • titles (list) – list with titles
  • title (str) – suptitle
  • kinds (list) – list with kinds of figures (amplitude’, ‘intensity’, ‘phase’, ‘real_field’, ‘contour’)
  • logarithm (bool) – If True, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
diffractio.utils_drawing.extract_image_from_video(nombre_video=None, num_frame='[0, ]', final_filename='prueba.png')[source]

Extract images form a video using imageMagick.

convert ‘animacion.avi[15,]’ animacion_frame.png. Extracts frame 15 (ony 15) convert ‘animacion.avi[15]’ animacion_frame.png. Extracts the first 15 convert ‘animacion.avi[5,10]’ animacion_frame.png. Extracts frame 5 and 10

diffractio.utils_drawing.make_video_from_file(self, files, filename='')[source]
diffractio.utils_drawing.normalize_draw(u, logarithm=0, normalize=False, cut_value=None)[source]

Gets a field and changes its caracteristics for drawing

Parameters:
  • u (field) – field
  • logarithm (float) – logarithm to image: np.log(logarithm*u + 1)
  • normalize (str or bool) – False, ‘mean’, ‘intensity’
diffractio.utils_drawing.prepare_drawing(u, kind='intensity', logarithm=False, normalize=False)[source]

It is necessary that figure is previously defined: plt.figure()

Parameters:
  • - field (u) –
  • - 'intensity', 'amplitude', 'phase' (kind) –
  • - True or False (logarithm) –
  • normalize – False, ‘maximum’, ‘intensity’, ‘area’
Returns:

I_drawing for direct plotting

Return type:

returns (numpy.array)

diffractio.utils_drawing.prepare_video(fps=15, title='', artist='', comment='')[source]
diffractio.utils_drawing.reduce_matrix_size(reduce_matrix, x, y, image, verbose=False)[source]

Reduces the size of matrix for drawing purposes. If the matrix is very big, the drawing process is slow.

Parameters:
  • reduce_matrix (str or (int, int)) – if str: ‘standard’, if (int, int) reduction_factor.
  • x (np.array) – array with x.
  • y (np.array) – array with y or z
  • image (np.array) – image to reduce the size.
  • verbose (bool) – if True, prints info
Returns:

reduced image

Return type:

(np.array)

diffractio.utils_drawing.view_image(filename)[source]

reproduces image

Parameters:filename (str) – filename

4.1.15. diffractio.utils_math module

Common functions to classes

diffractio.utils_math.amplitude2phase(u)[source]

Passes the amplitude of a complex field to phase. Previous phase is removed. \(u = A e^{i \phi} -> e^(i abs(A))\)

Parameters:u (numpy.array, dtype=complex) – complex field
Returns:only-phase complex vector.
Return type:(numpy.array)
diffractio.utils_math.binarize(vector, min_value=0, max_value=1)[source]

Binarizes vector between two levels, min and max. The central value is (min_value+max_value)/2

Parameters:
  • vector – (numpy.array) array with values to binarize
  • min_value (float) – minimum value for binarization
  • max_value (float) – maximum value for binarization
Returns:

binarized vector.

Return type:

(numpy.array)

diffractio.utils_math.cart2pol(x, y)[source]

cartesian to polar coordinate transformation.

Parameters:
  • x (np.array) – x coordinate
  • y (np.aray) – y coordinate
Returns:

rho numpy.array: phi

Return type:

numpy.array

diffractio.utils_math.curl(E, r)[source]

Returns the Curl of a field a given point (x0,y0,z0)

Parameters:
  • E (numpy.array) – complex field
  • r (numpy.array) – 3x1 array with position r=(x,y,z).
Returns:

Curl of the field at (x0,y0,z0)

Return type:

(numpy.array)

diffractio.utils_math.cut_function(x, y, length, x_center='')[source]

takes values of function inside (x_center+length/2: x_center+length/2)

diffractio.utils_math.delta_kronecker(a, b)[source]

Delta kronecker

Parameters:
  • a (np.float) – number
  • b (np.float) – number
Returns:

1 if a==b and 0 if a<>b

diffractio.utils_math.discretize(u, kind='amplitude', num_levels=2, factor=1, phase0=0, new_field=True, matrix=False)[source]

Discretize in a number of levels equal to num_levels.

Parameters:
  • kind (str) – “amplitude” o “phase”
  • num_levels (int) – number of levels for the discretization
  • factor (float) – from the level, how area is binarized. if 1 everything is binarized,
  • phase0 (float) –
  • new_field (bool) – if True returns new field
  • matrix (bool) – if True it returs a matrix
Returns:

if new_field is True returns scalar_fields_XY

Return type:

scalar_fields_XY

diffractio.utils_math.distance(x1, x2)[source]

Compute distance between two vectors.

Parameters:
  • x1 (numpy.array) – vector 1
  • x2 (numpy.array) – vector 2
Returns:

distance between vectors.

Return type:

(float)

diffractio.utils_math.divergence(E, r)[source]

Returns the divergence of a field a given point (x0,y0,z0).

Parameters:
  • E (numpy.array) – complex field
  • r (numpy.array) – 3x1 array with position r=(x,y,z).
Returns:

Divergence of the field at (x0,y0,z0)

Return type:

(float)

diffractio.utils_math.dot_product(A, B)[source]

Returns the dot product between two vectors.

Parameters:
  • A (numpy.array) – 3x1 vector array.
  • B (numpy.array) – 3x1 vector array.
Returns:

3x1 dot product

Return type:

(complex)

diffractio.utils_math.fZernike(X, Y, n, m, radius=5000.0)[source]

Zernike function for aberration computation.

Note

k>=l

if k is even then l is even. if k is odd then l is odd.

The first polinomial is the real part ant the second de imaginary part.

  • n m aberración
  • 0 0 piston
  • 1 -1 vertical tilt
  • 1 1 horizontal tilt
  • 2 -2 astigmatismo oblicuo
  • 2 0 desenfoque miopía si c>0 o desenfoque hipermetropía si c<0
  • 2 2 astigmatismo anormal si c>0 o astigmatismo normal si c<0
  • 3 -3 trebol oblicuo
  • 3 -1 coma vertical, c>0 empinamiento superior, c<0 emp. inferior
  • 3 1 como horizontal
  • 3 3 trebol horizontal
  • 4 -4 trebol de cuatro hojas oblicuo
  • 4 -2 astigmatismo secundario oblicuo
  • 4 0 esférica c>0 periferia más miópica que centro, c<0 periferia más hipertrópica que el centro
  • 4 2 astigmatismo secundario a favor o en contra de la regla
  • 4 4 trebol de cuatro hojas horizontal

Reference:

  1. Navarro, J. Arines, R. Rivera “Direct and inverse discrete Zernike transform” Opt. Express 17(26) 24269
diffractio.utils_math.fft_convolution1d(x, y)[source]

1D convolution, using FFT

Parameters:
  • x (numpy.array) – array 1 to convolve
  • y (numpy.array) – array 2 to convolve
Returns:

convolved function

diffractio.utils_math.fft_convolution2d(x, y)[source]

2D convolution, using FFT

Parameters:
  • x (numpy.array) – array 1 to convolve
  • y (numpy.array) – array 2 to convolve
Returns:

convolved function

diffractio.utils_math.fft_correlation1d(x, y)[source]

1D correlation, using FFT (fftconvolve)

Parameters:
  • x (numpy.array) – array 1 to convolve
  • y (numpy.array) – array 2 to convolve
Returns:

correlation function

Return type:

numpy.array

diffractio.utils_math.fft_correlation2d(x, y)[source]
Parameters:
  • x (numpy.array) – array 1 to convolve
  • y (numpy.array) – array 2 to convolve
Returns:

2d correlation function

Return type:

numpy.array

diffractio.utils_math.fft_filter(x, y, normalize=False)[source]

1D convolution, using FFT

Parameters:
  • x (numpy.array) – array 1 to convolve
  • y (numpy.array) – array 2 to convolve
Returns:

convolved function

diffractio.utils_math.filter_edge_1D(x, size=1.1, exponent=32)[source]

function 1 at center and reduced at borders. For propagation algorithms

Parameters:
  • x (np.array) – position
  • size (float) – related to relative position of x
  • exponent (integer) – related to shape of edges
Returns:

function for filtering

Return type:

np.array

diffractio.utils_math.filter_edge_2D(x, y, size=1.1, exponent=32)[source]

function 1 at center and reduced at borders. For propagation algorithms

Parameters:
  • x (np.array) – x position
  • y (np.array) – y position
  • size (float) – related to relative position of x and y
  • exponent (integer) – related to shape of edges
Returns:

function for filtering

Return type:

np.array

diffractio.utils_math.find_extrema(array2D, x, y, kind='max', verbose=False)[source]

In a 2D-array, formed by vectors x, and y, the maxima or minima are found

Parameters:
  • array2D (np. array 2D) – 2D array with variable
  • x (np.array 1D) – 1D array with x axis
  • y (np.array 1D) – 1D array with y axis
  • kind (str) – ‘min’ or ‘max’: detects minima or maxima
  • verbose (bool) – If True prints data.
Returns:

indexes of the position xy_ext (float, float): position of maximum extrema (float): value of maximum

Return type:

indexes (int,int)

diffractio.utils_math.get_amplitude(u, sign=False)[source]

Gets the amplitude of the field.

Parameters:
  • u (numpy.array) – Field.
  • sign (bool) – If True, sign is kept, else, it is removed
Returns:

numpy.array

Return type:

(numpy.array)

diffractio.utils_math.get_edges(x, f, kind_transition='amplitude', min_step=0, verbose=False, filename='')[source]

We have a binary mask and we obtain locations of edges. valid for litography engraving of gratings

Parameters:
  • x (float) – position x
  • f (numpy.array) – Field. If real function, use ‘amplitude’ in kind_transition.
  • kind_transition (str) – ‘amplitude’ ‘phase’ of the field where to get the transitions.
  • min_step (float) – minimum step for consider a transition
  • verbose (bool) – If True prints information about the process.
  • filename (str) – If not ‘’, saves the data on files. filename is the file name.
Returns:

array with +1, -1 with rasing or falling edges pos_transition (numpy.array): positions x of transitions raising (numpy.array): positions of raising falling (numpy.array): positions of falling

Return type:

type_transition (numpy.array)

diffractio.utils_math.get_k(x, flavour='-')[source]

provides k vector from x vector. Two flavours are provided (ordered + or disordered - )

Parameters:
  • x (np.array) – x array
  • flavour (str) – ‘+’ or ‘-’
Returns:

k vector

Return type:

kx (np.array)

diffractio.utils_math.get_phase(u)[source]

Gets the phase of the field.

Parameters:u (numpy.array) – Field.
Returns:numpy.array
Return type:(numpy.array)
diffractio.utils_math.laguerre_polynomial_nk(x, n=4, k=5)[source]

Auxiliar laguerre polinomial of orders n and k function y = LaguerreGen(varargin) LaguerreGen calculates the utilsized Laguerre polynomial L{n, alpha} This function computes the utilsized Laguerre polynomial L{n,alpha}. If no alpha is supplied, alpha is set to zero and this function calculates the “normal” Laguerre polynomial.

Parameters: - n = nonnegative integer as degree level - alpha >= -1 real number (input is optional)

The output is formated as a polynomial vector of degree (n+1) corresponding to MatLab norms (that is the highest coefficient is the first element).

Example: - polyval(LaguerreGen(n, alpha), x) evaluates L{n, alpha}(x) - roots(LaguerreGen(n, alpha)) calculates roots of L{n, alpha}

Calculation is done recursively using matrix operations for very fast execution time.

Author: Matthias.Trampisch@rub.de Date: 16.08.2007 Version 1.2

References

Szeg: “Orthogonal Polynomials” 1958, formula (5.1.10)

diffractio.utils_math.ndgrid(*args, **kwargs)[source]

n-dimensional gridding like Matlab’s NDGRID

Parameters:
  • input *args are an arbitrary number of numerical sequences, e.g. lists, arrays, or tuples. (The) –
  • i-th dimension of the i-th output argument (The) –
  • copies of the i-th input argument. (has) –

Example

>>> x, y, z = [0, 1], [2, 3, 4], [5, 6, 7, 8]
>>> X, Y, Z = ndgrid(x, y, z)
# unpacking the returned ndarray into X, Y, Z

Each of X, Y, Z has shape [len(v) for v in x, y, z].

>>> X.shape == Y.shape == Z.shape == (2, 3, 4)
True
>>> X
array([[[0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0]],
           [[1, 1, 1, 1],
                [1, 1, 1, 1],
                [1, 1, 1, 1]]])
>>> Y
array([[[2, 2, 2, 2],
                [3, 3, 3, 3],
                [4, 4, 4, 4]],
           [[2, 2, 2, 2],
                [3, 3, 3, 3],
                [4, 4, 4, 4]]])
>>> Z
array([[[5, 6, 7, 8],
                [5, 6, 7, 8],
                [5, 6, 7, 8]],
           [[5, 6, 7, 8],
                [5, 6, 7, 8],
                [5, 6, 7, 8]]])

With an unpacked argument list:

>>> V = [[0, 1], [2, 3, 4]]
>>> ndgrid(*V) # an array of two arrays with shape (2, 3)
array([[[0, 0, 0],
                [1, 1, 1]],
           [[2, 3, 4],
                [2, 3, 4]]])

For input vectors of different data kinds, same_dtype=False makes ndgrid() return a list of arrays with the respective dtype. >>> ndgrid([0, 1], [1.0, 1.1, 1.2], same_dtype=False) [array([[0, 0, 0], [1, 1, 1]]),

array([[ 1. , 1.1, 1.2], [ 1. , 1.1, 1.2]])]

Default is to return a single array.

>>> ndgrid([0, 1], [1.0, 1.1, 1.2])
array([[[ 0. ,  0. ,  0. ], [ 1. ,  1. ,  1. ]],
           [[ 1. ,  1.1,  1.2], [ 1. ,  1.1,  1.2]]])
diffractio.utils_math.nearest(vector, number)[source]

Computes the nearest element in vector to number.

Parameters:
  • vector (numpy.array) – array with numbers
  • number (float) – number to determine position
Returns:

index - index of vector which is closest to number. (float): value - value of vector[index]. (float): distance - difference between number and chosen element.

Return type:

(int)

diffractio.utils_math.nearest2(vector, numbers)[source]

Computes the nearest element in vector to numbers.

Parameters:
  • vector (numpy.array) – array with numbers
  • number (numpy.array) – numbers to determine position
Returns:

index - indexes of vector which is closest to number. (numpy.array): value - values of vector[indexes]. (numpy.array): distance - difference between numbers and chosen elements.

Return type:

(numpy.array)

diffractio.utils_math.normalize(v, order=2)[source]

Normalize vectors with different L norm (standard is 2).

Parameters:
  • v (numpy.array) – vector to normalize
  • order (int) – order for norm
Returns:

normalized vector.

Return type:

(numpy.array)

diffractio.utils_math.phase2amplitude(u)[source]

Passes the phase of a complex field to amplitude.

Parameters:u (numpy.array, dtype=complex) – complex field
Returns:amplitude without phase complex vector.
Return type:(numpy.array)
diffractio.utils_math.pol2cart(rho, phi)[source]

polar to cartesian coordinate transformation

Parameters:
  • rho (np.aray) – rho coordinate
  • rho – rho coordinate
Returns:

x numpy.array: y

Return type:

numpy.array

diffractio.utils_math.rotate_image(x, z, img, angle, pivot_point)[source]

similar to rotate image, but not from the center but from the given

Parameters:
  • img (np.array) – image to rotate
  • angle (float) – angle to rotate
  • pivot_point (float, float) – (z,x) position for rotation
Returns:

rotated image

Reference:
https://stackoverflow.com/questions/25458442/rotate-a-2d-image-around-specified-origin-in-python point
diffractio.utils_math.vector_product(A, B)[source]

Returns the vector product between two vectors.

Parameters:
  • A (numpy.array) – 3x1 vector array.
  • B (numpy.array) – 3x1 vector array.
Returns:

3x1 vector product array

Return type:

(numpy.array)

4.1.16. diffractio.utils_multiprocessing module

class diffractio.utils_multiprocessing.auxiliar_multiprocessing[source]

Bases: object

execute_multiprocessing(function, var_iterable, dict_constants={}, Ncores=8)[source]
method_single_proc(elem_iterable)[source]
diffractio.utils_multiprocessing.execute_multiprocessing(__function_process__, dict_Parameters, num_processors, verbose=False)[source]

Executes multiprocessing reading a dictionary.

Parameters:
  • function tu process, it only accepts a dictionary (__function_process__) –
  • dictionary / array with Parameters (dict_Parameters,) –
  • if 1 no multiprocessing is used (num_processors,) –
  • prints processing time (verbose,) –
Returns:

reults of multiprocessing processing time

Return type:

data

Examples

def __function_process__(xd):
x = xd[‘x’] y = xd[‘y’] # grt = copy.deepcopy(grating) suma = x + y return dict(sumas=suma, ij=xd[‘ij’])
def creation_dictionary_multiprocessing():

# create Parameters: for multiprocessing t1 = time.time() X = np.linspace(1, 2, 10) Y = np.linspace(1, 2, 1000) dict_Parameters = [] ij = 0 for i, x in enumerate(X):

for j, y in enumerate(Y):
dict_Parameters.append(dict(x=x, y=y, ij=[ij])) ij += 1

t2 = time.time() print(“time creation dictionary = {}”.format(t2 - t1)) return dict_Parameters

diffractio.utils_multiprocessing.separate_from_iterable(iterable, shape=0)[source]

This function does somehow the opposite of the previous one, it takes an iterable made of lists and separates each one in a different variable, reshaped with the desired shape

4.1.17. diffractio.utils_optics module

General purpose optics functions

diffractio.utils_optics.DOF(z, widths, w_factor=1.4142135623730951, w_fixed=0, has_draw=False, verbose=False)[source]

Determines Depth-of_focus (DOF) in terms of the width at different distances

Parameters:
  • z (np.array) – z positions
  • widths (np.array) – width at positions z
  • w_factor (float) – range to determine z where w = w_factor * w0, being w0 the beam waist
  • w_fixed (float) – If it is not 0, then it is used as w_min
  • has_draw (bool) – if True draws the depth of focus
  • verbose (bool) – if True, prints data

References

      1. Saleh and M. C. Teich, Fundamentals of photonics. john Wiley & sons, 2nd ed. 2007. Eqs (3.1-18) (3.1-22) page 79
Returns:Depth of focus (float): beam waist (float, float, float): postions (z_min, z_0, z_max) of the depth of focus
Return type:(float)
diffractio.utils_optics.FWHM1D(x, intensity, percentaje=0.5, remove_background=None, has_draw=False)[source]

remove_background = ‘min’, ‘mean’, None

diffractio.utils_optics.FWHM2D(x, y, intensity, percentaje=0.5, remove_background='None', has_draw=False, xlim=None)[source]

TODO: perform profiles at several angles and fit to a ellipse. Get dx, dy, angle, x_center, y_center

diffractio.utils_optics.MTF_ideal(frequencies, wavelength, diameter, focal, kind, verbose=False, has_draw=False)[source]

Determines the ideal MTF of a lens.

References

https://www.edmundoptics.com/resources/application-notes/optics/introduction-to-modulation-transfer-function/

https://www.optikos.com/wp-content/uploads/2015/10/How-to-Measure-MTF-and-other-Properties-of-Lenses.pdf

Parameters:
  • frequencies (numpy.array) – array with frequencies in lines/mm
  • wavelength (float) – wavelength of incoming light beam
  • diameter (float) – diameter of lens
  • focal (float) – focal distance of lens
  • kind (float) – ‘1D’, ‘2D’
  • verbose (bool) – if True displays limit frequency of the lens
Returns:

Normalized MTF of ideal lens (float) frequency_max: maximum frequency of the lens

Return type:

(numpy.array) MTF

diffractio.utils_optics.MTF_parameters(MTF, MTF_ideal, lines_mm=50, verbose=False)[source]

MTF parameters: strehl_ratio, mtf_50_ratio, freq_50_real, freq_50_ideal

References

https://www.edmundoptics.com/resources/application-notes/optics/introduction-to-modulation-transfer-function/strehl_ratio

frequencies of mtf ar given since both MTF can have different steps MTF:

Parameters:
  • MTF (N,2 numpy.array) – (freq, MTF) of system in lines/mm
  • MTF_ideal (M,2 numpy.array) – (freq, MTF) of ideal system in lines/mm
  • lines_mm (float) – (0-1) Height of MTF for ratios
Returns:

strehl_ratio (float): MTF_ratio at freq_obs height (float): frequency at freq_obs of MTF (float): frequency at freq_obs of MTF_ideal

Return type:

(float)

diffractio.utils_optics.beam_width_1D(u, x, remove_background=None)[source]

One dimensional beam width, according to D4σ or second moment width.

Parameters:
  • u (np.array) – field (not intensity).
  • x (np.array) – x
Returns:

width (float): x_mean

Return type:

(float)

References

https://en.wikipedia.org/wiki/Beam_diameter

diffractio.utils_optics.beam_width_2D(x, y, intensity, remove_background=False, has_draw=False)[source]

2D beam width, ISO11146 width

Parameters:
  • x (np.array) – 1d x
  • y (np.array) – 1d y
  • intensity (np.array) – intensity
Returns:

dx width x (float): dy width y (float): principal_axis, angle (str): (x_mean, y_mean, x2_mean, y2_mean, xy_mean), Moments

Return type:

(float)

References

diffractio.utils_optics.convert_amplitude2heigths(amplitude, wavelength, kappa, n_background)[source]

We have a phase and it is converted to a depth. It is useful to convert Scalar_mask_X to Scalar_mask_XZ.

Parameters:
  • phase (np.array) – Phases
  • wavelength (float) – wavelength
  • kappa (float) – refraction index of material.
  • n_background (float) – refraction index of background
Returns:

depths related to amplitudes

Return type:

(np.array)

diffractio.utils_optics.convert_phase2heigths(phase, wavelength, n, n_background)[source]

We have a phase and it is converted to a depth. It is useful to convert Scalar_mask_X to Scalar_mask_XZ

phase(x,z)= k (n-n_0) h(x,z).

Parameters:
  • phase (np.array) – Phases
  • wavelength (float) – wavelength
  • n (float or complex) – refraction index of material
  • n_background (float) – refraction index of background
Returns:

depths related to phases

Return type:

(np.array)

diffractio.utils_optics.detect_intensity_range(x, intensity, percentage=0.95, has_draw=True, logarithm=True)[source]

Determines positions x_min, x_max where intensity of the beam is percentage

Parameters:
  • x (np.array) – x positions
  • intensity (np.array) – Intensity of the 1D beam
  • percentage (float) – value 0-1 representing the percentage of intensity between area
  • has_draw (bool) – if True draws the field an the range
  • logarithm (bool) – when has_draw, draws logarithm or normal intensity
Returns:

positions (x_min, right) where intensity beam is enclosed at %.

Return type:

(float, float)

diffractio.utils_optics.drawTransmitancias(theta_i, n1, n2, R_perp, R_par, T_perp, T_par, filename='')[source]

Dibuja las ecuaciones de fresnel en function del angle de entrada

diffractio.utils_optics.draw_fresnel_coefficients(theta_i, n1, n2, r_perp, r_par, t_perp, t_par, filename='')[source]

Dibuja las ecuaciones de fresnel en function del angle de entrada

diffractio.utils_optics.field_parameters(u, has_amplitude_sign=False)[source]

Determines main parameters of field: amplitude intensity phase. All this parameters have the same dimension as u.

Parameters:
  • u (numpy.array) – optical field (comes usually form field.u)
  • has_amplitude_sign (bool) – If True - amplitude = np.sign(u) * np.abs(u), Else: amplitude = np.abs(u)
Returns:

np.abs(u) intensity (numpy.array): np.abs(u)**2 phase (numpy.array): np.angle(u)

Return type:

amplitude (numpy.array)

diffractio.utils_optics.fresnel_coefficients_complex(theta_i, n1, n2c)[source]

Calcula las components rs y rp mediante las eq. de Fresnel n^=n-ik .. rubric:: Example

theta_i=linspace(0*degrees,90*degrees,10),

Los parametros de entrada pueden ser arrays de numeros. Para drawlos el array debe ser theta_i n2c puede ser complejo

diffractio.utils_optics.fresnel_coefficients_dielectric(theta_i, n1, n2)[source]

Components rs, rp, ts y tp - Fresnel queations

Parameters:
  • theta_i (numpy.array or float) – angle of incidence.
  • n1 (float) – refraction index of first medium
  • n2 (float) – refraction index of second medium
Returns:

r_perp (numpy.array or float): r_par (numpy.array or float): t_perp (numpy.array or float): t_par

Return type:

(numpy.array or float)

diffractio.utils_optics.gauss_spectrum(wavelengths, w_central, Dw, normalize=True)[source]

returns weigths for a gaussian spectrum :param wavelengths: array with wavelengths :param w_central: central wavelength :param Dw: width of the spectrum :param normalize: if True sum of weights is 1

diffractio.utils_optics.lines_mm_2_cycles_degree(lines_mm, focal)[source]

Pasa líneas por mm a cyclos/grado, más tipico de ojo Infor saca estos cálculos 181022 :param lines_mm: lines_per_mm :type lines_mm: numpy.array or float :param focal: focal of lens :type focal: float

diffractio.utils_optics.lorentz_spectrum(wavelengths, w_central, Dw, normalize=True)[source]

returns weigths for a gaussian spectrum :param wavelengths: array with wavelengths :param w_central: central wavelength :param Dw: width of the spectrum :param normalize: if True sum of weights is 1

diffractio.utils_optics.normalize(u, kind='intensity')[source]

Normalizes a field to have intensity or amplitude, etc. 1

Parameters:
  • u (numpy.array) – optical field (comes usually form field.u)
  • kind (str) – ‘intensity, ‘amplitude’, ‘logarithm’… other.. Normalization technique
Returns
u (numpy.array): normalized optical field
diffractio.utils_optics.reflectance_transmitance_complex(theta_i, n1, n2c)[source]

Calcula las components rs y rp mediante las eq. de Fresnel n^=n-ik .. rubric:: Example

theta_i=linspace(0*degrees,90*degrees,10),

Los parametros de entrada pueden ser arrays de numeros. Para drawlos el array debe ser theta_i n2c puede ser complejo

diffractio.utils_optics.reflectance_transmitance_dielectric(theta_i, n1, n2)[source]

Transmittances R_perp, R_par, T_perp, T_par - Fresnel queations

Parameters:
  • theta_i (numpy.array or float) – angle of incidence.
  • n1 (float) – refraction index of first medium
  • n2 (float) – refraction index of second medium
Returns:

R_perp (numpy.array or float): R_par (numpy.array or float): T_perp (numpy.array or float): T_par

Return type:

(numpy.array or float)

diffractio.utils_optics.refraction_index(filename, wavelength, raw=False, has_draw=True)[source]

gets refraction index from https://refractiveindex.info .

  • Files has to be converted to xlsx format.
  • n and k checks has to be activated.
Parameters:
  • filename (str) – xlsx file
  • wavelength (float) – wavelength in microns, example, 0.6328.
  • raw (bool) – if True returns all the data in file.
  • has_draw (bool) – draw the data from the file
Returns:

n, k from each wavelength if raw is True (np.array, np.array): n,k for wavelengths in file

Return type:

if raw is False (float, float)

diffractio.utils_optics.roughness_1D(x, t, s, kind='normal')[source]

Rough surface, 1D

Parameters:
  • x (numpy.array) – array with x positions
  • t (float) – correlation lens
  • s (float) – std of roughness
  • kind (str) – ‘normal’, ‘uniform’
Returns:

(numpy.array) Topography of roughnness in microns.

References

JA Oglivy “Theory of wave scattering from random surfaces” Adam Hilger p.224.

diffractio.utils_optics.roughness_2D(x, y, t, s)[source]

Rough surface, 2D

Parameters:
  • x (numpy.array) – x positions
  • y (numpy.array) – y positions
  • t (float, float) – (tx, ty), correlation length of roughness
  • s (float) – std of heights
Returns:

(numpy.array) Topography of roughnness in microns.

Example

roughness(t=(50 * um, 25 * um), s=1 * um)

References

JA Oglivy “Theory of wave scattering from random surfaces” Adam Hilger p.224.

diffractio.utils_optics.uniform_spectrum(wavelengths, normalize=True)[source]

returns weigths for a gaussian spectrum :param wavelengths: array with wavelengths :param w_central: central wavelength :param Dw: width of the spectrum :param normalize: if True sum of weights is 1

diffractio.utils_optics.width_percentaje(x, y, percentaje=0.5, verbose=False)[source]

beam width (2*sigma) given at a certain height from maximum

Parameters:
  • x (np.array) – x
  • y (np.array) – y
  • percentaje (float) – percentaje of height. For example: 0.5
Returns:

width, width of at given % (list): x_list: (x[i_left], x[i_max], x[i_right]) (list): x_list: (i_left, i_max, i_right)

Return type:

(float)

Notes

y=np.exp(-x**2/(s**2)) percentaje=1/e -> width = 2*s y=np.exp(-x**2/(s**2)) percentaje=1/e**4 -> width = 4*s y=np.exp(-x**2/(2*s**2)) percentaje=1/e**2 = -> width = 4*s

4.1.18. diffractio.utils_slicer module

4.1.19. diffractio.utils_tests module

Common functions to classes

diffractio.utils_tests.benchmark_num_pixels(function, n_max=10)[source]

This function is for benchmarking using an increasing number of pixels 2**n.

Parameters:function (function) – Functions that has as argumetn the number of pixels 2**n.
diffractio.utils_tests.benchmark_processors_n_pixels(n_pixels)[source]
diffractio.utils_tests.compare_drawings_folders(folder1, folder2)[source]

look for identical images, open and verifies that are equal

diffractio.utils_tests.compare_npz_folders(folder1, folder2)[source]

look for identical files, open and verifies that all the dicts are equal

diffractio.utils_tests.comparison(proposal, solution, maximum_diff)[source]

This functions is mainly for testing. It compares compares proposal to solution.

Parameters:
  • proposal (numpy.matrix) – proposal of result.
  • solution (numpy.matrix) – results of the test.
  • maximum_diff (float) – maximum difference allowed.
Returns:

True if comparison is possitive, else False.

Return type:

(bool)

diffractio.utils_tests.ejecute_multiprocessing(num_cores, n_pixels)[source]
diffractio.utils_tests.run_benchmark(num_pixels)[source]
diffractio.utils_tests.save_data_test(cls, newpath, func_name, add_name='')[source]
diffractio.utils_tests.save_figure_test(newpath, func_name, add_name='')[source]

4.1.20. diffractio.vector_paraxial_fields_XY module

This module generates Vector_paraxial_field_XY class.

It is required also for generating masks and fields. The main atributes are:

  • self.Ex - x component of electric field
  • self.Ey - y component of electric field
  • self.x - x positions of the field
  • self.wavelength - wavelength of the incident field. The field is monocromatic
  • self.x - x positions of the field
  • self.y - y positions of the field
  • self.wavelength - wavdelength of the incident field. The field is monochromatic
  • self.Ex - x component of electric field. Equal size to x * y. complex field
  • self.Ey - y component of electric field. Equal size to x * y. complex field
  • self.X (numpy.array): equal size to x * y. complex field
  • self.Y (numpy.array): equal size to x * y. complex field
  • self.quality (float): quality of RS algorithm
  • self.info (str): description of data
  • self.type (str): Class of the field
  • self.date (str): date when performed

The magnitude is related to microns: micron = 1.

Class for XY paraxial vector fields

Definition of a scalar field
  • add, substract fields
  • save, load data, clean, get, normalize
  • cut_resample
  • appy_mask
Vector parameters
  • polarization_states
  • polarization_ellipse
Propagation
  • RS - Rayleigh Sommerfeld
Drawing functions
  • draw: intensity, intensities, phases, fields, stokes, param_ellipse, ellipses
class diffractio.vector_paraxial_fields_XY.Vector_paraxial_field_XY(x, y, wavelength, info='')[source]

Bases: object

Class for vectorial fields.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly 2**n.
  • y (numpy.array) – linear array with equidistant positions. The number of data is preferibly 2**n.
  • wavelength (float) – wavelength of the incident field
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly 2**n.

Type:numpy.array
self.y

linear array with equidistant positions. The number of data is preferibly 2**n.

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.Ex

Electric_x field

Type:numpy.array
self.Ey

Electric_y field

Type:numpy.array
RS(z=10000.0, n=1, new_field=True, amplification=(1, 1), verbose=False)[source]

Fast-Fourier-Transform method for numerical integration of diffraction Rayleigh-Sommerfeld formula. Thin Element Approximation is considered for determining the field just after the mask: \(\mathbf{E}_{0}(\zeta,\eta)=t(\zeta,\eta)\mathbf{E}_{inc}(\zeta,\eta)\) Is we have a field of size N*M, the result of propagation is also a field N*M. Nevertheless, there is a parameter amplification which allows us to determine the field in greater observation planes (jN)x(jM).

Parameters:
  • z (float) – distance to observation plane. if z<0 inverse propagation is executed
  • n (float) – refraction index
  • new_field (bool) – if False the computation goes to self.u if True a new instance is produced
  • amplification (int, int) – number of frames in x and y direction
  • verbose (bool) – if True it writes to shell. Not implemented yet
Returns:

Scalar_field_X else None

Return type:

if New_field is True

Note

One adventage of this approach is that it returns a quality parameter: if self.quality>1, propagation is right.

References

From Applied Optics vol 45 num 6 pp. 1102-1110 (2006)

VRS(z, n=1, new_field=True, verbose=False, amplification=(1, 1))[source]

Fast-Fourier-Transform method for numerical integration of diffraction Vector Rayleigh-Sommerfeld formula.

Parameters:
  • z (float) – distance to observation plane. if z<0 inverse propagation is executed
  • n (float) – refraction index
  • new_field (bool) – if False the computation goes to self.u if True a new instance is produced
  • verbose (bool) – if True it writes to shell. Not implemented yet
Returns:

Scalar_field_X else None

Return type:

if New_field is True

References

  1. Ye, C.-W. Qiu, K. Huang, J. Teng, B. Luk’yanchuk, y S. P. Yeo, «Creation of a longitudinally polarized subwavelength hotspot with an ultra-thin planar lens: vectorial Rayleigh–Sommerfeld method», Laser Phys. Lett., vol. 10, n.º 6, p. 065004, jun. 2013.

DOI: 10.1088/1612-2011/10/6/065004

http://stacks.iop.org/1612-202X/10/i=6/a=065004?key=crossref.890761f053b56d7a9eeb8fc6da4d9b4e

apply_mask(u)[source]

Multiply field by binary scalar mask: self.Ex = self.Ex * u.u

Parameters:u (Scalar_mask_XY) – mask
clear()[source]

simple - removes the field: self.E=0

cut_resample(x_limits='', y_limits='', num_points=[], new_field=False, interp_kind=(3, 1))[source]

Cuts the field to the range (x0,x1). (y0,y1). If one of this x0,x1 positions is out of the self.x range it do nothing. It is also valid for resampling the field, just write x0,x1 as the limits of self.x

Parameters:
  • x_limits (float,float) – (x0,x1) starting and final points to cut. if ‘’ - takes the current limit x[0] and x[-1]
  • y_limits (float,float) – (y0,y1) - starting and final points to cut. if ‘’ - takes the current limit y[0] and y[-1]
  • num_points (int) – it resamples x, y and u. [],’’,0,None -> it leave the points as it is
  • new_field (bool) – it returns a new Scalar_field_XY
  • interp_kind (int) – numbers between 1 and 5
draw(kind='intensity', logarithm=0, normalize=False, cut_value=None, num_ellipses=(11, 11), amplification=0.5, filename='', draw=True, **kwargs)[source]

Draws electromagnetic field

Parameters:
  • kind (str) – ‘intensity’, ‘intensities’, intensities_rz, ‘phases’, fields’, ‘stokes’, ‘param_ellipse’, ‘ellipses’
  • logarithm (float) – If >0, intensity is scaled in logarithm
  • normalize (bool) – If True, max(intensity)=1
  • title (str) – title of figure
  • filename (str) – if not ‘’ stores drawing in file,
  • cut_value (float) – If not None, cuts the maximum intensity to this value
  • num_ellipses (int) – number of ellipses for parameters_ellipse
  • amplification (float) – amplification of ellipses
  • TODO (#) – change to similar to v_matrix
get(kind='fields')[source]

Takes the vector field and divide in Scalar_field_XY

Parameters:kind (str) – ‘fields’, ‘intensity’, ‘intensities’, ‘phases’, ‘stokes’, ‘params_ellipse’
Returns:(Ex, Ey),
Return type:Scalar_field_XY
load_data(filename, verbose=False)[source]
Load data from a file to a Vector_paraxial_field_XY.
The methods included are: npz, matlab
Parameters:
  • filename (str) – filename
  • verbose (bool) – shows data process by screen
normalize()[source]

Normalizes the field

polarization_ellipse(pol_state=None, matrix=False)[source]

returns A, B, theta, h polarization parameter of elipses

Parameters:
  • pol_state (None or (I, Q, U, V)) – Polarization state previously computed
  • Matrix (bool) – if True returns Matrix, else Scalar_field_XY
Returns:

A, B, theta, h for Matrix=True CA, CB, Ctheta, Ch for Matrix=False

polarization_states(matrix=False)[source]

returns the Stokes parameters

Parameters:Matrix (bool) – if True returns Matrix, else Scalar_field_XY
Returns:S0,S1,S2,S3 images for Matrix=True S0,S1,S2,S3 for Matrix=False
save_data(filename, add_name='', description='', verbose=False)[source]

Common save data function to be used in all the modules. The methods included are: npz, matlab

Parameters:
  • filename (str) – filename
  • add_name= (str) – sufix to the name, if ‘date’ includes a date
  • description (str) – text to be stored in the dictionary to save.
  • verbose (bool) – If verbose prints filename.
Returns:

filename. If False, file could not be saved.

Return type:

(str)

diffractio.vector_paraxial_fields_XY.polarization_ellipse(self, pol_state=None, matrix=False)[source]

returns A, B, theta, h polarization parameter of elipses

Parameters:
  • pol_state (None or (I, Q, U, V)) – Polarization state previously computed
  • Matrix (bool) – if True returns Matrix, else Scalar_field_XY
Returns:

A, B, theta, h for Matrix=True CA, CB, Ctheta, Ch for Matrix=False

4.1.21. diffractio.vector_paraxial_masks_XY module

This module generates Vector_paraxial_mask_XY class for defining vector masks. Its parent is Vector_paraxial_field_XY.

The main atributes are:
self.x (numpy.array): linear array with equidistant positions. The number of data is preferibly 2**n. self.y (numpy.array): linear array with equidistant positions. The number of data is preferibly 2**n. self.wavelength (float): wavelength of the incident field. self.Ex (numpy.array): Electric_x field self.Ey (numpy.array): Electric_y field

Class for bidimensional vector XY masks

Functions
  • unique_masks
  • equal_masks
  • global_mask
  • complementary_masks
  • from_py_pol
  • polarizer_linear
  • quarter_waveplate
  • half_wave
  • polarizer_retarder
class diffractio.vector_paraxial_masks_XY.Vector_paraxial_mask_XY(x, y, wavelength, info='')[source]

Bases: diffractio.vector_paraxial_fields_XY.Vector_paraxial_field_XY

apply_circle(r0=None, radius=None)[source]

The same circular mask is applied to all the Jones Matrix.

Parameters:
  • r0 (float, float) – center, if None it is generated
  • radius (float, float) – radius, if None it is generated
apply_scalar_mask(u_mask)[source]

The same mask u_mask is applied to all the Jones Matrix.

Parameters:u_mask (scalar_mask_XY) – mask to apply.
complementary_masks(mask, state_0=array([[1, 0], [0, 0]]), state_1=array([[0, 0], [0, 1]]), is_binarized=True)[source]

Creates two different fields Ex and Ey from a mask and its complementary. For generality, is mask is a decimal number between 0 and 1, it takes the linear interpolation.

Parameters:
  • mask (scalar_mask_XY) – Mask preferently binary. if not, it is binarized
  • state_0 (2x1 numpy.array) – polarization matrix for 0s.
  • state_1 (2x1 numpy.array) – polarization matrix for 1s.

Warning

TODO: Mask should be binary. Else the function should binarize it.

draw(kind='amplitude', z_scale='um')[source]

Draws the mask. It must be different to sources.

Parameters:kind (str) – ‘amplitude’, ‘amplitudes’, ‘phase’, ‘phases’, ‘all’
from_py_pol(polarizer)[source]

Generates a constant polarization mask from py_pol polarization.Jones_matrix. This is the most general function to obtain a polarizer.

Parameters:polarizer (2x2 numpy.matrix) – Jones_matrix
half_waveplate(azimuth=0.0)[source]

Generates an XY half wave plate.

Parameters:azimuth (float) – polarizer angle
polarizer_linear(azimuth=0.0)[source]

Generates an XY linear polarizer.

Parameters:angle (float) – linear polarizer angle
polarizer_retarder(R=0.0, p1=1, p2=1, azimuth=0.0)[source]

Generates an XY retarder.

Parameters:
  • R (float) – retardance between Ex and Ey components.
  • p1 (float) – transmittance of fast axis.
  • p2 (float) – transmittance of slow axis.
  • azimuth (float) – linear polarizer angle
quarter_waveplate(azimuth=0.0)[source]

Generates an XY quarter wave plate.

Parameters:azimuth (float) – polarizer angle
rotate(angle, new_mask=False)[source]

Rotates the mask a certain angle.abs

Parameters:
  • angle (float) – rotation angle in radians
  • new_mask (bool) – if True generates a new mask
Returns:

Vector_paraxial_mask_XY

Return type:

if new_mask is True

to_py_pol()[source]

Pass mask to py_pol.jones_matrix

Returns:py_pol.jones_matrix
diffractio.vector_paraxial_masks_XY.rotation_matrix_Jones(angle)[source]

Creates an array of Jones 2x2 rotation matrices.

Parameters:angle (np.array) – array of angle of rotation, in radians.
Returns:2x2 matrix
Return type:numpy.array

4.1.22. diffractio.vector_paraxial_sources_XY module

This module generates Vector_paraxial_source_XY class for defining sources. Its parent is Vector_paraxial_field_XY.

The main atributes are:
  • x (numpy.array): linear array with equidistant positions. The number of data is preferibly 2**n.
  • y (numpy.array): linear array with equidistant positions. The number of data is preferibly 2**n.
  • wavelength (float): wavelength of the incident field
  • info (str): String with info about the simulation

The magnitude is related to microns: micron = 1.

Class for unidimensional scalar masks

Functions
  • plane_wave
  • azimuthal_wave
  • radial_wave
  • gauss_wave
  • hermite_gauss_wave
  • local_polarized_vector_wave
  • local_polarized_vector_wave_radial
  • local_polarized_vector_wave_hybrid
class diffractio.vector_paraxial_sources_XY.Vector_paraxial_source_XY(x, y, wavelength, info='')[source]

Bases: diffractio.vector_paraxial_fields_XY.Vector_paraxial_field_XY

Class for vectorial fields.

Parameters:
  • x (numpy.array) – linear array with equidistant positions. The number of data is preferibly 2**n.
  • y (numpy.array) – linear array with equidistant positions. The number of data is preferibly 2**n.
  • wavelength (float) – wavelength of the incident field
  • info (str) – String with info about the simulation
self.x

linear array with equidistant positions. The number of data is preferibly 2**n.

Type:numpy.array
self.y

linear array with equidistant positions. The number of data is preferibly 2**n.

Type:numpy.array
self.wavelength

wavelength of the incident field.

Type:float
self.Ex

Electric_x field

Type:numpy.array
self.Ey

Electric_y field

Type:numpy.array
azimuthal_inverse_wave(u=1, r0=(0.0, 0.0), radius=0.0)[source]

Provides a constant polarization to a scalar_source_xy

Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • r0 (float, float) – center of rotation
  • radius (float, float) – Radius of a circular mask
azimuthal_wave(u=1, r0=(0.0, 0.0), radius=0.0)[source]

Provides a constant polarization to a scalar_source_xy

Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • r0 (float, float) – center of rotation
  • radius (float, float) – Radius of a circular mask
constant_wave(u=1, v=(1, 0), has_normalization=False, radius=0.0)[source]

Provides a constant polarization to a scalar_source_xy

Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • v (float, float) – polarization vector
  • normalize (bool) – If True, normalize polarization vector
local_polarized_vector_wave(u=1, r0=(0.0, 0.0), m=1, fi0=0, radius=0.0)[source]

“local radial polarized vector wave.

Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • r0 (float, float) – r0 of beam
  • m (integer) – integer with order
  • fi0 (float) – initial phase
  • radius (float, float) – Radius of a circular mask

References

Qwien Zhan ‘Vectorial Optical Fields’ page 33

local_polarized_vector_wave_hybrid(u=1, r0=(0.0, 0.0), m=1, n=1, fi0=0, radius=(0, 0))[source]
local hibrid polarized vector wave.
Qwien Zhan ‘Vectorial Optial Fields’ page 36
Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • r0 (float, float) – center of beam
  • m (integer) – integer with order
  • n (integer) – integer with order
  • fi0 (float) – initial phase
  • radius (float, float) – Radius of a circular mask
local_polarized_vector_wave_radial(u=1, r0=(0.0, 0.0), m=1, fi0=0, radius=0.0)[source]

local radial polarized vector wave.

Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • r0 (float, float) – center of beam
  • m (integer) – integer with order
  • fi0 (float) – initial phase
  • radius (float, float) – Radius of a circular mask

References

Qwien Zhan ‘Vectorial Optial Fields’ page 36

mask_circle(r0=(0.0, 0.0), radius=0.0)[source]

Mask vector field using a circular mask.

Parameters:
  • r0 (float, float) – center of mask.
  • radius (float, float) – radius of mask
radial_inverse_wave(u=1, r0=(0.0, 0.0), radius=0.0)[source]

Provides a constant polarization to a scalar_source_xy

Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • r0 (float, float) – center of rotation
  • radius (float, float) – Radius of a circular mask
radial_wave(u=1, r0=(0.0, 0.0), radius=0.0)[source]

Provides a constant polarization to a scalar_source_xy

Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • r0 (float, float) – center of rotation
  • radius (float, float) – Radius of a circular mask
spiral_polarized_beam(u=1, r0=(0.0, 0.0), alpha=0, radius=(0, 0))[source]

Define spiral polarized beams:

Parameters:
  • u (Scalar_source_XY or np.complex) – field to apply the polarization or constant value
  • r0 (float, float) – center of radiality
  • radius (float) – mask for circle if radius >0.
  • alpha (float) – angle of spiral.
Reference:
  1. Ramirez-Sanchez, G. Piquero, and M. Santarsiero,“Generation and characterization of spirally polarized fields,” J. Opt. A11,085708 (2009)
to_py_pol()[source]

Pass Ex, Ey field to py_pol package for software analysis

diffractio.vector_paraxial_sources_XY.define_initial_field(EM, u=None)[source]

Defines the initial field EM = (Ex, Ey) in terms of u.

Parameters:
  • EM (vector_paraxial_source_XY) –
  • u (scalar_source_XY, or None, or 1) – if scalar_source it is written in Ex and Ey, is 1 Ex=1, Ey=1, if None, does nothing,

4.1.23. Module contents

Top-level package for Python Scalar and vector diffraction and interference.