eispy2d.utils package#

Submodules#

eispy2d.utils.draw module#

Geometric Shape Drawing Functions for Electromagnetic Inverse Scattering.

This module provides a comprehensive collection of functions for drawing various geometric shapes with specified electromagnetic properties. These functions are designed to create synthetic test objects for electromagnetic inverse scattering simulations and algorithm validation.

The module supports drawing both simple and complex shapes with customizable electromagnetic properties (relative permittivity and conductivity), positioning, rotation, and scaling. All shapes can be drawn on existing images or create new ones with specified resolution and background properties.

Key Features: - Support for both dielectric and conductive objects - Flexible positioning and rotation capabilities - Multiple drawing modes (new image or overlay on existing) - Consistent interface across all shape functions - Proper coordinate system handling with origin at image center - Rotation around object center with degree-based angles

Functions Overview: - Basic shapes: square, circle, ellipse, triangle, line, cross - Polygons: polygon, rhombus, trapezoid, parallelogram - Stars: star4, star5, star6 (4, 5, and 6-pointed stars) - Composite shapes: ring (annulus) - Random shapes: random (irregular polygon) - Patterns: wave, random_waves

Each function returns a tuple of (relative_permittivity, conductivity) arrays representing the electromagnetic properties of the created scene.

Coordinate System: - Origin (0, 0) is at the center of the image - X-axis points right, Y-axis points up - Angles are measured in degrees, counterclockwise from +X axis - Image coordinates use standard matrix indexing (row, column)

Examples

>>> import draw
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> # Create a simple dielectric square
>>> epsilon_r, sigma = draw.square(
...     side_length=0.5,
...     resolution=(64, 64),
...     object_rel_permittivity=2.0,
...     background_rel_permittivity=1.0
... )
>>> # Create a conducting circle
>>> epsilon_r, sigma = draw.circle(
...     radius=0.3,
...     resolution=(128, 128),
...     object_conductivity=1.0,
...     center=[0.1, -0.1],
...     rotate=45.0
... )
>>> # Overlay multiple objects
>>> epsilon_r, sigma = draw.square(
...     side_length=0.8,
...     resolution=(100, 100),
...     object_rel_permittivity=1.5
... )
>>> epsilon_r, sigma = draw.circle(
...     radius=0.2,
...     object_rel_permittivity=3.0,
...     rel_permittivity=epsilon_r,
...     conductivity=sigma
... )
>>> # Visualize results
>>> plt.figure(figsize=(10, 4))
>>> plt.subplot(1, 2, 1)
>>> plt.imshow(epsilon_r, cmap='jet', extent=[-1, 1, -1, 1])
>>> plt.title('Relative Permittivity')
>>> plt.colorbar()
>>> plt.subplot(1, 2, 2)
>>> plt.imshow(sigma, cmap='viridis', extent=[-1, 1, -1, 1])
>>> plt.title('Conductivity')
>>> plt.colorbar()
>>> plt.show()

Notes

All functions follow a consistent parameter naming convention: - Geometric parameters come first (size, dimensions) - Image parameters follow (axis_length_x, axis_length_y, resolution) - Background electromagnetic properties - Object electromagnetic properties - Positioning and rotation parameters - Optional existing image arrays for overlay operations

The functions handle input validation and provide appropriate error messages for missing required parameters. Either resolution or existing image arrays must be provided.

For wave-based patterns, the functions support both periodic and random wave generation with customizable amplitude and frequency characteristics.

eispy2d.utils.draw.circle(radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, center=[0.0, 0.0])#

Draw a circle.

Parameters:
  • radius (float) – Radius of the circle.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

eispy2d.utils.draw.cross(height, width, thickness, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, center=[0.0, 0.0], rotate=0.0, rel_permittivity=None, conductivity=None)#

Draw a cross.

Parameters:
  • height (float) – Parameters of the cross.

  • width (float) – Parameters of the cross.

  • thickness (float) – Parameters of the cross.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.ellipse(x_radius, y_radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, center=[0.0, 0.0], rotate=0.0)#

Draw an ellipse.

Parameters:
  • x_radius (float) – Ellipse radii in each axis.

  • y_radius (float) – Ellipse radii in each axis.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.isleft(x0, y0, x1, y1, x2, y2)#

Check if a point is left, on, or right of an infinite line.

The point to be tested is (x2, y2). The infinite line is defined by (x0, y0) -> (x1, y1).

Parameters:
  • x0 (float) – A point on the infinite line.

  • y0 (float) – A point on the infinite line.

  • x1 (float) – Another point on the infinite line.

  • y1 (float) – Another point on the infinite line.

  • x2 (float) – The point to be tested.

  • y2 (float) – The point to be tested.

Returns:

< 0 if point is on the left, = 0 if point is on the line, > 0 if point is on the right.

Return type:

float

References

eispy2d.utils.draw.line(length, thickness, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, center=[0.0, 0.0], rotate=0.0, rel_permittivity=None, conductivity=None)#

Draw a cross.

Parameters:
  • length (float) – Parameters of the line.

  • thickness (float) – Parameters of the line.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.parallelogram(length, height, inclination, center=[0.0, 0.0], rotate=0.0, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a paralellogram.

Parameters:
  • length (float) – Dimensions.

  • height (float) – Dimensions.

  • inclination (float) – In degrees.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default: None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.polygon(number_sides, radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, center=[0.0, 0.0], rotate=0.0, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a polygon with equal sides.

Parameters:
  • number_sides (int) – Number of sides.

  • radius (float) – Radius from the center to each vertex.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.random(number_sides, maximum_radius, minimum_radius=None, center=[0.0, 0.0], axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a random polygon.

Parameters:
  • number_sides (int) – Number of sides of the polygon.

  • maximum_radius (float) – Maximum radius from the origin to each vertex.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.random_gaussians(number_distributions, maximum_spread=0.8, minimum_spread=0.5, distance_from_border=0.1, resolution=None, surface_area=(1.0, 1.0), rel_permittivity_amplitude=0.0, conductivity_amplitude=0.0, axis_length_x=2.0, axis_length_y=2.0, background_conductivity=0.0, background_rel_permittivity=1.0, rel_permittivity=None, center=[0.0, 0.0], conductivity=None, rotate=0.0, edge_smoothing=0.03)#

Draw random Gaussian distributions with specified electromagnetic properties.

Parameters:
  • number_distributions (int) – Number of Gaussian distributions.

  • maximum_spread (float, default=0.8) – Maximum spread of Gaussian (proportional to area).

  • minimum_spread (float, default=0.5) – Minimum spread of Gaussian.

  • distance_from_border (float, default=0.1) – Minimum distance from border for distribution centers.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX).

  • surface_area (tuple, default=(1.0, 1.0)) – Proportion of image dimensions for distribution area.

  • rel_permittivity_amplitude (float, default=0.0) – Maximum amplitude of relative permittivity variation.

  • conductivity_amplitude (float, default=0.0) – Maximum amplitude of conductivity variation in S/m.

  • axis_length_x (float, default=2.0) – Physical length in x-direction.

  • axis_length_y (float, default=2.0) – Physical length in y-direction.

  • background_conductivity (float, default=0.0) – Background conductivity in S/m.

  • background_rel_permittivity (float, default=1.0) – Background relative permittivity.

  • rel_permittivity (numpy.ndarray, optional) – Existing permittivity array to overlay on.

  • center (list of float, default=[0.0, 0.0]) – Center position as [x, y] coordinates.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

  • rotate (float, default=0.0) – Rotation angle in degrees.

  • edge_smoothing (float, default=0.03) – Percentage of cells at boundary to smooth.

Returns:

(epsilon_r, sigma) arrays with the Gaussian distributions drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.draw.random_waves(number_waves, maximum_number_peaks, maximum_number_peaks_y=None, resolution=None, rel_permittivity_amplitude=0.0, conductivity_amplitude=0.0, axis_length_x=2.0, axis_length_y=2.0, background_rel_permittivity=1.0, background_conductivity=0.0, rel_permittivity=None, conductivity=None, wave_bounds_proportion=(1.0, 1.0), center=[0.0, 0.0], rotate=0.0, edge_smoothing=0.03)#

Draw random wave patterns with specified electromagnetic properties.

Parameters:
  • number_waves (int) – Number of wave components.

  • maximum_number_peaks (int) – Maximum number of peaks (controls smallest wavelength).

  • maximum_number_peaks_y (int, optional) – Maximum number of peaks in y-direction. If None, uses maximum_number_peaks.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX).

  • rel_permittivity_amplitude (float, default=0.0) – Maximum amplitude of relative permittivity variation.

  • conductivity_amplitude (float, default=0.0) – Maximum amplitude of conductivity variation in S/m.

  • axis_length_x (float, default=2.0) – Physical length in x-direction.

  • axis_length_y (float, default=2.0) – Physical length in y-direction.

  • background_rel_permittivity (float, default=1.0) – Background relative permittivity.

  • background_conductivity (float, default=0.0) – Background conductivity in S/m.

  • rel_permittivity (numpy.ndarray, optional) – Existing permittivity array to overlay on.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

  • wave_bounds_proportion (tuple, default=(1.0, 1.0)) – Proportion of image dimensions for wave area.

  • center (list of float, default=[0.0, 0.0]) – Center position as [x, y] coordinates.

  • rotate (float, default=0.0) – Rotation angle in degrees.

  • edge_smoothing (float, default=0.03) – Percentage of cells at boundary to smooth.

Returns:

(epsilon_r, sigma) arrays with the random wave pattern drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.draw.rhombus(x_radius, y_radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, center=[0.0, 0.0], rotate=0.0, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a rhombus.

Parameters:
  • x_radius (float) – Radii in each axis.

  • y_radius (float) – Radii in each axis.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default: None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.ring(inner_radius, outer_radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, center=[0.0, 0.0], background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a ring.

Parameters:
  • inner_radius (float) – Inner and outer radii of the ring.

  • outer_radius (float) – Inner and outer radii of the ring.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

eispy2d.utils.draw.square(side_length, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, center=[0.0, 0.0], rotate=0.0, rel_permittivity=None, conductivity=None)#

Draw a square with specified electromagnetic properties.

This function creates a square object with customizable electromagnetic properties, positioning, and rotation on a 2D grid. The square can be drawn on a new image or overlaid on existing permittivity and conductivity arrays.

Parameters:
  • side_length (float) – Length of the square’s side in the same units as axis_length_x/y.

  • axis_length_x (float, default=2.0) – Physical length of the image in the x-direction.

  • axis_length_y (float, default=2.0) – Physical length of the image in the y-direction.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX). Required if rel_permittivity and conductivity are not provided.

  • background_rel_permittivity (float, default=1.0) – Relative permittivity of the background medium.

  • background_conductivity (float, default=0.0) – Conductivity of the background medium in S/m.

  • object_rel_permittivity (float, default=1.0) – Relative permittivity of the square object.

  • object_conductivity (float, default=0.0) – Conductivity of the square object in S/m.

  • center (list of float, default=[0.0, 0.0]) – Center position of the square as [x, y] coordinates.

  • rotate (float, default=0.0) – Rotation angle in degrees (counterclockwise).

  • rel_permittivity (numpy.ndarray, optional) – Existing relative permittivity array to overlay on.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

Returns:

(epsilon_r, sigma) arrays with the square drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.draw.star4(radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, center=[0.0, 0.0], rotate=0.0)#

Draw a 4-point star.

Parameters:
  • radius (float) – Radius of the vertex from the center of the star.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default: None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.star5(radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, center=[0.0, 0.0], rotate=0.0)#

Draw a 5-point star.

Parameters:
  • radius (int) – Length from the center of the star to the main vertices.

  • maximum_radius (float) – Maximum radius from the origin to each vertex.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.star6(radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, rotate=0.0, center=[0.0, 0.0])#

Draw a six-pointed star (hexagram).

Parameters:
  • radius (float) – Length from the center to the maximum edge.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.trapezoid(upper_length, lower_length, height, axis_length_x=2.0, axis_length_y=2.0, resolution=None, center=[0.0, 0.0], rotate=0.0, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a trapezoid.

Parameters:
  • upper_length (float) – Dimensions.

  • lower_length (float) – Dimensions.

  • height (float) – Dimensions.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default: None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.draw.triangle(side_length, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, rotate=0.0, center=[0.0, 0.0])#

Draw an equilateral triangle with specified electromagnetic properties.

Parameters:
  • side_length (float) – Length of the triangle’s side.

  • axis_length_x (float, default=2.0) – Physical length of the image in the x-direction.

  • axis_length_y (float, default=2.0) – Physical length of the image in the y-direction.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX). Required if rel_permittivity and conductivity are not provided.

  • background_rel_permittivity (float, default=1.0) – Background relative permittivity.

  • background_conductivity (float, default=0.0) – Background conductivity in S/m.

  • object_rel_permittivity (float, default=1.0) – Triangle’s relative permittivity.

  • object_conductivity (float, default=0.0) – Triangle’s conductivity in S/m.

  • rel_permittivity (numpy.ndarray, optional) – Existing permittivity array to overlay on.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

  • rotate (float, default=0.0) – Rotation angle in degrees (counterclockwise).

  • center (list of float, default=[0.0, 0.0]) – Center position as [x, y] coordinates.

Returns:

(epsilon_r, sigma) arrays with the triangle drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.draw.wave(number_peaks, rel_permittivity_peak=1.0, conductivity_peak=0.0, rel_permittivity_valley=None, conductivity_valley=None, resolution=None, number_peaks_y=None, axis_length_x=2.0, axis_length_y=2.0, background_rel_permittivity=1.0, background_conductivity=0.0, rel_permittivity=None, conductivity=None, wave_bounds_proportion=(1.0, 1.0), center=[0.0, 0.0], rotate=0.0)#

Draw a wave pattern with specified electromagnetic properties.

Parameters:
  • number_peaks (int) – Number of peaks for both directions or for x-axis (if number_peaks_y is None).

  • rel_permittivity_peak (float, default=1.0) – Peak value of relative permittivity.

  • conductivity_peak (float, default=0.0) – Peak value of conductivity in S/m.

  • rel_permittivity_valley (float, optional) – Valley value of relative permittivity. If None, uses peak value.

  • conductivity_valley (float, optional) – Valley value of conductivity. If None, uses peak value.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX).

  • number_peaks_y (int, optional) – Number of peaks in y-direction. If None, uses number_peaks.

  • axis_length_x (float, default=2.0) – Physical length in x-direction.

  • axis_length_y (float, default=2.0) – Physical length in y-direction.

  • background_rel_permittivity (float, default=1.0) – Background relative permittivity.

  • background_conductivity (float, default=0.0) – Background conductivity in S/m.

  • rel_permittivity (numpy.ndarray, optional) – Existing permittivity array to overlay on.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

  • wave_bounds_proportion (tuple, default=(1.0, 1.0)) – Proportion of image dimensions for wave area.

  • center (list of float, default=[0.0, 0.0]) – Center position as [x, y] coordinates.

  • rotate (float, default=0.0) – Rotation angle in degrees.

Returns:

(epsilon_r, sigma) arrays with the wave pattern drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.draw.winding_number(x, y, xv, yv)#

Check if a point is within a polygon using the Winding Number Algorithm.

Parameters:
  • x (float) – The point to be tested.

  • y (float) – The point to be tested.

  • xv (numpy.ndarray) – 1D arrays with vertex coordinates of the polygon.

  • yv (numpy.ndarray) – 1D arrays with vertex coordinates of the polygon.

Returns:

True if the point is inside the polygon, False otherwise.

Return type:

bool

References

eispy2d.utils.statisticsutils module#

eispy2d.utils.statisticsutils.compare1sample(x, offset=0.0)#
eispy2d.utils.statisticsutils.compare2samples(x1, x2, paired=False)#
eispy2d.utils.statisticsutils.compare_multiple(data, all2all=False, all2one=None, paired=False)#
eispy2d.utils.statisticsutils.confint(data, alpha=0.05, alternative='two-sided')#
eispy2d.utils.statisticsutils.confintplot(data, axes=None, xlabel=None, ylabel=None, title=None, fontsize=10, confidence_level=0.95, xscale=None)#

Plot the confidence interval of means.

This routine plots a figure comparing the confidence interval of means among samples. The confidence intervals are computed at a 0.95 confidence level. This routine does not show any plot. It only draws the graphic.

Parameters:
  • data (either numpy.ndarray or list) – A 2-d array with the samples in which each column is a single sample or a list of 1-d arrays.

  • axes (matplotlib.Axes.axes, default: None) – A specified axes for plotting the graphics. If none is provided, then one will be created and returned.

  • title (str, default: None) – A possible title to the plot.

  • xlabel (str, default: None) – The label of the x-axis which represent the unit of the data.

  • ylabel (list of str, default: None) – A list with the name of the samples.

Returns:

fig : matplotlib.figure.Figure

Example

>>> import numpy as np
>>> from matplotlib import pyplot as plt
>>> y1 = np.random.normal(loc=2., size=30)
>>> y2 = np.random.normal(loc=4., size=60)
>>> y3 = np.random.normal(loc=6., size=10)
>>> confintplot([y1, y2, y3], title='Samples',
                ylabel=['Sample 1', 'Sample 2', 'Sample 3'])
>>> plt.show()
eispy2d.utils.statisticsutils.data_transformation(data, residuals_check=False, blocked=False)#

Try data transformation for normal distribution assumptions.

Currently, it only implements the Log and Square-Root transformations. The normality assumption may be tested on the data or in the residuals.

Parameters:
  • data (either numpy.ndarray or list) – If residuals is False, then the argument must be an 1-d array with the sample to be tested. Otherwise, it must be a list of arrays.

  • residuals (bool) – If True, the transformation will be tried over the residuals of the observations. Otherwise, the transformation will be tried over the own sample.

Returns:

If the transformation succeeds, then it returns the transformed data and a string containing the type of transformation. Otherwise, it returns None.

eispy2d.utils.statisticsutils.dunnetttest(y0, y)#

Perform all-to-one comparisons through Dunnett’s test.

The Dunnett’s test is a procedure for comparing a set of \(a-1\) treatments against a single one called the control group [1]_. The test is a modification of the usual t-test where, in each comparison, the null hypothesis is the equality of means. The significance level is fixed in 0.05.

Parameters:
  • y0 (numpy.ndarray) – Control sample (1-d array).

  • y (list or numpy.ndarray) – \(a-1\) treatments to be compared. The argument must be either a list of Numpy arrays or a matrix with shape (a-1, n).

Returns:

null_hypothesislist of bool

List of boolean values indicating the result of the null hypothesis. If True, it means that the test has failed in rejecting the null hypothesis. If False, then the null hypothesis of equality of means for the respective comparison has been reject at a 0.05 significance level.

References

eispy2d.utils.statisticsutils.factorial_analysis(data, alpha=0.05, group_names=None, ylabel=None)#

Perform factorial analysis.

Given a data set with some amount of factors and levels, the method performs the factorial analysis in order to find evidences for impact of single factors (main effects) and combination among them (interaction effects) [1]_.

In this current version, it only supports two or three factors and balanced data.

Parameters:
  • data (numpy.ndarray) – The data set in array format in which each dimension represents a factor and the number of elements represents the number of levels of respective factor. The shape must be either (a, b, n), for two-factors, or (a, b, c, n), for three factors. Obs.: the last dimension is the number of samples for each combination of factors-levels.

  • alpha (float, default: 0.05) – Significance level.

  • group_names (list, default: None) – Factor names for plot purposes.

  • ylabel (str) – Y-axis label for plot purposes (meaning of the data).

Returns:

null_hypothesislist

The list with the results of the null hypothesis of the statistic tests. If True, means that the test failed to reject the null hypothesis; if False, means the null hypothesis was rejected. For two-factor anaylsis, the each element represents the test on the following factors [A, B, AB]. For three-factor, [A, B, C, AB, AC, BC, ABC].

pvalueslist

The list with the p-values of each test. The order follows the same defined for null_hypothesis.

shapiro_pvalue: float

The p-value of the Shapiro-Wilk’s test for normality of residuals assumption. A p-value less than 0.05 means the rejection of the assumption.

fligner_pvalue: float

The p-value of the Fligner-Killen’s test for homoscedascity (variance equality) of samples. A p-value less than 0.05 means the rejection of the assumption.

figmatplotlib.figure.Figure

A plot showing the normality and homoscedascity assumption. The graphic way to anaylise the assumptions.

transformationNone or str

If None, no transformation was applied on the data in order to fix it for following the assumption. Otherwise, it is a string saying the type of transformation.

References

eispy2d.utils.statisticsutils.fittedcurve(x, a, b, c)#

Evaluate standard curve \(ax^b + c\) for Dunnett’s test fitting.

Parameters:
  • x (float) – Input value.

  • a (float) – Curve parameters.

  • b (float) – Curve parameters.

  • c (float) – Curve parameters.

Returns:

Evaluated curve value.

Return type:

float

eispy2d.utils.statisticsutils.homoscedasticityplot(data, axes=None, title=None, ylabel=None, names=None, legend_fontsize=None)#

Graphic investigation of homoscedasticity assumption.

This routine plots a figure comparing variance of samples for the purpose of investigating the assumption of homoscedasticity (samples with equal variance). Each samples is positioned in the x-axis in the correspondent value of its own mean. This routine does not show any plot. It only draws the graphic.

Parameters:
  • data (either numpy.ndarray or list) – A 2-d array with the samples in which each row is a single sample or a list of 1-d arrays.

  • axes (matplotlib.Axes.axes, default: None) – A specified axes for plotting the graphics. If none is provided, then one will be created and returned.

  • title (str, default: None) – A possible title to the plot.

  • ylabel (str, default: None) – The label of the y-axis which represent the unit of the data.

  • names (list of str, default: None) – A list with the name of the samples for legend purpose.

Returns:

fig : matplotlib.figure.Figure

Example

>>> import numpy as np
>>> from matplotlib import pyplot as plt
>>> y1 = np.random.normal(loc=2., size=30)
>>> y2 = np.random.normal(loc=4., size=60)
>>> homoscedasticityplot([y1, y2], title='Samples',
                         names=['Sample 1', 'Sample 2'])
>>> plt.show()
eispy2d.utils.statisticsutils.normalitiyplot(data, axes=None, title=None, fontsize=10)#

Graphic investigation of normality assumption.

This routine plots a figure comparing a sample to a standard normal distribution for the purpose of investigating the assumption of normality. This routine does not show any plot. It only draws the graphic.

Parameters:
  • data (numpy.ndarray) – An 1-d array representing the sample.

  • axes (matplotlib.Axes.axes, default: None) – A specified axes for plotting the graphics. If none is provided, then one will be created and returned.

  • title (str, default: None) – A possible title to the plot.

Returns:

fig : matplotlib.figure.Figure

Example

>>> import numpy as np
>>> from matplotlib import pyplot as plt
>>> y1 = np.random.normal(size=30)
>>> y2 = np.random.normal(size=60)
>>> fig = plt.figure()
>>> axes1 = fig.add_subplot(1, 2, 1)
>>> normalityplot(y1, axes=axes1, title='Sample 1')
>>> axes2 = fig.add_subplot(1, 2, 1)
>>> normalityplot(y2, axes=axes2, title='Sample 2')
>>> plt.show()
eispy2d.utils.statisticsutils.rcbd(data, alpha=0.05)#

Randomized Complete Block Design (RCBD) analysis.

Performs ANOVA for randomized complete block design.

Parameters:
  • data (numpy.ndarray or list) – 2D array where rows represent blocks and columns represent treatments.

  • alpha (float, default=0.05) – Significance level.

Returns:

  • F0 (float) – F-statistic.

  • pvalue (float) – P-value.

  • H0 (bool) – True if null hypothesis is not rejected.

eispy2d.utils.statisticsutils.residuals(data, blocked=False)#

Compute residuals for ANOVA analysis.

Parameters:
  • data (list of numpy.ndarray) – List of sample arrays.

  • blocked (bool, default=False) – Whether to use blocked design for residual calculation.

Returns:

Array of residuals.

Return type:

numpy.ndarray

eispy2d.utils.statisticsutils.ttest_ind_nonequalvar(y1, y2, alternative='two-sided', alpha=0.05)#

Perform T-Test on independent samples with non-equal variances.

Statistic test which compares two independent sample without assuming variance equality [1]_. The two-sided test is performed.

Parameters:
  • y1 (numpy.ndarray) – 1-d arrays representing the samples.

  • y2 (numpy.ndarray) – 1-d arrays representing the samples.

  • alpha (float, default: 0.05) – Significance level.

Returns:

null_hypothesisbool

Result of the null hypothesis test. If True, it means that the test has failed to reject the null hypothesis. If False, it means that the null hypothesis has been rejected at 1-alpha confidence level.

t0float

T statistic.

pvalue: float

nufloat

Degrees of freedom.

confinttuple of 2-float

Confidence interval (lower and upper bounds) of the true mean difference.

References

eispy2d.utils.statisticsutils.ttest_paired(y1, y2, alternative='two-sided', alpha=0.05)#

Perform paired t-test.

Parameters:
  • y1 (numpy.ndarray) – Paired samples.

  • y2 (numpy.ndarray) – Paired samples.

  • alternative ({'two-sided', 'less', 'greater'}, default='two-sided') – Alternative hypothesis.

  • alpha (float, default=0.05) – Significance level.

Returns:

  • t0 (float) – T-statistic.

  • H0 (bool) – True if null hypothesis is not rejected.

  • pvalue (float) – P-value.

  • confint (tuple) – Confidence interval.

eispy2d.utils.statisticsutils.violinplot(data, axes=None, labels=None, xlabel=None, ylabel=None, color='royalblue', yscale=None, title=None, show=False, file_name=None, file_path='', file_format='eps')#

Improved violinplot routine.

Obs: if no axes is provided, then a figure will be created and showed or saved.

Parameters:
  • data (list of numpy.ndarray) – A list of 1-d arrays meaning the samples.

  • axes (matplotlib.Axes.axes, default: None) – A specified axes for plotting the graphics. If none is provided, then one will be created and showed or saved.

  • labels (list of str, default: None) – Names of the samples.

  • xlabel (str, default: None)

  • ylabel (list of str, default: None)

  • color (str, default: 'b') – Color of boxes. Check some here

  • yscale (None or {'linear', 'log', 'symlog', 'logit', ...}) – Scale of y-axis. Check some options here <https:// matplotlib.org/3.1.1/api/_as_gen/ matplotlib.pyplot.yscale.html>

  • title (str, default: None) – A possible title to the plot.

  • show (bool) – If True, then the figure is shown. Otherwise, the figure is saved.

  • file_name (str) – File name when saving the figure.

  • file_path (str) – Path to the saved figure.

  • file_format ({'eps', 'png', 'pdf', 'svg'}) – Format of the saved figure.

Example

>>> import numpy as np
>>> from matplotlib import pyplot as plt
>>> y1 = np.random.normal(loc=2., size=30)
>>> y2 = np.random.normal(loc=4., size=60)
>>> y3 = np.random.normal(loc=6., size=10)
>>> violinplot([y1, y2, y3], title='Samples',
               labels=['Sample 1', 'Sample 2', 'Sample 3'],
               xlabel='Samples', ylabel='Unit', color='tab:blue',
               show=True)

eispy2d.utils.stopcriteria module#

class eispy2d.utils.stopcriteria.StopCriteria(max_evaluations=None, max_iterations=None, max_evals_woimp=None, max_iter_woimp=None, cost_function_threshold=None, improvement_threshold=None)#

Bases: object

__init__(max_evaluations=None, max_iterations=None, max_evals_woimp=None, max_iter_woimp=None, cost_function_threshold=None, improvement_threshold=None)#

Initialize stopping criteria for iterative algorithms.

Parameters:
  • max_evaluations (int, optional) – Maximum number of objective function evaluations.

  • max_iterations (int, optional) – Maximum number of iterations.

  • max_evals_woimp (int, optional) – Maximum number of evaluations without improvement.

  • max_iter_woimp (int, optional) – Maximum number of iterations without improvement.

  • cost_function_threshold (float, optional) – Threshold for the objective function value.

  • improvement_threshold (float, optional) – Minimum relative improvement (percentage) to be considered as improvement. Required if max_evals_woimp or max_iter_woimp is set.

Raises:
  • Error – If no stopping criterion is provided, or if improvement_threshold is missing when using improvement-based criteria.

  • MissingInputError – If improvement_threshold is missing when required.

__str__()#

Return string representation of the stopping criteria.

copy(new=None)#

Create a copy of the StopCriteria object.

Parameters:

new (StopCriteria, optional) – If provided, copies data into this object. If None, creates a new copy.

Returns:

New StopCriteria object if new=None, otherwise None.

Return type:

StopCriteria or None

reset_memory()#

Reset internal counters and stored values for stopping criteria.

stop(number_evaluations, number_iterations, current_best_evaluation)#

Check if any stopping criterion has been met.

Parameters:
  • number_evaluations (int) – Current number of objective function evaluations.

  • number_iterations (int) – Current number of iterations.

  • current_best_evaluation (float) – Current best objective function value.

Returns:

True if any stopping criterion is met, False otherwise.

Return type:

bool

Module contents#

Utilities module for eispy2d.

Collection of helper functions and classes: - draw: Geometric shape drawing for test generation - regularization: Regularization methods for ill-posed problems - stopcriteria: Convergence criteria for iterative algorithms - outputmode: Output aggregation for stochastic methods - statistics: Statistical tests and analysis tools - visualization: Plotting utilities for results

class eispy2d.utils.ConjugatedGradient(iterations)#

Bases: Regularization

__init__(iterations)#

Initialize Conjugated Gradient regularization.

Parameters:

iterations (int) – Number of iterations for the CG method.

solve(K, y)#

Solve the linear system using Conjugated Gradient method.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel) with shape (M, N).

  • y (numpy.ndarray) – Right-hand side vector or matrix with shape (M,) or (M, P).

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

The CG method solves the normal equations: \(K^*K x = K^*y\) using an iterative approach.

class eispy2d.utils.Landweber(iterations)#

Bases: Regularization

__init__(iterations)#

Initialize Landweber regularization.

Parameters:

iterations (int) – Number of iterations for the Landweber method.

solve(K, y)#

Solve the linear system using Landweber iteration.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel) with shape (M, N).

  • y (numpy.ndarray) – Right-hand side vector or matrix with shape (M,) or (M, P).

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

The Landweber iteration is given by:

\[x_{n+1} = x_n + a K^*(y - Kx_n)\]

where \(a = 1/\|K\|^2\).

class eispy2d.utils.LeastSquares(cutoff=None)#

Bases: Regularization

__init__(cutoff=None)#

Initialize Least Squares regularization with spectral cutoff.

Parameters:

cutoff (float, optional) – Cutoff threshold for singular values (rcond parameter). If None, uses default from numpy.linalg.lstsq.

solve(K, y)#

Solve the linear system using least squares with spectral cutoff.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel) with shape (M, N).

  • y (numpy.ndarray) – Right-hand side vector or matrix with shape (M,) or (M, P).

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

Uses numpy.linalg.lstsq with specified rcond cutoff for regularization by truncating small singular values.

class eispy2d.utils.Regularization#

Bases: ABC

abstractmethod solve(K, y)#
class eispy2d.utils.SingularValueDecomposition(tikhonov=0.0, cutoff=0.0)#

Bases: Regularization

__init__(tikhonov=0.0, cutoff=0.0)#

Initialize SVD-based regularization.

Parameters:
  • tikhonov (float, default: 0.0) – Tikhonov regularization parameter.

  • cutoff (float, default: 0.0) – Cutoff threshold for singular values.

solve(K=None, y=None, U=None, s=None, V=None)#

Solve the linear system using SVD-based regularization.

Parameters:
  • K (numpy.ndarray, optional) – Coefficient matrix (kernel) with shape (M, N). Required if U, s, V not provided.

  • y (numpy.ndarray, optional) – Right-hand side vector or matrix with shape (M,) or (M, P).

  • U (numpy.ndarray, optional) – Left singular vectors matrix from SVD.

  • s (numpy.ndarray, optional) – Singular values vector from SVD.

  • V (numpy.ndarray, optional) – Right singular vectors matrix from SVD.

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

The solution is computed using singular value decomposition:

\[x = \sum_{n} \frac{s_n}{s_n^2 + \alpha} (U_n^* y) V_n\]

where \(\alpha\) is the Tikhonov parameter and singular values below cutoff are truncated.

class eispy2d.utils.StopCriteria(max_evaluations=None, max_iterations=None, max_evals_woimp=None, max_iter_woimp=None, cost_function_threshold=None, improvement_threshold=None)#

Bases: object

__init__(max_evaluations=None, max_iterations=None, max_evals_woimp=None, max_iter_woimp=None, cost_function_threshold=None, improvement_threshold=None)#

Initialize stopping criteria for iterative algorithms.

Parameters:
  • max_evaluations (int, optional) – Maximum number of objective function evaluations.

  • max_iterations (int, optional) – Maximum number of iterations.

  • max_evals_woimp (int, optional) – Maximum number of evaluations without improvement.

  • max_iter_woimp (int, optional) – Maximum number of iterations without improvement.

  • cost_function_threshold (float, optional) – Threshold for the objective function value.

  • improvement_threshold (float, optional) – Minimum relative improvement (percentage) to be considered as improvement. Required if max_evals_woimp or max_iter_woimp is set.

Raises:
  • Error – If no stopping criterion is provided, or if improvement_threshold is missing when using improvement-based criteria.

  • MissingInputError – If improvement_threshold is missing when required.

__str__()#

Return string representation of the stopping criteria.

copy(new=None)#

Create a copy of the StopCriteria object.

Parameters:

new (StopCriteria, optional) – If provided, copies data into this object. If None, creates a new copy.

Returns:

New StopCriteria object if new=None, otherwise None.

Return type:

StopCriteria or None

reset_memory()#

Reset internal counters and stored values for stopping criteria.

stop(number_evaluations, number_iterations, current_best_evaluation)#

Check if any stopping criterion has been met.

Parameters:
  • number_evaluations (int) – Current number of objective function evaluations.

  • number_iterations (int) – Current number of iterations.

  • current_best_evaluation (float) – Current best objective function value.

Returns:

True if any stopping criterion is met, False otherwise.

Return type:

bool

class eispy2d.utils.Tikhonov(choice, parameter=None)#

Bases: Regularization

__init__(choice, parameter=None)#

Initialize Tikhonov regularization.

Parameters:
  • choice (int, float, or {'fixed', 'mozorov', 'lcurve'}) – Regularization parameter selection strategy: - If int or float: fixed regularization parameter value. - ‘fixed’: use a fixed parameter value (must provide parameter). - ‘mozorov’: use Morozov’s discrepancy principle. - ‘lcurve’: use L-curve criterion.

  • parameter (float, optional) – Fixed regularization parameter value (required if choice=’fixed’).

Raises:
solve(K, y)#

Solve the linear system using Tikhonov regularization.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel) with shape (M, N).

  • y (numpy.ndarray) – Right-hand side vector or matrix with shape (M,) or (M, P).

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

The solution is computed as: - For fixed parameter: \(x = (K^*K + \alpha I)^{-1}K^*y\) - For Morozov: automatically selects \(\alpha\) using discrepancy principle - For L-curve: automatically selects \(\alpha\) using L-curve criterion

eispy2d.utils.circle(radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, center=[0.0, 0.0])#

Draw a circle.

Parameters:
  • radius (float) – Radius of the circle.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

eispy2d.utils.compare1sample(x, offset=0.0)#
eispy2d.utils.compare2samples(x1, x2, paired=False)#
eispy2d.utils.compare_multiple(data, all2all=False, all2one=None, paired=False)#
eispy2d.utils.confint(data, alpha=0.05, alternative='two-sided')#
eispy2d.utils.confintplot(data, axes=None, xlabel=None, ylabel=None, title=None, fontsize=10, confidence_level=0.95, xscale=None)#

Plot the confidence interval of means.

This routine plots a figure comparing the confidence interval of means among samples. The confidence intervals are computed at a 0.95 confidence level. This routine does not show any plot. It only draws the graphic.

Parameters:
  • data (either numpy.ndarray or list) – A 2-d array with the samples in which each column is a single sample or a list of 1-d arrays.

  • axes (matplotlib.Axes.axes, default: None) – A specified axes for plotting the graphics. If none is provided, then one will be created and returned.

  • title (str, default: None) – A possible title to the plot.

  • xlabel (str, default: None) – The label of the x-axis which represent the unit of the data.

  • ylabel (list of str, default: None) – A list with the name of the samples.

Returns:

fig : matplotlib.figure.Figure

Example

>>> import numpy as np
>>> from matplotlib import pyplot as plt
>>> y1 = np.random.normal(loc=2., size=30)
>>> y2 = np.random.normal(loc=4., size=60)
>>> y3 = np.random.normal(loc=6., size=10)
>>> confintplot([y1, y2, y3], title='Samples',
                ylabel=['Sample 1', 'Sample 2', 'Sample 3'])
>>> plt.show()
eispy2d.utils.cross(height, width, thickness, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, center=[0.0, 0.0], rotate=0.0, rel_permittivity=None, conductivity=None)#

Draw a cross.

Parameters:
  • height (float) – Parameters of the cross.

  • width (float) – Parameters of the cross.

  • thickness (float) – Parameters of the cross.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.dunnetttest(y0, y)#

Perform all-to-one comparisons through Dunnett’s test.

The Dunnett’s test is a procedure for comparing a set of \(a-1\) treatments against a single one called the control group [1]_. The test is a modification of the usual t-test where, in each comparison, the null hypothesis is the equality of means. The significance level is fixed in 0.05.

Parameters:
  • y0 (numpy.ndarray) – Control sample (1-d array).

  • y (list or numpy.ndarray) – \(a-1\) treatments to be compared. The argument must be either a list of Numpy arrays or a matrix with shape (a-1, n).

Returns:

null_hypothesislist of bool

List of boolean values indicating the result of the null hypothesis. If True, it means that the test has failed in rejecting the null hypothesis. If False, then the null hypothesis of equality of means for the respective comparison has been reject at a 0.05 significance level.

References

eispy2d.utils.ellipse(x_radius, y_radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, center=[0.0, 0.0], rotate=0.0)#

Draw an ellipse.

Parameters:
  • x_radius (float) – Ellipse radii in each axis.

  • y_radius (float) – Ellipse radii in each axis.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.factorial_analysis(data, alpha=0.05, group_names=None, ylabel=None)#

Perform factorial analysis.

Given a data set with some amount of factors and levels, the method performs the factorial analysis in order to find evidences for impact of single factors (main effects) and combination among them (interaction effects) [1]_.

In this current version, it only supports two or three factors and balanced data.

Parameters:
  • data (numpy.ndarray) – The data set in array format in which each dimension represents a factor and the number of elements represents the number of levels of respective factor. The shape must be either (a, b, n), for two-factors, or (a, b, c, n), for three factors. Obs.: the last dimension is the number of samples for each combination of factors-levels.

  • alpha (float, default: 0.05) – Significance level.

  • group_names (list, default: None) – Factor names for plot purposes.

  • ylabel (str) – Y-axis label for plot purposes (meaning of the data).

Returns:

null_hypothesislist

The list with the results of the null hypothesis of the statistic tests. If True, means that the test failed to reject the null hypothesis; if False, means the null hypothesis was rejected. For two-factor anaylsis, the each element represents the test on the following factors [A, B, AB]. For three-factor, [A, B, C, AB, AC, BC, ABC].

pvalueslist

The list with the p-values of each test. The order follows the same defined for null_hypothesis.

shapiro_pvalue: float

The p-value of the Shapiro-Wilk’s test for normality of residuals assumption. A p-value less than 0.05 means the rejection of the assumption.

fligner_pvalue: float

The p-value of the Fligner-Killen’s test for homoscedascity (variance equality) of samples. A p-value less than 0.05 means the rejection of the assumption.

figmatplotlib.figure.Figure

A plot showing the normality and homoscedascity assumption. The graphic way to anaylise the assumptions.

transformationNone or str

If None, no transformation was applied on the data in order to fix it for following the assumption. Otherwise, it is a string saying the type of transformation.

References

eispy2d.utils.homoscedasticityplot(data, axes=None, title=None, ylabel=None, names=None, legend_fontsize=None)#

Graphic investigation of homoscedasticity assumption.

This routine plots a figure comparing variance of samples for the purpose of investigating the assumption of homoscedasticity (samples with equal variance). Each samples is positioned in the x-axis in the correspondent value of its own mean. This routine does not show any plot. It only draws the graphic.

Parameters:
  • data (either numpy.ndarray or list) – A 2-d array with the samples in which each row is a single sample or a list of 1-d arrays.

  • axes (matplotlib.Axes.axes, default: None) – A specified axes for plotting the graphics. If none is provided, then one will be created and returned.

  • title (str, default: None) – A possible title to the plot.

  • ylabel (str, default: None) – The label of the y-axis which represent the unit of the data.

  • names (list of str, default: None) – A list with the name of the samples for legend purpose.

Returns:

fig : matplotlib.figure.Figure

Example

>>> import numpy as np
>>> from matplotlib import pyplot as plt
>>> y1 = np.random.normal(loc=2., size=30)
>>> y2 = np.random.normal(loc=4., size=60)
>>> homoscedasticityplot([y1, y2], title='Samples',
                         names=['Sample 1', 'Sample 2'])
>>> plt.show()
eispy2d.utils.line(length, thickness, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, center=[0.0, 0.0], rotate=0.0, rel_permittivity=None, conductivity=None)#

Draw a cross.

Parameters:
  • length (float) – Parameters of the line.

  • thickness (float) – Parameters of the line.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.parallelogram(length, height, inclination, center=[0.0, 0.0], rotate=0.0, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a paralellogram.

Parameters:
  • length (float) – Dimensions.

  • height (float) – Dimensions.

  • inclination (float) – In degrees.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default: None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.polygon(number_sides, radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, center=[0.0, 0.0], rotate=0.0, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a polygon with equal sides.

Parameters:
  • number_sides (int) – Number of sides.

  • radius (float) – Radius from the center to each vertex.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.random(number_sides, maximum_radius, minimum_radius=None, center=[0.0, 0.0], axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a random polygon.

Parameters:
  • number_sides (int) – Number of sides of the polygon.

  • maximum_radius (float) – Maximum radius from the origin to each vertex.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.random_gaussians(number_distributions, maximum_spread=0.8, minimum_spread=0.5, distance_from_border=0.1, resolution=None, surface_area=(1.0, 1.0), rel_permittivity_amplitude=0.0, conductivity_amplitude=0.0, axis_length_x=2.0, axis_length_y=2.0, background_conductivity=0.0, background_rel_permittivity=1.0, rel_permittivity=None, center=[0.0, 0.0], conductivity=None, rotate=0.0, edge_smoothing=0.03)#

Draw random Gaussian distributions with specified electromagnetic properties.

Parameters:
  • number_distributions (int) – Number of Gaussian distributions.

  • maximum_spread (float, default=0.8) – Maximum spread of Gaussian (proportional to area).

  • minimum_spread (float, default=0.5) – Minimum spread of Gaussian.

  • distance_from_border (float, default=0.1) – Minimum distance from border for distribution centers.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX).

  • surface_area (tuple, default=(1.0, 1.0)) – Proportion of image dimensions for distribution area.

  • rel_permittivity_amplitude (float, default=0.0) – Maximum amplitude of relative permittivity variation.

  • conductivity_amplitude (float, default=0.0) – Maximum amplitude of conductivity variation in S/m.

  • axis_length_x (float, default=2.0) – Physical length in x-direction.

  • axis_length_y (float, default=2.0) – Physical length in y-direction.

  • background_conductivity (float, default=0.0) – Background conductivity in S/m.

  • background_rel_permittivity (float, default=1.0) – Background relative permittivity.

  • rel_permittivity (numpy.ndarray, optional) – Existing permittivity array to overlay on.

  • center (list of float, default=[0.0, 0.0]) – Center position as [x, y] coordinates.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

  • rotate (float, default=0.0) – Rotation angle in degrees.

  • edge_smoothing (float, default=0.03) – Percentage of cells at boundary to smooth.

Returns:

(epsilon_r, sigma) arrays with the Gaussian distributions drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.random_waves(number_waves, maximum_number_peaks, maximum_number_peaks_y=None, resolution=None, rel_permittivity_amplitude=0.0, conductivity_amplitude=0.0, axis_length_x=2.0, axis_length_y=2.0, background_rel_permittivity=1.0, background_conductivity=0.0, rel_permittivity=None, conductivity=None, wave_bounds_proportion=(1.0, 1.0), center=[0.0, 0.0], rotate=0.0, edge_smoothing=0.03)#

Draw random wave patterns with specified electromagnetic properties.

Parameters:
  • number_waves (int) – Number of wave components.

  • maximum_number_peaks (int) – Maximum number of peaks (controls smallest wavelength).

  • maximum_number_peaks_y (int, optional) – Maximum number of peaks in y-direction. If None, uses maximum_number_peaks.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX).

  • rel_permittivity_amplitude (float, default=0.0) – Maximum amplitude of relative permittivity variation.

  • conductivity_amplitude (float, default=0.0) – Maximum amplitude of conductivity variation in S/m.

  • axis_length_x (float, default=2.0) – Physical length in x-direction.

  • axis_length_y (float, default=2.0) – Physical length in y-direction.

  • background_rel_permittivity (float, default=1.0) – Background relative permittivity.

  • background_conductivity (float, default=0.0) – Background conductivity in S/m.

  • rel_permittivity (numpy.ndarray, optional) – Existing permittivity array to overlay on.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

  • wave_bounds_proportion (tuple, default=(1.0, 1.0)) – Proportion of image dimensions for wave area.

  • center (list of float, default=[0.0, 0.0]) – Center position as [x, y] coordinates.

  • rotate (float, default=0.0) – Rotation angle in degrees.

  • edge_smoothing (float, default=0.03) – Percentage of cells at boundary to smooth.

Returns:

(epsilon_r, sigma) arrays with the random wave pattern drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.rcbd(data, alpha=0.05)#

Randomized Complete Block Design (RCBD) analysis.

Performs ANOVA for randomized complete block design.

Parameters:
  • data (numpy.ndarray or list) – 2D array where rows represent blocks and columns represent treatments.

  • alpha (float, default=0.05) – Significance level.

Returns:

  • F0 (float) – F-statistic.

  • pvalue (float) – P-value.

  • H0 (bool) – True if null hypothesis is not rejected.

eispy2d.utils.rhombus(x_radius, y_radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, center=[0.0, 0.0], rotate=0.0, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a rhombus.

Parameters:
  • x_radius (float) – Radii in each axis.

  • y_radius (float) – Radii in each axis.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default: None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.ring(inner_radius, outer_radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, center=[0.0, 0.0], background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a ring.

Parameters:
  • inner_radius (float) – Inner and outer radii of the ring.

  • outer_radius (float) – Inner and outer radii of the ring.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

eispy2d.utils.square(side_length, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, center=[0.0, 0.0], rotate=0.0, rel_permittivity=None, conductivity=None)#

Draw a square with specified electromagnetic properties.

This function creates a square object with customizable electromagnetic properties, positioning, and rotation on a 2D grid. The square can be drawn on a new image or overlaid on existing permittivity and conductivity arrays.

Parameters:
  • side_length (float) – Length of the square’s side in the same units as axis_length_x/y.

  • axis_length_x (float, default=2.0) – Physical length of the image in the x-direction.

  • axis_length_y (float, default=2.0) – Physical length of the image in the y-direction.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX). Required if rel_permittivity and conductivity are not provided.

  • background_rel_permittivity (float, default=1.0) – Relative permittivity of the background medium.

  • background_conductivity (float, default=0.0) – Conductivity of the background medium in S/m.

  • object_rel_permittivity (float, default=1.0) – Relative permittivity of the square object.

  • object_conductivity (float, default=0.0) – Conductivity of the square object in S/m.

  • center (list of float, default=[0.0, 0.0]) – Center position of the square as [x, y] coordinates.

  • rotate (float, default=0.0) – Rotation angle in degrees (counterclockwise).

  • rel_permittivity (numpy.ndarray, optional) – Existing relative permittivity array to overlay on.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

Returns:

(epsilon_r, sigma) arrays with the square drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.star4(radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, center=[0.0, 0.0], rotate=0.0)#

Draw a 4-point star.

Parameters:
  • radius (float) – Radius of the vertex from the center of the star.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default: None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.star5(radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, center=[0.0, 0.0], rotate=0.0)#

Draw a 5-point star.

Parameters:
  • radius (int) – Length from the center of the star to the main vertices.

  • maximum_radius (float) – Maximum radius from the origin to each vertex.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.star6(radius, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, rotate=0.0, center=[0.0, 0.0])#

Draw a six-pointed star (hexagram).

Parameters:
  • radius (float) – Length from the center to the maximum edge.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.trapezoid(upper_length, lower_length, height, axis_length_x=2.0, axis_length_y=2.0, resolution=None, center=[0.0, 0.0], rotate=0.0, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None)#

Draw a trapezoid.

Parameters:
  • upper_length (float) – Dimensions.

  • lower_length (float) – Dimensions.

  • height (float) – Dimensions.

  • axis_length_x (float, default: 2.0) – Length of the size of the image.

  • axis_length_y (float, default: 2.0) – Length of the size of the image.

  • resolution (2-tuple) – Image resolution, in y and x directions, i.e., (NY, NX). Either this argument or rel_permittivity or conductivity must be given!

  • background_rel_permittivity (float, default: 1.0)

  • background_conductivity (float, default: 0.0)

  • object_rel_permittivity (float, default: 1.0)

  • object_conductivity (float, default: 0.0)

  • center (list, default: [0.0, 0.0]) – Center of the object in the image. The center of the image corresponds to the origin of the coordinates.

  • rel_permittivity (numpy.ndarray, default:None) – A predefined image in which the object will be drawn.

  • conductivity (numpy.ndarray, default: None) – A predefined image in which the object will be drawn.

  • rotate (float, default: 0.0 degrees) – Rotation of the object around its center. In degrees.

eispy2d.utils.triangle(side_length, axis_length_x=2.0, axis_length_y=2.0, resolution=None, background_rel_permittivity=1.0, background_conductivity=0.0, object_rel_permittivity=1.0, object_conductivity=0.0, rel_permittivity=None, conductivity=None, rotate=0.0, center=[0.0, 0.0])#

Draw an equilateral triangle with specified electromagnetic properties.

Parameters:
  • side_length (float) – Length of the triangle’s side.

  • axis_length_x (float, default=2.0) – Physical length of the image in the x-direction.

  • axis_length_y (float, default=2.0) – Physical length of the image in the y-direction.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX). Required if rel_permittivity and conductivity are not provided.

  • background_rel_permittivity (float, default=1.0) – Background relative permittivity.

  • background_conductivity (float, default=0.0) – Background conductivity in S/m.

  • object_rel_permittivity (float, default=1.0) – Triangle’s relative permittivity.

  • object_conductivity (float, default=0.0) – Triangle’s conductivity in S/m.

  • rel_permittivity (numpy.ndarray, optional) – Existing permittivity array to overlay on.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

  • rotate (float, default=0.0) – Rotation angle in degrees (counterclockwise).

  • center (list of float, default=[0.0, 0.0]) – Center position as [x, y] coordinates.

Returns:

(epsilon_r, sigma) arrays with the triangle drawn.

Return type:

tuple of numpy.ndarray

eispy2d.utils.wave(number_peaks, rel_permittivity_peak=1.0, conductivity_peak=0.0, rel_permittivity_valley=None, conductivity_valley=None, resolution=None, number_peaks_y=None, axis_length_x=2.0, axis_length_y=2.0, background_rel_permittivity=1.0, background_conductivity=0.0, rel_permittivity=None, conductivity=None, wave_bounds_proportion=(1.0, 1.0), center=[0.0, 0.0], rotate=0.0)#

Draw a wave pattern with specified electromagnetic properties.

Parameters:
  • number_peaks (int) – Number of peaks for both directions or for x-axis (if number_peaks_y is None).

  • rel_permittivity_peak (float, default=1.0) – Peak value of relative permittivity.

  • conductivity_peak (float, default=0.0) – Peak value of conductivity in S/m.

  • rel_permittivity_valley (float, optional) – Valley value of relative permittivity. If None, uses peak value.

  • conductivity_valley (float, optional) – Valley value of conductivity. If None, uses peak value.

  • resolution (tuple of int, optional) – Image resolution as (NY, NX).

  • number_peaks_y (int, optional) – Number of peaks in y-direction. If None, uses number_peaks.

  • axis_length_x (float, default=2.0) – Physical length in x-direction.

  • axis_length_y (float, default=2.0) – Physical length in y-direction.

  • background_rel_permittivity (float, default=1.0) – Background relative permittivity.

  • background_conductivity (float, default=0.0) – Background conductivity in S/m.

  • rel_permittivity (numpy.ndarray, optional) – Existing permittivity array to overlay on.

  • conductivity (numpy.ndarray, optional) – Existing conductivity array to overlay on.

  • wave_bounds_proportion (tuple, default=(1.0, 1.0)) – Proportion of image dimensions for wave area.

  • center (list of float, default=[0.0, 0.0]) – Center position as [x, y] coordinates.

  • rotate (float, default=0.0) – Rotation angle in degrees.

Returns:

(epsilon_r, sigma) arrays with the wave pattern drawn.

Return type:

tuple of numpy.ndarray