@@ -1994,6 +1994,53 @@ def generate_unit_locations(
19941994 distance_strict = False ,
19951995 seed = None ,
19961996):
1997+ """
1998+ Generate random 3D unit locations based on channel locations and distance constraints.
1999+
2000+ This function generates random 3D coordinates for a specified number of units,
2001+ ensuring the following:
2002+
2003+ 1) the x, y and z coordinates of the units are within a specified range:
2004+ * x and y coordinates are within the minimum and maximum x and y coordinates of the channel_locations
2005+ plus `margin_um`.
2006+ * z coordinates are within a specified range `(minimum_z, maximum_z)`
2007+ 2) the distance between any two units is greater than a specified minimum value
2008+
2009+ If the minimum distance constraint cannot be met within the allowed number of iterations,
2010+ the function can either raise an exception or issue a warning based on the `distance_strict` flag.
2011+
2012+ Parameters
2013+ ----------
2014+ num_units : int
2015+ Number of units to generate locations for.
2016+ channel_locations : numpy.ndarray
2017+ A 2D array of shape (num_channels, 2), where each row represents the (x, y) coordinates
2018+ of a channel.
2019+ margin_um : float, default 20.0
2020+ The margin to add around the minimum and maximum x and y channel coordinates when
2021+ generating unit locations
2022+ minimum_z : float, default 5.0
2023+ The minimum z-coordinate value for generated unit locations.
2024+ maximum_z : float, default 40.0
2025+ The maximum z-coordinate value for generated unit locations.
2026+ minimum_distance : float, default 20.0
2027+ The minimum allowable distance in micrometers between any two units
2028+ max_iteration : int, default 100
2029+ The maximum number of iterations to attempt generating unit locations that meet
2030+ the minimum distance constraint (default is 100).
2031+ distance_strict : bool, optionaldefault False
2032+ If True, the function will raise an exception if a solution meeting the distance
2033+ constraint cannot be found within the maximum number of iterations. If False, a warning
2034+ will be issued (default is False).
2035+ seed : int or None, optional
2036+ Random seed for reproducibility. If None, the seed is not set
2037+
2038+ Returns
2039+ -------
2040+ units_locations : numpy.ndarray
2041+ A 2D array of shape (num_units, 3), where each row represents the (x, y, z) coordinates
2042+ of a generated unit location.
2043+ """
19972044 rng = np .random .default_rng (seed = seed )
19982045 units_locations = np .zeros ((num_units , 3 ), dtype = "float32" )
19992046
0 commit comments