Skip to content

Commit

Permalink
Fix repeated points
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecea committed Aug 15, 2024
1 parent 8111544 commit fad0939
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions gplugins/path_length_analysis/path_length_analysis_from_gds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()]
Expand Down Expand Up @@ -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
Expand All @@ -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():
Expand Down

0 comments on commit fad0939

Please sign in to comment.