[yt-dev] Issues with accessing ActiveDimensions attribute?

Rasmi Elasmar re2300 at columbia.edu
Sun May 22 13:51:23 PDT 2016


Hi Nathan,

Thanks for your help -- that approach works perfectly (and it's much more
simple and elegant than the yt-2 method).


Thanks,

Rasmi

On Fri, May 20, 2016 at 3:21 PM, Nathan Goldbaum <nathan12343 at gmail.com>
wrote:

>
>
> On Fri, May 20, 2016 at 1:36 PM, Rasmi Elasmar <re2300 at columbia.edu>
> wrote:
>
>> Hi all,
>>
>> I'm trying to create two derived fields (one for stellar density, and one
>> for dark matter density) based on
>> <https://bitbucket.org/yt_analysis/yt/src/cee2a160c5351c376afea65bea3462792406154e/yt/frontends/enzo/fields.py?at=yt-2.x&fileviewer=file-view-default#fields.py-350>
>> these
>> <https://bitbucket.org/yt_analysis/yt/src/cee2a160c5351c376afea65bea3462792406154e/yt/frontends/enzo/fields.py?at=yt-2.x&fileviewer=file-view-default#fields.py-394>
>> from yt2. I'm running yt 3.2.3, and the star_density and dm_density fields
>> seem to have been removed. So far, the yt2 code has transferred fine, with
>> minimal changes:
>>
>>    - amrutils.CICDeposit_3() -> amrutils.CICDeposit.CICDeposit_3()
>>    - np.float64(data['dx']) -> np.float64(np.ravel(data['dx'])[0]
>>       - (data['dx'] appears to be a multidimensional array of all the
>>       same values of dx, so I'm just taking the first one -- is there a better
>>       way to do this?)
>>
>> Besides those two quirks, the code runs (I'm able to add a field using
>> ds.add_field), but I get an error when I try to access the data using
>> ds.all_data()['star_density'] (it seems now is when the field is actually
>> computed).
>>
>> I get the following error:
>>
>>> <ipython-input-5-1af8fbcb718a> in _spdensity(field, data)
>>>       1 def _spdensity(field, data):
>>> ----> 2     blank = np.zeros(data.ActiveDimensions, dtype='float64')
>>>       3     if data['particle_position_x'].size == 0: return blank
>>>       4     filter = data['creation_time'] > 0.0
>>>       5     if not filter.any(): return blank
>>> AttributeError: 'YTRegion' object has no attribute 'ActiveDimensions'
>>
>>
>> All the examples of ActiveDimensions that I saw in the docs and source
>> accessed ActiveDimensions as a property of some grid (i.e.
>> g.ActiveDimensions). Is there a simple way to access that from the
>> data/YTRegion object that I'm missing? I can access ds.index.grids and take
>> the first grid there, but ActiveDimensions differs across the grids (And
>> when I try to do this from within _spdensity, data doesn't have an
>> index.grids object, just fake_index (which can't access the grids)). Is
>> there something I'm missing?
>>
>>
>> Thanks,
>>
>> Rasmi
>>
>
> Hi Rasmi,
>
> Rather than directly porting your scripts from yt-2, which will be a bit
> painful, it would be much easier to use built-in features of yt-3 to
> accomplish this. In particular, you want to use particle filters and
> deposited fields.
>
> Here is a worked example where I construct "star" and "dark matter"
> particle filters for an Enzo dataset, then plot the deposited density of
> these two particle types.
>
> https://gist.github.com/b13bd7a545dda6819972eaaaf81e83f8
>
> Here's some more documentation on particle filters and deposited particle
> fields:
>
>
> http://yt-project.org/docs/dev/analyzing/filtering.html#filtering-particle-fields
>
> http://yt-project.org/docs/dev/analyzing/fields.html#deposited-particle-fields
>
> Hope that's helpful,
>
> Nathan
>
>
>>
>> _______________________________________________
>> yt-dev mailing list
>> yt-dev at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org
>>
>>
>
> _______________________________________________
> yt-dev mailing list
> yt-dev at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-dev-spacepope.org/attachments/20160522/8575b6e2/attachment-0001.html>


More information about the yt-dev mailing list