Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for overlap_sort() modifying self #595

Merged
merged 1 commit into from
Dec 7, 2022
Merged
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
7 changes: 3 additions & 4 deletions tests/test_data/test_monitor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,8 @@ def test_mode_solver_data_sort():
# test sorting function
data = make_mode_solver_data()
data_first = data.overlap_sort(track_freq="lowest")
data_last = data.overlap_sort(track_freq="highest")
data_center = data.overlap_sort(track_freq="central")
# these are probably not the best tests
assert data_first.field_components == data.field_components
data_last = data_first.overlap_sort(track_freq="highest")
data_center = data_first.overlap_sort(track_freq="central")
# check repeated sorting doesn't change anything
assert data_first.field_components == data_last.field_components
assert data_first.field_components == data_center.field_components
12 changes: 8 additions & 4 deletions tidy3d/components/data/monitor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,17 +672,21 @@ def _reorder_modes(
fields = {}
for field_name, field in self.field_components.items():

field_sorted = field.copy()

# Apply phase shift
field.data = field.data * np.exp(-1j * phase[None, None, None, :, :])
field_sorted.data = field_sorted.data * np.exp(-1j * phase[None, None, None, :, :])

# Rearrange modes
for freq_id in range(num_freqs):
field.data[..., freq_id, :] = field.data[..., freq_id, sorting[freq_id, :]]
field_sorted.data[..., freq_id, :] = field_sorted.data[
..., freq_id, sorting[freq_id, :]
]

fields[field_name] = field
fields[field_name] = field_sorted

# Rearrange propagation index data
index_data = self.n_complex
index_data = self.n_complex.copy()
for freq_id in range(num_freqs):
index_data.data[freq_id, :] = index_data.data[freq_id, sorting[freq_id, :]]

Expand Down