Skip to content

XY transposable sim.plot() plots (issue1072) VERSION 2 #2544

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

Open
wants to merge 56 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
657e53a
first attempt to add the "transpose" argument all 2D plot-related tid…
jewettaijfc Jun 5, 2025
8d1b9cc
reverted changes to corner_finder.py and added more changes to geomet…
jewettaijfc Jun 5, 2025
3223c81
added minimal changes to primitives.py
jewettaijfc Jun 5, 2025
99f0369
updated primitives.py and reverted monitor.py to its original state (…
jewettaijfc Jun 5, 2025
9dae10e
removed the "transpose" arguments from the various `_gds` functions i…
jewettaijfc Jun 6, 2025
eb94b5e
removed "transpose" argument from some validator functions. (oops. …
jewettaijfc Jun 6, 2025
26c1ef4
I fixed most of the problems with Scene.plot(). But Polyslabs are no…
jewettaijfc Jun 6, 2025
162d788
It's finally possible to plot PolySlab objects when transpose=True, f…
jewettaijfc Jun 6, 2025
efe0866
removed some crud from PolySlab.make_shapely_polygon()
jewettaijfc Jun 6, 2025
cb8ea88
plot_eps() works again (with transpose=True or False)
jewettaijfc Jun 7, 2025
581b38e
removed all the print() statements used for debugging (again. I put …
jewettaijfc Jun 7, 2025
319108f
changed the name of the "transpose" argument to "swap_axes" everywhere
jewettaijfc Jun 7, 2025
978d3f0
found a few more pesky gds-related functions that still had a "transp…
jewettaijfc Jun 7, 2025
cdf3fa4
added the "swap_axes" argument to TFSF.plot() to be consistent with t…
jewettaijfc Jun 7, 2025
61627c1
replaced (un)pop_axis() with (un)pop_axis_and_swap() everwhere where …
jewettaijfc Jun 8, 2025
fa61e43
Fixed a bug in Scene.plot_heat_charge_property(), and tested it (both…
jewettaijfc Jun 8, 2025
f3ab1fb
Fixed some bugs in HeatChargeSimulation.plot_sources(). It runs with…
jewettaijfc Jun 8, 2025
126479e
(Hopefully) Fixed a bug in HeatChargeSimulationData.plot_field() from…
jewettaijfc Jun 8, 2025
ce936c9
fixed a bug introduced when I renamed "pop_axis()" to "pop_axis_and_s…
jewettaijfc Jun 8, 2025
76d8ce1
added test_pop_axis_and_swap() to test_geometry.py
jewettaijfc Jun 9, 2025
d8f5a12
deleted some additional print() statements I am no longer using
jewettaijfc Jun 9, 2025
b6ecf4b
fixed a bug that broke HeatChargeSimulationData
jewettaijfc Jun 9, 2025
0750ca6
"vertices[:, (1, 0)]" --> "vertices[:, ::-1]"
jewettaijfc Jun 9, 2025
775fb5d
I fixed the last remaining unit test failure. I stil need modify the…
jewettaijfc Jun 9, 2025
4047c56
deleted test_polyslab.py
jewettaijfc Jun 9, 2025
b6cf0ba
removed 2 files ('report.log_BRANCH=develop' and 'results.prof_BRANCH…
jewettaijfc Jun 10, 2025
2463a7f
Added "swap_axes" argument to mode_solver.py. Updated unit tests for…
jewettaijfc Jun 10, 2025
bd28c12
Updated unit tests for test_simulation.py
jewettaijfc Jun 10, 2025
879c6e5
updated unit tests for test_scene.py and test_geometry.py. Removed t…
jewettaijfc Jun 11, 2025
69709c2
added/updated unit tests for test_source.py
jewettaijfc Jun 11, 2025
9becf0b
updated unit tests for test_heat.py and test_heat_charge.py
jewettaijfc Jun 11, 2025
c62c642
renamed the "swap_axes" argument --> "transpose"
jewettaijfc Jun 11, 2025
6a423b9
updated unit tests for test_eme.py
jewettaijfc Jun 11, 2025
68de5b6
added docstrings and removed the "transpose" argument from several fu…
jewettaijfc Jun 11, 2025
0647779
corrected typo in the docstrings
jewettaijfc Jun 11, 2025
1ff3556
reformatting some files manually. afraid to use "black"
jewettaijfc Jun 12, 2025
5aff2b2
reformatted using `black . --line-length 100`
jewettaijfc Jun 12, 2025
321abea
Ran `ruff check tidy3d --fix` to fix an import error in tcad/data/sim…
jewettaijfc Jun 12, 2025
7a15671
attempting to fix a linter error
jewettaijfc Jun 12, 2025
adfde1f
Revert "reformatting some files manually. afraid to use "black""
jewettaijfc Jun 12, 2025
aca545e
updated manually, following Tyler's suggestions. I also corrected th…
jewettaijfc Jun 12, 2025
3e32d3d
ran `pre-commit run --all-files`
jewettaijfc Jun 12, 2025
eacc7d9
updated test_pop_axis_and_swap()
jewettaijfc Jun 12, 2025
1bce334
removed an extra newline. (I fixed these problems earlier, but my fa…
jewettaijfc Jun 12, 2025
3236507
uncommented a plot test
jewettaijfc Jun 12, 2025
f9b57ba
(trivial update to a test function)
jewettaijfc Jun 12, 2025
95e1b63
fixed _pcolormesh_shape_doping_box() (hopefully), but I haven't remov…
jewettaijfc Jun 13, 2025
6a1572e
Added the argument , and all of the functions in and . Added warn…
jewettaijfc Jun 14, 2025
394c984
removed or commented out some crufty print() statements I was using f…
jewettaijfc Jun 14, 2025
ca576bd
Merge branch 'develop' into jewettaijfc/issue1072_v2
jewettaijfc Jun 14, 2025
d49eeae
removed the `plot()` functions used for debugging
jewettaijfc Jun 16, 2025
68c6d28
Fixed Box._do_intersections_plane(). I need to get that function imp…
jewettaijfc Jun 16, 2025
77ee113
Merge branch 'develop' into jewettaijfc/issue1072_v2
jewettaijfc Jun 16, 2025
28f4315
I added the argument to all of the functions named intersections_til…
jewettaijfc Jun 17, 2025
38a1031
Updated Cylinder.intersections_tilted_plane() and Cylinder._do_inters…
jewettaijfc Jun 17, 2025
75d6f1a
New approach suggested by Tyler: Update Geometry.plot_shape() functio…
jewettaijfc Jun 17, 2025
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
27 changes: 14 additions & 13 deletions tests/test_components/test_eme.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,22 @@ def test_eme_monitor():
)


def test_eme_simulation():
@pytest.mark.parametrize("transpose", [True, False])
def test_eme_simulation(transpose):
sim = make_eme_sim()
_ = sim.plot(x=0, ax=AX)
_ = sim.plot(y=0, ax=AX)
_ = sim.plot(z=0, ax=AX)
_ = sim.plot_grid(x=0, ax=AX)
_ = sim.plot_grid(y=0, ax=AX)
_ = sim.plot_grid(z=0, ax=AX)
_ = sim.plot_eps(x=0, ax=AX)
_ = sim.plot_eps(y=0, ax=AX)
_ = sim.plot_eps(z=0, ax=AX)
_ = sim.plot(x=0, ax=AX, transpose=transpose)
_ = sim.plot(y=0, ax=AX, transpose=transpose)
_ = sim.plot(z=0, ax=AX, transpose=transpose)
_ = sim.plot_grid(x=0, ax=AX, transpose=transpose)
_ = sim.plot_grid(y=0, ax=AX, transpose=transpose)
_ = sim.plot_grid(z=0, ax=AX, transpose=transpose)
_ = sim.plot_eps(x=0, ax=AX, transpose=transpose)
_ = sim.plot_eps(y=0, ax=AX, transpose=transpose)
_ = sim.plot_eps(z=0, ax=AX, transpose=transpose)
sim2 = sim.updated_copy(axis=1)
_ = sim2.plot(x=0, ax=AX)
_ = sim2.plot(y=0, ax=AX)
_ = sim2.plot(z=0, ax=AX)
_ = sim2.plot(x=0, ax=AX, transpose=transpose)
_ = sim2.plot(y=0, ax=AX, transpose=transpose)
_ = sim2.plot(z=0, ax=AX, transpose=transpose)

# need at least one freq
with pytest.raises(pd.ValidationError):
Expand Down
71 changes: 45 additions & 26 deletions tests/test_components/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@
_, AX = plt.subplots()


@pytest.mark.parametrize("component", GEO_TYPES)
def test_plot(component):
_ = component.plot(z=0, ax=AX)
@pytest.mark.parametrize("component, transpose", zip(GEO_TYPES, [True, False]))
def test_plot(component, transpose):
_ = component.plot(z=0, ax=AX, transpose=transpose)
plt.close()


def test_plot_with_units():
_ = BOX.plot(z=0, ax=AX, plot_length_units="nm")
@pytest.mark.parametrize("transpose", [True, False])
def test_plot_with_units(transpose):
_ = BOX.plot(z=0, ax=AX, plot_length_units="nm", transpose=transpose)
plt.close()


Expand Down Expand Up @@ -204,11 +205,11 @@ def test_array_to_vertices():
assert np.all(np.array(vertices) == np.array(vertices2))


@pytest.mark.parametrize("component", GEO_TYPES)
def test_intersections_plane(component):
assert len(component.intersections_plane(z=0.2)) > 0
assert len(component.intersections_plane(x=0.2)) > 0
assert len(component.intersections_plane(x=10000)) == 0
@pytest.mark.parametrize("component, transpose", zip(GEO_TYPES, [True, False]))
def test_intersections_plane(component, transpose):
assert len(component.intersections_plane(z=0.2, transpose=transpose)) > 0
assert len(component.intersections_plane(x=0.2, transpose=transpose)) > 0
assert len(component.intersections_plane(x=10000, transpose=transpose)) == 0


def test_intersections_plane_inf():
Expand Down Expand Up @@ -766,36 +767,49 @@ def test_geometry_touching_intersections_plane(x0):


def test_pop_axis():
b = td.Box(size=(1, 1, 1))
for axis in range(3):
coords = (1, 2, 3)
Lz, (Lx, Ly) = b.pop_axis(coords, axis=axis)
_coords = b.unpop_axis(Lz, (Lx, Ly), axis=axis)
Lz, (Lx, Ly) = td.Box.pop_axis(coords, axis=axis)
_coords = td.Box.unpop_axis(Lz, (Lx, Ly), axis=axis)
assert all(c == _c for (c, _c) in zip(coords, _coords))
_Lz, (_Lx, _Ly) = td.Box.pop_axis(_coords, axis=axis)
assert Lz == _Lz
assert Lx == _Lx
assert Ly == _Ly


@pytest.mark.parametrize("transpose", [True, False])
def test_pop_axis_and_swap(transpose):
for axis in range(3):
coords = (1, 2, 3)
Lz, (Lx, Ly) = td.Box.pop_axis_and_swap(coords, axis=axis, transpose=transpose)
_coords = td.Box.unpop_axis_and_swap(Lz, (Lx, Ly), axis=axis, transpose=transpose)
assert all(c == _c for (c, _c) in zip(coords, _coords))
_Lz, (_Lx, _Ly) = b.pop_axis(_coords, axis=axis)
_Lz, (_Lx, _Ly) = td.Box.pop_axis_and_swap(_coords, axis=axis, transpose=transpose)
assert Lz == _Lz
assert Lx == _Lx
assert Ly == _Ly


def test_2b_box_intersections():
@pytest.mark.parametrize("transpose", [True, False])
def test_2b_box_intersections(transpose):
plane = td.Box(size=(1, 4, 0))
box1 = td.Box(size=(1, 1, 1))
box2 = td.Box(size=(1, 1, 1), center=(3, 0, 0))

result = plane.intersections_with(box1)
result = plane.intersections_with(box1, transpose=transpose)
assert len(result) == 1
assert result[0].geom_type == "Polygon"
assert len(plane.intersections_with(box2)) == 0
assert len(plane.intersections_with(box2, transpose=transpose)) == 0

with pytest.raises(ValidationError):
_ = box1.intersections_with(box2)
_ = box1.intersections_with(box2, transpose=transpose)

assert len(box1.intersections_2dbox(plane)) == 1
assert len(box2.intersections_2dbox(plane)) == 0
assert len(box1.intersections_2dbox(plane, transpose=transpose)) == 1
assert len(box2.intersections_2dbox(plane, transpose=transpose)) == 0

with pytest.raises(ValidationError):
_ = box2.intersections_2dbox(box1)
_ = box2.intersections_2dbox(box1, transpose=transpose)


def test_polyslab_merge():
Expand Down Expand Up @@ -937,7 +951,8 @@ def test_to_gds(geometry, tmp_path):
assert len(cell.polygons) == 0


def test_custom_surface_geometry(tmp_path):
@pytest.mark.parametrize("transpose", [True, False])
def test_custom_surface_geometry(transpose, tmp_path):
# create tetrahedron STL
vertices = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
faces = np.array([[1, 2, 3], [0, 3, 2], [0, 1, 3], [0, 2, 1]])
Expand Down Expand Up @@ -970,9 +985,13 @@ def test_custom_surface_geometry(tmp_path):
assert np.isclose(geom.volume(), 1 / 6)

# test intersections
assert shapely.equals(geom.intersections_plane(x=0), shapely.Polygon([[0, 0], [0, 1], [1, 0]]))
assert shapely.equals(
geom.intersections_plane(z=0.5), shapely.Polygon([[0, 0], [0, 0.5], [0.5, 0]])
geom.intersections_plane(x=0, transpose=transpose),
shapely.Polygon([[0, 0], [0, 1], [1, 0]]),
)
assert shapely.equals(
geom.intersections_plane(z=0.5, transpose=transpose),
shapely.Polygon([[0, 0], [0, 0.5], [0.5, 0]]),
)

# test inside
Expand All @@ -981,7 +1000,7 @@ def test_custom_surface_geometry(tmp_path):

# test plot
_, ax = plt.subplots()
_ = geom.plot(z=0.1, ax=ax)
_ = geom.plot(z=0.1, ax=ax, transpose=transpose)
plt.close()

# test inconsistent winding
Expand Down Expand Up @@ -1031,7 +1050,7 @@ def test_custom_surface_geometry(tmp_path):
boundary_spec=td.BoundarySpec.all_sides(td.PML()),
)
_, ax = plt.subplots()
_ = sim.plot(y=0, ax=ax)
_ = sim.plot(y=0, ax=ax, transpose=transpose)
plt.close()

# allow small triangles
Expand Down
11 changes: 6 additions & 5 deletions tests/test_components/test_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,12 @@ def make_heat_sim(include_custom_source: bool = True):
return heat_sim


def test_heat_sim():
@pytest.mark.parametrize("transpose", [True, False])
def test_heat_sim(transpose):
bc_temp, bc_flux, bc_conv = make_heat_bcs()
heat_sim = make_heat_sim()

_ = heat_sim.plot(x=0)
_ = heat_sim.plot(x=0, transpose=transpose)

# wrong names given
for pl in [
Expand Down Expand Up @@ -373,14 +374,14 @@ def test_heat_sim():
with pytest.raises(pd.ValidationError):
heat_sim.updated_copy(monitors=[temp_mnt, temp_mnt])

_ = heat_sim.plot(x=0)
_ = heat_sim.plot(x=0, transpose=transpose)
plt.close()

_ = heat_sim.plot_heat_conductivity(y=0)
_ = heat_sim.plot_heat_conductivity(y=0, transpose=transpose)
plt.close()

heat_sim_sym = heat_sim.updated_copy(symmetry=(0, 1, 1))
_ = heat_sim_sym.plot_heat_conductivity(z=0, colorbar="source")
_ = heat_sim_sym.plot_heat_conductivity(z=0, colorbar="source", transpose=transpose)
plt.close()

# no negative symmetry
Expand Down
22 changes: 18 additions & 4 deletions tests/test_components/test_heat_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ def test_heat_charge_sources(structures):
_ = td.HeatSource(structures=["solid_structure"], rate="100")


def test_heat_charge_simulation(simulation_data):
@pytest.mark.parametrize("transpose", [True, False])
def test_heat_charge_simulation(transpose, simulation_data):
"""Tests 'HeatChargeSimulation' and 'ConductionSimulation' objects."""
heat_sim_data, cond_sim_data, voltage_capacitance_sim_data, current_voltage_simulation_data = (
simulation_data
Expand All @@ -876,6 +877,18 @@ def test_heat_charge_simulation(simulation_data):
"Current-Voltage simulation should be created successfully."
)

_ = heat_sim.plot_heat_conductivity(x=0, transpose=transpose)
plt.close()
_ = heat_sim.plot_property(x=0, property="heat_conductivity", transpose=transpose)
plt.close()
_ = cond_sim.plot_property(x=0, property="electric_conductivity", transpose=transpose)
plt.close()
for sim in (heat_sim, cond_sim, voltage_capacitance_sim, current_voltage_sim):
_ = sim.plot_boundaries(x=0, transpose=transpose)
plt.close()
_ = sim.plot_sources(x=0, transpose=transpose)
plt.close()


def test_sim_data_plotting(simulation_data):
"""Tests whether simulation data can be plotted and appropriate errors are raised."""
Expand Down Expand Up @@ -1433,7 +1446,8 @@ def test_plotting_functions(simulation_data):
heat_sim_data.plot_field("test", invalid_param=0)


def test_bandgap_monitor():
@pytest.mark.parametrize("transpose", [True, False])
def test_bandgap_monitor(transpose):
"""Test energy bandgap monitor ploting function."""
# create a triangle grid
tri_grid_points = td.PointDataArray(
Expand Down Expand Up @@ -1573,8 +1587,8 @@ def test_bandgap_monitor():

# test check for the voltage value in the list of arguments

tri_single_voltage_data.plot(x=0.0)
tri_multi_voltage_data.plot(x=0.0, voltage=1.0)
tri_single_voltage_data.plot(x=0.0, transpose=transpose)
tri_multi_voltage_data.plot(x=0.0, voltage=1.0, transpose=transpose)

with pytest.raises(DataError):
tri_multi_voltage_data.plot(x=0.0)
Expand Down
58 changes: 33 additions & 25 deletions tests/test_components/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ def test_validate_components_none():
assert SCENE._validate_num_mediums(val=None) is None


def test_plot_eps():
ax = SCENE_FULL.plot_eps(x=0)
@pytest.mark.parametrize("transpose", [True, False])
def test_plot_eps(transpose):
ax = SCENE_FULL.plot_eps(x=0, transpose=transpose)
SCENE_FULL._add_cbar_eps(eps_min=1, eps_max=2, ax=ax)
plt.close()


def test_plot_eps_multiphysics():
@pytest.mark.parametrize("transpose", [True, False])
def test_plot_eps_multiphysics(transpose):
s = td.Scene(
structures=[
td.Structure(
Expand All @@ -70,20 +72,22 @@ def test_plot_eps_multiphysics():
]
)
assert s.structures[0].medium.name == "SiO2"
s.plot_eps(x=0)
s.plot_eps(x=0, transpose=transpose)


def test_plot_eps_bounds():
_ = SCENE_FULL.plot_eps(x=0, hlim=[-0.45, 0.45])
@pytest.mark.parametrize("transpose", [True, False])
def test_plot_eps_bounds(transpose):
_ = SCENE_FULL.plot_eps(x=0, hlim=[-0.45, 0.45], transpose=transpose)
plt.close()
_ = SCENE_FULL.plot_eps(x=0, vlim=[-0.45, 0.45])
_ = SCENE_FULL.plot_eps(x=0, vlim=[-0.45, 0.45], transpose=transpose)
plt.close()
_ = SCENE_FULL.plot_eps(x=0, hlim=[-0.45, 0.45], vlim=[-0.45, 0.45])
_ = SCENE_FULL.plot_eps(x=0, hlim=[-0.45, 0.45], vlim=[-0.45, 0.45], transpose=transpose)
plt.close()


def test_plot():
SCENE_FULL.plot(x=0)
@pytest.mark.parametrize("transpose", [True, False])
def test_plot(transpose):
SCENE_FULL.plot(x=0, transpose=transpose)
plt.close()


Expand All @@ -93,44 +97,48 @@ def test_plot_1d_scene():
plt.close()


def test_plot_bounds():
_ = SCENE_FULL.plot(x=0, hlim=[-0.45, 0.45])
@pytest.mark.parametrize("transpose", [True, False])
def test_plot_bounds(transpose):
_ = SCENE_FULL.plot(x=0, hlim=[-0.45, 0.45], transpose=transpose)
plt.close()
_ = SCENE_FULL.plot(x=0, vlim=[-0.45, 0.45])
_ = SCENE_FULL.plot(x=0, vlim=[-0.45, 0.45], transpose=transpose)
plt.close()
_ = SCENE_FULL.plot(x=0, hlim=[-0.45, 0.45], vlim=[-0.45, 0.45])
_ = SCENE_FULL.plot(x=0, hlim=[-0.45, 0.45], vlim=[-0.45, 0.45], transpose=transpose)
plt.close()


def test_structure_alpha():
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=None)
@pytest.mark.parametrize("transpose", [True, False])
def test_structure_alpha(transpose):
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=None, transpose=transpose)
plt.close()
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=-1)
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=-1, transpose=transpose)
plt.close()
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=1)
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=1, transpose=transpose)
plt.close()
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=0.5)
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=0.5, transpose=transpose)
plt.close()
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=0.5, cbar=True)
_ = SCENE_FULL.plot_structures_eps(x=0, alpha=0.5, cbar=True, transpose=transpose)
plt.close()
new_structs = [
td.Structure(geometry=s.geometry, medium=SCENE_FULL.medium) for s in SCENE_FULL.structures
]
S2 = SCENE_FULL.copy(update={"structures": new_structs})
_ = S2.plot_structures_eps(x=0, alpha=0.5)
_ = S2.plot_structures_eps(x=0, alpha=0.5, transpose=transpose)
plt.close()


def test_plot_with_units():
@pytest.mark.parametrize("transpose", [True, False])
def test_plot_with_units(transpose):
scene_with_units = SCENE_FULL.updated_copy(plot_length_units="nm")
scene_with_units.plot(x=-0.5)
scene_with_units.plot(x=-0.5, transpose=transpose)


def test_filter_structures():
@pytest.mark.parametrize("transpose", [True, False])
def test_filter_structures(transpose):
s1 = td.Structure(geometry=td.Box(size=(1, 1, 1)), medium=SCENE.medium)
s2 = td.Structure(geometry=td.Box(size=(1, 1, 1), center=(1, 1, 1)), medium=SCENE.medium)
plane = td.Box(center=(0, 0, 1.5), size=(td.inf, td.inf, 0))
SCENE._filter_structures_plane_medium(structures=[s1, s2], plane=plane)
SCENE._filter_structures_plane_medium(structures=[s1, s2], plane=plane, transpose=transpose)


def test_get_structure_plot_params():
Expand Down
Loading
Loading