[yt-users] particle angular momentum profile error and accumulation profile

Nathan Goldbaum nathan12343 at gmail.com
Wed Jan 27 11:49:35 PST 2016


I've fixed it for you. Thanks for filing the issue!

On Wed, Jan 27, 2016 at 1:39 PM, Junhwan Choi (최준환)
<choi.junhwan at gmail.com> wrote:
> Hi Nathan,
>
> I just created issue.
> Accidentally, I made two same issues (w/ and w/o attached file), 1163 and 1164.
> Is there anyway that I can tell the issue is the resolved and I can
> update my version?
>
> Thank you,
> Junhwan
>
>
>
> On Wed, Jan 27, 2016 at 1:23 PM, Nathan Goldbaum <nathan12343 at gmail.com> wrote:
>> This seems like a bug. Any chance you can file an issue about it:
>>
>> https://bitbucket.org/yt_analysis/yt/issues/new
>>
>> Please attach your test script as that will help us to reproduce the issue.
>>
>> On Wed, Jan 27, 2016 at 1:21 PM, Junhwan Choi (최준환)
>> <choi.junhwan at gmail.com> wrote:
>>> Hi Nathan,
>>>
>>> Now I change as you suggested
>>> ===============================
>>> import matplotlib as matplotlib
>>> matplotlib.use('Agg')
>>> import yt
>>> import yt.units as units
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>>
>>> def _partradiuspc(field, data):
>>>     return data[('all','particle_radius')].in_units('pc')
>>> yt.add_field('partradiuspc', function=_partradiuspc,
>>> particle_type=True, units="pc")
>>>
>>> index = 45
>>> Nbin= 100
>>> rmax = 3000
>>> ds = yt.load("../DD%04d/DD%04d" % (index,index))
>>> ds.index
>>> ad= ds.all_data()
>>>
>>> center = ds.find_max(("gas", "density"))[1]
>>> rmin = max([1.0e-3,2.0*ds.index.get_smallest_dx().in_units('pc')])
>>>
>>> sphere = ds.sphere(center, rmax*units.pc)
>>> bulk_velocity = sphere.quantities['BulkVelocity']()
>>> sphere.set_field_parameter('bulk_velocity', bulk_velocity)
>>>
>>> profile = yt.Profile1D(sphere, 'partradiuspc', Nbin, x_min=rmin,
>>> x_max=rmax, x_log=True, weight_field=None)
>>> profile.add_fields(('all', 'particle_angular_momentum_x'))
>>> profile.add_fields(('all', 'particle_angular_momentum_y'))
>>> profile.add_fields(('all', 'particle_angular_momentum_z'))
>>>
>>> PartAngularMomentum = np.sqrt(profile[('all', 'particle_angular_momentum_x')]**2
>>>                               + profile[('all',
>>> 'particle_angular_momentum_y')]**2
>>>                               + profile[('all',
>>> 'particle_angular_momentum_z')]**2)
>>>
>>> plt.plot(profile.x, PartAngularMomentum, label='Total',linestyle="-",color='r')
>>>
>>> plt.xlabel('r [pc]')
>>> plt.ylabel('pang')
>>> ===================================
>>> And, I got the following error message
>>> ………………
>>> Traceback (most recent call last):
>>>   File "pang.py", line 26, in <module>
>>>     profile = yt.Profile1D(sphere, 'partradiuspc', Nbin, x_min=rmin,
>>> x_max=rmax, x_log=True, weight_field=None)
>>>   File "/home/jhchoi/common/src/yt/yt/data_objects/profiles.py", line
>>> 411, in __init__
>>>     self.x_field = data_source._determine_fields(x_field)[0]
>>>   File "/home/jhchoi/common/src/yt/yt/data_objects/data_containers.py",
>>> line 1001, in _determine_fields
>>>     raise YTFieldNotFound((ftype,fname),self.ds)
>>> yt.utilities.exceptions.YTFieldNotFound: Could not find field '('all',
>>> 'partradiuspc')' in DD0045.
>>>
>>> If I remove "particle_type=True" in add_field, it works.
>>> However, I am not sure that removing "particle_type=True" is ther
>>> right way or not, because the yt document suggest to include it.
>>>
>>> Thank you,
>>> Junhwan
>>>
>>>
>>> On Tue, Jan 26, 2016 at 2:15 PM, Nathan Goldbaum <nathan12343 at gmail.com> wrote:
>>>> Your 'radiuspc' field is a mesh field, but you're trying to compare it
>>>> with particle fields. Mesh fields and particle fields don't have the
>>>> same shape, which is why you're getting an error.
>>>>
>>>> You may want to use the particle_radius field instead. If you want to
>>>> create a derived field with different default units, you'll need to
>>>> specify particle_type=True in your add_field call.
>>>>
>>>> -Nathan
>>>>
>>>> On Tue, Jan 26, 2016 at 2:12 PM, Junhwan Choi (최준환)
>>>> <choi.junhwan at gmail.com> wrote:
>>>>> Hi yt users,
>>>>>
>>>>> I try to make a particle angular momentum profile using the following script:
>>>>> ================================
>>>>> import matplotlib as matplotlib
>>>>> matplotlib.use('Agg')
>>>>> import yt
>>>>> import yt.units as units
>>>>> import numpy as np
>>>>> import matplotlib.pyplot as plt
>>>>>
>>>>> def _radiuspc(field, data):
>>>>>     return data[('radius')].in_units('pc')
>>>>> yt.add_field('radiuspc', function=_radiuspc, units="pc")
>>>>>
>>>>> index = 45
>>>>> Nbin= 100
>>>>> rmax = 3000
>>>>> ds = yt.load("../DD%04d/DD%04d" % (index,index))
>>>>> ds.index
>>>>> ad= ds.all_data()
>>>>> center = ds.find_max(("gas", "density"))[1]
>>>>> rmin = max([1.0e-3,2.0*ds.index.get_smallest_dx().in_units('pc')])
>>>>>
>>>>> sphere = ds.sphere(center, rmax*units.pc)
>>>>> bulk_velocity = sphere.quantities['BulkVelocity']()
>>>>> sphere.set_field_parameter('bulk_velocity', bulk_velocity)
>>>>>
>>>>> profile = yt.Profile1D(sphere, 'radiuspc', Nbin, x_min=rmin,
>>>>> x_max=rmax, x_log=True, weight_field=None)
>>>>> profile.add_fields(('all', 'particle_angular_momentum_x'))
>>>>> profile.add_fields(('all', 'particle_angular_momentum_y'))
>>>>> profile.add_fields(('all', 'particle_angular_momentum_z'))
>>>>>
>>>>> PartAngularMomentum = np.sqrt(profile[('all', 'particle_angular_momentum_x')]**2
>>>>>                               + profile[('all',
>>>>> 'particle_angular_momentum_y')]**2
>>>>>                               + profile[('all',
>>>>> 'particle_angular_momentum_z')]**2)
>>>>>
>>>>> plt.plot(profile.x, PartAngularMomentum, label='Total',linestyle="-",color='r')
>>>>>
>>>>> plt.xlabel('r [pc]')
>>>>> plt.ylabel('pang')
>>>>> ======================================
>>>>> And I got the following error:
>>>>> ………..
>>>>> Traceback (most recent call last):
>>>>>   File "pang.py", line 26, in <module>
>>>>>     profile.add_fields(('all', 'particle_angular_momentum_x'))
>>>>>   File "/home/jhchoi/common/src/yt/yt/data_objects/profiles.py", line
>>>>> 112, in add_fields
>>>>>     self._bin_chunk(chunk, fields, temp_storage)
>>>>>   File "/home/jhchoi/common/src/yt/yt/data_objects/profiles.py", line
>>>>> 425, in _bin_chunk
>>>>>     rv = self._get_data(chunk, fields)
>>>>>   File "/home/jhchoi/common/src/yt/yt/data_objects/profiles.py", line
>>>>> 240, in _get_data
>>>>>     arr[:,i] = chunk[field][filter].in_units(units)
>>>>>   File "/home/jhchoi/common/src/yt/yt/units/yt_array.py", line 1123,
>>>>> in __getitem__
>>>>>     ret = super(YTArray, self).__getitem__(item)
>>>>> IndexError: index 1322 is out of bounds for axis 1 with size 1322
>>>>>
>>>>> I do not understand what the problem is?
>>>>>
>>>>> One more question:
>>>>> Is there any way to make accumulation density profile with yt.Profile1D(……)?
>>>>>
>>>>> Thank you in advance,
>>>>> Junhwan
>>>>> _______________________________________________
>>>>> yt-users mailing list
>>>>> yt-users at lists.spacepope.org
>>>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>>> _______________________________________________
>>>> yt-users mailing list
>>>> yt-users at lists.spacepope.org
>>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>> _______________________________________________
>>> yt-users mailing list
>>> yt-users at lists.spacepope.org
>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org



More information about the yt-users mailing list