<div dir="ltr">Hi José,<div><br></div><div>Dealing with plotting a hierarchical grid in full generality (with/without ghost zones, handling multiple possibly overlapping components, ...) is a hard problem. </div><div>This is especially the case for 2/3D grids, which are commonly plotted with heatmaps/colormaps. To go around this, we resample the grids to a uniform grid</div><div>for plotting purposes. In kuibit, these are "UniformGridData". These can be plotted directly. </div><div><br></div><div>In the 1D case, we can just resample everything onto the finest grid, and that's why you see more points. By default, the resampling method is just nearest </div><div>neighbor, so this method is not making data up, just adding more "intermediate" points where there are fewer.</div><div><br></div><div>Indeed, as you say, HierarchicalGridData objects have all the information to plot one level at the time and it is probably feasible to use them for simple 1D plots.</div><div><br></div><div>`HierarchicalGridData` can be iterated over: when you iterate over with something like:</div><div><br></div><div><font face="monospace">for ref_level, component, grid_data in hier_grid:</font></div><div><font face="monospace"> Here you plot the grid_data</font></div><div><br></div><div>(I haven't tested this)</div><div><br></div><div>kuibit also has a method `to_GridSeries()`. This is a specialized method for 1D variables. Currently, this is only implemented for UniformGridData, so you'd have</div><div>to merge the refinement levels to use it. We could extend it to HierarchicalGridData and instead of resampling to the finest grid, we'd just collect all the points.</div><div>In this way, you could just call this method and call `plt.plot` to have a line plot (as you do with timeseries in kuibit). This should be straightforward (it's essentially</div><div>what I sketched above) and I can guide you to the implementation if that's something you'd be interested in contributing.</div><div><br></div><div>Please, let me know if this helps,</div><div>Gabriele</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 8, 2024 at 10:05 AM José Ferreira <<a href="mailto:jpmferreira@ua.pt">jpmferreira@ua.pt</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<div>
<p style="margin:0px 0px 1.2em">Dear toolkit
community,</p>
<p style="margin:0px 0px 1.2em"><br>
</p>
<p style="margin:0px 0px 1.2em">I’m struggling to
find a way to plot a 1D quantity in Kuibit without merging the
different meshes originated from the mesh refinement.</p>
<p style="margin:0px 0px 1.2em">As a workaround, I
have made a Python script that reads the file of a grid function
and plots every point along the axis and its corresponding
value. I can share this script if somebody is interested, but it
is not very good as it breaks once you use checkpoints and has
hardcoded paths. </p>
<p style="margin:0px 0px 1.2em">However, it gets the
job done, as you can see in an example plot below, where it is
hopefully obvious that there is an increase in the number of
points as z approaches 0.</p>
<img src="https://i.imgur.com/o0Ke1oi.png" width="454" height="431">
<p style="margin:0px 0px 1.2em">Obviously, a solution
that uses Kuibit would be much better. However, I cannot come up
with such a solution and so I’m writing this e-mail.</p>
<p style="margin:0px 0px 1.2em"><br>
</p>
<p style="margin:0px 0px 1.2em">From the
documentation, the object that represents the simulation data
(including the mesh refinement levels), is the <code style="font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;font-weight:550;background-color:rgba(119,119,119,0.3);border-radius:3px;display:inline">HierarchicalGridData</code>,
and I know how to go from a grid function to this object.</p>
<p style="margin:0px 0px 1.2em">For instance, to get
the <code style="font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;font-weight:550;background-color:rgba(119,119,119,0.3);border-radius:3px;display:inline">HierarchicalGridData</code>
that represents the real part of a scalar field along the x-axis
at t=0, we do</p>
<pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;font-weight:550;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;background:rgb(255,255,255);color:rgb(0,0,0);display:block">sd = SimDir(<span style="font-weight:normal;color:rgb(0,0,255)">"<output>"</span>)
gf = <a href="http://sd.gf" target="_blank">sd.gf</a>
phi1=gf.x[<span style="font-weight:normal;color:rgb(0,0,255)">"phi1"</span>].get_time(<span style="color:rgb(0,0,255)">0</span>)
</code></pre>
<p style="margin:0px 0px 1.2em">All I have to do now
is plot this somehow. As it turns out, this is impossible,
because according to the documentation</p>
<blockquote style="margin:1.2em 0px;border-left:4px solid rgb(51,117,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
<p style="margin:0px 0px 1.2em">We cannot plot
directly this object, because it is a complicated object. To
plot it, we have to merge the refinement levels to a single <code style="font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;font-weight:550;background-color:rgba(119,119,119,0.3);border-radius:3px;display:inline">UniformGridData</code>.
We can do this with <code style="font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;font-weight:550;background-color:rgba(119,119,119,0.3);border-radius:3px;display:inline">refinement_levels_merged()</code>.</p>
</blockquote>
<p style="margin:0px 0px 1.2em">But, all of the
information regarding the mesh refinement levels is here, so it
should be possible to extract this information and plot it,
right?</p>
<p style="margin:0px 0px 1.2em">Looking at the
methods and variables in <code style="font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;font-weight:550;background-color:rgba(119,119,119,0.3);border-radius:3px;display:inline">HierarchicalGridData</code>
I came up with nothing.</p>
<p style="margin:0px 0px 1.2em">Does anybody have a
solution to this?</p>
<p style="margin:0px 0px 1.2em"><br>
</p>
<p style="margin:0px 0px 1.2em">Thank you in advance,</p>
<p style="margin:0px 0px 1.2em">Best Regards,</p>
<p style="margin:0px 0px 1.2em">José Ferreira</p>
<p style="margin:0px 0px 1.2em"><br>
</p>
<div title="MDH:PHA+RGVhciB0b29sa2l0IGNvbW11bml0eSw8L3A+PHA+PGJyPjwvcD48cD5JJ20gc3RydWdnbGlu
ZyB0byBmaW5kIGEgd2F5IHRvIHBsb3QgYSAxRCBxdWFudGl0eSBpbiBLdWliaXQgd2l0aG91dCBt
ZXJnaW5nIHRoZSBkaWZmZXJlbnQgbWVzaGVzIG9yaWdpbmF0ZWQgZnJvbSB0aGUgbWVzaCByZWZp
bmVtZW50LjwvcD48cD5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VzaCByZWZp
bmVtZW50IGxldmVscyBpcyBoZXJlLCBzbyBpdCBzaG91bGQgYmUgcG9zc2libGUgdG8gZXh0cmFj
dCB0aGlzIGluZm9ybWF0aW9uIGFuZCBwbG90IGl0LCByaWdodD88L3A+PHA+TG9va2luZyBhdCB0
aGUgbWV0aG9kcyBhbmQgdmFyaWFibGVzIGluIGBIaWVyYXJjaGljYWxHcmlkRGF0YWAgSSBjYW1l
IHVwIHdpdGggbm90aGluZy48YnI+PC9wPjxwPjxicj48L3A+" aria-hidden="true" style="height:0px;width:0px;max-height:0px;max-width:0px;overflow:hidden;font-size:0px;padding:0px;margin:0px"></div>
</div>
</div>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@einsteintoolkit.org" target="_blank">Users@einsteintoolkit.org</a><br>
<a href="http://lists.einsteintoolkit.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.einsteintoolkit.org/mailman/listinfo/users</a><br>
</blockquote></div>