utils#

Utility classes intended for internal use in Acoular.

get_file_basename(file[, alternative_basename])

Return the basename of the file.

find_basename(source[, alternative_basename])

Return the basename of the original source.

mole_fraction_of_water_vapor(h, t[, p])

Mole fraction of water vapor in the air for real gases.

Polygon(x, y)

Create an object representing a general polygon in a 2D plane.

class acoular.tools.utils.Polygon(x, y)#

Bases: object

Create an object representing a general polygon in a 2D plane.

This class allows defining a polygon by specifying the coordinates of its vertices and provides methods for checking whether a set of points lies inside the polygon, or if a point is closer to a side or vertex of the polygon.

Parameters:
xarray_like

Array of x-coordinates of the vertices that define the polygon. These coordinates should form a closed shape (i.e., the last point should be the same as the first point).

yarray_like

Array of y-coordinates of the vertices that define the polygon. These coordinates should correspond to the x-coordinates, forming a closed shape.

Attributes:
xnumpy.ndarray

Array of x-coordinates of the polygon vertices.

ynumpy.ndarray

Array of y-coordinates of the polygon vertices.

is_inside(xpoint, ypoint, smalld=1e-12)#

Check if a point or set of points are inside the polygon.

Parameters:
xpointfloat or array_like

Array of x-coordinates of the points to be tested.

ypointfloat or array_like

Array of y-coordinates of the points to be tested.

smalldfloat, optional

Tolerance used for floating point comparisons when checking if a point is exactly on a polygon’s edge. The default value is 1e-12.

Returns:
float or array_like

The distance from the point to the nearest point on the polygon. The values returned have the following meanings: - mindst < 0: Point is outside the polygon. - mindst = 0: Point is on an edge of the polygon. - mindst > 0: Point is inside the polygon.

Notes

The method uses an improved algorithm based on Nordbeck and Rydstedt for determining whether a point is inside a polygon [16].

acoular.tools.utils.get_file_basename(file, alternative_basename='void')#

Return the basename of the file.

Parameters:
filestr

File path.

Returns:
str

Basename of the file.

acoular.tools.utils.find_basename(source, alternative_basename='void')#

Return the basename of the original source.

Traverses the source chain of the object and returns the basename of the original source. If the source object does not have a basename, uses the alternative basename.

Parameters:
sourceinstance

Generator derived object

alternative_basenamestr

Alternative basename to use if the source object does not have a basename.

Returns:
str

Basename of the original source.

acoular.tools.utils.mole_fraction_of_water_vapor(h, t, p=101325)#

Mole fraction of water vapor in the air for real gases.

Calculates the mole fraction of water vapor in air from the relative humidity, based on the equations provided in the appendix of [21] and the enhancement factors from [22].

Parameters:
hfloat

Relative humidity as a fraction [0,1].

tfloat

Thermodynamic temperature in K.

pfloat

Atmospheric pressure in Pa (default is the standard pressure 101325 Pa).

Returns:
float

Mole fraction of water vapor.

Notes

The mole fraction is calculated as:

\[x_w = h \cdot f \cdot \frac{p_{sv}}{p},\]
where:
  • \(h\) is the relative humidity as a fraction [0,1].

  • \(f\) is the enhancement factor:

    \[f = 1.00062 + 3.14 \times 10^{-8} \cdot p + 5.6 \times 10^{-7} \cdot t^2.\]
  • \(p_{sv}\) is the saturation vapor pressure of water vapor in air:

    \[p_{sv} = \exp(A \cdot t^2 + B \cdot t + C + \frac{D}{t}),\]

    with the updated coefficients from [22]:

    \[\begin{split}A = 1.2378847 \times 10^{-5}, \\ B = -1.9121316 \times 10^{-2}, \\ C = 33.93711047, \\ D = -6.3431645 \times 10^3.\end{split}\]