Skip to content

Commit

Permalink
added classes DirectivityData and DirectivityDataArray
Browse files Browse the repository at this point in the history
  • Loading branch information
QimingFlex committed Jun 3, 2024
1 parent 7d580e3 commit 2f94cdf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
10 changes: 8 additions & 2 deletions tidy3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
from .components.data.data_array import ScalarFieldTimeDataArray, SpatialDataArray
from .components.data.data_array import ModeAmpsDataArray, ModeIndexDataArray
from .components.data.data_array import FluxDataArray, FluxTimeDataArray
from .components.data.data_array import FieldProjectionAngleDataArray
from .components.data.data_array import FieldProjectionAngleDataArray, DirectivityDataArray
from .components.data.data_array import FieldProjectionCartesianDataArray
from .components.data.data_array import FieldProjectionKSpaceDataArray
from .components.data.data_array import DiffractionDataArray
Expand All @@ -83,7 +83,11 @@
from .components.data.monitor_data import FluxData, FluxTimeData
from .components.data.monitor_data import ModeData, ModeSolverData
from .components.data.monitor_data import AbstractFieldProjectionData
from .components.data.monitor_data import FieldProjectionAngleData, FieldProjectionCartesianData
from .components.data.monitor_data import (
FieldProjectionAngleData,
DirectivityData,
FieldProjectionCartesianData,
)
from .components.data.monitor_data import FieldProjectionKSpaceData
from .components.data.monitor_data import DiffractionData
from .components.data.sim_data import SimulationData
Expand Down Expand Up @@ -261,6 +265,7 @@ def set_logging_level(level: str) -> None:
"FluxDataArray",
"FluxTimeDataArray",
"FieldProjectionAngleDataArray",
"DirectivityDataArray",
"FieldProjectionCartesianDataArray",
"FieldProjectionKSpaceDataArray",
"DiffractionDataArray",
Expand All @@ -279,6 +284,7 @@ def set_logging_level(level: str) -> None:
"ModeSolverData",
"AbstractFieldProjectionData",
"FieldProjectionAngleData",
"DirectivityData",
"FieldProjectionCartesianData",
"FieldProjectionKSpaceData",
"DiffractionData",
Expand Down
19 changes: 19 additions & 0 deletions tidy3d/components/data/data_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,24 @@ class FieldProjectionAngleDataArray(DataArray):
_data_attrs = {"long_name": "radiation vectors"}


class DirectivityDataArray(DataArray):
"""Far fields in frequency domain as a function of angles theta and phi.
Example
-------
>>> f = np.linspace(1e14, 2e14, 10)
>>> r = np.atleast_1d(5)
>>> theta = np.linspace(0, np.pi, 10)
>>> phi = np.linspace(0, 2*np.pi, 20)
>>> coords = dict(r=r, theta=theta, phi=phi, f=f)
>>> values = (1+1j) * np.random.random((len(r), len(theta), len(phi), len(f)))
>>> data = DirectivityDataArray(values, coords=coords)
"""

__slots__ = ()
_dims = ("r", "theta", "phi", "f")
_data_attrs = {"long_name": "radiation intensity"}


class FieldProjectionCartesianDataArray(DataArray):
"""Far fields in frequency domain as a function of local x and y coordinates.
Expand Down Expand Up @@ -980,6 +998,7 @@ class IndexedDataArray(DataArray):
GroupIndexDataArray,
ModeDispersionDataArray,
FieldProjectionAngleDataArray,
DirectivityDataArray,
FieldProjectionCartesianDataArray,
FieldProjectionKSpaceDataArray,
DiffractionDataArray,
Expand Down
39 changes: 37 additions & 2 deletions tidy3d/components/data/monitor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
from .data_array import FluxTimeDataArray, FluxDataArray
from .data_array import MixedModeDataArray, ModeAmpsDataArray
from .data_array import GroupIndexDataArray, ModeDispersionDataArray
from .data_array import FieldProjectionAngleDataArray, FieldProjectionCartesianDataArray
from .data_array import (
FieldProjectionAngleDataArray,
DirectivityDataArray,
FieldProjectionCartesianDataArray,
)
from .data_array import FieldProjectionKSpaceDataArray
from .data_array import DataArray, DiffractionDataArray
from .data_array import ScalarFieldDataArray, ScalarFieldTimeDataArray
Expand All @@ -29,7 +33,11 @@
from ..source import GaussianPulse, ModeSource, Source, PlaneWave
from ..monitor import MonitorType, FieldMonitor, FieldTimeMonitor, ModeSolverMonitor
from ..monitor import ModeMonitor, FluxMonitor, FluxTimeMonitor, PermittivityMonitor
from ..monitor import FieldProjectionAngleMonitor, FieldProjectionCartesianMonitor
from ..monitor import (
FieldProjectionAngleMonitor,
DirectivityMonitor,
FieldProjectionCartesianMonitor,
)
from ..monitor import FieldProjectionKSpaceMonitor, FieldProjectionSurface
from ..monitor import DiffractionMonitor
from ..source import SourceTimeType, CustomFieldSource
Expand Down Expand Up @@ -2203,6 +2211,32 @@ def renormalize_fields(self, proj_distance: float) -> FieldProjectionAngleData:
return self.make_renormalized_data(phase, proj_distance)


class DirectivityData(MonitorData):
"""Data associated with a :class:`.DirectivityMonitor`.
Example
-------
>>> from tidy3d import DirectivityDataArray
>>> f = np.linspace(1e14, 2e14, 10)
>>> r = np.atleast_1d(5)
>>> theta = np.linspace(0, np.pi, 10)
>>> phi = np.linspace(0, 2*np.pi, 20)
>>> coords = dict(r=r, theta=theta, phi=phi, f=f)
>>> scalar_field = DirectivityDataArray(farfield_values, coords=coords)
>>> monitor = DirectivityMonitor(center=(1,2,3), size=(2,2,2), freqs=f, name='n2f_monitor', phi=phi, theta=theta)
>>> data = DirectivityData(monitor=monitor,Directivity=scalar_field)
"""

monitor: DirectivityMonitor = pd.Field(
...,
title="DirectivityMonitor",
description="DirectivityMonitor with an angle-based projection grid.",
)

directivity: DirectivityDataArray = pd.Field(
..., title="Directivity", description="Directivity with an angle-based projection grid."
)


class FieldProjectionCartesianData(AbstractFieldProjectionData):
"""Data associated with a :class:`.FieldProjectionCartesianMonitor`: components of
projected fields.
Expand Down Expand Up @@ -2790,6 +2824,7 @@ def adjoint_source_amp(self, amp: DataArray) -> PlaneWave:
FluxData,
FluxTimeData,
FieldProjectionKSpaceData,
DirectivityData,
FieldProjectionCartesianData,
FieldProjectionAngleData,
DiffractionData,
Expand Down

0 comments on commit 2f94cdf

Please sign in to comment.