From 0abac19ca00b43e5af4a18a122abc2aa92e37db0 Mon Sep 17 00:00:00 2001 From: chrishavlin Date: Wed, 27 Nov 2024 14:44:53 -0600 Subject: [PATCH] add a note on why ratio is needed in BlockCollection.add_data --- yt_idv/scene_data/block_collection.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/yt_idv/scene_data/block_collection.py b/yt_idv/scene_data/block_collection.py index 62ca149b..e0b9f57b 100644 --- a/yt_idv/scene_data/block_collection.py +++ b/yt_idv/scene_data/block_collection.py @@ -77,13 +77,18 @@ def add_data(self, field, no_ghost=False): LE = np.array([b.LeftEdge for i, b in self.blocks.values()]).min(axis=0) RE = np.array([b.RightEdge for i, b in self.blocks.values()]).max(axis=0) self.diagonal = np.sqrt(((RE - LE) ** 2).sum()) - # Now we set up our buffer - vert = np.array(vert, dtype="f4") + + # Note: the block LeftEdge and RightEdge arrays are plain np arrays in + # units of code_length, so need to convert to unitary units (in range 0,1) + # after the fact: units = self.data_source.ds.units ratio = (units.code_length / units.unitary).base_value dx = np.array(dx, dtype="f4") * ratio le = np.array(le, dtype="f4") * ratio re = np.array(re, dtype="f4") * ratio + + # Now we set up our buffer + vert = np.array(vert, dtype="f4") self.vertex_array.attributes.append( VertexAttribute(name="model_vertex", data=vert) )