<div dir="ltr">Ok.  I'm really new to yt, so I apologize for the stupid question, but: how do I access the particle field explicitly and then convert to a grid? <div>-Jared</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 26, 2015 at 11:37 AM, Cameron Hummels <span dir="ltr"><<a href="mailto:chummels@gmail.com" target="_blank">chummels@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">The best way to do this would be to make the HI number density field from the particle fields and then deposit it on the grid and sample that.  The absorption spectrum infrastructure requires the fields it samples to be grid-based fields.</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 26, 2015 at 8:34 AM, Jared Coughlin <span dir="ltr"><<a href="mailto:Jared.W.Coughlin.29@nd.edu" target="_blank">Jared.W.Coughlin.29@nd.edu</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">My ultimate goal is to make an absorption spectrum, so I was trying to add an HI number density field.  I don't have any experience working with grid based codes, only sph, so I was assuming that I was using the particle positions.<span><font color="#888888"><div>-Jared</div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 26, 2015 at 11:25 AM, 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">So the issue is that you're combining particle fields, which are defined at the location of your SPH particles, with fields that are defined on the octree mesh.<div><br></div><div>data['Gas', 'InternalEnergy']<br></div><div><br></div><div>^ is a particle field defined at the locations of your SPH particles (particles of type 'Gas').</div><div><br></div><div>data['gas', 'density']<br></div><div><br></div><div>^ is a mesh field defined at the cell centers of the octree mesh yt constructs in memory. It's specifically generated an SPH smoothing operation.</div><div><br></div><div>The reasons the shapes of the arrays you're getting back are different is that the number of leaf octree cells is not the same as the number of Gas particles.</div><div><br></div><div>I'm not sure if what you're trying to do is supposed to use the mesh locations or the particle locations. The correct way to modify your script would be different in the two cases.</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 26, 2015 at 10:17 AM, Jared Coughlin <span dir="ltr"><<a href="mailto:Jared.W.Coughlin.29@nd.edu" target="_blank">Jared.W.Coughlin.29@nd.edu</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">Sorry about that! Here's the script: <div><br></div><div><a href="http://paste.yt-project.org/show/5842/" target="_blank">http://paste.yt-project.org/show/5842/</a><br></div><div><br></div><div>And the traceback:</div><div><br></div><div><a href="http://paste.yt-project.org/show/5843/" target="_blank">http://paste.yt-project.org/show/5843/</a><br></div><div><br></div><div>Thanks!</div><span><font color="#888888"><div>-Jared</div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 25, 2015 at 7:41 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"><span><br><br>On Tuesday, August 25, 2015, Jared Coughlin <<a href="mailto:Jared.W.Coughlin.29@nd.edu" target="_blank">Jared.W.Coughlin.29@nd.edu</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello! I'm really sorry for the barrage of questions; hopefully this will be the last one! <div>I now get the error:  operands could not be broadcast together with shapes (2072685,) (2153824,)</div><div>on line: fHI = (recomb * ne) / (gamma_HI + (gamma_c * ne))</div><div><br></div><div>I printed the shapes of all of those arrays, and this is what I get: </div><div>nH.shape </div><div>(16, 16, 16)</div><div>ne.shape </div><div>(16, 16, 16)</div><div>gamma_c.shape </div><div>(1,)</div><div>recomb.shape </div><div>(1,)</div><div>nH.shape </div><div>(2153824,)</div><div>ne.shape </div><div>(2153824,)</div><div>gamma_c.shape </div><div>(2072685,)</div><div>recomb.shape </div><div>(2072685,)</div><div><br></div><div>Firstly, I'm a little confused as to why their dimensions change, but what really matters are the bottom ones.  I know how many gas particles are in my gadget simulation: 2072685.  All of the arrays were created from either data["Gas", "InternalEnergy"] or data["gas", "density"], which should, I would imagine, have the same dimensions: the number of gas particles.  I was just wondering if anyone had seen something like this before? The function in question was posted to a pastebin in an earlier email on this thread, and I have since made all of the arrays YTArrays, as suggested above. Thanks!</div><div>-Jared</div><div><br></div></div></blockquote><div><br></div></span><div>Hey Jared,</div><div><br></div>I looked above but can't seem to find the correct link for the script you're using<span></span>. Can you pastebin your updated script and the full error tracrback you're seeing now?<div><div><span><font color="#888888"><div><br></div></font></span><div><span><font color="#888888">Nathan</font></span><div><div><br><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 25, 2015 at 5:58 PM, Jared Coughlin <span dir="ltr"><<a>Jared.W.Coughlin.29@nd.edu</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">Thanks, I'll try that!<span><font color="#888888"><div>-Jared</div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 25, 2015 at 5:55 PM, Andrew Myers <span dir="ltr"><<a>atmyers2@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">Hi Jared, <div><br></div><div>You probably don't want to loop over the entire array in pure python; that could be very slow for large datasets. One thing you can do is use slicing to select the elements of the array that meet your criterion:</div><div><br></div><div>indices = <span style="font-size:12.8000001907349px">data['gas','InternalEnergy'] <= 1e4</span></div><div><span style="font-size:12.8000001907349px">data['gas', 'InternalEnergy'][indices] = *something*</span><br></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">that would set all the elements where the InternalEnergy field is less than or equal to 1e4 to *something*. Usually you can express most operations you'd want to do this way without explicitly looping over the elements. </span></div><span><font color="#888888"><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">-Andrew</span></div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 25, 2015 at 2:44 PM, Jared Coughlin <span dir="ltr"><<a>Jared.W.Coughlin.29@nd.edu</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">That seemed to have worked, thanks!<div><br></div><div>I just have another quick question, if you wouldn't mind? In my function to generate my new field, there's an if statement that looks at the value of the temperature: if data['gas','InternalEnergy'] <= 1e4:</div><div>However, I get the error: "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()." I wasn't sure how to loop over the elements of the array to access a specific element, or if that's even possible? Using a.any() or a.all() don't seem to fit the bill for this particular problem, either. Thanks!</div><span><font color="#888888"><div>-Jared</div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 25, 2015 at 3:19 PM, Nathan Goldbaum <span dir="ltr"><<a>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>On Tue, Aug 25, 2015 at 2:17 PM, Jared Coughlin <span dir="ltr"><<a>Jared.W.Coughlin.29@nd.edu</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">Great, thanks! I tried that, and it gave me the error: "YTQuantity instances must be scalars." I'm not sure what to do about that, since all of these quantities depend on either temperature or density, both of which are arrays. I tried looking at the doc page for YTQuantity, but I didn't see anything that looked like it could solve this problem, though it's possible I missed it.  </div></blockquote><div><br></div></span><div>You need to use YTArray instead. YTQuantity is a subclass of YTArray that only holds scalars. YTArray can hold arrays of data with units.</div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span><font color="#888888"><div>-Jared</div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 24, 2015 at 8:13 PM, Nathan Goldbaum <span dir="ltr"><<a>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"><span><br><br>On Monday, August 24, 2015, Cameron Hummels <<a>chummels@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Jared,<div><br></div><div>The problem is one of units.  In order to make common arithmetic work like addition, yt requires both arguments going into the addition operator to have the same units.</div><div><br></div><div><span style="color:rgb(0,0,0);font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px">In your line, </span></div><div><span style="color:rgb(0,0,0);font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px">fHI = (recomb * ne) / (gamma_HI + (gamma_c *ne))</span></div><div><br></div><div>you're adding two things (gamma_HI) and (gamma_c*ne) that have different units--in this case, something with <span style="color:rgb(0,0,0);font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px">(code_mass/code_length**3) units and something with no units defined as (1).</span></div><div></div></div></blockquote><div><br></div></span><div>Just a quick clarification: they need not have the same units, just the same dimensions.  You can add two quantities with units of grams and solar masses (for example) but not grams and liters.<span></span></div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div><br></div><div>In order to fix this, you can re-assign the appropriate units to different arrays or quantities with the YTArray and YTQuantity classes.  In this case, make sure that the two arguments going into the addition have the same units.  If you want to recast "ne" to have number density units, you can do this:  from yt.units.yt_array import YTQuantity; ne = YTQuantity(ne, 'cm**-3').  For more info on units, check out <a href="http://yt-project.org/docs/dev/analyzing/units/index.html" target="_blank">http://yt-project.org/docs/dev/analyzing/units/index.html</a></div><div><br></div><div>I hope this helps!</div><div><br></div><div>Cameron</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 24, 2015 at 4:12 PM, Jared Coughlin <span dir="ltr"><<a>Jared.W.Coughlin.29@nd.edu</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">Hello! I have a gadget snapshot for which the standard internal energy block has been replaced by one containing the temperature.  I'm trying to calculate a derived field for the neutral hydrogen number density,  but I'm getting an error when I try to do ds.add_field():<div><br></div><div><a href="http://paste.yt-project.org/show/5833/" target="_blank">http://paste.yt-project.org/show/5833/</a></div><div><br></div><div>However, I get an error about being unable to add quantities with differing units:</div><div><br></div><div><a href="http://paste.yt-project.org/show/5834/" target="_blank">http://paste.yt-project.org/show/5834/</a></div><div><br></div><div>The docs say not to do any unit conversion because that is apparently taken care of behind the scenes, so I didn't.  I was just wondering if there was a way around this? Thanks! </div><span><font color="#888888"><div>-Jared<br><div><br></div></div></font></span></div>
<br>_______________________________________________<br>
yt-users mailing list<br>
<a>yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div>Cameron Hummels<div><span style="font-size:12.8000001907349px">NSF Postdoctoral Fellow</span></div><div><span style="font-size:12.8000001907349px">Department of Astronomy</span></div><div><span style="font-size:12.8000001907349px">California Institute of Technology</span><br></div><div><a href="http://chummels.org" style="font-size:12.8000001907349px" target="_blank">http://chummels.org</a><br></div></div></div></div>
</div>
</blockquote>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a>yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a>yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div></div></div><br></div></div>
<br>_______________________________________________<br>
yt-users mailing list<br>
<a>yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a>yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a>yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</blockquote></div></div></div></div></div>
<br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div>Cameron Hummels<div><span style="font-size:12.8000001907349px">NSF Postdoctoral Fellow</span></div><div><span style="font-size:12.8000001907349px">Department of Astronomy</span></div><div><span style="font-size:12.8000001907349px">California Institute of Technology</span><br></div><div><a href="http://chummels.org" style="font-size:12.8000001907349px" target="_blank">http://chummels.org</a><br></div></div></div></div>
</div>
</div></div><br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>