Obstacles¶
Support both computation and simulation of the reduction of critical area.
-
class
casex.obstacles.
Obstacles
(CA_width, CA_length, num_of_obstacles, trial_area_sidelength)[source]¶ This class has methods for computing the theoretical reduction in the size of the critical area when there are obstacles in the ground area as well as for simulating this reduction.
The theoretical reduction is based on the work [1].
Examples of how to MISSING DOC
-
num_of_obstacles
¶ Number of obstacles in the simulation.
- Type
int
-
trials_count
¶ Number of trials in the simulation.
- Type
int
-
CA_width
¶ [m] Width of critical area.
- Type
float
-
CA_length
¶ [m] Length of critical area.
- Type
float
-
intersected_obstacles
¶ List of all obstacles that have caused reduction in a CA.
- Type
List of Polygon
-
closest
¶ The point closest to the beginning of a CA for each reduced CA.
- Type
Point
-
CA_cut_off_coords
¶ Coordinates of CAs where they are cut off as a result of impact with an obstacle.
- Type
List of Point
-
obstacles_rtree
¶ Intermediate variables for increasing computations speed.
- Type
STRtree
-
CA_lengths
¶ List of the length of every CA after reduction
- Type
Array of floats
-
total_obstacle_area
¶ [m^2] The total area of all obstacles not considering any overlap (sum of the area of every obstacle).
- Type
float
-
total_coverage
¶ [m^2] The total area covered by obstacles. This means that overlapping areas are only counted once.
- Type
float
-
trial_area_sidelength
¶ [m] Length of each side of the square trial area.
- Type
float
-
obstacles
¶ A list of all obstacles in the simulation.
- Type
List of Polygon
-
CAs
¶ A list of all nominal CAs in the simulation (before potential reduction).
- Type
List of Polygon
-
CAs_reduced
¶ A list of all CAs after potential reduction.
- Type
List of Polygon
-
num_of_empty_CA
¶ The count of how many CAs have become empty in the simulation.
- Type
int
-
num_of_reduced_CA
¶ The count of how many CAs are reduced in the simulation.
- Type
int
-
class
DistributionParameters
(distribution_type: ‘DistributionType’, loc: float = 0.0, scale: float = 1.0)[source]¶
-
static
Minkowski_difference_convex_polygons
(A, B)[source]¶ Compute the polygon that is the Minkowski difference of two convex polygons A and B.
Compute the Minkowski difference of two convex polygons. This methods is based on the Minkowski sum for convex polygons, and it is therefore required that both input polygons are convex, otherwise the result is not correct.
The result is returned as a MultiPoint type.
- Parameters
A (Polygon) – The one polygon in the Minkowski difference.
B (Polygon) – The other polygon in the Minkowski difference.
- Returns
C – The result of the computation as a Multipoint (collection of points) and not a polygon.
- Return type
MultiPoint
-
static
Minkowski_sum_convex_polygons
(A, B)[source]¶ Compute the polygon that is the Minkowski sum of two convex polygons A and B.
This methods is based on convex hull for computing the Minkowski sum, and it is therefore required that both input polygons are convex, otherwise the result is not correct.
The result is returned as a MultiPoint type.
- Parameters
A (Polygon) – The one polygon in the Minkowski sum.
B (Polygon) – The other polygon in the Minkowski sum.
- Returns
C – The result of the computation as a Multipoint (collection of points) and not a polygon.
- Return type
MultiPoint
-
static
Minkowski_sum_convex_polygons_area
(w, x, a, b, theta1, theta2)[source]¶ Compute the area of the Minkowski sum of two rectangles polygons.
This is a fast method for computing the Minkowski sum of two polygons that are both rectangles.
For details on how this is done, see [1].
- Parameters
w (float) – Width of rectangle 1.
x (float) – Length of rectangle 1.
a (float) – Width of rectangle 2.
b (float) – Length of rectangle 2.
theta1 (float) – [deg] Angle of rectangle 1.
theta2 (float) – [deg] Angle of rectangle 2.
- Returns
area – Area of the Minkowski sum of the two rectangles.
- Return type
float
-
class
ObstaclesSizeProperties
(width_mu: float, width_sigma: float, length_mu: float, length_sigma: float)[source]¶
-
cdf
(x, obstacle_size_resolution=10, CA_orientation_resolution=10, obstacle_orientation_resolution=10, probability_threshold=0.0044318484119380075, show_progress=False)[source]¶ Compute the CDF for the length of the critical area when rectangular obstacles are present.
This is the CDF for the length of the critical area when there are a given obstacle density of rectangular obstacles with dimension given by normal distributions. To draw the full CDF, a typical input for x is an array ranging in value from 0 to the nominal length of the CA. Since this is usually a rather smooth curve, it can be approximated well by relatively few x values (typically 10 or 15).
The resolution should not be lower than
Note that this function relies on a previous call to generate_rectangular_obstacles_normal_distributed().
For a more detailed explanation of the CDF, see [1].
- Parameters
x (float array) – [m] The length of the critical area for which the CDF is computed. This can be a scalar or an array.
obstacle_size_resolution (int (default is 10)) – The number of points for the discretization of the two integrals for width and length of obstacles. A good starting value is 10. For high resolution, 20 is an approprite choice.
CA_orientation_resolution (int (default is 10)) – The number of points for the discretization of integral for CA orientation. A good starting value is 10. For high resolution, 20 is an approprite choice.
obstacle_orientation_resoltion (int (default is 10)) – The number of points for the discretization of the integral over the obstacle orientation. The value depends highly on the chosen distribution. If the orientation type is FIXED, this value is not used, as the integral does not need to be evaluated.
probability_threshold (float (default is PDF for normal distribution evaluated at 3 sigma, approx 0.0044)) – This value is used to speed up computation of the integrals. For any probability below this threshold, the contribution to the integrals is ignored. To include all values, set this to zero. Adjusting this value will affect the sanity checking, so if it becomes too large (i.e., too much of the integral contributions are ignored), a warning will be issued.
show_progress (bool (default False)) – Write the progress in percent to the prompt for the multple integral computation.
- Returns
p_x (float array) – The CDF value for the given x. This return parameter has the same type as input x.
expected_value (float) – [m] The expected value of the length.
beta (float) – The beta values as computed in [1].
acc_probability_check (float) – A sanity check on the triple integral. This values should be relatively close to 1, especially for high value of pdf_resolution.
pdf_width (np.array) – The PDF for the obstacle width as used in the integral.
pdf_length (np.array) – The PDF for the obstacle length as used in the integral.
pdf_CA_orientation (np.array) – The PDF for the CA orientation as used in the integral.
-
compute_CA_lengths
()[source]¶ Make a list of the actual lengths of the CAs.
- Parameters
None –
- Returns
- Return type
None
-
compute_coverage
(show_progress=False)[source]¶ Determine total obstacle coverage.
- Returns
- Return type
None
-
compute_reduced_CAs
(show_progress=False)[source]¶ Compute the reduction for each CA
Any CA that intersects with an obstacles is reduced such as to no longer intersect with any obstacles. This method runs through all CAs and all obstacles and produces a list of CAs that.
- Returns
- Return type
None
-
generate_CAs
(trials_count)[source]¶ Generate a number of critical areas for simulation.
A number of critical areas are generated with 2D uniformly distributed location and uniformly distributed orientation between 0 and 360 degrees. They are have the width and length as set at initialization of the class.
- Parameters
trials_count (int) – Number of trials to perform.
- Returns
- Return type
None
-
generate_rectangular_obstacles_along_curves
(width_mu, width_sigma, length_mu, length_sigma, houses_along_street, rows_of_houses, distance_between_two_houses)[source]¶ Generate a set of obstacles that follows a curve.
Rectangular obstacles are generated so that they follow a vertical curve and located in parts. This is to simulate houses along a road. The size and density of houses can be adjusted.
An area larger than the trial area is covered with obstacles, but only the ones inside the trial area are preserved. The number of obstacles is set to the number of obstacles preserved.
- Parameters
width_mu (float) – [m] The mean of the normal distribution of the width of the obstacles.
width_sigma (float) – The standard deviation of the normal distribution of the width of the obstacles.
length_mu (float) – [m] The mean of the normal distribution of the length of the obstacles.
length_sigma (float) – The standard deviation of the normal distribution of the length of the obstacles.
houses_along_street (float) – The number of houses along the road (22 is a good starting number).
rows_of_houses (float) – The number of rows of houses (12 is a good starting number).
distance_between_two_houses (float) – [m] The distance between two houses that make up the pair of houses that shares a common border, but are on two different streets (20 m is a good starting number).
- Returns
- Return type
None
-
generate_rectangular_obstacles_normal_distributed
(width_mu, width_sigma, length_mu, length_sigma)[source]¶ Generate a set of uniformly distributed rectangular obstacles.
This method generates a number of rectangular obstacles which a co-linear with the axes, and with width and length varying according to normal distributions with the mean and standard deviation as given by input parameters. The position of the obstacles are uniformly distributed in 2D in the trial area.
- Parameters
width_mu (float) – The mean of the normal distribution of the width of the obstacles.
width_sigma (float) – The standard deviation of the normal distribution of the width of the obstacles.
length_mu (float) – The mean of the normal distribution of the length of the obstacles.
length_sigma (float) – The standard deviation of the normal distribution of the length of the obstacles.
- Returns
- Return type
None
-
static
mirror_polygon_in_origin
(polygon)[source]¶ Compute the mirror of a polygon by negative all corner coordinates.
- Parameters
polygon (Polygon) – A polygon to be mirrored.
- Returns
m – A polygon that is the mirror of the original polygon
- Return type
Polygon
-
missed_obstacle_CA_intersections
()[source]¶ Identifies missed intersections metween obstacle and reduced CA.
In the simulation, it may happen that a critical areas is reduced, and the part of the critical area that has been reduced away intersects another obstacle that the one causing the reduction. If this overlap is such that the nominal critica area is not completely separated in two (i.e., the obstacle has a corner inside the CA without going all the way through), the overlapping area will not contribute correctly to the simulation results.
This is a rare event, and is therefore ignore. To visualize these problematic overlaps, this function provide a list of the affect obstacles and CAs, plus compute the area missed in the simulation.
- Returns
intersection area (MISSING DOC) – MISSING DOC
problematic obstacles (MISSING DOC) – MISSING DOC
problematic CAs (MISSING DOC) – MISSING DOC
-
static
set_limits
(ax, x0, xN, y0, yN, step=1)[source]¶ Set the axes limits for a axis in a plot.
- Parameters
ax (Handle MISSING DOC) – MISSING DOC
x0 (float) – MISSING DOC
xN (float) – MISSING DOC
y0 (float) – MISSING DOC
yN (float) – MISSING DOC
step (int, optional) – MISSING DOC
- Returns
- Return type
None
-
show_CDF
(ax, show_CA_as_size=True, line_label=None, line_color='blue', line_width=3)[source]¶ Plots the CDF
Plots a histogram of simulation results to the provided axis.
- Parameters
ax (handle) – Handle to the plotting axis.
show_CA_as_size (bool (default is True)) – If True, show the first axis as size of CA. If False, show the first axis as CA length (i.e., CA size divided by width).
line_label (text (default is None)) – If None, a label text is generated. If not None, the provided text is used for label text.
line_color (color (default is 'blue')) – Color of CDF graph (passed directly to plot).
line_width (float (default 3)) – Width of CDF graph (passed directly to plot).
- Returns
- Return type
None
-
show_simulation
(ax, problematic_obstacles=None, problematic_CAs=None, show_CAs=True, show_CA_first_point=False, show_CAs_reduced=True, show_obstacles=True, show_obstacles_intersected=True, show_debug_points=False)[source]¶ Visualize simulation with obstacles and critical areas.
This functions makes it easy to visualize the result of simulations. It will show the simulated square area with obstacles (possible showing which are impacted and which are not), critical areas (both which are “full” and which have been reduced).
It can also show a list of problematic obstacles and critical areas. For more details on what that is and how to detect them, see the help for sanity_check().
- Parameters
ax (axis to plot in) – Handle to the plot axis
problematic_obstacles (list of polygon (default None)) – Show the provided problematic obstacles (in yellow).
problematic_CAs (list of polygon (default None)) – Show the provided problematic CAs (in yellow).
show_CAs (bool (default True)) – Show the nominal critical areas.
show_CA_first_point (bool (default False)) – Show a point at the starting end of each CA.
show_CAs_reduced (bool (default True)) – Show the reduced critical areas.
show_obstacles (bool (default True)) – Show all obstacles (in green).
show_obstacles_intersected (bool (default True)) – Show the obstacles intersected by critical areas (in orange instead of green).
show_debug_points (bool (default False)) – Show debug points on the CAs to help verify that intersections and polygonal reduction is corrected. Typically only used for debugging.
- Returns
- Return type
None
-
singleton_objects_CDF
(x)[source]¶ CDF for singleton objects.
This implements equation (15) in the paper. MISSING DOCS
Note that this function requires objects to have been specified first.
- Parameters
x (float, scalar or np.array) – The length of the CA, typically starting from 0 to the full length (nominel CA size divded by width)
- Returns
- Return type
CDF with same number of samples as input x (but always as np.array)
-