producer.collisions module

Functions used to handle aperture collisions.

producer.collisions.remove_collisions(x, y, collision, maxgrp=18, plot=False)[source]

Remove “collisions” in a set of Cartesian coordinates.

Two coordinates collide if they are closer than the provided minimum distance.

The algorithm builds friends-of-friends groupings with a linking length set to the collision distance, and then determines the maximum number of group members that are all separated by at least the collision distance.

Iteration through all combinations of group members quickly becomes intractable for large groups; for a group of size \(n\), the total number of combinations is :math:2^n`. The maxgroup parameter sets the maximum size allowed for iterating through all possible combinations. Groups larger than this value are recursively “thinned” until its members are no greater than maxgrp. This thinning process can be very expensive for large groups. For fields that are dense relative to the collision distance, first consider iteratively running this function by starting with a relatively small collision distance and gradually increasing it to the desired value.

Parameters
  • x (numpy.ndarray) – Cartesian x coordinates

  • y (numpy.ndarray) – Cartesian y coordinates

  • collision (float) – The minimum distance to impose between coordinates.

  • maxgrp (int, optional) – The maximum size of a friends-of-friends group for which to iterate through all possible combinations to find the largest set of uncollided coordinates. See the function description.

  • plot (bool, optional) – Show a plot of the result.

Returns

The function returns the numpy.ndarray (array of integer arrays) with the friends-of-friends groups (each group is set by an integer array providing the indices of the coordinate members) and a numpy.ndarray with the indices of the uncollided coordinates.

Return type

tuple

producer.collisions.remove_collisions_plot(x, y, keep, collision, groups=None)[source]

Diagnostic plot for the results of remove_collisions().

Parameters
  • x (numpy.ndarray) – Cartesian x coordinates

  • y (numpy.ndarray) – Cartesian x coordinates

  • keep (numpy.ndarray) – Boolean array selecting the cartesian coordinates that do not collide.

  • collision (float) – The collision distance.

  • groups (array-like, optional) – The list of friends-of-friends groups constructed by remove_collisions().