<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi all,<div class=""><br class=""></div><div class="">I’m working on some updates to my yt-based pyXSIM package and I’m stuck and I thought I would email this list for some guidance. </div><div class=""><br class=""></div><div class="">I’m thinking of a situation where we have a data object (sphere, box, whatever) and it straddles a periodic boundary. I want to convert the coordinates such that the coordinates are translated with respect to some arbitrary origin (say, the center of a sphere but in theory it could be anywhere), but are also continuous, i.e, they do not wrap at the boundary. </div><div class=""><br class=""></div><div class="">I’ve looked at the functions get_radius and get_periodic_rvec in yt/fields/field_functions.py, and based on that I have come up with the code below, but it doesn’t quite work for any arbitrary value of the “ctr” argument (the origin). I think it’s because the functions I mentioned only need to calculate absolute value differences in order to compute a radius. </div><div class=""><br class=""></div><div class="">The x, y, and z arguments to the function below are the input coordinate arrays. Could anyone who is more familiar with this sort of thing point out what I should be doing? </div><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">John Z</div><div class=""><br class=""></div><div class=""><pre style="background-color: rgb(255, 255, 255); font-family: Menlo; font-size: 9pt;" class=""><span style="color:#000080;font-weight:bold;" class="">def </span>get_periodic_coords(ds, ctr, x, y, z):<br class="">    coords = ds.arr(np.zeros((<span style="color:#0000ff;" class="">3</span>, x.size)), <span style="color:#008080;font-weight:bold;" class="">"kpc"</span>)<br class="">    coords[<span style="color:#0000ff;" class="">0</span>, :] = (x - ctr[<span style="color:#0000ff;" class="">0</span>]).to(<span style="color:#008080;font-weight:bold;" class="">"kpc"</span>)<br class="">    coords[<span style="color:#0000ff;" class="">1</span>, :] = (y - ctr[<span style="color:#0000ff;" class="">1</span>]).to(<span style="color:#008080;font-weight:bold;" class="">"kpc"</span>)<br class="">    coords[<span style="color:#0000ff;" class="">2</span>, :] = (z - ctr[<span style="color:#0000ff;" class="">2</span>]).to(<span style="color:#008080;font-weight:bold;" class="">"kpc"</span>)<br class="">    <span style="color:#000080;font-weight:bold;" class="">if </span><span style="color:#000080;" class="">sum</span>(ds.periodicity) == <span style="color:#0000ff;" class="">0</span>:<br class="">        <span style="color:#000080;font-weight:bold;" class="">return </span>coords<br class="">    dw = ds.domain_width.to(<span style="color:#008080;font-weight:bold;" class="">"kpc"</span>)<br class="">    <span style="color:#000080;font-weight:bold;" class="">for </span>i <span style="color:#000080;font-weight:bold;" class="">in </span><span style="color:#000080;" class="">range</span>(<span style="color:#0000ff;" class="">3</span>):<br class="">        <span style="color:#000080;font-weight:bold;" class="">if </span>ds.periodicity[i]: <br class="">            c = coords[i, :]<br class="">            cdw = c - dw[i]<br class="">            mins = np.argmin([np.abs(c), np.abs(cdw)], <span style="color:#660099;" class="">axis</span>=<span style="color:#0000ff;" class="">0</span>)<br class="">            ii = np.where(mins == <span style="color:#0000ff;" class="">1</span>)[<span style="color:#0000ff;" class="">0</span>]<br class="">            coords[i, ii] = coords[i, ii] - dw[i]<br class="">    <span style="color:#000080;font-weight:bold;" class="">return </span>coords<br class=""></pre><div class=""><br class=""></div></div></body></html>