Skip to content

XY transposable plots V3 part 2: Updated all remaining plot functions (issue1072) #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 1 commit into
base: jewettaijfc/issue1072_v3_part1_geom
Choose a base branch
from
Open
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
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
26 changes: 14 additions & 12 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 Expand Up @@ -526,21 +527,22 @@ def make_heat_sim_data():
return heat_sim_data


def test_sim_data():
@pytest.mark.parametrize("transpose", [True, False])
def test_sim_data(transpose):
heat_sim_data = make_heat_sim_data()
_ = heat_sim_data.plot_field("test", z=0)
_ = heat_sim_data.plot_field("tri")
_ = heat_sim_data.plot_field("tet", y=0.5)
_ = heat_sim_data.plot_field("test", z=0, transpose=transpose)
_ = heat_sim_data.plot_field("tri", transpose=transpose)
_ = heat_sim_data.plot_field("tet", y=0.5, transpose=transpose)
plt.close()

with pytest.raises(DataError):
_ = heat_sim_data.plot_field("empty")
_ = heat_sim_data.plot_field("empty", transpose=transpose)

with pytest.raises(DataError):
_ = heat_sim_data.plot_field("test")
_ = heat_sim_data.plot_field("test", transpose=transpose)

with pytest.raises(KeyError):
_ = heat_sim_data.plot_field("test3", x=0)
_ = heat_sim_data.plot_field("test3", x=0, transpose=transpose)

with pytest.raises(pd.ValidationError):
_ = heat_sim_data.updated_copy(data=[heat_sim_data.data[0]] * 2)
Expand Down
75 changes: 46 additions & 29 deletions tests/test_components/test_heat_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,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,
Expand Down Expand Up @@ -1057,33 +1058,46 @@ def test_heat_charge_simulation(simulation_data):
mesher = mesh_data.mesher
assert mesher is not None, "VolumeMesher 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):
@pytest.mark.parametrize("transpose", [True, False])
def test_sim_data_plotting(transpose: bool, simulation_data):
"""Tests whether simulation data can be plotted and appropriate errors are raised."""
heat_sim_data, cond_sim_data, cap_sim_data, fc_sim_data, mesh_data = simulation_data

# Plotting temperature data
heat_sim_data.plot_field("test", z=0)
heat_sim_data.plot_field("tri")
heat_sim_data.plot_field("tet", y=0.5)
heat_sim_data.plot_field("test", z=0, transpose=transpose)
heat_sim_data.plot_field("tri", transpose=transpose)
heat_sim_data.plot_field("tet", y=0.5, transpose=transpose)

# Plotting voltage data
cond_sim_data.plot_field("v_test", z=0)
cond_sim_data.plot_field("v_tri")
cond_sim_data.plot_field("v_tet", y=0.5)
cond_sim_data.plot_field("v_test", z=0, transpose=transpose)
cond_sim_data.plot_field("v_tri", transpose=transpose)
cond_sim_data.plot_field("v_tet", y=0.5, transpose=transpose)
plt.close()

# Test plotting with no data
with pytest.raises(DataError):
heat_sim_data.plot_field("empty")
heat_sim_data.plot_field("empty", transpose=transpose)

# Test plotting with 3D data
with pytest.raises(DataError):
heat_sim_data.plot_field("test")
heat_sim_data.plot_field("test", transpose=transpose)

# Test plotting with invalid key
with pytest.raises(KeyError):
heat_sim_data.plot_field("test3", x=0)
heat_sim_data.plot_field("test3", x=0, transpose=transpose)

# Test updating simulation data with duplicate data
with pytest.raises(pd.ValidationError):
Expand All @@ -1099,42 +1113,43 @@ def test_sim_data_plotting(simulation_data):
heat_sim_data.updated_copy(simulation=sim)


def test_mesh_plotting(simulation_data):
@pytest.mark.parametrize("transpose", [True, False])
def test_mesh_plotting(transpose: bool, simulation_data):
"""Tests whether mesh can be plotted and appropriate errors are raised."""
heat_sim_data, cond_sim_data, cap_sim_data, fc_sim_data, mesh_data = simulation_data

# Plotting mesh from unstructured temperature data
heat_sim_data.plot_mesh("tri")
heat_sim_data.plot_mesh("tet", y=0.5)
heat_sim_data.plot_mesh("tri", transpose=transpose)
heat_sim_data.plot_mesh("tet", y=0.5, transpose=transpose)

# Plotting mesh from unstructured voltage data
cond_sim_data.plot_mesh("v_tri", structures_fill=False)
cond_sim_data.plot_mesh("v_tet", y=0.5)
cond_sim_data.plot_mesh("v_tri", structures_fill=False, transpose=transpose)
cond_sim_data.plot_mesh("v_tet", y=0.5, transpose=transpose)

# Plotting mesh from mesh data
mesh_data.plot_mesh("mesh_test", z=0)
mesh_data.plot_mesh("mesh_test", z=0, transpose=transpose)

plt.close()

# Test plotting from structured data
with pytest.raises(DataError):
heat_sim_data.plot_mesh("test")
heat_sim_data.plot_mesh("test", transpose=transpose)

# Test plotting with no data
with pytest.raises(DataError):
heat_sim_data.plot_mesh("empty")
heat_sim_data.plot_mesh("empty", transpose=transpose)

# Test plotting with 3D data
with pytest.raises(DataError):
heat_sim_data.plot_mesh("tet")
heat_sim_data.plot_mesh("tet", transpose=transpose)

# Test plotting with invalid key
with pytest.raises(KeyError):
heat_sim_data.plot_mesh("test3", x=0)
heat_sim_data.plot_mesh("test3", x=0, transpose=transpose)

# Test plotting with invalid field_name
with pytest.raises(DataError):
mesh_data.plot_mesh("mesh_test", z=0, field_name="wrong")
mesh_data.plot_mesh("mesh_test", z=0, field_name="wrong", transpose=transpose)


def test_conduction_simulation_has_conductors(conduction_simulation, structures):
Expand Down Expand Up @@ -1635,27 +1650,29 @@ def test_dynamic_simulation_updates(heat_simulation):
assert updated_sim.monitors[-1].name == "new_temp_mnt"


def test_plotting_functions(simulation_data):
@pytest.mark.parametrize("transpose", [True, False])
def test_plotting_functions(transpose: bool, simulation_data):
"""Test plotting functions with various data."""
heat_sim_data, cond_sim_data, cap_sim_data, fc_sim_data, mesh_data = simulation_data

# Valid plotting
try:
heat_sim_data.plot_field("test", z=0)
cond_sim_data.plot_field("v_test", y=1)
heat_sim_data.plot_field("test", z=0, transpose=transpose)
cond_sim_data.plot_field("v_test", y=1, transpose=transpose)
except Exception as e:
pytest.fail(f"Plotting raised an exception unexpectedly: {e}")

# Invalid field name
with pytest.raises(KeyError):
heat_sim_data.plot_field("non_existent_field")
heat_sim_data.plot_field("non_existent_field", transpose=transpose)

# Invalid plotting parameters
with pytest.raises(KeyError):
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 @@ -1795,8 +1812,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
24 changes: 13 additions & 11 deletions tests/test_components/test_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,18 @@ def get_mode_sim():
return sim


def test_mode_sim():
@pytest.mark.parametrize("transpose", [True, False])
def test_mode_sim(transpose: bool):
with AssertLogLevel(None):
sim = get_mode_sim()
_ = sim.plot(ax=AX)
_ = sim.plot(ax=AX, fill_structures=False, hlim=(-1, 1), vlim=(-1, 1))
_ = sim.plot(y=0, ax=AX)
_ = sim.plot_mode_plane(ax=AX)
_ = sim.plot_eps_mode_plane(ax=AX)
_ = sim.plot_structures_eps_mode_plane(ax=AX)
_ = sim.plot_grid_mode_plane(ax=AX)
_ = sim.plot_pml_mode_plane(ax=AX)
_ = sim.plot(ax=AX, transpose=transpose)
_ = sim.plot(ax=AX, fill_structures=False, hlim=(-1, 1), vlim=(-1, 1), transpose=transpose)
_ = sim.plot(y=0, ax=AX, transpose=transpose)
_ = sim.plot_mode_plane(ax=AX, transpose=transpose)
_ = sim.plot_eps_mode_plane(ax=AX, transpose=transpose)
_ = sim.plot_structures_eps_mode_plane(ax=AX, transpose=transpose)
_ = sim.plot_grid_mode_plane(ax=AX, transpose=transpose)
_ = sim.plot_pml_mode_plane(ax=AX, transpose=transpose)
_ = sim.reduced_simulation_copy
_ = sim.run_local()
_ = sim._mode_solver.sim_data
Expand Down Expand Up @@ -327,9 +328,10 @@ def get_mode_sim_data():
return sim_data


def test_mode_sim_data():
@pytest.mark.parametrize("transpose", [True, False])
def test_mode_sim_data(transpose: bool):
sim_data = get_mode_sim_data()
_ = sim_data.plot_field("Ey", ax=AX, mode_index=0, f=FS[0])
_ = sim_data.plot_field("Ey", ax=AX, mode_index=0, f=FS[0], transpose=transpose)


def test_plane_crosses_symmetry_plane_warning(monkeypatch):
Expand Down
Loading