From 05f4565169aba51e6ba6ce42d27d0e498256fb1b Mon Sep 17 00:00:00 2001 From: dbochkov-flexcompute Date: Fri, 2 Dec 2022 21:05:05 -0600 Subject: [PATCH] Bug fix for overlap_sort() modifying self --- tests/test_data/test_monitor_data.py | 7 +++---- tidy3d/components/data/monitor_data.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/test_data/test_monitor_data.py b/tests/test_data/test_monitor_data.py index 09403946c..efdb9c84c 100644 --- a/tests/test_data/test_monitor_data.py +++ b/tests/test_data/test_monitor_data.py @@ -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 diff --git a/tidy3d/components/data/monitor_data.py b/tidy3d/components/data/monitor_data.py index e3130cf08..7fc6e34b3 100644 --- a/tidy3d/components/data/monitor_data.py +++ b/tidy3d/components/data/monitor_data.py @@ -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, :]]