Skip to content
Merged

Gds #69

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions PR.json

This file was deleted.

59 changes: 0 additions & 59 deletions Untitled.ipynb

This file was deleted.

16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ h5py
rich
nlopt
matplotlib

# required to get xarray to not complain
dask

# required for running tidy3d, may try to remove later
shapely
descartes
pydantic
PyYAML

# may add later
shapely
# required to get xarray to not complain
dask

# required for code quality checking
black
Expand All @@ -31,4 +28,7 @@ nbsphinx
ipython
autodoc_pydantic
sphinx-copybutton
m2r2
m2r2

# required for web
boto3
65 changes: 65 additions & 0 deletions tidy3d/components/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .types import Literal, Bound, Size, Coordinate, Axis, Coordinate2D
from .types import Vertices, Ax, Shapely
from .viz import add_ax_if_none
from ..log import Tidy3dKeyError

# add this around extents of plots
PLOT_BUFFER = 0.3
Expand Down Expand Up @@ -801,6 +802,70 @@ def set_center(cls, val, values):
values["center"] = cls.unpop_axis(z0, (x0, y0), axis=values.get("axis"))
return val

@classmethod
def from_gdspy( # pylint:disable=too-many-arguments
cls,
gds_cell,
axis: Axis,
slab_bounds: Tuple[float, float],
gds_layer: int,
gds_dtype: int,
polygon_index: pydantic.NonNegativeInt = 1,
gds_scale: pydantic.PositiveFloat = 1.0,
):
"""Import :class:`PolySlab` from a ``gdspy.Cell``.

Parameters
----------
gds_cell : gdspy.Cell
``gdspy.Cell`` containing 2D geometric data.
axis : int
Integer index into the polygon's slab axis. (0,1,2) -> (x,y,z).
slab_bounds: Tuple[float, float]
Minimum and maximum positions of the slab along ``axis``.
gds_layer : int
Layer index in the ``gds_cell``.
gds_dtype : int
Data type index in the ``gds_cell``.
polygon_index : int = 0
Index into the list of polygons at given ``gds_layer`` and ``gds_dtype``.
Must be non-negative.
gds_scale : float = 1.0
Length scale used in GDS file in units of micron.
For example, if gds file uses nanometers, set ``gds_scale=1e-3``.
Must be positive.

Returns
-------
:class:`PolySlab`
Geometry with slab along ``axis`` and geometry defined by gds cell in plane.
"""

vert_dict = gds_cell.get_polygons(by_spec=True)
try:
key = (gds_layer, gds_dtype)
list_of_vertices = vert_dict[key]
except Exception as e:
raise Tidy3dKeyError(
f"Can't load gds_cell, gds_layer={gds_layer} and gds_dtype={gds_dtype} not found. "
f"Found (layer, dtype) list of {list(vert_dict.keys())} in cell."
) from e

# select polygon index
try:
vertices = list_of_vertices[polygon_index]
except Exception as e:
raise Tidy3dKeyError(
f"no polygon vertices found at index {polygon_index}. "
f"{len(list_of_vertices)} polygons returned at "
f"gds_layer={gds_layer} and gds_dtype={gds_dtype}."
) from e

vertices *= gds_scale
vertices = vertices.tolist()

return cls(vertices=vertices, axis=axis, slab_bounds=slab_bounds)

def inside(self, x, y, z) -> bool: # pylint:disable=too-many-locals
"""Returns True if point ``(x,y,z)`` inside volume of geometry.

Expand Down