You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-currently: trying to improve code performance based on practical profiling results
-voronoi_region_vertices_spherical_surface() function has been reverted to the pre-vectorization state (after all that work!) because it surprisingly performs better with all the Python for loops (in practical testing) -- it was worth a shot...
'''Calculate the surface area of a polygon on the surface of a sphere. Based on equation provided here: http://mathworld.wolfram.com/SphericalPolygon.html'''
array_ordered_Voronoi_polygon_vertices=filter_polygon_vertex_coordinates_for_extreme_proximity(array_ordered_Voronoi_polygon_vertices,sphere_radius) #filter vertices for extreme proximity
128
129
#theta = calculate_and_sum_up_inner_sphere_surface_angles_Voronoi_polygon(array_ordered_Voronoi_polygon_vertices,sphere_radius) #suppressing this calculation while I test the pure-planar SA calculation approach
'''Returns a dictionary with the sorted (non-intersecting) polygon vertices for the Voronoi regions associated with each generator (original data point) index. A dictionary entry would be structured as follows: `{generator_index : array_polygon_vertices, ...}`. Now modifying the function to return a numpy array of indices instead -- to improve performance, reduce memory usage, etc.'''
392
+
'''Returns a dictionary with the sorted (non-intersecting) polygon vertices for the Voronoi regions associated with each generator (original data point) index. A dictionary entry would be structured as follows: `{generator_index : array_polygon_vertices, ...}`.'''
assertfacet_coordinate_array_Delaunay_triangulation.shape[0] ==array_Voronoi_vertices.shape[0], "The number of Delaunay triangles should match the number of Voronoi vertices."
397
401
#now, the tricky part--building up a useful Voronoi polygon data structure
398
-
#testing new code idea -- directly grab the Voronoi indices closest to each generator
399
-
distance_matrix_generators_to_Voronoi_vertices=scipy.spatial.distance.cdist(self.original_point_array,array_Voronoi_vertices) #too many decimals causes problems in practical test cases
400
-
#distance_matrix_generators_to_Voronoi_vertices = numpy.around(distance_matrix_generators_to_Voronoi_vertices,decimals=3) #too many decimals causes problems in practical test cases
401
-
#each Voronoi vertex (column in above distance matrix) should have >= 3 minimum distance values relative to the generators (rows) for which it is a Voronoi cell vertex
402
-
#so, I want access to the row and column index information for the columnwise minima (then all flagged values for a given row form the set of Voronoi vertices for that generator)
#distance_matrix_indices_for_columnar_minima = numpy.where(distance_matrix_generators_to_Voronoi_vertices.T == minimum_distances_generators_to_Voronoi_vertices)[::-1] #a bit tricky to get columnar indices and then use back on original distance matrix
405
-
distance_matrix_indices_for_columnar_minima=numpy.where(abs(distance_matrix_generators_to_Voronoi_vertices.T-minimum_distances_generators_to_Voronoi_vertices) <0.001)[::-1] #a bit tricky to get columnar indices and then use back on original distance matrix
#now, each row of the above distance array corresponds to a single Voronoi vertex, which each column of that row representing the distance to the respective generator point
406
+
#if we iterate through each of the rows and determine the indices of the minimum distances, we obtain the indices of the generators for which that voronoi vertex is a polygon vertex
407
+
generator_Voronoi_region_dictionary= {} #store the indices of the generators for which a given Voronoi vertex is also a polygon vertex
assertindices_of_generators_for_which_this_Voronoi_point_is_a_polygon_vertex.size>=3, "By definition, a Voronoi vertex must be equidistant to at least 3 generators, but in this case only got {num_gens} generators for Voronoi vertex at {coords}, which has 5 closest distances: {distances}.".format(num_gens=indices_of_generators_for_which_this_Voronoi_point_is_a_polygon_vertex.size,coords=array_Voronoi_vertices[Voronoi_point_index],distances=numpy.sort(Voronoi_point_distance_array)[0:5])
414
+
generator_Voronoi_region_dictionary[Voronoi_point_index] =indices_of_generators_for_which_this_Voronoi_point_is_a_polygon_vertex#so dictionary looks like 0: array(12,17,27), ...
415
+
416
+
#now, go through the above dictionary and collect the Voronoi point indices forming the polygon for each generator index
polygon_hull_object=scipy.spatial.ConvexHull(current_array_Voronoi_vertices[...,:2]) #trying to project to 2D for edge ordering, and then restore to 3D after
assertcurrent_Voronoi_polygon_surface_area_on_sphere>0, "Obtained a surface area of zero for a Voronoi region [Actual value = {actual_value}; polygon_vertices = {polygon_vertices}].".format(actual_value=current_Voronoi_polygon_surface_area_on_sphere,polygon_vertices=Voronoi_polygon_sorted_vertex_array)
447
+
assertcurrent_Voronoi_polygon_surface_area_on_sphere>0, "Obtained a surface area of zero for a Voronoi region."
0 commit comments