<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 14, 2015 at 8:08 PM, Junhwan Choi (최준환) <span dir="ltr"><<a href="mailto:choi.junhwan@gmail.com" target="_blank">choi.junhwan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Nathan,<br>
<br>
Now, I change the previous script as follow:<br>
<span class="">======================<br>
import matplotlib as matplotlib<br>
matplotlib.use('Agg')<br>
import yt<br>
import yt.units as units<br>
import numpy as np<br>
import matplotlib.pyplot as plt<br>
<br>
<br>
def _radiuspc(field, data):<br>
    return data[('radius')].in_units('pc')<br>
yt.add_field('radiuspc', function=_radiuspc, units="pc")<br>
<br>
rmax = 1000<br>
Nbin = 50<br>
ds = yt.load("../DD0099/DD0099")<br>
ds.index<br>
ad= ds.all_data()<br>
<br>
center = ds.find_max("density")[1]<br>
my_sphere = ds.sphere("center", (rmax, "pc"))<br>
<br>
rmin = max([0.1,2.0*ds.index.get_smallest_dx().in_units('pc')])<br>
</span>profile = yt.Profile1D(my_sphere, 'radiuspc', Nbin, x_min=rmin,<br>
x_max=rmax, x_log=True, weight_field='cell_volume')<br>
profile.add_fields(('gas','density'))<br>
<br>
plt.plot(np.log10(profile['radiuspc']), np.log10(profile['density']))<br>
plt.savefig('ProfGasDensity')<br>
=======================<br>
It changes BinnedProfile1D to Profile1D.<br>
And, now I get new error message.<br>
……<br>
<span class="">Traceback (most recent call last):<br>
</span>  File "test_prof.py", line 30, in <module><br>
    plt.plot(np.log10(profile['radiuspc']), np.log10(profile['density']))<br></blockquote><div><br></div><div><br></div><div>Profile1D objects have a somewhat different API compared to the old BinnedProfile1D objects.</div><div><br></div><div>In the line above, you should be doing something like plt.plot(np.log10(profile.x), np.log10(profile['density']))</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  File "/home/jhchoi/common-anaconda/src/yt/yt/data_objects/profiles.py",<br>
line 930, in __getitem__<br>
    raise KeyError(field)<br>
KeyError: 'radiuspc' </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Do I need set radiuspc in add_fields, too?<br>
Or, may the different field_type between radiuspc and density cause a conflict?<br>
I tried couple different tests, but I cannot resolve it yet.<br>
<br>
Thank you for your help, again.<br>
<span class="HOEnZb"><font color="#888888">Junhwan<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
On Mon, Dec 14, 2015 at 5:08 PM, Nathan Goldbaum <<a href="mailto:nathan12343@gmail.com">nathan12343@gmail.com</a>> wrote:<br>
> Hi Junhwan,<br>
><br>
> Which yt version is this? If it's yt-3 or newer, you should probably be<br>
> using Profile1D instead of BinnedProfile1D. The latter was deprecated and<br>
> will be removed in yt 3.3.<br>
><br>
> On Mon, Dec 14, 2015 at 5:00 PM, Junhwan Choi (최준환) <<a href="mailto:choi.junhwan@gmail.com">choi.junhwan@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Dear yt users and developers,<br>
>><br>
>> I get an error while I try to make a  radial-averaged  profile using yt.<br>
>> In order to compute the profile I wrote the following script:<br>
>> ===================================<br>
>> import matplotlib as matplotlib<br>
>> matplotlib.use('Agg')<br>
>> import yt<br>
>> import yt.units as units<br>
>> import numpy as np<br>
>> import matplotlib.pyplot as plt<br>
>><br>
>> def _radiuspc(field, data):<br>
>>     return data[('radius')].in_units('pc')<br>
>> yt.add_field('radiuspc', function=_radiuspc, units="pc")<br>
>><br>
>> rmax = 1000<br>
>> Nbin = 50<br>
>> ds = yt.load("../DD0099/DD0099")<br>
>> ds.index<br>
>> ad= ds.all_data()<br>
>><br>
>> center = ds.find_max("density")[1]<br>
>> my_sphere = ds.sphere("center", (rmax, "pc"))<br>
>><br>
>> rmin = max([0.1,2.0*ds.index.get_smallest_dx().in_units('pc')])<br>
>> profile = yt.BinnedProfile1D(my_sphere, Nbin, 'radius', rmin,<br>
>> rmax*units.pc, log_space=True, end_collect=False)<br>
>> profile.add_fields(('gas','density'), weight='cell_volume')<br>
>><br>
>> plt.plot(na.log10(profile['radius']), na.log10(profile['density']))<br>
>> plt.savefig('ProfGasDensity')<br>
>> ===================================<br>
>><br>
>> And, I get an following error to compute the density profile<br>
>> …….<br>
>> yt : [INFO     ] 2015-12-14 17:54:21,484 Max Value is 5.46111e-09 at<br>
>> 0.5093630427891190 0.4991425970893048 0.5065899804849306<br>
>> Traceback (most recent call last):<br>
>>   File "test_prof.py", line 26, in <module><br>
>>     profile.add_fields(('gas','density'), weight='cell_volume')<br>
>>   File "/home/jhchoi/common-anaconda/src/yt/yt/data_objects/profiles.py",<br>
>> line 117, in add_fields<br>
>>     self["%s_std" % field] = np.sqrt(std_data[field])<br>
>> TypeError: not all arguments converted during string formatting<br>
>><br>
>> Could anyone inform me how to resolve this error?<br>
>><br>
>> Thank you in advance,<br>
>> Junhwan<br>
>> _______________________________________________<br>
>> yt-users mailing list<br>
>> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> yt-users mailing list<br>
> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
><br>
_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
</div></div></blockquote></div><br></div></div>