Skip to content

Commit 1103e5d

Browse files
Fix data typs
1 parent b5d7b26 commit 1103e5d

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

tidy3d/plugins/smatrix/data/data.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ def get_antenna_metrics_data(
113113
"""
114114
# Use the first port as default if none specified
115115
if port_amplitudes is None:
116-
port_amplitudes = {self.ports[0].name: None}
117-
port_names = [port.name for port in self.ports]
116+
port_amplitudes = {self.simulation.ports[0].name: None}
117+
port_names = [port.name for port in self.simulation.ports]
118118
# Check port names, and create map from port to amplitude
119119
port_dict = {}
120120
for key in port_amplitudes.keys():
121-
port = self.get_port_by_name(port_name=key)
121+
port = self.simulation.get_port_by_name(port_name=key)
122122
port_dict[port] = port_amplitudes[key]
123123
# Get the radiation monitor, use first as default
124124
# if none specified
125125
if monitor_name is None:
126-
rad_mon = self.radiation_monitors[0]
126+
rad_mon = self.simulation.radiation_monitors[0]
127127
else:
128-
rad_mon = self.get_radiation_monitor_by_name(monitor_name)
128+
rad_mon = self.simulation.get_radiation_monitor_by_name(monitor_name)
129129

130130
# Create data arrays for holding the superposition of all port power wave amplitudes
131131
f = list(rad_mon.freqs)
@@ -135,7 +135,7 @@ def get_antenna_metrics_data(
135135
# Retrieve associated simulation data
136136
combined_directivity_data = None
137137
for port, amplitude in port_dict.items():
138-
sim_data_port = self.batch_data[self._task_name(port=port)]
138+
sim_data_port = self.simulation.batch_data[self.simulation._task_name(port=port)]
139139
radiation_data = sim_data_port[rad_mon.name]
140140

141141
a, b = self.compute_power_wave_amplitudes_at_each_port(
@@ -176,35 +176,37 @@ def get_antenna_metrics_data(
176176
@cached_property
177177
def port_reference_impedances(self) -> PortDataArray:
178178
"""The reference impedance used at each port for definining power wave amplitudes."""
179-
return self._port_reference_impedances(self.batch_data)
179+
return self._port_reference_impedances(self.simulation.batch_data)
180180

181181
def _port_reference_impedances(self, batch_data) -> PortDataArray:
182182
"""Tabulates the reference impedance of each port at each frequency using the
183183
supplied :class:`.BatchData`.
184184
"""
185185
# TODO properly refactor, plugins data types should not have web methods.
186186

187-
port_names = [port.name for port in self.ports]
187+
port_names = [port.name for port in self.simulation.ports]
188188

189189
values = np.zeros(
190-
(len(self.freqs), len(port_names)),
190+
(len(self.simulation.freqs), len(port_names)),
191191
dtype=complex,
192192
)
193-
coords = {"f": np.array(self.freqs), "port": port_names}
193+
coords = {"f": np.array(self.simulation.freqs), "port": port_names}
194194
port_impedances = PortDataArray(values, coords=coords)
195-
for port in self.ports:
195+
for port in self.simulation.ports:
196196
if isinstance(port, WavePort):
197197
# Mode solver data for each wave port is stored in its associated SimulationData
198-
sim_data_port = batch_data[self._task_name(port=port)]
198+
sim_data_port = batch_data[self.simulation._task_name(port=port)]
199199
# WavePorts have a port impedance calculated from its associated modal field distribution
200200
# and is frequency dependent.
201201
impedances = port.compute_port_impedance(sim_data_port).values
202202
port_impedances.loc[{"port": port.name}] = impedances.squeeze()
203203
else:
204204
# LumpedPorts have a constant reference impedance
205-
port_impedances.loc[{"port": port.name}] = np.full(len(self.freqs), port.impedance)
205+
port_impedances.loc[{"port": port.name}] = np.full(
206+
len(self.simulation.freqs), port.impedance
207+
)
206208

207-
port_impedances = TerminalComponentModeler._set_port_data_array_attributes(port_impedances)
209+
port_impedances = self.simulation._set_port_data_array_attributes(port_impedances)
208210
return port_impedances
209211

210212
def compute_power_wave_amplitudes_at_each_port(
@@ -225,13 +227,13 @@ def compute_power_wave_amplitudes_at_each_port(
225227
tuple[:class:`.PortDataArray`, :class:`.PortDataArray`]
226228
Incident (a) and reflected (b) power wave amplitudes at each port.
227229
"""
228-
port_names = [port.name for port in self.ports]
230+
port_names = [port.name for port in self.simulation.ports]
229231
values = np.zeros(
230-
(len(self.freqs), len(port_names)),
232+
(len(self.simulation.freqs), len(port_names)),
231233
dtype=complex,
232234
)
233235
coords = {
234-
"f": np.array(self.freqs),
236+
"f": np.array(self.simulation.freqs),
235237
"port": port_names,
236238
}
237239

@@ -240,7 +242,7 @@ def compute_power_wave_amplitudes_at_each_port(
240242
a = V_matrix.copy(deep=True)
241243
b = V_matrix.copy(deep=True)
242244

243-
for port_out in self.ports:
245+
for port_out in self.simulation.ports:
244246
V_out, I_out = compute_port_VI(port_out, sim_data)
245247
indexer = {"port": port_out.name}
246248
V_matrix.loc[indexer] = V_out

0 commit comments

Comments
 (0)