<div dir="ltr">That's exactly what I need, thanks so much Nathan!</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 8, 2016 at 3:58 PM, Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Mon, Aug 8, 2016 at 2:49 PM, Rasmi Elasmar <span dir="ltr"><<a href="mailto:re2300@columbia.edu" target="_blank">re2300@columbia.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>I'm trying to gaussian smooth a 3D field of gas. I'm convolving the field with a gaussian kernel, but my results look odd. I think this might be because of how I'm reshaping my data. You can see my scripts <a href="https://github.com/rasmi/deviant-cosmology/blob/master/scripts/convolve.py" target="_blank">here</a> and <a href="https://github.com/rasmi/deviant-cosmology/blob/4f6b4886c01c92cfe3987d4a66e25ba84ecebf86/scripts/convolve.py" target="_blank">here</a>, and a more detailed explanation with plots <a href="https://github.com/astropy/astropy/issues/5169#issuecomment-238304706" target="_blank">here</a>.</div><div><br></div><div>My suspicion (and someone from astropy's) is that I'm reshaping data improperly. I access the fields like this:</div><div><span style="color:rgb(51,51,51);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap">ad </span><span style="color:rgb(167,29,93);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap">=</span><span style="color:rgb(51,51,51);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap"> ds.all_data()</span><br></div><div><span style="color:rgb(51,51,51);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap">density </span><span style="color:rgb(167,29,93);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap">=</span><span style="color:rgb(51,51,51);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap"> ad[fields[</span><span style="color:rgb(24,54,145);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap"><span>'</span>density<span>'</span></span><span style="color:rgb(51,51,51);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap">]]</span><span style="color:rgb(51,51,51);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap"><br></span></div><div>Which gives me a 1D array of length (1024^3) = 1073741824. To convolve this with a 3D gaussian kernel, I attempt to reshape the 1D array into its original 3D shape:</div><div><span style="color:rgb(51,51,51);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap">density </span><span style="color:rgb(167,29,93);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap">=</span><span style="color:rgb(51,51,51);font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;line-height:20px;white-space:pre-wrap"> density.reshape(ds.domain_dime<wbr>nsions)</span><br></div>Which gives me a 3D 1024^3 matrix, but I'm not sure if this is correct. Does this correctly transform the 1D data from ds.all_data()[field] back into its 3D grid, or are things being misaligned somehow? Is there a better way to access a certain field's data in 3D without getting it in 1D first and reshaping?</div></blockquote><div><br></div></span><div>HI Ramsi,</div><div><br></div><div>As you've discovered, yt data objects return data as a flattened, unordered 1D array. Simply reshaping the data as you've done will not produce what you're expect them to produce, since the data are unordered.</div><div><br></div><div>It sounds like you're dealing with a uniform resolution dataset, and what I'm saying to you probably doesn't make much sense in that context, but keep in mind that yt can deal with multiresolution data natively, where this flattened, unordered representation is the most convenient way to deal with the data.</div><div><br></div><div>For this particular use case, I'd bet that what you really want is either a covering_grid data object or an arbitrary_grid data object:</div><div><br></div><div><a href="http://yt-project.org/doc/examining/low_level_inspection.html#examining-grid-data-in-a-fixed-resolution-array" target="_blank">http://yt-project.org/doc/<wbr>examining/low_level_<wbr>inspection.html#examining-<wbr>grid-data-in-a-fixed-<wbr>resolution-array</a><br></div><div><a href="http://yt-project.org/doc/analyzing/objects.html#arbitrary-grid" target="_blank">http://yt-project.org/doc/<wbr>analyzing/objects.html#<wbr>arbitrary-grid</a><br></div><div><br></div><div><a href="http://yt-project.org/doc/reference/api/generated/yt.data_objects.construction_data_containers.YTArbitraryGrid.html" target="_blank">http://yt-project.org/doc/<wbr>reference/api/generated/yt.<wbr>data_objects.construction_<wbr>data_containers.<wbr>YTArbitraryGrid.html</a><br></div><div><a href="http://yt-project.org/doc/reference/api/generated/yt.data_objects.construction_data_containers.YTCoveringGrid.html" target="_blank">http://yt-project.org/doc/<wbr>reference/api/generated/yt.<wbr>data_objects.construction_<wbr>data_containers.<wbr>YTCoveringGrid.html</a><br></div><div><br></div><div>A covering grid is a uniform resolution 3D version of the data object. For multiresolution data, this will simply sample the data at a single resolution level, using nearest neighbor interpolation where the data are too coarse, and sampling when the data are too finely resolved. Covering grids are somewhat restrictive, as the resolution of the grid much be a power-of-two multiple of the coarsest resolution of your data.</div><div><br></div><div>Arbitrary_grid lets you create uniform resolution data at an arbitrary position or resolution, so it's a bit more flexible, although it's not necessarily as "honest" a representation of the original dataset.</div><div><br></div><div>Hope that helped clear things up, please let us know if you have additional questions.</div><div><br></div><div>-Nathan</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div><br></div><div>Thanks,</div><div><br></div><div>Rasmi</div></div>
<br>______________________________<wbr>_________________<br>
yt-dev mailing list<br>
<a href="mailto:yt-dev@lists.spacepope.org" target="_blank">yt-dev@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/lis<wbr>tinfo.cgi/yt-dev-spacepope.org</a><br>
<br></blockquote></div><br></div></div>
<br>______________________________<wbr>_________________<br>
yt-dev mailing list<br>
<a href="mailto:yt-dev@lists.spacepope.org">yt-dev@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-dev-spacepope.<wbr>org</a><br>
<br></blockquote></div><br></div>