Skip to content

Commit 817ad32

Browse files
committed
clean up remaining generated test outputs
1 parent ca4c1a3 commit 817ad32

3 files changed

Lines changed: 75 additions & 71 deletions

File tree

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import tempfile
23
from pathlib import Path
34

45
import pytest
@@ -23,53 +24,54 @@
2324

2425
@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
2526
def test_vtk(solver_output_path: Path, solver_output_simid_jobid: tuple[int, int], zarr_path: Path) -> None:
26-
sim_id, job_id = solver_output_simid_jobid
27-
result = Result(solver_output_dir=solver_output_path, sim_id=sim_id, job_id=job_id, zarr_dir=zarr_path)
28-
mesh: CartesianMesh = result.mesh
29-
domain_names: list[str] = mesh.get_volume_domain_names()
30-
assert domain_names == ["Nucleus", "cytosol", "ec"]
31-
channel_names = [c.label for c in result.channel_data]
32-
assert channel_names == ["region_mask", "t", "x", "y", "z", "C_cyt", "Ran_cyt", "RanC_cyt", "RanC_nuc", "J_r0"]
33-
times: list[float] = result.time_points
34-
assert times == [0.0, 0.25, 0.5, 0.75, 1.0]
27+
with tempfile.TemporaryDirectory() as tmpdirname, Path(tmpdirname) as tmp_dir:
28+
sim_id, job_id = solver_output_simid_jobid
29+
result = Result(solver_output_dir=solver_output_path, sim_id=sim_id, job_id=job_id, zarr_dir=tmp_dir)
30+
mesh: CartesianMesh = result.mesh
31+
domain_names: list[str] = mesh.get_volume_domain_names()
32+
assert domain_names == ["Nucleus", "cytosol", "ec"]
33+
channel_names = [c.label for c in result.channel_data]
34+
assert channel_names == ["region_mask", "t", "x", "y", "z", "C_cyt", "Ran_cyt", "RanC_cyt", "RanC_nuc", "J_r0"]
35+
times: list[float] = result.time_points
36+
assert times == [0.0, 0.25, 0.5, 0.75, 1.0]
3537

36-
domain_name = domain_names[0]
38+
domain_name = domain_names[0]
3739

38-
vis_mesh: VisMesh = from_mesh_data(cartesian_mesh=mesh, domain_name=domain_name, b_volume=True)
40+
vis_mesh: VisMesh = from_mesh_data(cartesian_mesh=mesh, domain_name=domain_name, b_volume=True)
3941

40-
assert vis_mesh.visVoxels is not None
41-
finite_volume_indices: list[FiniteVolumeIndex] = [
42-
vox.finiteVolumeIndex for vox in vis_mesh.visVoxels if vox.finiteVolumeIndex is not None
43-
]
44-
finite_volume_index_data: FiniteVolumeIndexData = FiniteVolumeIndexData(
45-
domainName=domain_name, finiteVolumeIndices=finite_volume_indices
46-
)
47-
empty_mesh_file: Path = Path(f"empty_mesh_{domain_name}.vtu")
48-
index_file: Path = Path(f"index_file_{domain_name}.json")
49-
assert empty_mesh_file.name == "empty_mesh_Nucleus.vtu"
50-
assert index_file.name == "index_file_Nucleus.json"
51-
write_finite_volume_index_data(
52-
finite_volume_index_file=index_file, finite_volume_index_data=finite_volume_index_data
53-
)
42+
assert vis_mesh.visVoxels is not None
43+
finite_volume_indices: list[FiniteVolumeIndex] = [
44+
vox.finiteVolumeIndex for vox in vis_mesh.visVoxels if vox.finiteVolumeIndex is not None
45+
]
46+
finite_volume_index_data: FiniteVolumeIndexData = FiniteVolumeIndexData(
47+
domainName=domain_name, finiteVolumeIndices=finite_volume_indices
48+
)
49+
empty_mesh_file = tmp_dir / f"empty_mesh_{domain_name}.vtu"
50+
index_file = tmp_dir / f"index_file_{domain_name}.json"
51+
assert empty_mesh_file.name == "empty_mesh_Nucleus.vtu"
52+
assert index_file.name == "index_file_Nucleus.json"
53+
write_finite_volume_index_data(
54+
finite_volume_index_file=index_file, finite_volume_index_data=finite_volume_index_data
55+
)
5456

55-
write_finite_volume_smoothed_vtk_grid_and_index_data(
56-
vis_mesh=vis_mesh, domain_name=domain_name, vtu_file=empty_mesh_file, index_file=index_file
57-
)
57+
write_finite_volume_smoothed_vtk_grid_and_index_data(
58+
vis_mesh=vis_mesh, domain_name=domain_name, vtu_file=empty_mesh_file, index_file=index_file
59+
)
5860

59-
var_name = "Nucleus::RanC_nuc"
60-
simple_var_name = var_name.split("::")[-1]
61-
time: float = times[0]
62-
data_array: NDArray1D = result.pde_dataset.get_data(var_name, time)
63-
new_mesh_file: Path = Path(f"mesh_{domain_name}_{simple_var_name}_{time}.vtu")
64-
assert new_mesh_file.name == "mesh_Nucleus_RanC_nuc_0.0.vtu"
65-
write_data_array_to_new_vtk_file(
66-
empty_mesh_file=empty_mesh_file, var_name=var_name, data=data_array, new_mesh_file=new_mesh_file
67-
)
61+
var_name = "Nucleus::RanC_nuc"
62+
simple_var_name = var_name.split("::")[-1]
63+
time: float = times[0]
64+
data_array: NDArray1D = result.pde_dataset.get_data(var_name, time)
65+
new_mesh_file = tmp_dir / f"mesh_{domain_name}_{simple_var_name}_{time}.vtu"
66+
assert new_mesh_file.name == "mesh_Nucleus_RanC_nuc_0.0.vtu"
67+
write_data_array_to_new_vtk_file(
68+
empty_mesh_file=empty_mesh_file, var_name=var_name, data=data_array, new_mesh_file=new_mesh_file
69+
)
6870

69-
# plot with pyvista
70-
pyvista_mesh = pyvista.read(str(new_mesh_file))
71-
# pyvista_mesh.plot()
72-
plotter = pyvista.Plotter(off_screen=True)
73-
plotter.add_mesh(pyvista_mesh)
74-
plotter.screenshot(f"mesh_{domain_name}_{simple_var_name}_{time}.png")
75-
plotter.close()
71+
# plot with pyvista
72+
pyvista_mesh = pyvista.read(str(new_mesh_file))
73+
# pyvista_mesh.plot()
74+
plotter = pyvista.Plotter(off_screen=True)
75+
plotter.add_mesh(pyvista_mesh)
76+
plotter.screenshot(tmp_dir / f"mesh_{domain_name}_{simple_var_name}_{time}.png")
77+
plotter.close()

tests/sim_results/test_result.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# test result class
22
import os
3+
import tempfile
34
from pathlib import Path
45

56
import numpy as np
@@ -13,21 +14,22 @@
1314

1415
@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
1516
def test_plot_slice_2D(solver_output_path: Path, solver_output_simid_jobid: tuple[int, int], zarr_path: Path) -> None:
16-
sim_id, job_id = solver_output_simid_jobid
17-
result = Result(solver_output_dir=solver_output_path, sim_id=sim_id, job_id=job_id, zarr_dir=zarr_path)
18-
19-
expected_labels = ["region_mask", "t", "x", "y", "z", "C_cyt", "Ran_cyt", "RanC_cyt", "RanC_nuc", "J_r0"]
20-
assert [channel.label for channel in result.channel_data] == expected_labels
21-
22-
concentrations: NDArray2D = result.concentrations
23-
expected_concentrations = [
24-
[0.00000000e00, 1.66853643e-07, 5.37844509e-07, 1.01317108e-06, 1.53753808e-06],
25-
[0.00000000e00, 1.66853643e-07, 5.37844509e-07, 1.01317108e-06, 1.53753808e-06],
26-
[0.00000000e00, 1.16874344e-06, 1.74755208e-06, 2.05505998e-06, 2.20346703e-06],
27-
[1.07657211e-05, 9.43012400e-06, 8.48032450e-06, 7.69749002e-06, 7.02471598e-06],
28-
[0.00000000e00, 1.16776305e-06, 1.73912167e-06, 2.02778643e-06, 2.14461288e-06],
29-
]
30-
assert str(concentrations) == str(np.array(object=expected_concentrations, dtype=np.float64))
31-
assert result.zarr_dataset.shape == (5, 10, 25, 71, 71)
32-
33-
result.plotter.plot_slice_2d(channel_name="Ran_cyt", time_index=0, z_index=0)
17+
with tempfile.TemporaryDirectory() as dirname, Path(dirname) as tmp_dir:
18+
sim_id, job_id = solver_output_simid_jobid
19+
result = Result(solver_output_dir=solver_output_path, sim_id=sim_id, job_id=job_id, zarr_dir=tmp_dir)
20+
21+
expected_labels = ["region_mask", "t", "x", "y", "z", "C_cyt", "Ran_cyt", "RanC_cyt", "RanC_nuc", "J_r0"]
22+
assert [channel.label for channel in result.channel_data] == expected_labels
23+
24+
concentrations: NDArray2D = result.concentrations
25+
expected_concentrations = [
26+
[0.00000000e00, 1.66853643e-07, 5.37844509e-07, 1.01317108e-06, 1.53753808e-06],
27+
[0.00000000e00, 1.66853643e-07, 5.37844509e-07, 1.01317108e-06, 1.53753808e-06],
28+
[0.00000000e00, 1.16874344e-06, 1.74755208e-06, 2.05505998e-06, 2.20346703e-06],
29+
[1.07657211e-05, 9.43012400e-06, 8.48032450e-06, 7.69749002e-06, 7.02471598e-06],
30+
[0.00000000e00, 1.16776305e-06, 1.73912167e-06, 2.02778643e-06, 2.14461288e-06],
31+
]
32+
assert str(concentrations) == str(np.array(object=expected_concentrations, dtype=np.float64))
33+
assert result.zarr_dataset.shape == (5, 10, 25, 71, 71)
34+
35+
result.plotter.plot_slice_2d(channel_name="Ran_cyt", time_index=0, z_index=0)

tests/vcml/test_vcml_writer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def test_vcml_writer_1D(vcml_spatial_model_1d_path: Path) -> None:
3636
assert compartment.dim == new_compartment.dim
3737

3838
# write out the new vcml string to a file so that it can be compared with original vcml file
39-
new_vcml_path = vcml_spatial_model_1d_path.with_name("new_vcml.xml")
40-
with open(new_vcml_path, "w") as f:
41-
f.write(new_vcml_str)
39+
# new_vcml_path = vcml_spatial_model_1d_path.with_name("new_vcml.xml")
40+
# with open(new_vcml_path, "w") as f:
41+
# f.write(new_vcml_str)
4242

4343
assert biomodel == new_biomodel
4444

@@ -76,9 +76,9 @@ def test_vcml_writer_3D(vcml_spatial_small_3d_path: Path) -> None:
7676
assert compartment.dim == new_compartment.dim
7777

7878
# write out the new vcml string to a file so that it can be compared with original vcml file
79-
new_vcml_path = vcml_spatial_small_3d_path.with_name("new_vcml_3d.xml")
80-
with open(new_vcml_path, "w") as f:
81-
f.write(new_vcml_str)
79+
# new_vcml_path = vcml_spatial_small_3d_path.with_name("new_vcml_3d.xml")
80+
# with open(new_vcml_path, "w") as f:
81+
# f.write(new_vcml_str)
8282

8383
assert biomodel == new_biomodel
8484

@@ -116,8 +116,8 @@ def test_vcml_writer_bunny_3D(vcml_spatial_bunny_3d_path: Path) -> None:
116116
assert compartment.dim == new_compartment.dim
117117

118118
# write out the new vcml string to a file so that it can be compared with original vcml file
119-
new_vcml_path = vcml_spatial_bunny_3d_path.with_name("new_vcml_3d.xml")
120-
with open(new_vcml_path, "w") as f:
121-
f.write(new_vcml_str)
119+
# new_vcml_path = vcml_spatial_bunny_3d_path.with_name("new_vcml_3d.xml")
120+
# with open(new_vcml_path, "w") as f:
121+
# f.write(new_vcml_str)
122122

123123
assert biomodel == new_biomodel

0 commit comments

Comments
 (0)