<div dir="ltr"><div>One more thing. Adding</div><div><br></div><div>    try:</div><div>        data.NumberOfParticles</div><div>    except AttributeError:</div><div>        return blank</div><div> </div><div>before "if data.NumberOfParticles == 0: return blank" allows the projection to complete without errors even with ValidateSpatial(0). This might work as a stopgap.</div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 22, 2013 at 9:57 AM, Michael Kuhlen <span dir="ltr"><<a href="mailto:mqk@astro.berkeley.edu" target="_blank">mqk@astro.berkeley.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">Hi Matt<div><br></div><div>First, I got the idea for ValidateGridType from the definition of the field "particle_density" in yt/data_objects/universal_fields.py, which uses data.NumerOfParticles and does not result in an error with AMRSmoothedCoveringGrid. So I guess that field also returns interpolated particle density?</div>



<div><br></div><div>Secondly, simply commenting out the test for NumberOfParticles == 0 doesn't work, "DataCubeError: CombineGrids: Three dimensions required for g_data[0]." Let me know if you want the full traceback.</div>


<div><br></div><div>Btw, here's an example script with which you should be able to reproduce the error: <a href="http://paste.yt-project.org/show/3069/" target="_blank">http://paste.yt-project.org/show/3069/</a></div>

<div class="gmail_extra">
<br></div><div class="gmail_extra">Mike</div><div><div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 22, 2013 at 2:10 AM, Matthew Turk <span dir="ltr"><<a href="mailto:matthewturk@gmail.com" target="_blank">matthewturk@gmail.com</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Mike,<br>
<br>
I think that the checks for .NumberOfParticles may be unnecessary in<br>
the dm_density calls.  Removing those, and simply returning an empty<br>
deposition field if there are no particles, will likely give the same<br>
results as what it currently does.  Switching between ValidateGridType<br>
and ValidateSpatial will turn on/off fields in ways I think we may<br>
want to avoid.  For particle density fields specifically it would<br>
likely result in estimates for particle density that are generated at<br>
a coarser level then interpolated to a finer level.<br>
<br>
-Matt<br>
<div><div><br>
On Tue, Jan 22, 2013 at 1:38 AM, Michael Kuhlen <<a href="mailto:mqk@astro.berkeley.edu" target="_blank">mqk@astro.berkeley.edu</a>> wrote:<br>
> Sorry to revive this old(ish) thread, but I've been experiencing similar<br>
> troubles to Renyue's. Mine, however, were not completely fixed by switching<br>
> from yt.utilities.amr_utils to yt.utilities.lib. I was still getting this<br>
> error:<br>
><br>
> AttributeError: 'AMRSmoothedCoveringGrid' object has no attribute<br>
> 'NumberOfParticles'<br>
><br>
> The solution for me was to switch from validators=[ValidateSpatial(0)] to<br>
> validators=[ValidateGridType()] in the add_field() call. Since many of the<br>
> fields defined in yt/frontends/*/fields.py still use ValidateSpatial(0), I'm<br>
> getting the same NumberOfParticles AttributeError when I try to do volume<br>
> renderings of "built-in" fields like dm_density.<br>
><br>
> Cheers,<br>
> Mike<br>
><br>
><br>
><br>
><br>
><br>
><br>
> On Sun, Jan 13, 2013 at 1:11 PM, Renyue Cen <<a href="mailto:cen@astro.princeton.edu" target="_blank">cen@astro.princeton.edu</a>> wrote:<br>
>><br>
>> HI Matt,<br>
>><br>
>> That worked (after I remove the following things that I added following<br>
>> 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<br>
>> CICDeposit_3 import a line before.<br>
>><br>
>> Thanks very much,<br>
>> Renyue<br>
>><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<br>
>> > 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" target="_blank">cen@astro.princeton.edu</a>><br>
>> > 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<br>
>> >> 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" target="_blank">cen@astro.princeton.edu</a>><br>
>> >>> wrote:<br>
>> >>>> Hi Matt,<br>
>> >>>><br>
>> >>>> It seems that my attempt to reuse "star_density" for a subset of<br>
>> >>>> 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<br>
>> >>>> "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 -<br>
>> >>>> data['creation_time']) < 1.e8<br>
>> >>>>   filter  = data.pf.time_units['years']*(data.pf.current_time -<br>
>> >>>> data['creation_time']) < 1.e6<br>
>> >>>>   if not filter.any(): return blank<br>
>> >>>><br>
>> >>>> amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64),<br>
>> >>>><br>
>> >>>> data["particle_position_y"][filter].astype(na.float64),<br>
>> >>>><br>
>> >>>> data["particle_position_z"][filter].astype(na.float64),<br>
>> >>>><br>
>> >>>> data["particle_mass"][filter].astype(na.float32),<br>
>> >>>>                          na.int64(na.where(filter)[0].size),<br>
>> >>>>                          blank,<br>
>> >>>> na.array(data.LeftEdge).astype(na.float64),<br>
>> >>>><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)],<br>
>> >>>> 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,<br>
>> >>>> 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<br>
>> >>>> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py",<br>
>> >>>> line 316, in __init__<br>
>> >>>>   for field in self.fields]<br>
>> >>>> File<br>
>> >>>> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",<br>
>> >>>> line 71, in __missing__<br>
>> >>>>   return self.fallback[key]<br>
>> >>>> File<br>
>> >>>> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",<br>
>> >>>> line 71, in __missing__<br>
>> >>>>   return self.fallback[key]<br>
>> >>>> File<br>
>> >>>> "/u/jhwise/local/lib/python2.7/site-packages/yt-2.4-py2.7-linux-x86_64.egg/yt/data_objects/field_info_container.py",<br>
>> >>>> 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<br>
>> >>>> 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<br>
>> >>>>> 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<br>
>> >>>>> <<a href="mailto:cen@astro.princeton.edu" target="_blank">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<br>
>> >>>>>> 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" target="_blank">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>
><br>
><br>
><br>
><br>
> --<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: <a href="tel:%28831%29%20588-1468" value="+18315881468" target="_blank">(831) 588-1468</a>      B-116 Hearst Field Annex # 3411  *<br>
> *  skype username: mikekuhlen      Berkeley, CA 94720               *<br>
> *                                                                   *<br>
> *********************************************************************<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" 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: <a href="tel:%28831%29%20588-1468" value="+18315881468" target="_blank">(831) 588-1468</a>      B-116 Hearst Field Annex # 3411  *<br>


*  skype username: mikekuhlen      Berkeley, CA 94720               *<br>
*                                                                   *<br>*********************************************************************<br>
</div></div></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: <a href="tel:%28831%29%20588-1468" value="+18315881468" target="_blank">(831) 588-1468</a>      B-116 Hearst Field Annex # 3411  *<br>
*  skype username: mikekuhlen      Berkeley, CA 94720               *<br>
*                                                                   *<br>*********************************************************************<br>
</div></div>