From fad093909ee34327765705a0e600849594a24ddd Mon Sep 17 00:00:00 2001 From: mdecea Date: Thu, 15 Aug 2024 13:48:36 -0700 Subject: [PATCH] Fix repeated points --- .../path_length_analysis_from_gds.py | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/gplugins/path_length_analysis/path_length_analysis_from_gds.py b/gplugins/path_length_analysis/path_length_analysis_from_gds.py index 9293722a..3de64dd8 100644 --- a/gplugins/path_length_analysis/path_length_analysis_from_gds.py +++ b/gplugins/path_length_analysis/path_length_analysis_from_gds.py @@ -166,13 +166,24 @@ def centerline_single_poly_2_ports(poly, under_sampling, port_list) -> np.ndarra inds = np.argsort(outer_points[:, 0]) outer_points = outer_points[inds, :] - # Apply undersampling if necessary - inner_points = np.append( - inner_points[::under_sampling], np.array([inner_points[-1]]), axis=0 - ) - outer_points = np.append( - outer_points[::under_sampling], np.array([outer_points[-1]]), axis=0 - ) + # # (OLD, keep juts in case for now) Apply undersampling if necessary + # inner_points = np.append( + # inner_points[::under_sampling], np.array([inner_points[-1]]), axis=0 + # ) + # outer_points = np.append( + # outer_points[::under_sampling], np.array([outer_points[-1]]), axis=0 + # ) + + # Apply undersampling if necessary, and add the last point if it is not there + last_inner_pt = inner_points[-1] + inner_points = inner_points[::under_sampling] + if last_inner_pt not in inner_points: + inner_points = np.append(inner_points, np.array([last_inner_pt]), axis=0) + + last_outer_pt = outer_points[-1] + outer_points = outer_points[::under_sampling] + if last_outer_pt not in outer_points: + outer_points = np.append(outer_points, np.array([last_outer_pt]), axis=0) # There is a chance that the length of inner and outer is different # Interpolate if that's the case @@ -236,7 +247,7 @@ def centerline_single_poly_2_ports(poly, under_sampling, port_list) -> np.ndarra def extract_paths( component: gf.typings.Component | kf.Instance, - layer: gf.typings.LayerSpec = (1, 0), + layer: tuple[int, int] = (1, 0), plot: bool = False, filter_function: Callable = None, under_sampling: int = 1, @@ -298,14 +309,16 @@ def extract_paths( ) # Perform over-under to merge all physically connected polygons - polygons = component.get_polygons(layers=(layer,), by="tuple")[layer] + polygons = gf.functions.get_polygons(component, layers=(layer,), by="tuple")[layer] r = gf.kdb.Region(polygons) r = r.sized(0.05) r = r.sized(-0.05) simplified_component = gf.Component() simplified_component.add_polygon(r, layer=layer) - polys = simplified_component.get_polygons(merge=True, by="tuple")[layer] + polys = gf.functions.get_polygons(simplified_component, merge=True, by="tuple")[ + layer + ] paths = dict() @@ -507,7 +520,9 @@ def extract_paths( ev_paths[f"{port1};{port2}"] = gf.Path(evan_path) if plot: - points = simplified_component.get_polygons(merge=True, by="tuple")[layer] + points = gf.functions.get_polygons( + simplified_component, merge=True, by="tuple" + )[layer] plt.figure() for chunk in points: xs = [pt.x * 1e-3 for pt in chunk.each_point_hull()] @@ -648,10 +663,10 @@ def _demo_routes(): if __name__ == "__main__": # c0 = gf.components.bend_euler(npoints=20) # c0 = gf.components.bend_euler(cross_section="xs_sc", with_arc_floorplan=True) - # c0 = gf.components.bend_circular() + c0 = gf.components.bend_circular() # c0 = gf.components.bend_s(npoints=50) # c0 = gf.components.mmi2x2() - c0 = gf.components.coupler() + # c0 = gf.components.coupler() ev_coupling = True # c0 = _demo_routes() # ev_coupling = False @@ -668,7 +683,7 @@ def _demo_routes(): under_sampling=1, evanescent_coupling=ev_coupling, # consider_ports=["o2", "o3"], - port_positions=[(-10.0, -1.6), (30.0, -1.6)], + # port_positions=[(-10.0, -1.6), (30.0, -1.6)], ) r_and_l_dict = get_min_radius_and_length_path_dict(path_dict) for ports, (min_radius, length) in r_and_l_dict.items():