Skip to content

Commit

Permalink
Try to track down inconsistencies in test output
Browse files Browse the repository at this point in the history
* Increase number of particles in GMM test set
* Force no downsampling
  • Loading branch information
apontzen committed Sep 29, 2023
1 parent 014bef9 commit 933e9e6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 30 deletions.
20 changes: 20 additions & 0 deletions src/topsy/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,26 @@ def get_sph_image(self) -> np.ndarray:
im = np_im[:,:,0]
return im

def get_presentation_image(self) -> np.ndarray:
texture_view = self.context.get_current_texture()
size = texture_view.size
bytes_per_pixel = 4 # NB this might be wrong in principle!
data = self.device.queue.read_texture(
{
"texture": texture_view.texture,
"mip_level": 0,
"origin": (0, 0, 0),
},
{
"offset": 0,
"bytes_per_row": bytes_per_pixel * size[0],
"rows_per_image": size[1],
},
size,
)

return np.frombuffer(data, np.uint8).reshape(size[1], size[0], 4)


def save(self, filename='output.pdf'):
image = self.get_sph_image()
Expand Down
62 changes: 32 additions & 30 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy.testing as npt

import topsy
from topsy.drawreason import DrawReason


from topsy.canvas import offscreen
Expand All @@ -13,46 +14,47 @@
def setup_module():
global vis, folder
np.random.seed(1337)
vis = topsy._test(1000, render_resolution=200, canvas_class = offscreen.VisualizerCanvas)
vis = topsy._test(10000, render_resolution=200, canvas_class = offscreen.VisualizerCanvas)

folder = Path(__file__).parent / "output"
folder.mkdir(exist_ok=True)

def test_render():
result = vis.canvas.draw()
image = np.frombuffer(result, dtype=np.dtype('u1')).reshape((480,640,4))
plt.imsave(folder / "test.png", image) # needs manual verification
vis.draw(reason=DrawReason.EXPORT)
result = vis.get_presentation_image()
plt.imsave(folder / "test.png", result) # needs manual verification

def test_sph_output():
vis.canvas.draw()
vis.draw(reason=DrawReason.EXPORT)
result = vis.get_sph_image()
assert result.shape == (200,200)
np.save(folder / "test.npy", result) # for debugging
test = result[::20,::20].flatten()
expect = np.array([6.6993198e-14, 1.1507333e-13, 1.7919646e-13, 2.4612135e-13,
2.9066495e-13, 2.8998280e-13, 2.4486413e-13, 1.7858511e-13,
1.1692387e-13, 7.2200106e-14, 1.2295605e-13, 2.3070537e-13,
3.9220626e-13, 5.8140309e-13, 7.2356704e-13, 7.2395855e-13,
5.7850269e-13, 3.8981690e-13, 2.3143754e-13, 1.2701774e-13,
2.1470363e-13, 4.4307169e-13, 8.4494868e-13, 1.4483490e-12,
2.0638049e-12, 2.2089444e-12, 1.6153356e-12, 8.8054764e-13,
4.4565604e-13, 2.1992054e-13, 3.3929980e-13, 7.7498327e-13,
1.7074509e-12, 3.5581679e-12, 7.1763611e-12, 1.1240477e-11,
6.7540001e-12, 2.4406371e-12, 8.5188578e-13, 3.5051858e-13,
4.6225659e-13, 1.1472580e-12, 2.8631052e-12, 7.8389873e-12,
4.1710101e-11, 1.3738759e-10, 4.3650156e-11, 6.5835722e-12,
1.5117496e-12, 4.9551118e-13, 5.2268747e-13, 1.3379199e-12,
3.5099410e-12, 1.2415209e-11, 1.2423079e-10, 4.4262038e-08,
1.2358496e-10, 9.5642834e-12, 1.8539040e-12, 5.8338073e-13,
4.8245164e-13, 1.1989600e-12, 2.9855599e-12, 9.4497708e-12,
4.7168668e-11, 1.2785455e-10, 3.6405660e-11, 5.7495324e-12,
1.4845271e-12, 5.4782660e-13, 3.6776891e-13, 8.5198087e-13,
1.8806679e-12, 4.1391638e-12, 9.1587961e-12, 1.2461185e-11,
6.2175061e-12, 2.2534507e-12, 9.6120670e-13, 4.2535973e-13,
2.3635561e-13, 5.1153889e-13, 9.9384986e-13, 1.7036724e-12,
2.4265887e-12, 2.4533247e-12, 1.7540835e-12, 1.0575305e-12,
5.7956190e-13, 2.8566545e-13, 1.3080068e-13, 2.7080400e-13,
4.8454578e-13, 7.4089178e-13, 9.3455235e-13, 9.4375126e-13,
7.7476540e-13, 5.3613396e-13, 3.2055389e-13, 1.6914180e-13],

expect = np.array([3.9287383e-13, 5.5050257e-13, 7.6353989e-13, 1.0141182e-12,
1.2393138e-12, 1.3240675e-12, 1.2094989e-12, 9.7496121e-13,
7.3494753e-13, 5.3885184e-13, 5.5531962e-13, 8.6450085e-13,
1.3481805e-12, 2.0611694e-12, 2.8464824e-12, 3.1656967e-12,
2.7328623e-12, 1.9321500e-12, 1.2500829e-12, 8.1329621e-13,
7.8355118e-13, 1.3631815e-12, 2.5299955e-12, 4.9601534e-12,
8.3184406e-12, 9.9214205e-12, 7.7984988e-12, 4.4260927e-12,
2.2768317e-12, 1.2318675e-12, 1.0535535e-12, 2.0777362e-12,
5.0366386e-12, 1.4153312e-11, 3.6467555e-11, 5.4102028e-11,
3.1363929e-11, 1.1786298e-11, 4.2883514e-12, 1.8357449e-12,
1.2924806e-12, 2.9085404e-12, 9.0102639e-12, 4.0556905e-11,
2.7220667e-10, 1.2469481e-09, 2.3019615e-10, 2.9873597e-11,
7.1707609e-12, 2.5135124e-12, 1.3953204e-12, 3.3737598e-12,
1.1420813e-11, 6.7440817e-11, 1.1875348e-09, 1.7286030e-07,
1.0353859e-09, 5.0008213e-11, 8.8475668e-12, 2.8494353e-12,
1.2956567e-12, 3.0306443e-12, 9.2138432e-12, 3.9570687e-11,
2.7873756e-10, 8.7612456e-10, 2.3548541e-10, 3.2350695e-11,
7.3600839e-12, 2.5689867e-12, 1.0495618e-12, 2.1662457e-12,
5.3645061e-12, 1.4507441e-11, 3.7246033e-11, 5.5721056e-11,
3.3367049e-11, 1.2087110e-11, 4.4923006e-12, 1.9295540e-12,
7.7805151e-13, 1.3838001e-12, 2.6602041e-12, 5.2666170e-12,
9.0259146e-12, 1.0758684e-11, 8.2174345e-12, 4.7123286e-12,
2.4574930e-12, 1.3119297e-12, 5.5245814e-13, 8.6899753e-13,
1.3761681e-12, 2.1119391e-12, 2.9193512e-12, 3.2884075e-12,
2.8896930e-12, 2.0867015e-12, 1.3551895e-12, 8.6546113e-13],
dtype=np.float32)
npt.assert_allclose(test, expect, rtol=1e-4)

0 comments on commit 933e9e6

Please sign in to comment.