<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Michael,<div><br></div><div>This happens to me occasionally and I was told that it might be due to</div><div>some subregions in your region that got no particles or something like that.</div><div>It seems due to AMRKDTree construction, as I understand it.</div><div><br></div><div>Renyue</div><div><br><div><div>On Jan 22, 2013, at 1:38 AM, Michael Kuhlen wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Sorry to revive this old(ish) thread, but I've been experiencing similar troubles to Renyue's. Mine, however, were not completely fixed by switching from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this error:<div>
<div><br></div><div><div>AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute 'NumberOfParticles'</div></div><div><br></div><div style="">The solution for me was to switch from validators=[ValidateSpatial(0)] to validators=[ValidateGridType()] in the add_field() call. Since many of the fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm getting the same NumberOfParticles AttributeError when I try to do volume renderings of "built-in" fields like dm_density.</div>
<div style=""><br></div><div style="">Cheers,</div><div style="">Mike</div><div style=""><br></div><div style=""><br></div><div style=""><br></div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <span dir="ltr"><<a href="mailto:cen@astro.princeton.edu" target="_blank">cen@astro.princeton.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">HI Matt,<br>
<br>
That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3":<br>
#from yt.utilities.cosmology import Cosmology<br>
#from field_info_container import \<br>
# add_field, \<br>
# ValidateDataField, \<br>
# ValidateGridType, \<br>
# ValidateParameter, \<br>
# ValidateSpatial, \<br>
# NeedsGridType, \<br>
# NeedsOriginalGrid, \<br>
# NeedsDataField, \<br>
# NeedsProperty, \<br>
# NeedsParameter<br>
<br>
which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.<br>
<br>
Thanks very much,<br>
Renyue<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:<br>
<br>
> Hi Renyue,<br>
><br>
> No, that should work. What I'm actually seeing now is that you do in<br>
> fact use amr_utils -- I missed this before -- to get the CICDeposit_3.<br>
> The exception from the NameError is probably killing its<br>
> availability.<br>
><br>
> So here's what to do:<br>
><br>
> 1) Replace your previous import, which I suggested you remove, of<br>
> yt.utilities.amr_utils with:<br>
><br>
> from yt.utilities.lib import CICDeposit_3<br>
><br>
> 2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3<br>
><br>
> And try again?<br>
><br>
> -Matt<br>
><br>
> On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <<a href="mailto:cen@astro.princeton.edu">cen@astro.princeton.edu</a>> wrote:<br>
>> Hi Matt,<br>
>><br>
>> This field (SFRdensity) was defined before the<br>
>> pf = ...<br>
>> statement, along with some other simpler definitions of gas variables that did not require CIC<br>
>> and seem to work.<br>
>><br>
>> Was I using the wrong syntax or something?<br>
>><br>
>> Renyue<br>
>><br>
>> On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:<br>
>><br>
>>> Hi Renyue,<br>
>>><br>
>>> One important thing to note is that the field has to be added before<br>
>>> you instantiate the parameter file; i.e., you must do:<br>
>>><br>
>>> add_field( ... )<br>
>>> pf = ...<br>
>>><br>
>>> because the parameter file, upon creation of the hierarchy, performs<br>
>>> an auto-detection step. This auto-detection step determines which<br>
>>> fields are available based on their dependencies.<br>
>>><br>
>>> -Matt<br>
>>><br>
>>> On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <<a href="mailto:cen@astro.princeton.edu">cen@astro.princeton.edu</a>> wrote:<br>
>>>> Hi Matt,<br>
>>>><br>
>>>> It seems that my attempt to reuse "star_density" for a subset of stars does not work:<br>
>>>> "star_density" remains the density of all stars when plotted.<br>
>>>> But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn<br>
>>>> fed to camera to volume render. Here is what I did:<br>
>>>><br>
>>>> def _convertDensity(data):<br>
>>>> return data.convert("Density")<br>
>>>> def _SFRdensity(field, data):<br>
>>>> blank = na.zeros(data.ActiveDimensions, dtype='float32')<br>
>>>> if data.NumberOfParticles == 0: return blank<br>
>>>> # filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8<br>
>>>> filter = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6<br>
>>>> if not filter.any(): return blank<br>
>>>> amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64),<br>
>>>> data["particle_position_y"][filter].astype(na.float64),<br>
>>>> data["particle_position_z"][filter].astype(na.float64),<br>
>>>> data["particle_mass"][filter].astype(na.float32),<br>
>>>> na.int64(na.where(filter)[0].size),<br>
>>>> blank, na.array(data.LeftEdge).astype(na.float64),<br>
>>>> na.array(data.ActiveDimensions).astype(na.int32),<br>
>>>> na.float64(data['dx']))<br>
>>>> return blank<br>
>>>> add_field("SFRdensity", function=_SFRdensity,<br>
>>>> validators=[ValidateSpatial(0)], convert_function=_convertDensity)<br>
>>>><br>
>>>> volume3 = AMRKDTree(pf, fields=["SFRdensity"]<br>
>>>> ,no_ghost=False, tree_type="domain"<br>
>>>> ,le=c-0.5*WW, re=c+0.5*WW)<br>
>>>> cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None<br>
>>>> ,north_vector=dir)<br>
>>>><br>
>>>><br>
>>>> with the following error message:<br>
>>>><br>
>>>> Traceback (most recent call last):<br>
>>>> File "SFR.py", line 393, in <module><br>
>>>> ,le=c-0.5*WW, re=c+0.5*WW)<br>
>>>> File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py", line 316, in __init__<br>
>>>> for field in self.fields]<br>
>>>> File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__<br>
>>>> return self.fallback[key]<br>
>>>> File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 71, in __missing__<br>
>>>> return self.fallback[key]<br>
>>>> File "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py", line 70, in __missing__<br>
>>>> raise KeyError("No field named %s" % key)<br>
>>>> KeyError: 'No field named SFRdensity'<br>
>>>><br>
>>>><br>
>>>> So I must be doing something wrong with defining the SFRdensity field.<br>
>>>><br>
>>>> Thanks very much,<br>
>>>> Renyue<br>
>>>><br>
>>>><br>
>>>> On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:<br>
>>>><br>
>>>>> Hi Renyue,<br>
>>>>><br>
>>>>> The module amr_utils became lib a while back. But my guess is that<br>
>>>>> you probably don't need to import it anyway, unless you are explicitly<br>
>>>>> using one of the routines it provides.<br>
>>>>><br>
>>>>> -Matt<br>
>>>>><br>
>>>>> On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <<a href="mailto:cen@astro.princeton.edu">cen@astro.princeton.edu</a>> wrote:<br>
>>>>>> Hi,<br>
>>>>>><br>
>>>>>> I am trying to compute gridded density of some subset of particles.<br>
>>>>>> So I tried to import some modules first in the python script as follows:<br>
>>>>>><br>
>>>>>> from yt.data_objects.field_info_container import \<br>
>>>>>> FieldInfoContainer, \<br>
>>>>>> NullFunc, \<br>
>>>>>> TranslationFunc, \<br>
>>>>>> FieldInfo, \<br>
>>>>>> ValidateParameter, \<br>
>>>>>> ValidateDataField, \<br>
>>>>>> ValidateProperty, \<br>
>>>>>> ValidateSpatial, \<br>
>>>>>> ValidateGridType<br>
>>>>>> import yt.data_objects.universal_fields<br>
>>>>>> from yt.utilities.physical_constants import mh<br>
>>>>>> from yt.funcs import *<br>
>>>>>> import yt.utilities.amr_utils as amr_utils<br>
>>>>>><br>
>>>>>><br>
>>>>>> But I got this error message:<br>
>>>>>><br>
>>>>>> Traceback (most recent call last):<br>
>>>>>> File "SFR.py", line 28, in <module><br>
>>>>>> import yt.utilities.amr_utils as amr_utils<br>
>>>>>> ImportError: No module named amr_utils<br>
>>>>>><br>
>>>>>><br>
>>>>>> Am I doing something wrong?<br>
>>>>>><br>
>>>>>> Thanks,<br>
>>>>>> Renyue<br>
>>>><br>
>><br>
<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" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>*********************************************************************<br>* *<br>* Dr. Michael Kuhlen Theoretical Astrophysics Center *<br>
* email: <a href="mailto:mqk@astro.berkeley.edu" target="_blank">mqk@astro.berkeley.edu</a> UC Berkeley *<br>* cell phone: (831) 588-1468 B-116 Hearst Field Annex # 3411 *<br>* skype username: mikekuhlen Berkeley, CA 94720 *<br>
* *<br>*********************************************************************<br>
</div>
</blockquote></div><br></div></body></html>