[yt-users] yt.utilities.amr_utils

Renyue Cen cen at astro.princeton.edu
Sun Jan 13 13:11:46 PST 2013


HI Matt,

That worked (after I remove the following things that I added following the line " from yt.utilities.lib import CICDeposit_3":
#from yt.utilities.cosmology import Cosmology
#from field_info_container import \
#    add_field, \
#    ValidateDataField, \
#    ValidateGridType, \
#    ValidateParameter, \
#    ValidateSpatial, \
#    NeedsGridType, \
#    NeedsOriginalGrid, \
#    NeedsDataField, \
#    NeedsProperty, \
#    NeedsParameter

which was copied elsewhere earlier and apparent messed up with the CICDeposit_3 import a line before.

Thanks very much,
Renyue


On Jan 13, 2013, at 3:35 PM, Matthew Turk wrote:

> Hi Renyue,
> 
> No, that should work.  What I'm actually seeing now is that you do in
> fact use amr_utils -- I missed this before -- to get the CICDeposit_3.
> The exception from the NameError is probably killing its
> availability.
> 
> So here's what to do:
> 
> 1) Replace your previous import, which I suggested you remove, of
> yt.utilities.amr_utils with:
> 
> from yt.utilities.lib import CICDeposit_3
> 
> 2) Change your call to CICDeposit_3 from amr_utils.CICDeposit_3 to CICDeposit_3
> 
> And try again?
> 
> -Matt
> 
> On Sun, Jan 13, 2013 at 3:31 PM, Renyue Cen <cen at astro.princeton.edu> wrote:
>> Hi Matt,
>> 
>> This field (SFRdensity) was defined before the
>> pf = ...
>> statement, along with some other simpler definitions of gas variables that did not require CIC
>> and seem to work.
>> 
>> Was I using the wrong syntax or something?
>> 
>> Renyue
>> 
>> On Jan 13, 2013, at 3:25 PM, Matthew Turk wrote:
>> 
>>> Hi Renyue,
>>> 
>>> One important thing to note is that the field has to be added before
>>> you instantiate the parameter file; i.e., you must do:
>>> 
>>> add_field( ... )
>>> pf = ...
>>> 
>>> because the parameter file, upon creation of the hierarchy, performs
>>> an auto-detection step.  This auto-detection step determines which
>>> fields are available based on their dependencies.
>>> 
>>> -Matt
>>> 
>>> On Sun, Jan 13, 2013 at 3:22 PM, Renyue Cen <cen at astro.princeton.edu> wrote:
>>>> Hi Matt,
>>>> 
>>>> It seems that my attempt to reuse "star_density" for a subset of stars does not work:
>>>> "star_density" remains the density of all stars when plotted.
>>>> But I also failed to redefine a new density that is called "SFRdensity" and feed it to AMRKDTree which is in turn
>>>> fed to camera to volume render. Here is what I did:
>>>> 
>>>> def _convertDensity(data):
>>>>   return data.convert("Density")
>>>> def _SFRdensity(field, data):
>>>>   blank = na.zeros(data.ActiveDimensions, dtype='float32')
>>>>   if data.NumberOfParticles == 0: return blank
>>>> #   filter  = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e8
>>>>   filter  = data.pf.time_units['years']*(data.pf.current_time - data['creation_time']) < 1.e6
>>>>   if not filter.any(): return blank
>>>>   amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64),
>>>>                          data["particle_position_y"][filter].astype(na.float64),
>>>>                          data["particle_position_z"][filter].astype(na.float64),
>>>>                          data["particle_mass"][filter].astype(na.float32),
>>>>                          na.int64(na.where(filter)[0].size),
>>>>                          blank, na.array(data.LeftEdge).astype(na.float64),
>>>>                          na.array(data.ActiveDimensions).astype(na.int32),
>>>>                          na.float64(data['dx']))
>>>>   return blank
>>>> add_field("SFRdensity", function=_SFRdensity,
>>>>         validators=[ValidateSpatial(0)], convert_function=_convertDensity)
>>>> 
>>>>   volume3 = AMRKDTree(pf, fields=["SFRdensity"]
>>>>              ,no_ghost=False, tree_type="domain"
>>>>              ,le=c-0.5*WW, re=c+0.5*WW)
>>>>   cam = pf.h.camera(c, L, W, (Nvec,Nvec), tf3, volume=volume3, no_ghost=False,log_fields=None
>>>>                 ,north_vector=dir)
>>>> 
>>>> 
>>>> with the following error message:
>>>> 
>>>> Traceback (most recent call last):
>>>> File "SFR.py", line 393, in <module>
>>>>   ,le=c-0.5*WW, re=c+0.5*WW)
>>>> 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__
>>>>   for field in self.fields]
>>>> 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__
>>>>   return self.fallback[key]
>>>> 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__
>>>>   return self.fallback[key]
>>>> 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__
>>>>   raise KeyError("No field named %s" % key)
>>>> KeyError: 'No field named SFRdensity'
>>>> 
>>>> 
>>>> So I must be doing something wrong with defining the SFRdensity field.
>>>> 
>>>> Thanks very much,
>>>> Renyue
>>>> 
>>>> 
>>>> On Jan 13, 2013, at 1:20 PM, Matthew Turk wrote:
>>>> 
>>>>> Hi Renyue,
>>>>> 
>>>>> The module amr_utils became lib a while back.  But my guess is that
>>>>> you probably don't need to import it anyway, unless you are explicitly
>>>>> using one of the routines it provides.
>>>>> 
>>>>> -Matt
>>>>> 
>>>>> On Sun, Jan 13, 2013 at 12:18 PM, Renyue Cen <cen at astro.princeton.edu> wrote:
>>>>>> Hi,
>>>>>> 
>>>>>> I am trying to compute gridded density of some subset of particles.
>>>>>> So I tried to import some modules first in the python script as follows:
>>>>>> 
>>>>>> from yt.data_objects.field_info_container import \
>>>>>>  FieldInfoContainer, \
>>>>>>  NullFunc, \
>>>>>>  TranslationFunc, \
>>>>>>  FieldInfo, \
>>>>>>  ValidateParameter, \
>>>>>>  ValidateDataField, \
>>>>>>  ValidateProperty, \
>>>>>>  ValidateSpatial, \
>>>>>>  ValidateGridType
>>>>>> import yt.data_objects.universal_fields
>>>>>> from yt.utilities.physical_constants import mh
>>>>>> from yt.funcs import *
>>>>>> import yt.utilities.amr_utils as amr_utils
>>>>>> 
>>>>>> 
>>>>>> But I got this error message:
>>>>>> 
>>>>>> Traceback (most recent call last):
>>>>>> File "SFR.py", line 28, in <module>
>>>>>>  import yt.utilities.amr_utils as amr_utils
>>>>>> ImportError: No module named amr_utils
>>>>>> 
>>>>>> 
>>>>>> Am I doing something wrong?
>>>>>> 
>>>>>> Thanks,
>>>>>> Renyue
>>>> 
>> 




More information about the yt-users mailing list