Ejemplo n.º 1
0
def test_load_gds():
    with open(os.path.join(TESTDATA, "rect.gds"), "rb") as fp:
        gds_file = gds.GDSImport(fp)
    polygons = gds_file.get_polygons((100, 0))

    assert len(polygons) == 1
    np.testing.assert_almost_equal(
        polygons[0], [[-1, 0.7], [-5, 0.7], [-5, 0.2], [-1, 0.2]])
Ejemplo n.º 2
0
def test_load_gds_diff_units():
    """Tests that loading GDS file with different units work.

    "rect_um.gds" is identical to "rect.gds" except for the fact that the
    precision changes from 1e-9 (nm) to 1e-6 (um) (the unit of the files
    are the same (both are um)). This means that the polygons should be 1000
    times larger than in "rect.gds".
    """
    with open(os.path.join(TESTDATA, "rect_um.gds"), "rb") as fp:
        gds_file = gds.GDSImport(fp)
    polygons = gds_file.get_polygons((100, 0))

    assert len(polygons) == 1
    np.testing.assert_almost_equal(
        polygons[0], [[-1000, 700], [-5000, 700], [-5000, 200], [-1000, 200]])
Ejemplo n.º 3
0
def _create_grid(eps_spec: optplan.EpsilonSpec,
                 edge_coords: fdfd_tools.EdgeCoords, wlen: float,
                 ext_dir: gridlock.Direction, filepath: str) -> gridlock.Grid:
    if eps_spec.type == "gds":
        # Make grid object.
        grid = gridlock.Grid(
            edge_coords,
            ext_dir=ext_dir,
            initial=_get_mat_index(eps_spec.mat_stack.background, wlen)**2,
            num_grids=3)

        # Draw layers.
        _draw_gds_on_grid(
            gds_stack=eps_spec.mat_stack.stack,
            grid=grid,
            gds_path=os.path.join(filepath, eps_spec.gds),
            wlen=wlen)

        # Make epsilon.
        grid.render()
    elif eps_spec.type == "gds_mesh":
        # Make grid object.
        grid = gridlock.Grid(
            edge_coords,
            ext_dir=ext_dir,
            initial=_get_mat_index(eps_spec.background, wlen)**2,
            num_grids=3)

        # Load GDS.
        with open(os.path.join(filepath, eps_spec.gds), "rb") as gds_file:
            gds = gdslib.GDSImport(gds_file)

        # Draw meshes.
        for mesh in eps_spec.mesh_list:
            _draw_mesh_on_grid(mesh, grid, gds, wlen)

        # Make epsilon.
        grid.render()
    else:
        raise NotImplementedError(
            "Epsilon spec not implemented for type {}".format(eps_spec.type))
    # Return epsilon and dxes.
    return grid
Ejemplo n.º 4
0
def _draw_gds_on_grid(gds_stack: List[optplan.GdsMaterialStackLayer],
                      grid: gridlock.Grid,
                      gds_path: str,
                      wlen: Optional[float] = None) -> None:
    """Draws onto a `Grid` based on a GDS file.

    Args:
        gds_stack: Stack element info on the layer, extent and refractive index.
        grid: Grid object to draw on.
        gds_path: Path of the gds.
        wlen: Wavelength required for index calculations.
    """

    # Load GDS.
    with open(gds_path, "rb") as gds_file:
        gds = gdslib.GDSImport(gds_file)

    # Draw layers
    for stack_element in gds_stack:
        layer = tuple(stack_element.gds_layer)
        polygons = gds.get_polygons(layer)
        extents = np.array(stack_element.extents)
        center = extents.mean()
        thickness = np.diff(extents)[0]
        polygon_center = np.zeros(3)
        polygon_center[grid.ext_dir] = center
        perm_bg = _get_mat_index(stack_element.background, wlen)**2
        perm_fg = _get_mat_index(stack_element.foreground, wlen)**2

        # Draw background
        grid.draw_slab(
            dir_slab=grid.ext_dir,
            center=center,
            thickness=thickness,
            eps=perm_bg)
        for polygon in polygons:
            polygon = np.around(polygon * NM_PER_UM)
            grid.draw_polygon(
                center=polygon_center,
                polygon=polygon,
                thickness=thickness,
                eps=perm_fg)
Ejemplo n.º 5
0
def test_no_valid_cell():
    with pytest.raises(ValueError, match="valid cell"):
        with open(os.path.join(TESTDATA, "tlc_test_gds3.gds"), "rb") as fp:
            gds_file = gds.GDSImport(fp)
Ejemplo n.º 6
0
def test_same_num_polygons_load():
    with pytest.raises(ValueError, match="same number"):
        with open(os.path.join(TESTDATA, "tlc_test_gds2.gds"), "rb") as fp:
            gds_file = gds.GDSImport(fp)
Ejemplo n.º 7
0
def test_name_not_found():
    with pytest.raises(ValueError, match="name not found"):
        with open(os.path.join(TESTDATA, "tlc_test_gds1.gds"), "rb") as fp:
            gds_file = gds.GDSImport(fp, "CELL3")
Ejemplo n.º 8
0
def test_named_cell_load():
    with open(os.path.join(TESTDATA, "tlc_test_gds1.gds"), "rb") as fp:
        gds_file = gds.GDSImport(fp, "CELL2")
    assert gds_file.top_level_cell.name == "CELL2"