RectGrid#
- class acoular.grids.RectGrid
Bases:
GridProvides a 2D Cartesian grid for beamforming results.
This grid is composed of square or nearly square cells and lies on a plane perpendicular to the z-axis. It is defined by the lower and upper x- and y-limits and a constant z-coordinate.
- x_min
The lower x-limit that defines the grid. Default is
-1.
- x_max
The upper x-limit that defines the grid. Default is
1.
- y_min
The lower y-limit that defines the grid. Default is
-1.
- y_max
The upper y-limit that defines the grid. Default is
1.
- z
The constant z-coordinate of the grid plane. Default is
1.0.
- increment
The side length of each cell. Default is
0.1.
- nxsteps
Number of grid points along x-axis. (read-only)
- nysteps
Number of grid points along y-axis. (read-only)
- extent
The grid’s extension in
matplotlib.pyplot.imshowcompatible form. (read-only)
- digest
A unique identifier for the grid, based on its properties. (read-only)
- index(x, y)
Find the indices of a grid point near a given coordinate.
- indices(*r)
Find the indices of a subdomain in the grid.
Supports rectangular, circular, and polygonal subdomains.
- Parameters:
- Returns:
tupleA 2-tuple of indices or slices corresponding to the subdomain.
- export_gpos(filename)
Export the grid positions to an XML file.
This method generates an XML file containing the positions of all grid points. Each point is represented by a
<pos>element withName,x,y, andzattributes. The generated XML is formatted to match the structure required for importing into theImportGridclass.- Parameters:
- filename
str The path to the file to which the grid positions will be written. The file extension must be
.xml.
- filename
- Raises:
OSErrorIf the file cannot be written due to permissions issues or invalid file paths.
Notes
The file will be saved in UTF-8 encoding.
The
Nameattribute for each point is set as"Point {i+1}", whereiis the index of the grid point.If subgrids are defined, they will be included as the
subgridattribute.
Examples
Export a grid with 100 points to an XML file:
>>> import acoular as ac >>> import numpy as np >>> grid = ac.ImportGrid() >>> # Create some grid points >>> points = np.arange(9).reshape(3, 3) >>> grid.pos = points >>> grid.export_gpos('grid_points.xml')
The generated
grid_points.xmlfile will look like this:<?xml version="1.1" encoding="utf-8"?><Grid name="grid_points"> <pos Name="Point 1" x="0" y="1" z="2"/> <pos Name="Point 2" x="3" y="4" z="5"/> <pos Name="Point 3" x="6" y="7" z="8"/> </Grid>
- subdomain(sector)
Return the indices for a subdomain in the grid.
Allows arbitrary subdomains of type
Sector.- Parameters:
- sector
Sectorobject Sector describing the subdomain.
- sector
- Returns:
Notes
The
numpy.where()method is used to determine the the indices.
- size
The total number of grid points. This property is automatically calculated based on other defining attributes of the grid. (read-only)
- shape
The shape of the grid, represented as a tuple. Primarily useful for Cartesian grids. (read-only)