diff --git a/PR.json b/PR.json deleted file mode 100644 index e473a34b83..0000000000 --- a/PR.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": null, - "frequency_range": [ - -1e+16, - 1e+16 - ], - "eps_inf": 1.0, - "poles": [ - [ - [ - 1.0, - 1.0 - ], - [ - 0.0, - 2.2 - ] - ] - ], - "type": "PoleResidue" -} \ No newline at end of file diff --git a/Untitled.ipynb b/Untitled.ipynb deleted file mode 100644 index e203c71cf8..0000000000 --- a/Untitled.ipynb +++ /dev/null @@ -1,59 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 2, - "id": "cd7b162c-38b8-493f-87eb-91e6c263f0fe", - "metadata": {}, - "outputs": [], - "source": [ - "import sys; sys.path.append('.')\n", - "import tidy3d as td\n", - "from tidy3d.components.base import Tidy3dBaseModel" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "443f96c7-ae3a-4f6a-8963-e8e76abf7a76", - "metadata": {}, - "outputs": [], - "source": [ - "class Inf(Tidy3dBaseModel):\n", - "\n", - " self.sign : bool = True\n", - " self.shift : \n", - " def __neg__(self):\n", - " if self.is_positive:\n", - " self.is_positive = False\n", - " else:\n", - " self.is_positive = True\n", - " return self\n", - "\n", - " def __lt__(self, other):\n", - " return " - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.7" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/requirements.txt b/requirements.txt index 91fd4edbf3..3850dda8be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 @@ -31,4 +28,7 @@ nbsphinx ipython autodoc_pydantic sphinx-copybutton -m2r2 \ No newline at end of file +m2r2 + +# required for web +boto3 diff --git a/tidy3d/components/geometry.py b/tidy3d/components/geometry.py index 55d5ae01c1..9e3936349e 100644 --- a/tidy3d/components/geometry.py +++ b/tidy3d/components/geometry.py @@ -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 @@ -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.