[yt-users] Radial-averaged Profile error

Junhwan Choi (최준환) choi.junhwan at gmail.com
Mon Dec 14 18:43:32 PST 2015


Thank you, now it looks running.
Junhwan

On Mon, Dec 14, 2015 at 8:31 PM, Nathan Goldbaum <nathan12343 at gmail.com> wrote:
>
>
> On Mon, Dec 14, 2015 at 8:08 PM, Junhwan Choi (최준환) <choi.junhwan at gmail.com>
> wrote:
>>
>> Hi Nathan,
>>
>> Now, I change the previous script as follow:
>> ======================
>> 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")
>>
>> rmax = 1000
>> Nbin = 50
>> ds = yt.load("../DD0099/DD0099")
>> ds.index
>> ad= ds.all_data()
>>
>> center = ds.find_max("density")[1]
>> my_sphere = ds.sphere("center", (rmax, "pc"))
>>
>> rmin = max([0.1,2.0*ds.index.get_smallest_dx().in_units('pc')])
>> profile = yt.Profile1D(my_sphere, 'radiuspc', Nbin, x_min=rmin,
>> x_max=rmax, x_log=True, weight_field='cell_volume')
>> profile.add_fields(('gas','density'))
>>
>> plt.plot(np.log10(profile['radiuspc']), np.log10(profile['density']))
>> plt.savefig('ProfGasDensity')
>> =======================
>> It changes BinnedProfile1D to Profile1D.
>> And, now I get new error message.
>> ……
>> Traceback (most recent call last):
>>   File "test_prof.py", line 30, in <module>
>>     plt.plot(np.log10(profile['radiuspc']), np.log10(profile['density']))
>
>
>
> Profile1D objects have a somewhat different API compared to the old
> BinnedProfile1D objects.
>
> In the line above, you should be doing something like
> plt.plot(np.log10(profile.x), np.log10(profile['density']))
>
>
>>
>>   File "/home/jhchoi/common-anaconda/src/yt/yt/data_objects/profiles.py",
>> line 930, in __getitem__
>>     raise KeyError(field)
>> KeyError: 'radiuspc'
>>
>>
>> Do I need set radiuspc in add_fields, too?
>> Or, may the different field_type between radiuspc and density cause a
>> conflict?
>> I tried couple different tests, but I cannot resolve it yet.
>>
>> Thank you for your help, again.
>> Junhwan
>>
>>
>>
>>
>>
>> On Mon, Dec 14, 2015 at 5:08 PM, Nathan Goldbaum <nathan12343 at gmail.com>
>> wrote:
>> > Hi Junhwan,
>> >
>> > Which yt version is this? If it's yt-3 or newer, you should probably be
>> > using Profile1D instead of BinnedProfile1D. The latter was deprecated
>> > and
>> > will be removed in yt 3.3.
>> >
>> > On Mon, Dec 14, 2015 at 5:00 PM, Junhwan Choi (최준환)
>> > <choi.junhwan at gmail.com>
>> > wrote:
>> >>
>> >> Dear yt users and developers,
>> >>
>> >> I get an error while I try to make a  radial-averaged  profile using
>> >> yt.
>> >> In order to compute the profile I wrote 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")
>> >>
>> >> rmax = 1000
>> >> Nbin = 50
>> >> ds = yt.load("../DD0099/DD0099")
>> >> ds.index
>> >> ad= ds.all_data()
>> >>
>> >> center = ds.find_max("density")[1]
>> >> my_sphere = ds.sphere("center", (rmax, "pc"))
>> >>
>> >> rmin = max([0.1,2.0*ds.index.get_smallest_dx().in_units('pc')])
>> >> profile = yt.BinnedProfile1D(my_sphere, Nbin, 'radius', rmin,
>> >> rmax*units.pc, log_space=True, end_collect=False)
>> >> profile.add_fields(('gas','density'), weight='cell_volume')
>> >>
>> >> plt.plot(na.log10(profile['radius']), na.log10(profile['density']))
>> >> plt.savefig('ProfGasDensity')
>> >> ===================================
>> >>
>> >> And, I get an following error to compute the density profile
>> >> …….
>> >> yt : [INFO     ] 2015-12-14 17:54:21,484 Max Value is 5.46111e-09 at
>> >> 0.5093630427891190 0.4991425970893048 0.5065899804849306
>> >> Traceback (most recent call last):
>> >>   File "test_prof.py", line 26, in <module>
>> >>     profile.add_fields(('gas','density'), weight='cell_volume')
>> >>   File
>> >> "/home/jhchoi/common-anaconda/src/yt/yt/data_objects/profiles.py",
>> >> line 117, in add_fields
>> >>     self["%s_std" % field] = np.sqrt(std_data[field])
>> >> TypeError: not all arguments converted during string formatting
>> >>
>> >> Could anyone inform me how to resolve this error?
>> >>
>> >> 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
>



More information about the yt-users mailing list