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

Junhwan Choi (최준환) choi.junhwan at gmail.com
Tue Jan 26 12:12:53 PST 2016


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



More information about the yt-users mailing list