Skip to content

Commit a515d75

Browse files
committed
Lint data/ dirs
1 parent b98eef2 commit a515d75

26 files changed

Lines changed: 417 additions & 383 deletions

File tree

tidy3d/components/base_sim/data/monitor_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import pydantic.v1 as pd
88

9-
from ...data.dataset import Dataset
10-
from ..monitor import AbstractMonitor
9+
from tidy3d.components.base_sim.monitor import AbstractMonitor
10+
from tidy3d.components.data.dataset import Dataset
1111

1212

1313
class AbstractMonitorData(Dataset, ABC):

tidy3d/components/base_sim/data/sim_data.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
from __future__ import annotations
44

55
from abc import ABC
6-
from typing import Dict, Tuple, Union
6+
from typing import Union
77

88
import numpy as np
99
import pydantic.v1 as pd
1010
import xarray as xr
1111

12-
from ....exceptions import DataError, Tidy3dKeyError, ValidationError
13-
from ...base import Tidy3dBaseModel, skip_if_fields_missing
14-
from ...data.utils import UnstructuredGridDatasetType
15-
from ...types import FieldVal
16-
from ..simulation import AbstractSimulation
12+
from tidy3d.components.base import Tidy3dBaseModel, skip_if_fields_missing
13+
from tidy3d.components.base_sim.simulation import AbstractSimulation
14+
from tidy3d.components.data.utils import UnstructuredGridDatasetType
15+
from tidy3d.components.types import FieldVal
16+
from tidy3d.exceptions import DataError, Tidy3dKeyError, ValidationError
17+
1718
from .monitor_data import AbstractMonitorData
1819

1920

@@ -28,7 +29,7 @@ class AbstractSimulationData(Tidy3dBaseModel, ABC):
2829
description="Original :class:`AbstractSimulation` associated with the data.",
2930
)
3031

31-
data: Tuple[AbstractMonitorData, ...] = pd.Field(
32+
data: tuple[AbstractMonitorData, ...] = pd.Field(
3233
...,
3334
title="Monitor Data",
3435
description="List of :class:`AbstractMonitorData` instances "
@@ -47,7 +48,7 @@ def __getitem__(self, monitor_name: str) -> AbstractMonitorData:
4748
return monitor_data.symmetry_expanded_copy
4849

4950
@property
50-
def monitor_data(self) -> Dict[str, AbstractMonitorData]:
51+
def monitor_data(self) -> dict[str, AbstractMonitorData]:
5152
"""Dictionary mapping monitor name to its associated :class:`AbstractMonitorData`."""
5253
return {monitor_data.monitor.name: monitor_data for monitor_data in self.data}
5354

tidy3d/components/data/data_array.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from __future__ import annotations
44

55
from abc import ABC
6-
from typing import Any, Dict, List, Mapping, Union
6+
from collections.abc import Mapping
7+
from typing import Any, Optional, Union
78

89
import autograd.numpy as anp
910
import h5py
@@ -17,19 +18,19 @@
1718
from xarray.core.utils import OrderedSet, either_dict_or_kwargs
1819
from xarray.core.variable import as_variable
1920

20-
from ...compat import alignment
21-
from ...constants import (
21+
from tidy3d.compat import alignment
22+
from tidy3d.components.autograd import TidyArrayBox, get_static, interpn, is_tidy_box
23+
from tidy3d.components.geometry.bound_ops import bounds_contains
24+
from tidy3d.components.types import Axis, Bound
25+
from tidy3d.constants import (
2226
HERTZ,
2327
MICROMETER,
2428
PICOSECOND_PER_NANOMETER_PER_KILOMETER,
2529
RADIAN,
2630
SECOND,
2731
WATT,
2832
)
29-
from ...exceptions import DataError, FileError
30-
from ..autograd import TidyArrayBox, get_static, interpn, is_tidy_box
31-
from ..geometry.bound_ops import bounds_contains
32-
from ..types import Axis, Bound
33+
from tidy3d.exceptions import DataError, FileError
3334

3435
# maps the dimension names to their attributes
3536
DIM_ATTRS = {
@@ -69,7 +70,7 @@ class DataArray(xr.DataArray):
6970
# stores an ordered tuple of strings corresponding to the data dimensions
7071
_dims = ()
7172
# stores a dictionary of attributes corresponding to the data values
72-
_data_attrs: Dict[str, str] = {}
73+
_data_attrs: dict[str, str] = {}
7374

7475
def __init__(self, data, *args, **kwargs):
7576
# if data is a vanilla autograd box, convert to our box
@@ -118,7 +119,7 @@ def assign_data_attrs(cls, val):
118119
val.attrs[attr_name] = attr
119120
return val
120121

121-
def _interp_validator(self, field_name: str = None) -> None:
122+
def _interp_validator(self, field_name: Optional[str] = None) -> None:
122123
"""Ensure the data can be interpolated or selected by checking for duplicate coordinates.
123124
124125
NOTE
@@ -152,17 +153,17 @@ def assign_coord_attrs(cls, val):
152153
def __modify_schema__(cls, field_schema):
153154
"""Sets the schema of DataArray object."""
154155

155-
schema = dict(
156-
title="DataArray",
157-
type="xr.DataArray",
158-
properties=dict(
159-
_dims=dict(
160-
title="_dims",
161-
type="Tuple[str, ...]",
162-
),
163-
),
164-
required=["_dims"],
165-
)
156+
schema = {
157+
"title": "DataArray",
158+
"type": "xr.DataArray",
159+
"properties": {
160+
"_dims": {
161+
"title": "_dims",
162+
"type": "Tuple[str, ...]",
163+
},
164+
},
165+
"required": ["_dims"],
166+
}
166167
field_schema.update(schema)
167168

168169
@classmethod
@@ -261,7 +262,7 @@ def __hash__(self) -> int:
261262
token_str = dask.base.tokenize(self)
262263
return hash(token_str)
263264

264-
def multiply_at(self, value: complex, coord_name: str, indices: List[int]) -> Self:
265+
def multiply_at(self, value: complex, coord_name: str, indices: list[int]) -> Self:
265266
"""Multiply self by value at indices."""
266267
if isbox(self.data) or isbox(value):
267268
return self._ag_multiply_at(value, coord_name, indices)
@@ -270,7 +271,7 @@ def multiply_at(self, value: complex, coord_name: str, indices: List[int]) -> Se
270271
self_mult[{coord_name: indices}] *= value
271272
return self_mult
272273

273-
def _ag_multiply_at(self, value: complex, coord_name: str, indices: List[int]) -> Self:
274+
def _ag_multiply_at(self, value: complex, coord_name: str, indices: list[int]) -> Self:
274275
"""Autograd multiply_at override when tracing."""
275276
key = {coord_name: indices}
276277
_, index_tuple, _ = self.variable._broadcast_indexes(key)

tidy3d/components/data/dataset.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
from __future__ import annotations
44

55
from abc import ABC, abstractmethod
6-
from typing import Any, Callable, Dict, Optional, Union, get_args
6+
from typing import Any, Callable, Optional, Union, get_args
77

88
import numpy as np
99
import pydantic.v1 as pd
1010
import xarray as xr
1111

12-
from ...constants import C_0, PICOSECOND_PER_NANOMETER_PER_KILOMETER, UnitScaling
13-
from ...exceptions import DataError
14-
from ...log import log
15-
from ..base import Tidy3dBaseModel
16-
from ..types import Axis, xyz
12+
from tidy3d.components.base import Tidy3dBaseModel
13+
from tidy3d.components.types import Axis, xyz
14+
from tidy3d.constants import C_0, PICOSECOND_PER_NANOMETER_PER_KILOMETER, UnitScaling
15+
from tidy3d.exceptions import DataError
16+
from tidy3d.log import log
17+
1718
from .data_array import (
1819
DataArray,
1920
EMEScalarFieldDataArray,
@@ -44,7 +45,7 @@ class AbstractFieldDataset(Dataset, ABC):
4445

4546
@property
4647
@abstractmethod
47-
def field_components(self) -> Dict[str, DataArray]:
48+
def field_components(self) -> dict[str, DataArray]:
4849
"""Maps the field components to their associated data."""
4950

5051
def apply_phase(self, phase: float) -> AbstractFieldDataset:
@@ -60,15 +61,15 @@ def apply_phase(self, phase: float) -> AbstractFieldDataset:
6061

6162
@property
6263
@abstractmethod
63-
def grid_locations(self) -> Dict[str, str]:
64+
def grid_locations(self) -> dict[str, str]:
6465
"""Maps field components to the string key of their grid locations on the yee lattice."""
6566

6667
@property
6768
@abstractmethod
68-
def symmetry_eigenvalues(self) -> Dict[str, Callable[[Axis], float]]:
69+
def symmetry_eigenvalues(self) -> dict[str, Callable[[Axis], float]]:
6970
"""Maps field components to their (positive) symmetry eigenvalues."""
7071

71-
def package_colocate_results(self, centered_fields: Dict[str, ScalarFieldDataArray]) -> Any:
72+
def package_colocate_results(self, centered_fields: dict[str, ScalarFieldDataArray]) -> Any:
7273
"""How to package the dictionary of fields computed via self.colocate()."""
7374
return xr.Dataset(centered_fields)
7475

@@ -182,7 +183,7 @@ class ElectromagneticFieldDataset(AbstractFieldDataset, ABC):
182183
)
183184

184185
@property
185-
def field_components(self) -> Dict[str, DataArray]:
186+
def field_components(self) -> dict[str, DataArray]:
186187
"""Maps the field components to their associated data."""
187188
fields = {
188189
"Ex": self.Ex,
@@ -195,22 +196,22 @@ def field_components(self) -> Dict[str, DataArray]:
195196
return {field_name: field for field_name, field in fields.items() if field is not None}
196197

197198
@property
198-
def grid_locations(self) -> Dict[str, str]:
199+
def grid_locations(self) -> dict[str, str]:
199200
"""Maps field components to the string key of their grid locations on the yee lattice."""
200-
return dict(Ex="Ex", Ey="Ey", Ez="Ez", Hx="Hx", Hy="Hy", Hz="Hz")
201+
return {"Ex": "Ex", "Ey": "Ey", "Ez": "Ez", "Hx": "Hx", "Hy": "Hy", "Hz": "Hz"}
201202

202203
@property
203-
def symmetry_eigenvalues(self) -> Dict[str, Callable[[Axis], float]]:
204+
def symmetry_eigenvalues(self) -> dict[str, Callable[[Axis], float]]:
204205
"""Maps field components to their (positive) symmetry eigenvalues."""
205206

206-
return dict(
207-
Ex=lambda dim: -1 if (dim == 0) else +1,
208-
Ey=lambda dim: -1 if (dim == 1) else +1,
209-
Ez=lambda dim: -1 if (dim == 2) else +1,
210-
Hx=lambda dim: +1 if (dim == 0) else -1,
211-
Hy=lambda dim: +1 if (dim == 1) else -1,
212-
Hz=lambda dim: +1 if (dim == 2) else -1,
213-
)
207+
return {
208+
"Ex": lambda dim: -1 if (dim == 0) else +1,
209+
"Ey": lambda dim: -1 if (dim == 1) else +1,
210+
"Ez": lambda dim: -1 if (dim == 2) else +1,
211+
"Hx": lambda dim: +1 if (dim == 0) else -1,
212+
"Hy": lambda dim: +1 if (dim == 1) else -1,
213+
"Hz": lambda dim: +1 if (dim == 2) else -1,
214+
}
214215

215216

216217
class FieldDataset(ElectromagneticFieldDataset):
@@ -422,7 +423,7 @@ class AuxFieldDataset(AbstractFieldDataset, ABC):
422423
)
423424

424425
@property
425-
def field_components(self) -> Dict[str, DataArray]:
426+
def field_components(self) -> dict[str, DataArray]:
426427
"""Maps the field components to their associated data."""
427428
fields = {
428429
"Nfx": self.Nfx,
@@ -432,19 +433,19 @@ def field_components(self) -> Dict[str, DataArray]:
432433
return {field_name: field for field_name, field in fields.items() if field is not None}
433434

434435
@property
435-
def grid_locations(self) -> Dict[str, str]:
436+
def grid_locations(self) -> dict[str, str]:
436437
"""Maps field components to the string key of their grid locations on the yee lattice."""
437-
return dict(Nfx="Ex", Nfy="Ey", Nfz="Ez")
438+
return {"Nfx": "Ex", "Nfy": "Ey", "Nfz": "Ez"}
438439

439440
@property
440-
def symmetry_eigenvalues(self) -> Dict[str, Callable[[Axis], float]]:
441+
def symmetry_eigenvalues(self) -> dict[str, Callable[[Axis], float]]:
441442
"""Maps field components to their (positive) symmetry eigenvalues."""
442443

443-
return dict(
444-
Nfx=lambda dim: +1,
445-
Nfy=lambda dim: +1,
446-
Nfz=lambda dim: +1,
447-
)
444+
return {
445+
"Nfx": lambda dim: +1,
446+
"Nfy": lambda dim: +1,
447+
"Nfz": lambda dim: +1,
448+
}
448449

449450

450451
class AuxFieldTimeDataset(AuxFieldDataset):
@@ -559,7 +560,7 @@ class ModeSolverDataset(ElectromagneticFieldDataset):
559560
)
560561

561562
@property
562-
def field_components(self) -> Dict[str, DataArray]:
563+
def field_components(self) -> dict[str, DataArray]:
563564
"""Maps the field components to their associated data."""
564565
fields = {
565566
"Ex": self.Ex,
@@ -632,19 +633,19 @@ class PermittivityDataset(AbstractFieldDataset):
632633
"""
633634

634635
@property
635-
def field_components(self) -> Dict[str, ScalarFieldDataArray]:
636+
def field_components(self) -> dict[str, ScalarFieldDataArray]:
636637
"""Maps the field components to their associated data."""
637-
return dict(eps_xx=self.eps_xx, eps_yy=self.eps_yy, eps_zz=self.eps_zz)
638+
return {"eps_xx": self.eps_xx, "eps_yy": self.eps_yy, "eps_zz": self.eps_zz}
638639

639640
@property
640-
def grid_locations(self) -> Dict[str, str]:
641+
def grid_locations(self) -> dict[str, str]:
641642
"""Maps field components to the string key of their grid locations on the yee lattice."""
642-
return dict(eps_xx="Ex", eps_yy="Ey", eps_zz="Ez")
643+
return {"eps_xx": "Ex", "eps_yy": "Ey", "eps_zz": "Ez"}
643644

644645
@property
645-
def symmetry_eigenvalues(self) -> Dict[str, Callable[[Axis], float]]:
646+
def symmetry_eigenvalues(self) -> dict[str, Callable[[Axis], float]]:
646647
"""Maps field components to their (positive) symmetry eigenvalues."""
647-
return dict(eps_xx=None, eps_yy=None, eps_zz=None)
648+
return {"eps_xx": None, "eps_yy": None, "eps_zz": None}
648649

649650
eps_xx: ScalarFieldDataArray = pd.Field(
650651
...,

0 commit comments

Comments
 (0)